proof-measure is a separate, public, unauthenticated Dragonchain service. Adds: - client.UnauthenticatedClient: HMAC-free transport mirroring Client's marshal/decode/error handling. - proofmeasure.ProofMeasureClient: GetSecurity / Report / Health, default base URL https://proof-measure.dragonchain.com; standalone + a DragonchainSDK.ProofMeasure handle. - models for SecurityResult/RawMeasure/ReportRequest/TransactionReport/etc (decimals as strings, timestamps int64). - httptest unit tests.
116 lines
4.4 KiB
Go
Executable File
116 lines
4.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 (
|
|
"net/http"
|
|
|
|
"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/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 {
|
|
client *client.Client
|
|
Transaction *transaction.TransactionClient
|
|
TransactionType *transactiontype.TransactionTypeClient
|
|
Contract *contract.ContractClient
|
|
Block *block.BlockClient
|
|
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 {
|
|
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{
|
|
client: c,
|
|
Transaction: transaction.NewTransactionClient(c),
|
|
TransactionType: transactiontype.NewTransactionTypeClient(c),
|
|
Contract: contract.NewContractClient(c),
|
|
Block: block.NewBlockClient(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 {
|
|
return sdk.client
|
|
}
|