Skip to content

Commit b36c9bc

Browse files
committed
add field to mark requests as external for solana service
1 parent f60f14b commit b36c9bc

9 files changed

Lines changed: 258 additions & 28 deletions

File tree

pkg/chains/solana/proto_helpers.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,29 @@ func ConvertGetAccountInfoOptsToProto(o *solana.GetAccountInfoOpts) *GetAccountI
358358
}
359359
}
360360

361+
func ConvertGetAccountInfoRequestFromProto(p *GetAccountInfoWithOptsRequest) (solana.GetAccountInfoRequest, error) {
362+
if p == nil {
363+
return solana.GetAccountInfoRequest{}, fmt.Errorf("nil GetAccountInfoWithOptsRequest")
364+
}
365+
addr, err := ConvertPublicKeyFromProto(p.GetAccount())
366+
if err != nil {
367+
return solana.GetAccountInfoRequest{}, err
368+
}
369+
return solana.GetAccountInfoRequest{
370+
Account: addr,
371+
Opts: ConvertGetAccountInfoOptsFromProto(p.GetOpts()),
372+
IsExternal: p.GetIsExternal(),
373+
}, nil
374+
}
375+
376+
func ConvertGetAccountInfoRequestToProto(r solana.GetAccountInfoRequest) *GetAccountInfoWithOptsRequest {
377+
return &GetAccountInfoWithOptsRequest{
378+
Account: r.Account[:],
379+
Opts: ConvertGetAccountInfoOptsToProto(r.Opts),
380+
IsExternal: r.IsExternal,
381+
}
382+
}
383+
361384
func ConvertGetMultipleAccountsOptsFromProto(p *GetMultipleAccountsOpts) *solana.GetMultipleAccountsOpts {
362385
if p == nil {
363386
return nil
@@ -825,11 +848,11 @@ func ConvertGetTransactionRequestFromProto(p *GetTransactionRequest) (solana.Get
825848
if err != nil {
826849
return solana.GetTransactionRequest{}, err
827850
}
828-
return solana.GetTransactionRequest{Signature: sig}, nil
851+
return solana.GetTransactionRequest{Signature: sig, IsExternal: p.GetIsExternal()}, nil
829852
}
830853

831854
func ConvertGetTransactionRequestToProto(r solana.GetTransactionRequest) *GetTransactionRequest {
832-
return &GetTransactionRequest{Signature: r.Signature[:]}
855+
return &GetTransactionRequest{Signature: r.Signature[:], IsExternal: r.IsExternal}
833856
}
834857

835858
func ConvertGetBalanceReplyFromProto(p *GetBalanceReply) *solana.GetBalanceReply {
@@ -996,8 +1019,9 @@ func ConvertGetMultipleAccountsRequestFromProto(p *GetMultipleAccountsWithOptsRe
9961019
}
9971020
accts, _ := ConvertPublicKeysFromProto(p.Accounts)
9981021
return &solana.GetMultipleAccountsRequest{
999-
Accounts: accts,
1000-
Opts: ConvertGetMultipleAccountsOptsFromProto(p.Opts),
1022+
Accounts: accts,
1023+
Opts: ConvertGetMultipleAccountsOptsFromProto(p.Opts),
1024+
IsExternal: p.GetIsExternal(),
10011025
}
10021026
}
10031027

@@ -1006,8 +1030,9 @@ func ConvertGetMultipleAccountsRequestToProto(r *solana.GetMultipleAccountsReque
10061030
return nil
10071031
}
10081032
return &GetMultipleAccountsWithOptsRequest{
1009-
Accounts: ConvertPublicKeysToProto(r.Accounts),
1010-
Opts: ConvertGetMultipleAccountsOptsToProto(r.Opts),
1033+
Accounts: ConvertPublicKeysToProto(r.Accounts),
1034+
Opts: ConvertGetMultipleAccountsOptsToProto(r.Opts),
1035+
IsExternal: r.IsExternal,
10111036
}
10121037
}
10131038

@@ -1150,6 +1175,7 @@ func ConvertSimulateTXRequestFromProto(p *SimulateTXRequest) (solana.SimulateTXR
11501175
Receiver: recv,
11511176
EncodedTransaction: p.EncodedTransaction,
11521177
Opts: ConvertSimulateTXOptsFromProto(p.Opts),
1178+
IsExternal: p.GetIsExternal(),
11531179
}, nil
11541180
}
11551181

@@ -1158,6 +1184,7 @@ func ConvertSimulateTXRequestToProto(r solana.SimulateTXRequest) *SimulateTXRequ
11581184
Receiver: r.Receiver[:],
11591185
EncodedTransaction: r.EncodedTransaction,
11601186
Opts: ConvertSimulateTXOptsToProto(r.Opts),
1187+
IsExternal: r.IsExternal,
11611188
}
11621189
}
11631190

pkg/chains/solana/proto_helpers_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,73 @@ func TestGetSignatureStatusesConverters(t *testing.T) {
386386
require.Equal(t, conv.ConfirmationStatusType_CONFIRMATION_STATUS_TYPE_CONFIRMED, rep2.Results[0].ConfirmationStatus)
387387
}
388388

