Add godoc to Create and CreateBulk explaining they return immediately without waiting for block inclusion. Update package-level example to show both fire-and-forget and wait-for-block patterns. Add Transaction Modes section to README with code examples.
99 lines
3.4 KiB
Go
Executable File
99 lines
3.4 KiB
Go
Executable File
// 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
|
|
|
|
import (
|
|
"git.dragonchain.com/dragonchain/prime-sdk-go/block"
|
|
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
|
"git.dragonchain.com/dragonchain/prime-sdk-go/contract"
|
|
"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 {
|
|
client *client.Client
|
|
Transaction *transaction.TransactionClient
|
|
TransactionType *transactiontype.TransactionTypeClient
|
|
Contract *contract.ContractClient
|
|
Block *block.BlockClient
|
|
System *system.SystemClient
|
|
}
|
|
|
|
// 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 {
|
|
c := client.NewClient(publicID, authKeyID, authKey, baseURL)
|
|
return &DragonchainSDK{
|
|
client: c,
|
|
Transaction: transaction.NewTransactionClient(c),
|
|
TransactionType: transactiontype.NewTransactionTypeClient(c),
|
|
Contract: contract.NewContractClient(c),
|
|
Block: block.NewBlockClient(c),
|
|
System: system.NewSystemClient(c),
|
|
}
|
|
}
|
|
|
|
// 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 {
|
|
return sdk.client
|
|
}
|