Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions pkg/chains/solana/proto_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,29 @@ func ConvertGetAccountInfoOptsToProto(o *solana.GetAccountInfoOpts) *GetAccountI
}
}

func ConvertGetAccountInfoRequestFromProto(p *GetAccountInfoWithOptsRequest) (solana.GetAccountInfoRequest, error) {
if p == nil {
return solana.GetAccountInfoRequest{}, fmt.Errorf("nil GetAccountInfoWithOptsRequest")
}
addr, err := ConvertPublicKeyFromProto(p.GetAccount())
if err != nil {
return solana.GetAccountInfoRequest{}, err
}
return solana.GetAccountInfoRequest{
Account: addr,
Opts: ConvertGetAccountInfoOptsFromProto(p.GetOpts()),
IsExternal: p.GetIsExternal(),
}, nil
}

func ConvertGetAccountInfoRequestToProto(r solana.GetAccountInfoRequest) *GetAccountInfoWithOptsRequest {
return &GetAccountInfoWithOptsRequest{
Account: r.Account[:],
Opts: ConvertGetAccountInfoOptsToProto(r.Opts),
IsExternal: r.IsExternal,
}
}

func ConvertGetMultipleAccountsOptsFromProto(p *GetMultipleAccountsOpts) *solana.GetMultipleAccountsOpts {
if p == nil {
return nil
Expand Down Expand Up @@ -825,11 +848,11 @@ func ConvertGetTransactionRequestFromProto(p *GetTransactionRequest) (solana.Get
if err != nil {
return solana.GetTransactionRequest{}, err
}
return solana.GetTransactionRequest{Signature: sig}, nil
return solana.GetTransactionRequest{Signature: sig, IsExternal: p.GetIsExternal()}, nil
}

func ConvertGetTransactionRequestToProto(r solana.GetTransactionRequest) *GetTransactionRequest {
return &GetTransactionRequest{Signature: r.Signature[:]}
return &GetTransactionRequest{Signature: r.Signature[:], IsExternal: r.IsExternal}
}

func ConvertGetBalanceReplyFromProto(p *GetBalanceReply) *solana.GetBalanceReply {
Expand Down Expand Up @@ -996,8 +1019,9 @@ func ConvertGetMultipleAccountsRequestFromProto(p *GetMultipleAccountsWithOptsRe
}
accts, _ := ConvertPublicKeysFromProto(p.Accounts)
return &solana.GetMultipleAccountsRequest{
Accounts: accts,
Opts: ConvertGetMultipleAccountsOptsFromProto(p.Opts),
Accounts: accts,
Opts: ConvertGetMultipleAccountsOptsFromProto(p.Opts),
IsExternal: p.GetIsExternal(),
}
}

Expand All @@ -1006,8 +1030,9 @@ func ConvertGetMultipleAccountsRequestToProto(r *solana.GetMultipleAccountsReque
return nil
}
return &GetMultipleAccountsWithOptsRequest{
Accounts: ConvertPublicKeysToProto(r.Accounts),
Opts: ConvertGetMultipleAccountsOptsToProto(r.Opts),
Accounts: ConvertPublicKeysToProto(r.Accounts),
Opts: ConvertGetMultipleAccountsOptsToProto(r.Opts),
IsExternal: r.IsExternal,
}
}

Expand Down Expand Up @@ -1150,6 +1175,7 @@ func ConvertSimulateTXRequestFromProto(p *SimulateTXRequest) (solana.SimulateTXR
Receiver: recv,
EncodedTransaction: p.EncodedTransaction,
Opts: ConvertSimulateTXOptsFromProto(p.Opts),
IsExternal: p.GetIsExternal(),
}, nil
}

Expand All @@ -1158,6 +1184,7 @@ func ConvertSimulateTXRequestToProto(r solana.SimulateTXRequest) *SimulateTXRequ
Receiver: r.Receiver[:],
EncodedTransaction: r.EncodedTransaction,
Opts: ConvertSimulateTXOptsToProto(r.Opts),
IsExternal: r.IsExternal,
}
}

Expand Down
67 changes: 67 additions & 0 deletions pkg/chains/solana/proto_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,73 @@ func TestGetSignatureStatusesConverters(t *testing.T) {
require.Equal(t, conv.ConfirmationStatusType_CONFIRMATION_STATUS_TYPE_CONFIRMED, rep2.Results[0].ConfirmationStatus)
}