389+
func TestExternalRequestProtoRoundTrip(t *testing.T) {
390+
t.Run("GetAccountInfoRequest", func(t *testing.T) {
391+
pk := typesolana.PublicKey{}
392+
copy(pk[:], mkBytes(typesolana.PublicKeyLength, 0xAB))
393+
d := typesolana.GetAccountInfoRequest{
394+
Account: pk,
395+
Opts: &typesolana.GetAccountInfoOpts{
396+
Encoding: typesolana.EncodingBase64,
397+
Commitment: typesolana.CommitmentFinalized,
398+
},
399+
IsExternal: true,
400+
}
401+
pb := conv.ConvertGetAccountInfoRequestToProto(d)
402+
got, err := conv.ConvertGetAccountInfoRequestFromProto(pb)
403+
require.NoError(t, err)
404+
require.Equal(t, d, got)
405+
})
406+
407+
t.Run("GetMultipleAccountsRequest", func(t *testing.T) {
408+
d := &typesolana.GetMultipleAccountsRequest{
409+
Accounts: []typesolana.PublicKey{
410+
{1},
411+
func() (pk typesolana.PublicKey) { copy(pk[:], mkBytes(typesolana.PublicKeyLength, 0xCD)); return pk }(),
412+
},
413+
Opts: &typesolana.GetMultipleAccountsOpts{
414+
Encoding: typesolana.EncodingJSONParsed,
415+
Commitment: typesolana.CommitmentProcessed,
416+
},
417+
IsExternal: true,
418+
}
419+
pb := conv.ConvertGetMultipleAccountsRequestToProto(d)
420+
got := conv.ConvertGetMultipleAccountsRequestFromProto(pb)
421+
require.Equal(t, d.Accounts[0], got.Accounts[0])
422+
require.Equal(t, d.Accounts[1], got.Accounts[1])
423+
require.Equal(t, d.IsExternal, got.IsExternal)
424+
require.Equal(t, d.Opts, got.Opts)
425+
})
426+
427+
t.Run("GetTransactionRequest", func(t *testing.T) {
428+
var sig typesolana.Signature
429+
copy(sig[:], mkBytes(typesolana.SignatureLength, 0xEF))
430+
d := typesolana.GetTransactionRequest{Signature: sig, IsExternal: true}
431+
pb := conv.ConvertGetTransactionRequestToProto(d)
432+
got, err := conv.ConvertGetTransactionRequestFromProto(pb)
433+
require.NoError(t, err)
434+
require.Equal(t, d, got)
435+
})
436+
437+
t.Run("SimulateTXRequest", func(t *testing.T) {
438+
var recv typesolana.PublicKey
439+
copy(recv[:], mkBytes(typesolana.PublicKeyLength, 0x11))
440+
d := typesolana.SimulateTXRequest{
441+
Receiver: recv,
442+
EncodedTransaction: "txdata",
443+
Opts: &typesolana.SimulateTXOpts{
444+
SigVerify: true,
445+
Commitment: typesolana.CommitmentConfirmed,
446+
},
447+
IsExternal: true,
448+
}
449+
pb := conv.ConvertSimulateTXRequestToProto(d)
450+
got, err := conv.ConvertSimulateTXRequestFromProto(pb)
451+
require.NoError(t, err)
452+
require.Equal(t, d, got)
453+
})
454+
}
455+
389456
func TestErrorJoinBehavior_PublicKeys(t *testing.T) {
390457
in := [][]byte{
391458
mkBytes(typesolana.PublicKeyLength-1, 0x01),

pkg/chains/solana/solana.pb.go

Lines changed: 48 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/chains/solana/solana.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ message GetAccountInfoWithOptsReply {
107107
message GetAccountInfoWithOptsRequest {
108108
bytes account = 1; // 32-byte Pubkey
109109
GetAccountInfoOpts opts = 2;
110+
bool is_external = 3;
110111
}
111112

112113
// Reply for GetBalance.
@@ -172,6 +173,7 @@ message GetMultipleAccountsWithOptsReply {
172173
message GetMultipleAccountsWithOptsRequest {
173174
repeated bytes accounts = 1; // list of 32-byte Pubkeys
174175
GetMultipleAccountsOpts opts = 2;
176+
bool is_external = 3;
175177
}
176178

177179
// Reply for GetSignatureStatuses.
@@ -304,6 +306,7 @@ message GetTransactionReply {
304306
// GetTransaction request.
305307
message GetTransactionRequest {
306308
bytes signature = 1; // 64-byte signature
309+
bool is_external = 2;
307310
}
308311

309312
// RPC read context.
@@ -332,6 +335,7 @@ message SimulateTXRequest {
332335
bytes receiver = 1; // 32-byte program id (target)
333336
string encoded_transaction = 2; // base64/base58 tx
334337
SimulateTXOpts opts = 3;
338+
bool is_external = 4;
335339
}
336340

337341
// Accounts to return during simulation.

0 commit comments

Comments
 (0)