From 08bc9afad766ad456295163564aa4c4c8f1dcf54 Mon Sep 17 00:00:00 2001 From: yihau Date: Sat, 13 Apr 2024 18:28:22 +0800 Subject: [PATCH] add UnitConsumed to simulateTransaction RPC method --- client/rpc_simulate_transaction.go | 18 ++++++++++-------- client/rpc_simulate_transaction_test.go | 3 +++ rpc/simulate_transaction.go | 9 +++++---- rpc/simulate_transaction_test.go | 2 ++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/client/rpc_simulate_transaction.go b/client/rpc_simulate_transaction.go index 41f74f14..851ba5c2 100644 --- a/client/rpc_simulate_transaction.go +++ b/client/rpc_simulate_transaction.go @@ -10,10 +10,11 @@ import ( ) type SimulateTransaction struct { - Err any - Logs []string - Accounts []*AccountInfo - ReturnData *ReturnData + Err any + Logs []string + Accounts []*AccountInfo + ReturnData *ReturnData + UnitConsumed *uint64 } type SimulateTransactionConfig struct { @@ -135,10 +136,11 @@ func convertSimulateTransaction(v rpc.ValueWithContext[rpc.SimulateTransactionVa } return SimulateTransaction{ - Err: v.Value.Err, - Logs: v.Value.Logs, - Accounts: accountInfos, - ReturnData: returnData, + Err: v.Value.Err, + Logs: v.Value.Logs, + Accounts: accountInfos, + ReturnData: returnData, + UnitConsumed: v.Value.UnitConsumed, }, nil } diff --git a/client/rpc_simulate_transaction_test.go b/client/rpc_simulate_transaction_test.go index fca71204..807dd064 100644 --- a/client/rpc_simulate_transaction_test.go +++ b/client/rpc_simulate_transaction_test.go @@ -6,6 +6,7 @@ import ( "github.com/blocto/solana-go-sdk/common" "github.com/blocto/solana-go-sdk/internal/client_test" + "github.com/blocto/solana-go-sdk/pkg/pointer" "github.com/blocto/solana-go-sdk/rpc" ) @@ -36,6 +37,7 @@ func TestClient_SimulateTransaction(t *testing.T) { ProgramId: common.PublicKeyFromString("35HSbe2xiLfid5QJeETGnUsGhkAiJWRKPrEGdQQ5xXrP"), Data: []byte{1, 2, 3, 4, 5}, }, + UnitConsumed: pointer.Get[uint64](185), }, ExpectedError: nil, }, @@ -75,6 +77,7 @@ func TestClient_SimulateTransactionAndContext(t *testing.T) { ProgramId: common.PublicKeyFromString("35HSbe2xiLfid5QJeETGnUsGhkAiJWRKPrEGdQQ5xXrP"), Data: []byte{1, 2, 3, 4, 5}, }, + UnitConsumed: pointer.Get[uint64](185), }, }, ExpectedError: nil, diff --git a/rpc/simulate_transaction.go b/rpc/simulate_transaction.go index 0ec548ff..38153493 100644 --- a/rpc/simulate_transaction.go +++ b/rpc/simulate_transaction.go @@ -10,10 +10,11 @@ type SimulateTransaction ValueWithContext[SimulateTransactionValue] // SimulateTransactionValue is a part of SimulateTransactionResponseResult type SimulateTransactionValue struct { - Err any `json:"err"` - Logs []string `json:"logs,omitempty"` - Accounts []*AccountInfo `json:"accounts,omitempty"` - ReturnData *ReturnData `json:"returnData,omitempty"` + Err any `json:"err"` + Logs []string `json:"logs,omitempty"` + Accounts []*AccountInfo `json:"accounts,omitempty"` + ReturnData *ReturnData `json:"returnData,omitempty"` + UnitConsumed *uint64 `json:"unitsConsumed,omitempty"` } type SimulateTransactionConfig struct { diff --git a/rpc/simulate_transaction_test.go b/rpc/simulate_transaction_test.go index 7f063ad4..71c503a2 100644 --- a/rpc/simulate_transaction_test.go +++ b/rpc/simulate_transaction_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/blocto/solana-go-sdk/internal/client_test" + "github.com/blocto/solana-go-sdk/pkg/pointer" ) func TestSimulateTransaction(t *testing.T) { @@ -207,6 +208,7 @@ func TestSimulateTransaction(t *testing.T) { ProgramId: "35HSbe2xiLfid5QJeETGnUsGhkAiJWRKPrEGdQQ5xXrP", Data: []any{"AQIDBAU=", "base64"}, }, + UnitConsumed: pointer.Get[uint64](185), }, }, },