Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d8e23768f | |||
| bc2b622873 | |||
| d945029f33 | |||
| 621e359817 | |||
| 18ac756d44 | |||
| 4dabbcd23a | |||
| c3d6d017df | |||
| e15b205f9c | |||
| ee3c6941ee | |||
| eb6100b736 |
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
143
README.md
Normal file → Executable file
143
README.md
Normal file → Executable file
@@ -5,7 +5,7 @@ A self-contained Go SDK for interacting with Dragonchain nodes.
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go
|
go get git.dragonchain.com/dragonchain/prime-sdk-go
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -14,11 +14,13 @@ go get git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go"
|
"git.dragonchain.com/dragonchain/prime-sdk-go"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -30,13 +32,17 @@ func main() {
|
|||||||
"https://your-dragonchain-endpoint.com",
|
"https://your-dragonchain-endpoint.com",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create a context with timeout
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
// Check system health
|
// Check system health
|
||||||
if err := client.System.Health(); err != nil {
|
if err := client.System.Health(ctx); err != nil {
|
||||||
log.Fatal("Health check failed:", err)
|
log.Fatal("Health check failed:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get system status
|
// Get system status
|
||||||
status, err := client.System.Status()
|
status, err := client.System.Status(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to get status:", err)
|
log.Fatal("Failed to get status:", err)
|
||||||
}
|
}
|
||||||
@@ -51,7 +57,7 @@ func main() {
|
|||||||
Tag: "example-tag",
|
Tag: "example-tag",
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Transaction.Create(txn)
|
resp, err := client.Transaction.Create(ctx, txn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to create transaction:", err)
|
log.Fatal("Failed to create transaction:", err)
|
||||||
}
|
}
|
||||||
@@ -59,33 +65,124 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Transaction Modes
|
||||||
|
|
||||||
|
`Create` and `CreateBulk` return **immediately** with the assigned transaction ID(s). They do **not** wait for block inclusion. Blocks are assembled asynchronously on a ~5-second cycle.
|
||||||
|
|
||||||
|
### Fire and Forget
|
||||||
|
|
||||||
|
Most use cases only need the transaction ID. No polling required.
|
||||||
|
|
||||||
|
```go
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
resp, err := client.Transaction.Create(ctx, &models.TransactionCreateRequest{
|
||||||
|
TxnType: "my-transaction-type",
|
||||||
|
Payload: `{"message": "Hello Dragonchain"}`,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Transaction ID: %s\n", resp.TransactionID)
|
||||||
|
// Done — no need to wait for a block.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Wait for Block
|
||||||
|
|
||||||
|
If you need the block ID (e.g. for interchain verification or Daria), poll `Get` until `Header.BlockId` is populated.
|
||||||
|
|
||||||
|
```go
|
||||||
|
resp, err := client.Transaction.Create(ctx, &models.TransactionCreateRequest{
|
||||||
|
TxnType: "my-transaction-type",
|
||||||
|
Payload: `{"message": "Hello Dragonchain"}`,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Poll until the transaction is included in a block.
|
||||||
|
ticker := time.NewTicker(2 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for range ticker.C {
|
||||||
|
txn, err := client.Transaction.Get(ctx, resp.TransactionID)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if txn.Header.BlockId != "" {
|
||||||
|
fmt.Printf("Block ID: %s\n", txn.Header.BlockId)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Available Endpoints
|
## Available Endpoints
|
||||||
|
|
||||||
|
All API methods accept a `context.Context` as their first parameter for timeout and cancellation control.
|
||||||
|
|
||||||
### System
|
### System
|
||||||
- `Health()` - Check system health
|
- `Health(ctx)` - Check system health
|
||||||
- `Status()` - Get system status
|
- `Status(ctx)` - Get system status
|
||||||
|
|
||||||
### Transaction
|
### Transaction
|
||||||
- `Create(req)` - Create a new transaction
|
- `Create(ctx, req)` - Create a new transaction
|
||||||
- `CreateBulk(req)` - Create multiple transactions
|
- `CreateBulk(ctx, req)` - Create multiple transactions
|
||||||
- `Get(transactionID)` - Get transaction by ID
|
- `Get(ctx, transactionID)` - Get transaction by ID
|
||||||
|
- `List(ctx)` - List all transactions
|
||||||
|
|
||||||
### Transaction Type
|
### Transaction Type
|
||||||
- `Create(req)` - Create a new transaction type
|
- `Create(ctx, req)` - Create a new transaction type
|
||||||
- `Get(txnType)` - Get transaction type by name
|
- `Get(ctx, txnType)` - Get transaction type by name
|
||||||
- `List()` - List all transaction types
|
- `List(ctx)` - List all transaction types
|
||||||
- `Delete(txnType)` - Delete a transaction type
|
- `Delete(ctx, txnType)` - Delete a transaction type
|
||||||
|
|
||||||
### Smart Contract
|
### Smart Contract
|
||||||
- `Create(req)` - Create a new smart contract
|
- `Create(ctx, req)` - Create a new smart contract
|
||||||
- `Get(contractID)` - Get smart contract by ID
|
- `Get(ctx, contractID)` - Get smart contract by ID
|
||||||
- `List()` - List all smart contracts
|
- `List(ctx)` - List all smart contracts
|
||||||
- `Update(contractID, req)` - Update a smart contract
|
- `Update(ctx, contractID, req)` - Update a smart contract
|
||||||
- `Upload(contractID, req)` - Upload smart contract code
|
- `Upload(ctx, contractID, filepath)` - Upload smart contract code
|
||||||
- `Delete(contractID)` - Delete a smart contract
|
- `Delete(ctx, contractID)` - Delete a smart contract
|
||||||
|
|
||||||
### Block
|
### Block
|
||||||
- `Get(blockID)` - Get block by ID
|
- `Get(ctx, blockID)` - Get block by ID
|
||||||
|
|
||||||
|
### Proof Measure (public, unauthenticated)
|
||||||
|
- `GetSecurity(ctx, network, since)` - A network's accumulated security since `since` (unix seconds; `0` = service default), as raw measure + USD valuation. `network` = `"BTC"` or `"ETH"`.
|
||||||
|
- `Report(ctx, req)` - Per-transaction "securedBy" report over interchain anchors.
|
||||||
|
- `Health(ctx)` - Service liveness.
|
||||||
|
|
||||||
|
## Proof Measure
|
||||||
|
|
||||||
|
`proof-measure` is a separate, **public, unauthenticated** Dragonchain service
|
||||||
|
(the measured-immutability / "securedBy" metric) at
|
||||||
|
`https://proof-measure.dragonchain.com`. It needs no credentials. The SDK exposes
|
||||||
|
it two ways:
|
||||||
|
|
||||||
|
```go
|
||||||
|
// 1. Via the main SDK (targets the default public endpoint):
|
||||||
|
sec, err := client.ProofMeasure.GetSecurity(ctx, "BTC", time.Now().Add(-time.Hour).Unix())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("BTC secured by %s (%s) since %d\n", sec.ValueUSDFormatted, sec.Raw.Value+" "+sec.Raw.Unit, sec.SinceUnix)
|
||||||
|
|
||||||
|
// 2. Standalone (no prime credentials needed; empty URL = public prod):
|
||||||
|
import "git.dragonchain.com/dragonchain/prime-sdk-go/proofmeasure"
|
||||||
|
|
||||||
|
pm := proofmeasure.NewProofMeasureClient("") // or a custom base URL
|
||||||
|
report, err := pm.Report(ctx, &models.ReportRequest{
|
||||||
|
TransactionID: "tx-123", PrimeID: "my-prime", BlockID: "42",
|
||||||
|
Anchors: []models.ReportAnchorInput{
|
||||||
|
{Network: "BTC", TxHash: "0x...", Timestamp: anchorUnix},
|
||||||
|
{Network: "ETH", TxHash: "0x...", Timestamp: anchorUnix},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Secured by %s across %d anchors\n", report.TotalValueUSDFormatted, len(report.Anchors))
|
||||||
|
```
|
||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
|
|
||||||
@@ -93,4 +190,4 @@ The SDK uses HMAC-SHA256 authentication. You need to provide:
|
|||||||
- `publicID` - Your Dragonchain public ID
|
- `publicID` - Your Dragonchain public ID
|
||||||
- `authKeyID` - Your authentication key ID
|
- `authKeyID` - Your authentication key ID
|
||||||
- `authKey` - Your authentication key
|
- `authKey` - Your authentication key
|
||||||
- `baseURL` - The base URL of your Dragonchain node (e.g., "https://mychain.dragonchain.com")
|
- `baseURL` - The base URL of your Dragonchain node (e.g., "https://chains.dragonchain.com")
|
||||||
22
block/block.go
Normal file → Executable file
22
block/block.go
Normal file → Executable file
@@ -1,10 +1,11 @@
|
|||||||
package block
|
package block
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlockClient struct {
|
type BlockClient struct {
|
||||||
@@ -15,10 +16,23 @@ func NewBlockClient(c *client.Client) *BlockClient {
|
|||||||
return &BlockClient{client: c}
|
return &BlockClient{client: c}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockClient) Get(blockID string) (*models.Block, error) {
|
func (bc *BlockClient) Get(ctx context.Context, blockID string) (*models.Block, error) {
|
||||||
var resp models.Block
|
var resp models.Block
|
||||||
path := fmt.Sprintf("/api/v1/block/%s", blockID)
|
path := fmt.Sprintf("/api/v1/block/%s", blockID)
|
||||||
err := bc.client.Get(path, &resp)
|
err := bc.client.Get(ctx, path, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInterchain traces a block to the validator (verification) blocks that
|
||||||
|
// validated it and the public-chain interchain anchors those validator blocks
|
||||||
|
// were bundled into.
|
||||||
|
func (bc *BlockClient) GetInterchain(ctx context.Context, blockID string) (*models.InterchainTrace, error) {
|
||||||
|
var resp models.InterchainTrace
|
||||||
|
path := fmt.Sprintf("/api/v1/block/%s/interchain", blockID)
|
||||||
|
err := bc.client.Get(ctx, path, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
52
client/client.go
Normal file → Executable file
52
client/client.go
Normal file → Executable file
@@ -2,6 +2,7 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
@@ -22,14 +23,23 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(publicID, authKeyID, authKey, baseURL string) *Client {
|
func NewClient(publicID, authKeyID, authKey, baseURL string) *Client {
|
||||||
|
return NewClientWithHTTPClient(publicID, authKeyID, authKey, baseURL, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientWithHTTPClient is like NewClient but uses a caller-supplied
|
||||||
|
// *http.Client — e.g. one whose transport is SSRF-guarded, or one with a
|
||||||
|
// non-default timeout. A nil hc falls back to the package default (30s
|
||||||
|
// timeout, default transport), so existing callers are unaffected.
|
||||||
|
func NewClientWithHTTPClient(publicID, authKeyID, authKey, baseURL string, hc *http.Client) *Client {
|
||||||
|
if hc == nil {
|
||||||
|
hc = &http.Client{Timeout: 30 * time.Second}
|
||||||
|
}
|
||||||
return &Client{
|
return &Client{
|
||||||
publicID: publicID,
|
publicID: publicID,
|
||||||
authKeyID: authKeyID,
|
authKeyID: authKeyID,
|
||||||
authKey: authKey,
|
authKey: authKey,
|
||||||
baseURL: strings.TrimSuffix(baseURL, "/"),
|
baseURL: strings.TrimSuffix(baseURL, "/"),
|
||||||
httpClient: &http.Client{
|
httpClient: hc,
|
||||||
Timeout: 30 * time.Second,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +72,7 @@ func (c *Client) createHmac(msgStr string) []byte {
|
|||||||
return h.Sum(nil)
|
return h.Sum(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) doRequest(method, path, contentType string, body any, response any) error {
|
func (c *Client) doRequest(ctx context.Context, method, path, contentType string, body any, response any) error {
|
||||||
var bodyBytes []byte
|
var bodyBytes []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -83,7 +93,7 @@ func (c *Client) doRequest(method, path, contentType string, body any, response
|
|||||||
}
|
}
|
||||||
|
|
||||||
fullURL := c.baseURL + path
|
fullURL := c.baseURL + path
|
||||||
req, err := http.NewRequest(method, fullURL, bytes.NewBuffer(bodyBytes))
|
req, err := http.NewRequestWithContext(ctx, method, fullURL, bytes.NewBuffer(bodyBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create request: %w", err)
|
return fmt.Errorf("failed to create request: %w", err)
|
||||||
}
|
}
|
||||||
@@ -127,18 +137,34 @@ func checkByteSlice(body interface{}) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Get(path string, response any) error {
|
func (c *Client) InternalId() string {
|
||||||
return c.doRequest(http.MethodGet, path, "", nil, response)
|
return c.publicID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Post(path, contentType string, body any, response any) error {
|
func (c *Client) PublicId() string {
|
||||||
return c.doRequest(http.MethodPost, path, contentType, body, response)
|
return c.publicID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Put(path, contentType string, body any, response any) error {
|
func (c *Client) AuthKeyId() string {
|
||||||
return c.doRequest(http.MethodPut, path, contentType, body, response)
|
return c.authKeyID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Delete(path string, response any) error {
|
func (c *Client) Endpoint() string {
|
||||||
return c.doRequest(http.MethodDelete, path, "", nil, response)
|
return c.baseURL
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Get(ctx context.Context, path string, response any) error {
|
||||||
|
return c.doRequest(ctx, http.MethodGet, path, "", nil, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Post(ctx context.Context, path, contentType string, body any, response any) error {
|
||||||
|
return c.doRequest(ctx, http.MethodPost, path, contentType, body, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Put(ctx context.Context, path, contentType string, body any, response any) error {
|
||||||
|
return c.doRequest(ctx, http.MethodPut, path, contentType, body, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Delete(ctx context.Context, path string, response any) error {
|
||||||
|
return c.doRequest(ctx, http.MethodDelete, path, "", nil, response)
|
||||||
}
|
}
|
||||||
|
|||||||
103
client/unauthenticated.go
Normal file
103
client/unauthenticated.go
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UnauthenticatedClient is a minimal HTTP client for public Dragonchain services
|
||||||
|
// that require no HMAC credentials (e.g. the proof-measure service). It mirrors
|
||||||
|
// Client's body marshaling, status handling, and response decoding, but sends no
|
||||||
|
// Authorization/Dragonchain/Timestamp headers.
|
||||||
|
type UnauthenticatedClient struct {
|
||||||
|
baseURL string
|
||||||
|
httpClient *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUnauthenticatedClient builds an UnauthenticatedClient with the default
|
||||||
|
// HTTP client (30s timeout).
|
||||||
|
func NewUnauthenticatedClient(baseURL string) *UnauthenticatedClient {
|
||||||
|
return NewUnauthenticatedClientWithHTTPClient(baseURL, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUnauthenticatedClientWithHTTPClient is like NewUnauthenticatedClient but
|
||||||
|
// routes requests through the caller-supplied *http.Client (e.g. an SSRF-guarded
|
||||||
|
// transport). A nil hc falls back to the package default.
|
||||||
|
func NewUnauthenticatedClientWithHTTPClient(baseURL string, hc *http.Client) *UnauthenticatedClient {
|
||||||
|
if hc == nil {
|
||||||
|
hc = &http.Client{Timeout: 30 * time.Second}
|
||||||
|
}
|
||||||
|
return &UnauthenticatedClient{
|
||||||
|
baseURL: strings.TrimSuffix(baseURL, "/"),
|
||||||
|
httpClient: hc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Endpoint returns the configured base URL.
|
||||||
|
func (c *UnauthenticatedClient) Endpoint() string { return c.baseURL }
|
||||||
|
|
||||||
|
func (c *UnauthenticatedClient) doRequest(ctx context.Context, method, path, contentType string, body any, response any) error {
|
||||||
|
var bodyBytes []byte
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if body != nil {
|
||||||
|
if b, ok := body.([]byte); ok {
|
||||||
|
bodyBytes = b
|
||||||
|
} else {
|
||||||
|
bodyBytes, err = json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to marshal request body: %w", err)
|
||||||
|
}
|
||||||
|
contentType = "application/json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fullURL := c.baseURL + path
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, fullURL, bytes.NewBuffer(bodyBytes))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create request: %w", err)
|
||||||
|
}
|
||||||
|
if contentType != "" {
|
||||||
|
req.Header.Set("Content-Type", contentType)
|
||||||
|
}
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
resp, err := c.httpClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to execute request: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to read response body: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode >= 400 {
|
||||||
|
return fmt.Errorf("API error (status %d): %s", resp.StatusCode, strings.TrimSpace(string(respBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if response != nil && len(respBody) > 0 {
|
||||||
|
if err := json.Unmarshal(respBody, response); err != nil {
|
||||||
|
return fmt.Errorf("failed to unmarshal response: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get performs an unauthenticated GET and decodes the JSON response.
|
||||||
|
func (c *UnauthenticatedClient) Get(ctx context.Context, path string, response any) error {
|
||||||
|
return c.doRequest(ctx, http.MethodGet, path, "", nil, response)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Post performs an unauthenticated POST and decodes the JSON response.
|
||||||
|
func (c *UnauthenticatedClient) Post(ctx context.Context, path, contentType string, body any, response any) error {
|
||||||
|
return c.doRequest(ctx, http.MethodPost, path, contentType, body, response)
|
||||||
|
}
|
||||||
29
contract/contract.go
Normal file → Executable file
29
contract/contract.go
Normal file → Executable file
@@ -1,11 +1,12 @@
|
|||||||
package contract
|
package contract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContractClient struct {
|
type ContractClient struct {
|
||||||
@@ -16,45 +17,45 @@ func NewContractClient(c *client.Client) *ContractClient {
|
|||||||
return &ContractClient{client: c}
|
return &ContractClient{client: c}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ContractClient) Create(req *models.SmartContractCreateRequest) (*models.SmartContract, error) {
|
func (cc *ContractClient) Create(ctx context.Context, req *models.SmartContractCreateRequest) (*models.SmartContract, error) {
|
||||||
var resp models.SmartContract
|
var resp models.SmartContract
|
||||||
err := cc.client.Post("/api/v1/contract", models.ContentTypeJSON, req, &resp)
|
err := cc.client.Post(ctx, "/api/v1/contract", models.ContentTypeJSON, req, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ContractClient) Get(contractID string) (*models.SmartContract, error) {
|
func (cc *ContractClient) Get(ctx context.Context, contractID string) (*models.SmartContract, error) {
|
||||||
var resp models.SmartContract
|
var resp models.SmartContract
|
||||||
path := fmt.Sprintf("/api/v1/contract/%s", contractID)
|
path := fmt.Sprintf("/api/v1/contract/%s", contractID)
|
||||||
err := cc.client.Get(path, &resp)
|
err := cc.client.Get(ctx, path, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ContractClient) List() (*models.ListResponse, error) {
|
func (cc *ContractClient) List(ctx context.Context) (*models.ListResponse, error) {
|
||||||
var resp models.ListResponse
|
var resp models.ListResponse
|
||||||
err := cc.client.Get("/api/v1/contract", &resp)
|
err := cc.client.Get(ctx, "/api/v1/contract", &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ContractClient) Update(contractID string, req *models.SmartContractUpdateRequest) (*models.SuccessResponse, error) {
|
func (cc *ContractClient) Update(ctx context.Context, contractID string, req *models.SmartContractUpdateRequest) (*models.SuccessResponse, error) {
|
||||||
var resp models.SuccessResponse
|
var resp models.SuccessResponse
|
||||||
path := fmt.Sprintf("/api/v1/contract/%s", contractID)
|
path := fmt.Sprintf("/api/v1/contract/%s", contractID)
|
||||||
err := cc.client.Put(path, models.ContentTypeJSON, req, &resp)
|
err := cc.client.Put(ctx, path, models.ContentTypeJSON, req, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ContractClient) Upload(contractID string, filepath string) (*models.SuccessResponse, error) {
|
func (cc *ContractClient) Upload(ctx context.Context, contractID string, filepath string) (*models.SuccessResponse, error) {
|
||||||
fileContent, err := os.ReadFile(filepath)
|
fileContent, err := os.ReadFile(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read file: %w", err)
|
return nil, fmt.Errorf("failed to read file: %w", err)
|
||||||
@@ -62,17 +63,17 @@ func (cc *ContractClient) Upload(contractID string, filepath string) (*models.Su
|
|||||||
|
|
||||||
var resp models.SuccessResponse
|
var resp models.SuccessResponse
|
||||||
path := fmt.Sprintf("/api/v1/contract/%s/upload", contractID)
|
path := fmt.Sprintf("/api/v1/contract/%s/upload", contractID)
|
||||||
err = cc.client.Put(path, "application/octet-stream", fileContent, &resp)
|
err = cc.client.Put(ctx, path, "application/octet-stream", fileContent, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ContractClient) Delete(contractID string) (*models.SuccessResponse, error) {
|
func (cc *ContractClient) Delete(ctx context.Context, contractID string) (*models.SuccessResponse, error) {
|
||||||
var resp models.SuccessResponse
|
var resp models.SuccessResponse
|
||||||
path := fmt.Sprintf("/api/v1/contract/%s", contractID)
|
path := fmt.Sprintf("/api/v1/contract/%s", contractID)
|
||||||
err := cc.client.Delete(path, &resp)
|
err := cc.client.Delete(ctx, path, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
0
credentials/credentials.go
Normal file → Executable file
0
credentials/credentials.go
Normal file → Executable file
94
dragonchain.go
Normal file → Executable file
94
dragonchain.go
Normal file → Executable file
@@ -1,14 +1,68 @@
|
|||||||
|
// Package sdk provides a Go SDK for interacting with Dragonchain nodes.
|
||||||
|
//
|
||||||
|
// All API methods require a context.Context parameter for timeout and cancellation control.
|
||||||
|
//
|
||||||
|
// Example — fire and forget (most use cases):
|
||||||
|
//
|
||||||
|
// client := sdk.NewDragonchainSDK(
|
||||||
|
// "your-public-id",
|
||||||
|
// "your-auth-key-id",
|
||||||
|
// "your-auth-key",
|
||||||
|
// "https://your-dragonchain-endpoint.com",
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
// defer cancel()
|
||||||
|
//
|
||||||
|
// resp, err := client.Transaction.Create(ctx, &models.TransactionCreateRequest{
|
||||||
|
// TxnType: "my-transaction-type",
|
||||||
|
// Payload: `{"message": "Hello Dragonchain"}`,
|
||||||
|
// })
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
// fmt.Printf("Transaction ID: %s\n", resp.TransactionID)
|
||||||
|
// // Done — no need to wait for a block.
|
||||||
|
//
|
||||||
|
// Example — wait for block inclusion (interchain / Daria):
|
||||||
|
//
|
||||||
|
// resp, err := client.Transaction.Create(ctx, &models.TransactionCreateRequest{
|
||||||
|
// TxnType: "my-transaction-type",
|
||||||
|
// Payload: `{"message": "Hello Dragonchain"}`,
|
||||||
|
// })
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Poll until the transaction is included in a block.
|
||||||
|
// ticker := time.NewTicker(2 * time.Second)
|
||||||
|
// defer ticker.Stop()
|
||||||
|
// for range ticker.C {
|
||||||
|
// txn, err := client.Transaction.Get(ctx, resp.TransactionID)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
// if txn.Header.BlockId != "" {
|
||||||
|
// fmt.Printf("Block ID: %s\n", txn.Header.BlockId)
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
package sdk
|
package sdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/block"
|
"net/http"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/contract"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/block"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/system"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/transaction"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/contract"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/transactiontype"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/proofmeasure"
|
||||||
|
"git.dragonchain.com/dragonchain/prime-sdk-go/system"
|
||||||
|
"git.dragonchain.com/dragonchain/prime-sdk-go/transaction"
|
||||||
|
"git.dragonchain.com/dragonchain/prime-sdk-go/transactiontype"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DragonchainSDK is the main SDK client for interacting with Dragonchain nodes.
|
||||||
|
// It provides access to all API endpoints through specialized client instances.
|
||||||
type DragonchainSDK struct {
|
type DragonchainSDK struct {
|
||||||
client *client.Client
|
client *client.Client
|
||||||
Transaction *transaction.TransactionClient
|
Transaction *transaction.TransactionClient
|
||||||
@@ -16,10 +70,33 @@ type DragonchainSDK struct {
|
|||||||
Contract *contract.ContractClient
|
Contract *contract.ContractClient
|
||||||
Block *block.BlockClient
|
Block *block.BlockClient
|
||||||
System *system.SystemClient
|
System *system.SystemClient
|
||||||
|
// ProofMeasure calls the public proof-measure service (measured immutability
|
||||||
|
// / "securedBy"). It is a separate, unauthenticated service, so this handle
|
||||||
|
// targets its default public endpoint (proofmeasure.DefaultBaseURL); for a
|
||||||
|
// custom endpoint construct a proofmeasure.ProofMeasureClient directly.
|
||||||
|
ProofMeasure *proofmeasure.ProofMeasureClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDragonchainSDK creates a new Dragonchain SDK client.
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
// - publicID: Your Dragonchain public ID
|
||||||
|
// - authKeyID: Your authentication key ID
|
||||||
|
// - authKey: Your authentication key
|
||||||
|
// - baseURL: The base URL of your Dragonchain node (e.g., "https://mychain.dragonchain.com")
|
||||||
|
//
|
||||||
|
// Returns a configured SDK client ready to make API calls.
|
||||||
|
// All API methods on the returned client require a context.Context parameter.
|
||||||
func NewDragonchainSDK(publicID, authKeyID, authKey, baseURL string) *DragonchainSDK {
|
func NewDragonchainSDK(publicID, authKeyID, authKey, baseURL string) *DragonchainSDK {
|
||||||
c := client.NewClient(publicID, authKeyID, authKey, baseURL)
|
return NewDragonchainSDKWithHTTPClient(publicID, authKeyID, authKey, baseURL, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDragonchainSDKWithHTTPClient is like NewDragonchainSDK but routes every
|
||||||
|
// request through the caller-supplied *http.Client. Pass a client whose
|
||||||
|
// transport enforces an SSRF policy (guarded dialer + redirect checks) when
|
||||||
|
// the baseURL is attacker-influenced. A nil hc falls back to the SDK default.
|
||||||
|
func NewDragonchainSDKWithHTTPClient(publicID, authKeyID, authKey, baseURL string, hc *http.Client) *DragonchainSDK {
|
||||||
|
c := client.NewClientWithHTTPClient(publicID, authKeyID, authKey, baseURL, hc)
|
||||||
return &DragonchainSDK{
|
return &DragonchainSDK{
|
||||||
client: c,
|
client: c,
|
||||||
Transaction: transaction.NewTransactionClient(c),
|
Transaction: transaction.NewTransactionClient(c),
|
||||||
@@ -27,9 +104,12 @@ func NewDragonchainSDK(publicID, authKeyID, authKey, baseURL string) *Dragonchai
|
|||||||
Contract: contract.NewContractClient(c),
|
Contract: contract.NewContractClient(c),
|
||||||
Block: block.NewBlockClient(c),
|
Block: block.NewBlockClient(c),
|
||||||
System: system.NewSystemClient(c),
|
System: system.NewSystemClient(c),
|
||||||
|
ProofMeasure: proofmeasure.NewProofMeasureClientWithHTTPClient("", hc),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetClient returns the underlying HTTP client used by the SDK.
|
||||||
|
// This can be useful for advanced use cases or custom implementations.
|
||||||
func (sdk *DragonchainSDK) GetClient() *client.Client {
|
func (sdk *DragonchainSDK) GetClient() *client.Client {
|
||||||
return sdk.client
|
return sdk.client
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
Normal file → Executable file
2
go.mod
Normal file → Executable file
@@ -1,4 +1,4 @@
|
|||||||
module git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go
|
module git.dragonchain.com/dragonchain/prime-sdk-go
|
||||||
|
|
||||||
go 1.24.5
|
go 1.24.5
|
||||||
|
|
||||||
|
|||||||
140
models/models.go
Normal file → Executable file
140
models/models.go
Normal file → Executable file
@@ -78,6 +78,7 @@ type SmartContractCreateRequest struct {
|
|||||||
ExecutionOrder string `json:"executionOrder"`
|
ExecutionOrder string `json:"executionOrder"`
|
||||||
EnvironmentVariables map[string]string `json:"environmentVariables,omitempty"`
|
EnvironmentVariables map[string]string `json:"environmentVariables,omitempty"`
|
||||||
Secrets map[string]string `json:"secret,omitempty"`
|
Secrets map[string]string `json:"secret,omitempty"`
|
||||||
|
Remote bool `json:"remote,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SmartContractUpdateRequest struct {
|
type SmartContractUpdateRequest struct {
|
||||||
@@ -101,6 +102,13 @@ type SmartContract struct {
|
|||||||
|
|
||||||
EnvVars map[string]string `json:"envVars"`
|
EnvVars map[string]string `json:"envVars"`
|
||||||
Secrets []string `json:"secrets"`
|
Secrets []string `json:"secrets"`
|
||||||
|
|
||||||
|
GrpcConnectionInfo *GrpcConnectionInfo `json:"grpcConnectionInfo,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GrpcConnectionInfo struct {
|
||||||
|
Address string `json:"address"`
|
||||||
|
ApiKey string `json:"apiKey,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SmartContractExecutionInfo struct {
|
type SmartContractExecutionInfo struct {
|
||||||
@@ -114,17 +122,22 @@ type SmartContractExecutionInfo struct {
|
|||||||
|
|
||||||
type Block struct {
|
type Block struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
ID string `json:"block_id"`
|
Header BlockHeader `json:"header"`
|
||||||
Timestamp string `json:"timestamp"`
|
|
||||||
PrevID string `json:"prev_id"`
|
|
||||||
PrevProof string `json:"prev_proof"`
|
|
||||||
Transactions []string `json:"transactions"`
|
Transactions []string `json:"transactions"`
|
||||||
Proof BlockProof `json:"proof"`
|
Proof BlockProof `json:"proof"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BlockHeader struct {
|
||||||
|
BlockId string `json:"blockId"`
|
||||||
|
DcId string `json:"dcId"`
|
||||||
|
PrevId string `json:"prevId"`
|
||||||
|
PrevProof string `json:"prevProof"`
|
||||||
|
Timestamp string `json:"timestamp"`
|
||||||
|
}
|
||||||
|
|
||||||
type BlockProof struct {
|
type BlockProof struct {
|
||||||
Scheme string `json:"scheme"`
|
|
||||||
Proof string `json:"proof"`
|
Proof string `json:"proof"`
|
||||||
|
Scheme string `json:"scheme,omitempty"`
|
||||||
Nonce int64 `json:"nonce,omitempty"`
|
Nonce int64 `json:"nonce,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,3 +170,120 @@ type ListResponse struct {
|
|||||||
Items []interface{} `json:"items"`
|
Items []interface{} `json:"items"`
|
||||||
TotalCount int `json:"total_count"`
|
TotalCount int `json:"total_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VerificationBlock is a validator's verification of a prime block.
|
||||||
|
type VerificationBlock struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
PrimeChainId string `json:"primeChainId"`
|
||||||
|
PrimeBlockId string `json:"primeBlockId"`
|
||||||
|
Timestamp string `json:"timestamp"`
|
||||||
|
VerifierPublicKey string `json:"verifierPublicKey"`
|
||||||
|
VerifierSignature string `json:"verifierSignature"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InterchainTransaction is an anchor broadcast to a public blockchain (e.g. ETH
|
||||||
|
// or BTC) that bundles one or more validator blocks. ValidatorBlocks holds the
|
||||||
|
// prime block ids covered; CoveredPrimeChainIds the prime chains they belong to.
|
||||||
|
type InterchainTransaction struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
Timestamp string `json:"timestamp"`
|
||||||
|
ChainId string `json:"chainId"`
|
||||||
|
TransHash string `json:"transHash"`
|
||||||
|
BlockId string `json:"blockId"`
|
||||||
|
ValidatorBlocks []string `json:"validatorBlocks"`
|
||||||
|
ValidatorBlockhash string `json:"validatorBlockhash"`
|
||||||
|
Signature string `json:"signature"`
|
||||||
|
CoveredPrimeChainIds []string `json:"coveredPrimeChainIds"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InterchainTrace links a prime block to the validator (verification) blocks
|
||||||
|
// that validated it and the public-chain interchain anchors those validator
|
||||||
|
// blocks were bundled into. Returned by Transaction.GetInterchain and
|
||||||
|
// Block.GetInterchain.
|
||||||
|
type InterchainTrace struct {
|
||||||
|
BlockId string `json:"blockId"`
|
||||||
|
ValidatorBlocks []VerificationBlock `json:"validatorBlocks"`
|
||||||
|
InterchainTransactions []InterchainTransaction `json:"interchainTransactions"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- proof-measure service (measured immutability / "securedBy") ---
|
||||||
|
//
|
||||||
|
// Decimal-valued fields are transmitted as strings (full precision); timestamps
|
||||||
|
// are int64 unix seconds.
|
||||||
|
|
||||||
|
// RawMeasure is a network's native cumulative security measure: cumulative
|
||||||
|
// hashes for PoW, stake-seconds for PoS.
|
||||||
|
type RawMeasure struct {
|
||||||
|
Value string `json:"value"` // human-scaled mantissa (e.g. "484.44")
|
||||||
|
Unit string `json:"unit"` // e.g. "Zettahashes", "ETH·s"
|
||||||
|
Base string `json:"base"` // unscaled base amount (hashes or stake-seconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SecurityResult is the security a single network accrued for a window/anchor,
|
||||||
|
// exposed as the raw native measure AND a USD valuation (energy cost for PoW,
|
||||||
|
// staked value for PoS), plus a normalized 0..1 score.
|
||||||
|
type SecurityResult struct {
|
||||||
|
Network string `json:"network"`
|
||||||
|
Consensus string `json:"consensus"` // "pow" | "pos"
|
||||||
|
Raw RawMeasure `json:"raw"`
|
||||||
|
ValueUSD string `json:"valueUsd"` // decimal string
|
||||||
|
ValueUSDFormatted string `json:"valueUsdFormatted"` // e.g. "$1,234.56"
|
||||||
|
Label string `json:"label"` // e.g. "$X energy consumed" / "$X staked"
|
||||||
|
NormalizedScore string `json:"normalizedScore"` // decimal string in [0,1]
|
||||||
|
SinceUnix int64 `json:"since"` // window/anchor start (unix seconds)
|
||||||
|
AsOfUnix int64 `json:"asOf"` // latest sample time (unix seconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReportAnchorInput is one anchor supplied in a report request. Provide either
|
||||||
|
// Network ("BTC"/"ETH") or the public-chain numeric ChainID; Network wins.
|
||||||
|
type ReportAnchorInput struct {
|
||||||
|
Network string `json:"network,omitempty"`
|
||||||
|
ChainID string `json:"chainId,omitempty"`
|
||||||
|
TxHash string `json:"txHash"`
|
||||||
|
Timestamp int64 `json:"timestamp"` // anchor time, unix seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReportRequest is the body of ProofMeasure.Report: a transaction's interchain
|
||||||
|
// anchors. The service computes the security each anchor's network accumulated
|
||||||
|
// since the anchor and returns a TransactionReport.
|
||||||
|
type ReportRequest struct {
|
||||||
|
TransactionID string `json:"transactionId"`
|
||||||
|
PrimeID string `json:"primeId"`
|
||||||
|
BlockID string `json:"blockId"`
|
||||||
|
Anchors []ReportAnchorInput `json:"anchors"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AnchorSecurity is one interchain anchor with the security its public network
|
||||||
|
// has accumulated since the anchor was placed.
|
||||||
|
type AnchorSecurity struct {
|
||||||
|
Network string `json:"network"`
|
||||||
|
AnchorTimestamp int64 `json:"anchorTimestamp"` // unix seconds
|
||||||
|
AnchorTxHash string `json:"anchorTxHash"`
|
||||||
|
Security SecurityResult `json:"security"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HashPower is the combined raw hash power across a report's PoW anchors.
|
||||||
|
type HashPower struct {
|
||||||
|
Value string `json:"value"`
|
||||||
|
Units string `json:"units"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransactionReport is the per-transaction "securedBy" report: every public-chain
|
||||||
|
// anchor covering the transaction's block with both raw and USD security, plus
|
||||||
|
// combined totals. HashPower is nil when there are no PoW anchors.
|
||||||
|
type TransactionReport struct {
|
||||||
|
TransactionID string `json:"transactionId"`
|
||||||
|
PrimeID string `json:"primeId"`
|
||||||
|
BlockID string `json:"blockId"`
|
||||||
|
Anchors []AnchorSecurity `json:"anchors"`
|
||||||
|
TotalValueUSD string `json:"totalValueUsd"`
|
||||||
|
TotalValueUSDFormatted string `json:"totalValueUsdFormatted"`
|
||||||
|
HashPower *HashPower `json:"hashPower"`
|
||||||
|
TotalNormalizedScore string `json:"totalNormalizedScore"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HealthResponse is the proof-measure liveness payload.
|
||||||
|
type HealthResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
||||||
|
|||||||
78
proofmeasure/proofmeasure.go
Normal file
78
proofmeasure/proofmeasure.go
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
// Package proofmeasure is a client for the Dragonchain proof-measure service —
|
||||||
|
// the measured-immutability / "securedBy" metric for L1–L5 verification chains.
|
||||||
|
//
|
||||||
|
// proof-measure is a separate, public, UNauthenticated service (no API keys),
|
||||||
|
// so this client takes only a base URL. It exposes a network's accumulated
|
||||||
|
// security as both a raw measure (cumulative hashes / stake-seconds) and a USD
|
||||||
|
// valuation, plus a per-transaction "securedBy" report over interchain anchors.
|
||||||
|
package proofmeasure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
||||||
|
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DefaultBaseURL is the public production proof-measure endpoint.
|
||||||
|
const DefaultBaseURL = "https://proof-measure.dragonchain.com"
|
||||||
|
|
||||||
|
// ProofMeasureClient calls the proof-measure HTTP API.
|
||||||
|
type ProofMeasureClient struct {
|
||||||
|
client *client.UnauthenticatedClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProofMeasureClient builds a client for the proof-measure service. An empty
|
||||||
|
// baseURL defaults to the public production endpoint (DefaultBaseURL).
|
||||||
|
func NewProofMeasureClient(baseURL string) *ProofMeasureClient {
|
||||||
|
return NewProofMeasureClientWithHTTPClient(baseURL, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProofMeasureClientWithHTTPClient is like NewProofMeasureClient but routes
|
||||||
|
// requests through the caller-supplied *http.Client. A nil hc uses the default.
|
||||||
|
func NewProofMeasureClientWithHTTPClient(baseURL string, hc *http.Client) *ProofMeasureClient {
|
||||||
|
if baseURL == "" {
|
||||||
|
baseURL = DefaultBaseURL
|
||||||
|
}
|
||||||
|
return &ProofMeasureClient{
|
||||||
|
client: client.NewUnauthenticatedClientWithHTTPClient(baseURL, hc),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSecurity returns the security a public network (network = "BTC" or "ETH")
|
||||||
|
// has accumulated since the given unix timestamp, as both a raw measure and a
|
||||||
|
// USD valuation. A non-positive since omits the parameter, letting the service
|
||||||
|
// apply its default window.
|
||||||
|
func (pc *ProofMeasureClient) GetSecurity(ctx context.Context, network string, since int64) (*models.SecurityResult, error) {
|
||||||
|
path := fmt.Sprintf("/api/v1/security/%s", network)
|
||||||
|
if since > 0 {
|
||||||
|
path = fmt.Sprintf("%s?since=%d", path, since)
|
||||||
|
}
|
||||||
|
var resp models.SecurityResult
|
||||||
|
if err := pc.client.Get(ctx, path, &resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Report computes the per-transaction "securedBy" report for the supplied
|
||||||
|
// interchain anchors: each anchor's raw + USD security since it was placed, plus
|
||||||
|
// combined totals.
|
||||||
|
func (pc *ProofMeasureClient) Report(ctx context.Context, req *models.ReportRequest) (*models.TransactionReport, error) {
|
||||||
|
var resp models.TransactionReport
|
||||||
|
if err := pc.client.Post(ctx, "/api/v1/report", models.ContentTypeJSON, req, &resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Health reports service liveness and DB reachability.
|
||||||
|
func (pc *ProofMeasureClient) Health(ctx context.Context) (*models.HealthResponse, error) {
|
||||||
|
var resp models.HealthResponse
|
||||||
|
if err := pc.client.Get(ctx, "/api/v1/health", &resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
135
proofmeasure/proofmeasure_test.go
Normal file
135
proofmeasure/proofmeasure_test.go
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
package proofmeasure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetSecurity(t *testing.T) {
|
||||||
|
var gotPath string
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
gotPath = r.URL.RequestURI()
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = io.WriteString(w, `{
|
||||||
|
"network":"BTC","consensus":"pow",
|
||||||
|
"raw":{"value":"71.63","unit":"Yottahashes","base":"7.16e25"},
|
||||||
|
"valueUsd":"13928170.26","valueUsdFormatted":"$13,928,170.26",
|
||||||
|
"label":"$13,928,170.26 energy consumed","normalizedScore":"0.9234",
|
||||||
|
"since":1780504894,"asOf":1780591253}`)
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
pc := NewProofMeasureClient(srv.URL)
|
||||||
|
res, err := pc.GetSecurity(context.Background(), "BTC", 1780504894)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetSecurity: %v", err)
|
||||||
|
}
|
||||||
|
if gotPath != "/api/v1/security/BTC?since=1780504894" {
|
||||||
|
t.Errorf("path = %q, want /api/v1/security/BTC?since=1780504894", gotPath)
|
||||||
|
}
|
||||||
|
if res.Network != "BTC" || res.Consensus != "pow" {
|
||||||
|
t.Errorf("network/consensus = %q/%q", res.Network, res.Consensus)
|
||||||
|
}
|
||||||
|
if res.Raw.Unit != "Yottahashes" || res.ValueUSD != "13928170.26" {
|
||||||
|
t.Errorf("raw.unit=%q valueUsd=%q", res.Raw.Unit, res.ValueUSD)
|
||||||
|
}
|
||||||
|
if res.SinceUnix != 1780504894 || res.AsOfUnix != 1780591253 {
|
||||||
|
t.Errorf("since/asOf = %d/%d", res.SinceUnix, res.AsOfUnix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetSecurity_NoSinceOmitsParam(t *testing.T) {
|
||||||
|
var gotPath string
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
gotPath = r.URL.RequestURI()
|
||||||
|
_, _ = io.WriteString(w, `{"network":"ETH","consensus":"pos"}`)
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
if _, err := NewProofMeasureClient(srv.URL).GetSecurity(context.Background(), "ETH", 0); err != nil {
|
||||||
|
t.Fatalf("GetSecurity: %v", err)
|
||||||
|
}
|
||||||
|
if gotPath != "/api/v1/security/ETH" {
|
||||||
|
t.Errorf("path = %q, want /api/v1/security/ETH (no since)", gotPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReport(t *testing.T) {
|
||||||
|
var gotMethod, gotPath string
|
||||||
|
var gotReq models.ReportRequest
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
gotMethod, gotPath = r.Method, r.URL.Path
|
||||||
|
_ = json.NewDecoder(r.Body).Decode(&gotReq)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = io.WriteString(w, `{
|
||||||
|
"transactionId":"tx-1","primeId":"p-1","blockId":"42",
|
||||||
|
"anchors":[{"network":"BTC","anchorTimestamp":1712345678,"anchorTxHash":"0xabc",
|
||||||
|
"security":{"network":"BTC","consensus":"pow","valueUsd":"100.00"}}],
|
||||||
|
"totalValueUsd":"100.00","totalValueUsdFormatted":"$100.00",
|
||||||
|
"hashPower":{"value":"40.06","units":"Yottahashes"},"totalNormalizedScore":"0.9"}`)
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
pc := NewProofMeasureClient(srv.URL)
|
||||||
|
rep, err := pc.Report(context.Background(), &models.ReportRequest{
|
||||||
|
TransactionID: "tx-1", PrimeID: "p-1", BlockID: "42",
|
||||||
|
Anchors: []models.ReportAnchorInput{{Network: "BTC", TxHash: "0xabc", Timestamp: 1712345678}},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Report: %v", err)
|
||||||
|
}
|
||||||
|
if gotMethod != http.MethodPost || gotPath != "/api/v1/report" {
|
||||||
|
t.Errorf("method/path = %s %s", gotMethod, gotPath)
|
||||||
|
}
|
||||||
|
if len(gotReq.Anchors) != 1 || gotReq.Anchors[0].Network != "BTC" {
|
||||||
|
t.Errorf("request anchors not sent: %+v", gotReq.Anchors)
|
||||||
|
}
|
||||||
|
if rep.TotalValueUSD != "100.00" || rep.HashPower == nil || rep.HashPower.Units != "Yottahashes" {
|
||||||
|
t.Errorf("report decode wrong: %+v", rep)
|
||||||
|
}
|
||||||
|
if len(rep.Anchors) != 1 || rep.Anchors[0].Security.Network != "BTC" {
|
||||||
|
t.Errorf("report anchors decode wrong: %+v", rep.Anchors)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHealth(t *testing.T) {
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.URL.Path != "/api/v1/health" {
|
||||||
|
t.Errorf("health path = %q", r.URL.Path)
|
||||||
|
}
|
||||||
|
_, _ = io.WriteString(w, `{"status":"ok"}`)
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
h, err := NewProofMeasureClient(srv.URL).Health(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Health: %v", err)
|
||||||
|
}
|
||||||
|
if h.Status != "ok" {
|
||||||
|
t.Errorf("status = %q, want ok", h.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDefaultBaseURL(t *testing.T) {
|
||||||
|
if NewProofMeasureClient("") == nil {
|
||||||
|
t.Fatal("nil client for empty base URL")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestErrorStatus(t *testing.T) {
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
_, _ = io.WriteString(w, `bad request`)
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
if _, err := NewProofMeasureClient(srv.URL).Health(context.Background()); err == nil {
|
||||||
|
t.Fatal("expected an error on 400 status, got nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
14
system/system.go
Normal file → Executable file
14
system/system.go
Normal file → Executable file
@@ -1,8 +1,10 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
"context"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
|
||||||
|
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
||||||
|
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SystemClient struct {
|
type SystemClient struct {
|
||||||
@@ -13,13 +15,13 @@ func NewSystemClient(c *client.Client) *SystemClient {
|
|||||||
return &SystemClient{client: c}
|
return &SystemClient{client: c}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *SystemClient) Health() error {
|
func (sc *SystemClient) Health(ctx context.Context) error {
|
||||||
return sc.client.Get("/api/v1/health", nil)
|
return sc.client.Get(ctx, "/api/v1/health", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *SystemClient) Status() (*models.SystemStatus, error) {
|
func (sc *SystemClient) Status(ctx context.Context) (*models.SystemStatus, error) {
|
||||||
var resp models.SystemStatus
|
var resp models.SystemStatus
|
||||||
err := sc.client.Get("/api/v1/status", &resp)
|
err := sc.client.Get(ctx, "/api/v1/status", &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
47
transaction/transaction.go
Normal file → Executable file
47
transaction/transaction.go
Normal file → Executable file
@@ -1,10 +1,11 @@
|
|||||||
package transaction
|
package transaction
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransactionClient struct {
|
type TransactionClient struct {
|
||||||
@@ -15,38 +16,60 @@ func NewTransactionClient(c *client.Client) *TransactionClient {
|
|||||||
return &TransactionClient{client: c}
|
return &TransactionClient{client: c}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TransactionClient) Create(req *models.TransactionCreateRequest) (*models.TransactionCreateResponse, error) {
|
// Create submits a new transaction and returns immediately with the assigned transaction ID.
|
||||||
|
// It does NOT wait for the transaction to be included in a block. Block processing happens
|
||||||
|
// asynchronously on a ~5-second cycle. If you need the block ID (e.g. for interchain
|
||||||
|
// verification), poll Get until Header.BlockId is populated.
|
||||||
|
func (tc *TransactionClient) Create(ctx context.Context, req *models.TransactionCreateRequest) (*models.TransactionCreateResponse, error) {
|
||||||
var resp models.TransactionCreateResponse
|
var resp models.TransactionCreateResponse
|
||||||
err := tc.client.Post("/api/v1/transaction", models.ContentTypeJSON, req, &resp)
|
err := tc.client.Post(ctx, "/api/v1/transaction", models.ContentTypeJSON, req, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TransactionClient) CreateBulk(req *models.TransactionBulkRequest) (*models.TransactionBulkResponse, error) {
|
// CreateBulk submits multiple transactions and returns immediately with the assigned transaction IDs.
|
||||||
|
// It does NOT wait for the transactions to be included in a block. Block processing happens
|
||||||
|
// asynchronously on a ~5-second cycle. If you need block IDs, poll Get for each transaction
|
||||||
|
// until Header.BlockId is populated.
|
||||||
|
func (tc *TransactionClient) CreateBulk(ctx context.Context, req *models.TransactionBulkRequest) (*models.TransactionBulkResponse, error) {
|
||||||
var resp models.TransactionBulkResponse
|
var resp models.TransactionBulkResponse
|
||||||
err := tc.client.Post("/api/v1/transaction/bulk", models.ContentTypeJSON, req, &resp)
|
err := tc.client.Post(ctx, "/api/v1/transaction/bulk", models.ContentTypeJSON, req, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TransactionClient) Get(transactionID string) (*models.Transaction, error) {
|
func (tc *TransactionClient) Get(ctx context.Context, transactionID string) (*models.Transaction, error) {
|
||||||
var resp models.Transaction
|
var resp models.Transaction
|
||||||
path := fmt.Sprintf("/api/v1/transaction/%s", transactionID)
|
path := fmt.Sprintf("/api/v1/transaction/%s", transactionID)
|
||||||
err := tc.client.Get(path, &resp)
|
err := tc.client.Get(ctx, path, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TransactionClient) List() (*models.ListTransactionsResponse, error) {
|
// GetInterchain traces a transaction to the validator (verification) blocks that
|
||||||
var resp models.ListTransactionsResponse
|
// validated its prime block and the public-chain interchain anchors those
|
||||||
path := "/api/v1/transaction/"
|
// validator blocks were bundled into. If the transaction is still pending (not
|
||||||
err := tc.client.Get(path, &resp)
|
// yet in a block) the trace's slices are empty.
|
||||||
|
func (tc *TransactionClient) GetInterchain(ctx context.Context, transactionID string) (*models.InterchainTrace, error) {
|
||||||
|
var resp models.InterchainTrace
|
||||||
|
path := fmt.Sprintf("/api/v1/transaction/%s/interchain", transactionID)
|
||||||
|
err := tc.client.Get(ctx, path, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tc *TransactionClient) List(ctx context.Context) (*models.ListTransactionsResponse, error) {
|
||||||
|
var resp models.ListTransactionsResponse
|
||||||
|
path := "/api/v1/transaction/"
|
||||||
|
err := tc.client.Get(ctx, path, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
21
transactiontype/transactiontype.go
Normal file → Executable file
21
transactiontype/transactiontype.go
Normal file → Executable file
@@ -1,10 +1,11 @@
|
|||||||
package transactiontype
|
package transactiontype
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
||||||
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
"git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransactionTypeClient struct {
|
type TransactionTypeClient struct {
|
||||||
@@ -15,38 +16,38 @@ func NewTransactionTypeClient(c *client.Client) *TransactionTypeClient {
|
|||||||
return &TransactionTypeClient{client: c}
|
return &TransactionTypeClient{client: c}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ttc *TransactionTypeClient) Create(req *models.TransactionTypeCreateRequest) (*models.TransactionTypeCreateResponse, error) {
|
func (ttc *TransactionTypeClient) Create(ctx context.Context, req *models.TransactionTypeCreateRequest) (*models.TransactionTypeCreateResponse, error) {
|
||||||
var resp models.TransactionTypeCreateResponse
|
var resp models.TransactionTypeCreateResponse
|
||||||
err := ttc.client.Post("/api/v1/transaction-type", models.ContentTypeJSON, req, &resp)
|
err := ttc.client.Post(ctx, "/api/v1/transaction-type", models.ContentTypeJSON, req, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ttc *TransactionTypeClient) Get(txnType string) (*models.TransactionType, error) {
|
func (ttc *TransactionTypeClient) Get(ctx context.Context, txnType string) (*models.TransactionType, error) {
|
||||||
var resp models.TransactionType
|
var resp models.TransactionType
|
||||||
path := fmt.Sprintf("/api/v1/transaction-type/%s", txnType)
|
path := fmt.Sprintf("/api/v1/transaction-type/%s", txnType)
|
||||||
err := ttc.client.Get(path, &resp)
|
err := ttc.client.Get(ctx, path, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ttc *TransactionTypeClient) List() (*models.TransactionListResponse, error) {
|
func (ttc *TransactionTypeClient) List(ctx context.Context) (*models.TransactionListResponse, error) {
|
||||||
var resp models.TransactionListResponse
|
var resp models.TransactionListResponse
|
||||||
err := ttc.client.Get("/api/v1/transaction-types", &resp)
|
err := ttc.client.Get(ctx, "/api/v1/transaction-types", &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ttc *TransactionTypeClient) Delete(txnType string) (*models.SuccessResponse, error) {
|
func (ttc *TransactionTypeClient) Delete(ctx context.Context, txnType string) (*models.SuccessResponse, error) {
|
||||||
var resp models.SuccessResponse
|
var resp models.SuccessResponse
|
||||||
path := fmt.Sprintf("/api/v1/transaction-type/%s", txnType)
|
path := fmt.Sprintf("/api/v1/transaction-type/%s", txnType)
|
||||||
err := ttc.client.Delete(path, &resp)
|
err := ttc.client.Delete(ctx, path, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user