func TestExternalRequestProtoRoundTrip(t *testing.T) {
t.Run("GetAccountInfoRequest", func(t *testing.T) {
pk := typesolana.PublicKey{}
copy(pk[:], mkBytes(typesolana.PublicKeyLength, 0xAB))
d := typesolana.GetAccountInfoRequest{
Account: pk,
Opts: &typesolana.GetAccountInfoOpts{
Encoding: typesolana.EncodingBase64,
Commitment: typesolana.CommitmentFinalized,
},
IsExternal: true,
}
pb := conv.ConvertGetAccountInfoRequestToProto(d)
got, err := conv.ConvertGetAccountInfoRequestFromProto(pb)
require.NoError(t, err)
require.Equal(t, d, got)
})

t.Run("GetMultipleAccountsRequest", func(t *testing.T) {
d := &typesolana.GetMultipleAccountsRequest{
Accounts: []typesolana.PublicKey{
{1},
func() (pk typesolana.PublicKey) { copy(pk[:], mkBytes(typesolana.PublicKeyLength, 0xCD)); return pk }(),
},
Opts: &typesolana.GetMultipleAccountsOpts{
Encoding: typesolana.EncodingJSONParsed,
Commitment: typesolana.CommitmentProcessed,
},
IsExternal: true,
}
pb := conv.ConvertGetMultipleAccountsRequestToProto(d)
got := conv.ConvertGetMultipleAccountsRequestFromProto(pb)
require.Equal(t, d.Accounts[0], got.Accounts[0])
require.Equal(t, d.Accounts[1], got.Accounts[1])
require.Equal(t, d.IsExternal, got.IsExternal)
require.Equal(t, d.Opts, got.Opts)
})

t.Run("GetTransactionRequest", func(t *testing.T) {
var sig typesolana.Signature
copy(sig[:], mkBytes(typesolana.SignatureLength, 0xEF))
d := typesolana.GetTransactionRequest{Signature: sig, IsExternal: true}
pb := conv.ConvertGetTransactionRequestToProto(d)
got, err := conv.ConvertGetTransactionRequestFromProto(pb)
require.NoError(t, err)
require.Equal(t, d, got)
})

t.Run("SimulateTXRequest", func(t *testing.T) {
var recv typesolana.PublicKey
copy(recv[:], mkBytes(typesolana.PublicKeyLength, 0x11))
d := typesolana.SimulateTXRequest{
Receiver: recv,
EncodedTransaction: "txdata",
Opts: &typesolana.SimulateTXOpts{
SigVerify: true,
Commitment: typesolana.CommitmentConfirmed,
},
IsExternal: true,
}
pb := conv.ConvertSimulateTXRequestToProto(d)
got, err := conv.ConvertSimulateTXRequestFromProto(pb)
require.NoError(t, err)
require.Equal(t, d, got)
})
}

func TestErrorJoinBehavior_PublicKeys(t *testing.T) {
in := [][]byte{
mkBytes(typesolana.PublicKeyLength-1, 0x01),
Expand Down
58 changes: 49 additions & 9 deletions pkg/chains/solana/solana.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/chains/solana/solana.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ message GetAccountInfoWithOptsReply {
message GetAccountInfoWithOptsRequest {
bytes account = 1; // 32-byte Pubkey
GetAccountInfoOpts opts = 2;
bool is_external = 3; // if true, limits like response size limit may be applied
}

// Reply for GetBalance.
Expand Down Expand Up @@ -172,6 +173,7 @@ message GetMultipleAccountsWithOptsReply {
message GetMultipleAccountsWithOptsRequest {
repeated bytes accounts = 1; // list of 32-byte Pubkeys
GetMultipleAccountsOpts opts = 2;
bool is_external = 3; // if true, limits like response size limit may be applied
}

// Reply for GetSignatureStatuses.
Expand Down Expand Up @@ -304,6 +306,7 @@ message GetTransactionReply {
// GetTransaction request.
message GetTransactionRequest {
bytes signature = 1; // 64-byte signature
bool is_external = 2; // if true, limits like response size limit may be applied
}

// RPC read context.
Expand Down Expand Up @@ -332,6 +335,7 @@ message SimulateTXRequest {
bytes receiver = 1; // 32-byte program id (target)
string encoded_transaction = 2; // base64/base58 tx
SimulateTXOpts opts = 3;
bool is_external = 4; // if true, limits like response size limit may be applied
}

// Accounts to return during simulation.
Expand Down
Loading
Loading