Compare commits
7 Commits
feature/co
...
v0.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
| bc2b622873 | |||
| d945029f33 | |||
| 621e359817 | |||
| 18ac756d44 | |||
| 4dabbcd23a | |||
| c3d6d017df | |||
| e15b205f9c |
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
57
README.md
Normal file → Executable file
57
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
|
||||||
@@ -19,8 +19,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"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() {
|
||||||
@@ -65,6 +65,57 @@ 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.
|
All API methods accept a `context.Context` as their first parameter for timeout and cancellation control.
|
||||||
|
|||||||
17
block/block.go
Normal file → Executable file
17
block/block.go
Normal file → Executable file
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"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 {
|
||||||
@@ -25,3 +25,16 @@ func (bc *BlockClient) Get(ctx context.Context, blockID string) (*models.Block,
|
|||||||
}
|
}
|
||||||
return &resp, nil
|
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 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|||||||
23
client/client.go
Normal file → Executable file
23
client/client.go
Normal file → Executable file
@@ -23,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,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
contract/contract.go
Normal file → Executable file
4
contract/contract.go
Normal file → Executable file
@@ -5,8 +5,8 @@ import (
|
|||||||
"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 {
|
||||||
|
|||||||
0
credentials/credentials.go
Normal file → Executable file
0
credentials/credentials.go
Normal file → Executable file
89
dragonchain.go
Normal file → Executable file
89
dragonchain.go
Normal file → Executable file
@@ -2,57 +2,62 @@
|
|||||||
//
|
//
|
||||||
// All API methods require a context.Context parameter for timeout and cancellation control.
|
// All API methods require a context.Context parameter for timeout and cancellation control.
|
||||||
//
|
//
|
||||||
// Example usage:
|
// Example — fire and forget (most use cases):
|
||||||
//
|
//
|
||||||
// package main
|
// client := sdk.NewDragonchainSDK(
|
||||||
//
|
// "your-public-id",
|
||||||
// import (
|
// "your-auth-key-id",
|
||||||
// "context"
|
// "your-auth-key",
|
||||||
// "fmt"
|
// "https://your-dragonchain-endpoint.com",
|
||||||
// "log"
|
|
||||||
// "time"
|
|
||||||
//
|
|
||||||
// "git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go"
|
|
||||||
// "git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
|
||||||
// )
|
// )
|
||||||
//
|
//
|
||||||
// func main() {
|
// ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
// client := sdk.NewDragonchainSDK(
|
// defer cancel()
|
||||||
// "your-public-id",
|
|
||||||
// "your-auth-key-id",
|
|
||||||
// "your-auth-key",
|
|
||||||
// "https://your-dragonchain-endpoint.com",
|
|
||||||
// )
|
|
||||||
//
|
//
|
||||||
// ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
// resp, err := client.Transaction.Create(ctx, &models.TransactionCreateRequest{
|
||||||
// defer cancel()
|
// 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.
|
||||||
//
|
//
|
||||||
// // Check system health
|
// Example — wait for block inclusion (interchain / Daria):
|
||||||
// if err := client.System.Health(ctx); err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
// // Create a transaction
|
// resp, err := client.Transaction.Create(ctx, &models.TransactionCreateRequest{
|
||||||
// txn := &models.TransactionCreateRequest{
|
// TxnType: "my-transaction-type",
|
||||||
// TxnType: "my-transaction-type",
|
// Payload: `{"message": "Hello Dragonchain"}`,
|
||||||
// Payload: map[string]interface{}{"message": "Hello Dragonchain"},
|
// })
|
||||||
// }
|
// if err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
// resp, err := client.Transaction.Create(ctx, txn)
|
// // 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 {
|
// if err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
// fmt.Printf("Created transaction: %s\n", resp.TransactionID)
|
// 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/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.
|
// DragonchainSDK is the main SDK client for interacting with Dragonchain nodes.
|
||||||
@@ -77,7 +82,15 @@ type DragonchainSDK struct {
|
|||||||
// Returns a configured SDK client ready to make API calls.
|
// Returns a configured SDK client ready to make API calls.
|
||||||
// All API methods on the returned client require a context.Context parameter.
|
// 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),
|
||||||
|
|||||||
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
|
||||||
|
|
||||||
|
|||||||
65
models/models.go
Normal file → Executable file
65
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 {
|
||||||
@@ -113,18 +121,23 @@ 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"`
|
Transactions []string `json:"transactions"`
|
||||||
PrevID string `json:"prev_id"`
|
Proof BlockProof `json:"proof"`
|
||||||
PrevProof string `json:"prev_proof"`
|
}
|
||||||
Transactions []string `json:"transactions"`
|
|
||||||
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,39 @@ 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"`
|
||||||
|
}
|
||||||
|
|||||||
4
system/system.go
Normal file → Executable file
4
system/system.go
Normal file → Executable file
@@ -3,8 +3,8 @@ package system
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"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 SystemClient struct {
|
type SystemClient struct {
|
||||||
|
|||||||
26
transaction/transaction.go
Normal file → Executable file
26
transaction/transaction.go
Normal file → Executable file
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"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 {
|
||||||
@@ -16,6 +16,10 @@ func NewTransactionClient(c *client.Client) *TransactionClient {
|
|||||||
return &TransactionClient{client: c}
|
return &TransactionClient{client: c}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
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(ctx, "/api/v1/transaction", models.ContentTypeJSON, req, &resp)
|
err := tc.client.Post(ctx, "/api/v1/transaction", models.ContentTypeJSON, req, &resp)
|
||||||
@@ -25,6 +29,10 @@ func (tc *TransactionClient) Create(ctx context.Context, req *models.Transaction
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
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(ctx, "/api/v1/transaction/bulk", models.ContentTypeJSON, req, &resp)
|
err := tc.client.Post(ctx, "/api/v1/transaction/bulk", models.ContentTypeJSON, req, &resp)
|
||||||
@@ -44,6 +52,20 @@ func (tc *TransactionClient) Get(ctx context.Context, transactionID string) (*mo
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInterchain traces a transaction to the validator (verification) blocks that
|
||||||
|
// validated its prime block and the public-chain interchain anchors those
|
||||||
|
// validator blocks were bundled into. If the transaction is still pending (not
|
||||||
|
// 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) {
|
func (tc *TransactionClient) List(ctx context.Context) (*models.ListTransactionsResponse, error) {
|
||||||
var resp models.ListTransactionsResponse
|
var resp models.ListTransactionsResponse
|
||||||
path := "/api/v1/transaction/"
|
path := "/api/v1/transaction/"
|
||||||
|
|||||||
4
transactiontype/transactiontype.go
Normal file → Executable file
4
transactiontype/transactiontype.go
Normal file → Executable file
@@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user