From 9ae0236f45de50354b53f3c914e545a61fb167f4 Mon Sep 17 00:00:00 2001 From: ilija Date: Mon, 23 Dec 2024 22:45:06 +0100 Subject: [PATCH] Fix nil idlType handling and update test IDL names --- pkg/solana/chainreader/batch.go | 1 - pkg/solana/chainreader/chain_reader.go | 7 ++++++- pkg/solana/chainreader/chain_reader_test.go | 8 ++++---- pkg/solana/codec/anchoridl.go | 5 +++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/solana/chainreader/batch.go b/pkg/solana/chainreader/batch.go index 43e4971b9..d5990601d 100644 --- a/pkg/solana/chainreader/batch.go +++ b/pkg/solana/chainreader/batch.go @@ -77,7 +77,6 @@ func doMethodBatchCall(ctx context.Context, client MultipleAccountGetter, bindin results[idx].err, binding.Decode(ctx, data[idx], results[idx].returnVal), ) - continue } diff --git a/pkg/solana/chainreader/chain_reader.go b/pkg/solana/chainreader/chain_reader.go index 706db02b0..9b2c4bf36 100644 --- a/pkg/solana/chainreader/chain_reader.go +++ b/pkg/solana/chainreader/chain_reader.go @@ -294,7 +294,12 @@ type accountIDLTypes struct { } func (s *SolanaChainReaderService) addAccountRead(namespace string, itemType string, idl codec.IDL, idlType codec.IdlTypeDef, readDefinition config.ReadDefinition) error { - if err := s.addCodecDef(true, namespace, itemType, codec.ChainConfigTypeAccountDef, idl, idlType, readDefinition.InputModifications); err != nil { + inputAccountIDLDef := codec.NilIdlTypeDefTy + // TODO: + // if hasPDA{ + // inputAccountIDLDef = pdaType + // } + if err := s.addCodecDef(true, namespace, itemType, codec.ChainConfigTypeAccountDef, idl, inputAccountIDLDef, readDefinition.InputModifications); err != nil { return err } diff --git a/pkg/solana/chainreader/chain_reader_test.go b/pkg/solana/chainreader/chain_reader_test.go index 357332851..f44f9e9a5 100644 --- a/pkg/solana/chainreader/chain_reader_test.go +++ b/pkg/solana/chainreader/chain_reader_test.go @@ -454,7 +454,7 @@ func (r *chainReaderInterfaceTester) Setup(t *testing.T) { ReadType: config.Account, OutputModifications: codeccommon.ModifiersConfig{ &codeccommon.AddressBytesToStringModifierConfig{ - Fields: []string{"Accountstruct.Accountstr"}, + Fields: []string{"AccountStruct.AccountStr"}, }, &codeccommon.HardCodeModifierConfig{OffChainValues: map[string]any{"ExtraField": AnyExtraValue}}, }, @@ -810,7 +810,7 @@ const ( {"name": "nestedStaticStruct","type": {"defined": "MidLevelStaticStruct"}}, {"name": "oracleID","type": "u8"}, {"name": "oracleIDs","type": {"array": ["u8",32]}}, - {"name": "accountstruct","type": {"defined": "accountstruct"}}, + {"name": "accountStruct","type": {"defined": "accountStruct"}}, {"name": "accounts","type": {"vec": "bytes"}} ] @@ -818,12 +818,12 @@ const ( }` accountStructIDL = `{ - "name": "accountstruct", + "name": "accountStruct", "type": { "kind": "struct", "fields": [ {"name": "account", "type": "bytes"}, - {"name": "accountstr", "type": {"array": ["u8",32]}} + {"name": "accountStr", "type": {"array": ["u8",32]}} ] } }` diff --git a/pkg/solana/codec/anchoridl.go b/pkg/solana/codec/anchoridl.go index e54710c5c..3fc296e97 100644 --- a/pkg/solana/codec/anchoridl.go +++ b/pkg/solana/codec/anchoridl.go @@ -312,6 +312,11 @@ type IdlTypeDefTyEnum struct { Variants IdlEnumVariantSlice `json:"variants,omitempty"` } +var NilIdlTypeDefTy = IdlTypeDef{Type: IdlTypeDefTy{ + Kind: "struct", + Fields: &IdlTypeDefStruct{}, +}} + type IdlTypeDefTy struct { Kind IdlTypeDefTyKind `json:"kind"`