Skip to content

Commit

Permalink
Add maxSupportedTransactionVersion to getBlock RPC (#103)
Browse files Browse the repository at this point in the history
* Add maxSupportedTransactionVersion to getBlock RPC

* Fix response base64 tx on test case

* Handle tx version dynamic type

* MaxSupportedTransactionVersion param full name
  • Loading branch information
thiagosantana-mb authored Sep 30, 2022
1 parent b8c054d commit f805c11
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
10 changes: 6 additions & 4 deletions rpc/get_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ const (
type GetBlockTransaction struct {
Transaction any `json:"transaction"`
Meta *TransactionMeta `json:"meta"`
Version any `json:"version"`
}

type GetBlockConfig struct {
Encoding GetBlockConfigEncoding `json:"encoding,omitempty"` // default: "json"
TransactionDetails GetBlockConfigTransactionDetails `json:"transactionDetails,omitempty"` // default: "full", either "full", "signatures", "none"
Rewards *bool `json:"rewards,omitempty"` // default: true
Commitment Commitment `json:"commitment,omitempty"` // "processed" is not supported
Encoding GetBlockConfigEncoding `json:"encoding,omitempty"` // default: "json"
TransactionDetails GetBlockConfigTransactionDetails `json:"transactionDetails,omitempty"` // default: "full", either "full", "signatures", "none"
Rewards *bool `json:"rewards,omitempty"` // default: true
Commitment Commitment `json:"commitment,omitempty"` // "processed" is not supported
MaxSupportedTransactionVersion *uint8 `json:"maxSupportedTransactionVersion,omitempty"` // default: nil legacy only
}

type GetBlockConfigEncoding string
Expand Down
62 changes: 62 additions & 0 deletions rpc/get_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,68 @@ func TestGetBlock(t *testing.T) {
},
ExpectedError: nil,
},
{
RequestBody: `{"jsonrpc":"2.0", "id":1, "method":"getBlock", "params":[33, {"encoding": "base64", "rewards": false, "maxSupportedTransactionVersion": 0}]}`,
ResponseBody: `{"jsonrpc":"2.0","result":{"blockHeight":33,"blockTime":1631803928,"blockhash":"HUonDijNaSHAPobKtAkg1ewJjy2wECpynbCq5wQ5dkCT","parentSlot":32,"previousBlockhash":"CXjZvhmFVa4ATW8Qq7XSXJFmB25aEqfHiEbCieujPd9q","transactions":[{"meta":{"err":null,"fee":10000,"innerInstructions":[],"logMessages":["Program Vote111111111111111111111111111111111111111 invoke [1]","Program Vote111111111111111111111111111111111111111 success"],"postBalances":[499999835001,1000000000000000,143487360,1169280,1],"postTokenBalances":[],"preBalances":[499999845001,1000000000000000,143487360,1169280,1],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"transaction":["AQiClQkvASAMI63iTE4VCNKpvDttDlM70bXlosqCRJ4kPeiPcPmIwW4AFNFTjmil/X1BSQJV6yUnXdQ+1+KSlAKAAQACBNcUkx66ahmo9NxsAZr/Jk9fv2jFoo7gs7mHVc451knTB0TvGBo/9u4tBgYjoLxl6Y29BFXLmb1J7Q+3GgPKqJ8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ3pq+XM5t6yI0YkskERvUAAjCSZvYuU8EYJEmCAAAAc4JUQCBBCFja0HaW7x24Mm7k1W45VWHvtEvczqYmigABAwQBAAACDQAAAAC4J9QJAAAAAP4A","base64"], "version": "legacy"}]},"id":1}`,
RpcCall: func(rc RpcClient) (any, error) {
return rc.GetBlockWithConfig(
context.TODO(),
33,
GetBlockConfig{
Encoding: GetBlockConfigEncodingBase64,
Rewards: pointer.Get[bool](false),
MaxSupportedTransactionVersion: pointer.Get[uint8](0),
},
)
},
ExpectedResponse: JsonRpcResponse[GetBlock]{
JsonRpc: "2.0",
Id: 1,
Error: nil,
Result: GetBlock{
ParentSlot: 32,
BlockHeight: pointer.Get[int64](33),
BlockTime: pointer.Get[int64](1631803928),
PreviousBlockhash: "CXjZvhmFVa4ATW8Qq7XSXJFmB25aEqfHiEbCieujPd9q",
Blockhash: "HUonDijNaSHAPobKtAkg1ewJjy2wECpynbCq5wQ5dkCT",
Transactions: []GetBlockTransaction{
{
Meta: &TransactionMeta{
Err: nil,
Fee: 10000,
PreBalances: []int64{
499999845001,
1000000000000000,
143487360,
1169280,
1,
},
PostBalances: []int64{
499999835001,
1000000000000000,
143487360,
1169280,
1,
},
PreTokenBalances: []TransactionMetaTokenBalance{},
PostTokenBalances: []TransactionMetaTokenBalance{},
LogMessages: []string{
"Program Vote111111111111111111111111111111111111111 invoke [1]",
"Program Vote111111111111111111111111111111111111111 success",
},
InnerInstructions: []TransactionMetaInnerInstruction{},
},
Transaction: []any{
"AQiClQkvASAMI63iTE4VCNKpvDttDlM70bXlosqCRJ4kPeiPcPmIwW4AFNFTjmil/X1BSQJV6yUnXdQ+1+KSlAKAAQACBNcUkx66ahmo9NxsAZr/Jk9fv2jFoo7gs7mHVc451knTB0TvGBo/9u4tBgYjoLxl6Y29BFXLmb1J7Q+3GgPKqJ8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ3pq+XM5t6yI0YkskERvUAAjCSZvYuU8EYJEmCAAAAc4JUQCBBCFja0HaW7x24Mm7k1W45VWHvtEvczqYmigABAwQBAAACDQAAAAC4J9QJAAAAAP4A",
"base64",
},
Version: "legacy",
},
},
},
},
ExpectedError: nil,
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
Expand Down

0 comments on commit f805c11

Please sign in to comment.