Enable request timeout and cancellation control by adding context.Context as the first parameter to all SDK API methods. This allows users to: - Set per-request timeouts - Cancel in-flight requests - Pass request-scoped values
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package transaction
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/client"
|
|
"git.dragonchain.com/dragonchain/dragonchain-prime-sdk-go/models"
|
|
)
|
|
|
|
type TransactionClient struct {
|
|
client *client.Client
|
|
}
|
|
|
|
func NewTransactionClient(c *client.Client) *TransactionClient {
|
|
return &TransactionClient{client: c}
|
|
}
|
|
|
|
func (tc *TransactionClient) Create(ctx context.Context, req *models.TransactionCreateRequest) (*models.TransactionCreateResponse, error) {
|
|
var resp models.TransactionCreateResponse
|
|
err := tc.client.Post(ctx, "/api/v1/transaction", models.ContentTypeJSON, req, &resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (tc *TransactionClient) CreateBulk(ctx context.Context, req *models.TransactionBulkRequest) (*models.TransactionBulkResponse, error) {
|
|
var resp models.TransactionBulkResponse
|
|
err := tc.client.Post(ctx, "/api/v1/transaction/bulk", models.ContentTypeJSON, req, &resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (tc *TransactionClient) Get(ctx context.Context, transactionID string) (*models.Transaction, error) {
|
|
var resp models.Transaction
|
|
path := fmt.Sprintf("/api/v1/transaction/%s", 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 {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|