Add Remote field to SmartContractCreateRequest and GrpcConnectionInfo struct to SmartContract model for remote smart contract execution via gRPC.
56 lines
1.5 KiB
Go
Executable File
56 lines
1.5 KiB
Go
Executable File
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
|
|
}
|