Document fire-and-forget transaction mode
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.
This commit is contained in:
@@ -2,47 +2,50 @@
|
||||
//
|
||||
// All API methods require a context.Context parameter for timeout and cancellation control.
|
||||
//
|
||||
// Example usage:
|
||||
// Example — fire and forget (most use cases):
|
||||
//
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "context"
|
||||
// "fmt"
|
||||
// "log"
|
||||
// "time"
|
||||
//
|
||||
// "git.dragonchain.com/dragonchain/prime-sdk-go"
|
||||
// "git.dragonchain.com/dragonchain/prime-sdk-go/models"
|
||||
// client := sdk.NewDragonchainSDK(
|
||||
// "your-public-id",
|
||||
// "your-auth-key-id",
|
||||
// "your-auth-key",
|
||||
// "https://your-dragonchain-endpoint.com",
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
// 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()
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// // Check system health
|
||||
// if err := client.System.Health(ctx); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// Example — wait for block inclusion (interchain / Daria):
|
||||
//
|
||||
// // Create a transaction
|
||||
// txn := &models.TransactionCreateRequest{
|
||||
// TxnType: "my-transaction-type",
|
||||
// Payload: map[string]interface{}{"message": "Hello Dragonchain"},
|
||||
// }
|
||||
// resp, err := client.Transaction.Create(ctx, &models.TransactionCreateRequest{
|
||||
// TxnType: "my-transaction-type",
|
||||
// Payload: `{"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 {
|
||||
// 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user