From 809f1add1dd8ceeb7f628872d2c231a1aef01fea Mon Sep 17 00:00:00 2001 From: ilija Date: Tue, 24 Dec 2024 17:58:57 +0100 Subject: [PATCH] Standardize var name 4 read mapping to genericName<>chainSpecificName --- .../relayinterface/chain_components_test.go | 38 ++++++++++------ .../chainreader/account_read_binding.go | 24 +++++----- pkg/solana/chainreader/chain_reader.go | 44 +++++++++---------- pkg/solana/chainreader/chain_reader_test.go | 20 ++++----- pkg/solana/chainreader/lookup.go | 38 +++++++--------- pkg/solana/codec/codec_entry.go | 30 ++++++------- pkg/solana/codec/codec_test.go | 2 +- pkg/solana/codec/decoder.go | 4 +- pkg/solana/codec/encoder.go | 4 +- pkg/solana/codec/solana.go | 16 +++---- pkg/solana/codec/types.go | 4 +- 11 files changed, 113 insertions(+), 111 deletions(-) diff --git a/integration-tests/relayinterface/chain_components_test.go b/integration-tests/relayinterface/chain_components_test.go index 95a7ceb24..047706035 100644 --- a/integration-tests/relayinterface/chain_components_test.go +++ b/integration-tests/relayinterface/chain_components_test.go @@ -6,6 +6,7 @@ package relayinterface import ( "context" "encoding/binary" + "encoding/json" "io" "os" "path/filepath" @@ -19,13 +20,14 @@ import ( "github.com/gagliardetto/solana-go/text" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink-common/pkg/codec" + commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec" "github.com/smartcontractkit/chainlink-common/pkg/logger" commontestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils" "github.com/smartcontractkit/chainlink-common/pkg/types" . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with . "github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink-solana/pkg/solana/codec" contract "github.com/smartcontractkit/chainlink-solana/contracts/generated/contract_reader_interface" "github.com/smartcontractkit/chainlink-solana/integration-tests/solclient" @@ -105,7 +107,7 @@ func RunChainComponentsInLoopSolanaTests[T TestingT[T]](t T, it ChainComponentsI func RunContractReaderSolanaTests[T TestingT[T]](t T, it *SolanaChainComponentsInterfaceTester[T]) { RunContractReaderInterfaceTests(t, it, false, true) - testCases := []Testcase[T]{} + var testCases []Testcase[T] RunTests(t, it, testCases) } @@ -113,7 +115,7 @@ func RunContractReaderSolanaTests[T TestingT[T]](t T, it *SolanaChainComponentsI func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfaceTester[T]) { RunContractReaderInterfaceTests(t, it, false, true) - testCases := []Testcase[T]{} + var testCases []Testcase[T] RunTests(t, it, testCases) } @@ -129,8 +131,8 @@ type SolanaChainComponentsInterfaceTesterHelper[T TestingT[T]] interface { type SolanaChainComponentsInterfaceTester[T TestingT[T]] struct { TestSelectionSupport - Helper SolanaChainComponentsInterfaceTesterHelper[T] - cr *chainreader.SolanaChainReaderService + Helper SolanaChainComponentsInterfaceTesterHelper[T] + cr *chainreader.SolanaChainReaderService contractReaderConfig config.ContractReader } @@ -140,30 +142,30 @@ func (it *SolanaChainComponentsInterfaceTester[T]) Setup(t T) { it.contractReaderConfig = config.ContractReader{ Namespaces: map[string]config.ChainContractReader{ AnyContractName: { - IDL: string(it.Helper.GetJSONEncodedIDL(t)), + IDL: mustUnmarshalIDL(t, string(it.Helper.GetJSONEncodedIDL(t))), Reads: map[string]config.ReadDefinition{ MethodReturningUint64: { ChainSpecificName: "DataAccount", ReadType: config.Account, - OutputModifications: codec.ModifiersConfig{ - &codec.PropertyExtractorConfig{FieldName: "U64Value"}, + OutputModifications: commoncodec.ModifiersConfig{ + &commoncodec.PropertyExtractorConfig{FieldName: "U64Value"}, }, }, MethodReturningUint64Slice: { ChainSpecificName: "DataAccount", - OutputModifications: codec.ModifiersConfig{ - &codec.PropertyExtractorConfig{FieldName: "U64Slice"}, + OutputModifications: commoncodec.ModifiersConfig{ + &commoncodec.PropertyExtractorConfig{FieldName: "U64Slice"}, }, }, }, }, AnySecondContractName: { - IDL: string(it.Helper.GetJSONEncodedIDL(t)), + IDL: mustUnmarshalIDL(t, string(it.Helper.GetJSONEncodedIDL(t))), Reads: map[string]config.ReadDefinition{ MethodReturningUint64: { ChainSpecificName: "DataAccount", - OutputModifications: codec.ModifiersConfig{ - &codec.PropertyExtractorConfig{FieldName: "U64Value"}, + OutputModifications: commoncodec.ModifiersConfig{ + &commoncodec.PropertyExtractorConfig{FieldName: "U64Value"}, }, }, }, @@ -414,3 +416,13 @@ func setupTestValidator(t *testing.T, upgradeAuthority string) (string, string) return client.SetupLocalSolNodeWithFlags(t, flags...) } + +func mustUnmarshalIDL[T TestingT[T]](t T, rawIDL string) codec.IDL { + var idl codec.IDL + if err := json.Unmarshal([]byte(rawIDL), &idl); err != nil { + t.Errorf("failed to unmarshal test IDL", err) + t.FailNow() + } + + return idl +} diff --git a/pkg/solana/chainreader/account_read_binding.go b/pkg/solana/chainreader/account_read_binding.go index c2cfaf6ff..826897369 100644 --- a/pkg/solana/chainreader/account_read_binding.go +++ b/pkg/solana/chainreader/account_read_binding.go @@ -11,21 +11,19 @@ import ( "github.com/smartcontractkit/chainlink-solana/pkg/solana/codec" ) -// accountReadBinding provides decoding and reading Solana Account data using a defined codec. The -// `idlAccount` refers to the account onChainName in the IDL for which the codec has a type mapping. +// accountReadBinding provides decoding and reading Solana Account data using a defined codec. type accountReadBinding struct { - namespace, onChainName, chainAgnosticName string - codec types.RemoteCodec - key solana.PublicKey - opts *rpc.GetAccountInfoOpts + namespace, genericName string + codec types.RemoteCodec + key solana.PublicKey + opts *rpc.GetAccountInfoOpts } -func newAccountReadBinding(namespace, onChainName, chainAgnosticName string, opts *rpc.GetAccountInfoOpts) *accountReadBinding { +func newAccountReadBinding(namespace, genericName string, opts *rpc.GetAccountInfoOpts) *accountReadBinding { return &accountReadBinding{ - namespace: namespace, - onChainName: onChainName, - chainAgnosticName: chainAgnosticName, - opts: opts, + namespace: namespace, + genericName: genericName, + opts: opts, } } @@ -44,9 +42,9 @@ func (b *accountReadBinding) GetAddress() solana.PublicKey { } func (b *accountReadBinding) CreateType(forEncoding bool) (any, error) { - return b.codec.CreateType(codec.WrapItemType(forEncoding, b.namespace, b.chainAgnosticName, codec.ChainConfigTypeAccountDef), forEncoding) + return b.codec.CreateType(codec.WrapItemType(forEncoding, b.namespace, b.genericName, codec.ChainConfigTypeAccountDef), forEncoding) } func (b *accountReadBinding) Decode(ctx context.Context, bts []byte, outVal any) error { - return b.codec.Decode(ctx, bts, outVal, codec.WrapItemType(false, b.namespace, b.chainAgnosticName, codec.ChainConfigTypeAccountDef)) + return b.codec.Decode(ctx, bts, outVal, codec.WrapItemType(false, b.namespace, b.genericName, codec.ChainConfigTypeAccountDef)) } diff --git a/pkg/solana/chainreader/chain_reader.go b/pkg/solana/chainreader/chain_reader.go index 0345ccc9a..aad6bec31 100644 --- a/pkg/solana/chainreader/chain_reader.go +++ b/pkg/solana/chainreader/chain_reader.go @@ -116,15 +116,15 @@ func (s *SolanaChainReaderService) GetLatestValue(ctx context.Context, readIdent s.wg.Add(1) defer s.wg.Done() - vals, ok := s.lookup.getContractForReadIdentifiers(readIdentifier) + values, ok := s.lookup.getContractForReadIdentifiers(readIdentifier) if !ok { return fmt.Errorf("%w: no contract for read identifier %s", types.ErrInvalidType, readIdentifier) } batch := []call{ { - ContractName: vals.contract, - ReadName: vals.name.onChainName, + ContractName: values.contract, + ReadName: values.genericName, Params: params, ReturnVal: returnVal, }, @@ -227,31 +227,31 @@ func (s *SolanaChainReaderService) CreateContractType(readIdentifier string, for return nil, fmt.Errorf("%w: no contract for read identifier", types.ErrInvalidConfig) } - return s.bindings.CreateType(values.contract, values.name.onChainName, forEncoding) + return s.bindings.CreateType(values.contract, values.genericName, forEncoding) } -func (s *SolanaChainReaderService) addCodecDef(forEncoding bool, namespace, chainAgnosticName string, readType codec.ChainConfigType, idl codec.IDL, idlDefinition interface{}, modCfg commoncodec.ModifiersConfig) error { +func (s *SolanaChainReaderService) addCodecDef(forEncoding bool, namespace, genericName string, readType codec.ChainConfigType, idl codec.IDL, idlDefinition interface{}, modCfg commoncodec.ModifiersConfig) error { mod, err := modCfg.ToModifier(codec.DecoderHooks...) if err != nil { return err } - cEntry, err := codec.CreateCodecEntry(idlDefinition, chainAgnosticName, idl, mod) + cEntry, err := codec.CreateCodecEntry(idlDefinition, genericName, idl, mod) if err != nil { return err } if forEncoding { - s.parsed.EncoderDefs[codec.WrapItemType(forEncoding, namespace, chainAgnosticName, readType)] = cEntry + s.parsed.EncoderDefs[codec.WrapItemType(forEncoding, namespace, genericName, readType)] = cEntry } else { - s.parsed.DecoderDefs[codec.WrapItemType(forEncoding, namespace, chainAgnosticName, readType)] = cEntry + s.parsed.DecoderDefs[codec.WrapItemType(forEncoding, namespace, genericName, readType)] = cEntry } return nil } func (s *SolanaChainReaderService) init(namespaces map[string]config.ChainContractReader) error { for namespace, nameSpaceDef := range namespaces { - for readName, read := range nameSpaceDef.Reads { + for genericName, read := range nameSpaceDef.Reads { injectAddressModifier(read.InputModifications, read.OutputModifications) idlDef, err := codec.FindDefinitionFromIDL(codec.ChainConfigTypeAccountDef, read.ChainSpecificName, nameSpaceDef.IDL) if err != nil { @@ -262,19 +262,20 @@ func (s *SolanaChainReaderService) init(namespaces map[string]config.ChainContra case config.Account: accountIDLDef, isOk := idlDef.(codec.IdlTypeDef) if !isOk { - return fmt.Errorf("unexpected type %T from IDL definition for account read: %q, with onchain onChainName: %q, of type: %q", accountIDLDef, readName, read.ChainSpecificName, read.ReadType) + return fmt.Errorf("unexpected type %T from IDL definition for account read: %q, with chainSpecificName: %q, of type: %q", accountIDLDef, genericName, read.ChainSpecificName, read.ReadType) } - if err = s.addAccountRead(namespace, readName, nameSpaceDef.IDL, accountIDLDef, read); err != nil { + if err = s.addAccountRead(namespace, genericName, nameSpaceDef.IDL, accountIDLDef, read); err != nil { return err } case config.Event: eventIDlDef, isOk := idlDef.(codec.IdlEvent) if !isOk { - return fmt.Errorf("unexpected type %T from IDL definition for log read: %q, with onchain onChainName: %q, of type: %q", eventIDlDef, readName, read.ChainSpecificName, read.ReadType) + return fmt.Errorf("unexpected type %T from IDL definition for log read: %q, with chainSpecificName: %q, of type: %q", eventIDlDef, genericName, read.ChainSpecificName, read.ReadType) } // TODO s.addLogRead() + return fmt.Errorf("implement me") default: - return fmt.Errorf("unexpected read type %q for: %q in namespace: %q", read.ReadType, readName, namespace) + return fmt.Errorf("unexpected read type %q for: %q in namespace: %q", read.ReadType, genericName, namespace) } } } @@ -282,30 +283,25 @@ func (s *SolanaChainReaderService) init(namespaces map[string]config.ChainContra return nil } -func (s *SolanaChainReaderService) addAccountRead(namespace string, itemType string, idl codec.IDL, idlType codec.IdlTypeDef, readDefinition config.ReadDefinition) error { +func (s *SolanaChainReaderService) addAccountRead(namespace string, genericName string, idl codec.IDL, idlType codec.IdlTypeDef, readDefinition config.ReadDefinition) error { inputAccountIDLDef := codec.NilIdlTypeDefTy // TODO: // if hasPDA{ // inputAccountIDLDef = pdaType // } - if err := s.addCodecDef(true, namespace, itemType, codec.ChainConfigTypeAccountDef, idl, inputAccountIDLDef, readDefinition.InputModifications); err != nil { + if err := s.addCodecDef(true, namespace, genericName, codec.ChainConfigTypeAccountDef, idl, inputAccountIDLDef, readDefinition.InputModifications); err != nil { return err } - if err := s.addCodecDef(false, namespace, itemType, codec.ChainConfigTypeAccountDef, idl, idlType, readDefinition.OutputModifications); err != nil { + if err := s.addCodecDef(false, namespace, genericName, codec.ChainConfigTypeAccountDef, idl, idlType, readDefinition.OutputModifications); err != nil { return err } - s.lookup.addReadNameForContract(namespace, namePair{ - onChainName: itemType, - genericName: idlType.Name, - }) + s.lookup.addReadNameForContract(namespace, genericName) - s.bindings.AddReadBinding(namespace, itemType, newAccountReadBinding( + s.bindings.AddReadBinding(namespace, genericName, newAccountReadBinding( namespace, - readDefinition.ChainSpecificName, - itemType, - // TODO codec is not created at this point, set codec for all bindings after init + genericName, createRPCOpts(readDefinition.RPCOpts), )) diff --git a/pkg/solana/chainreader/chain_reader_test.go b/pkg/solana/chainreader/chain_reader_test.go index 6d04f6d15..8b24a9c82 100644 --- a/pkg/solana/chainreader/chain_reader_test.go +++ b/pkg/solana/chainreader/chain_reader_test.go @@ -312,16 +312,6 @@ func newTestConfAndCodec(t *testing.T) (types.RemoteCodec, config.ContractReader return testCodec, conf } -func mustUnmarshalIDL(t *testing.T, rawIDL string) codec.IDL { - var idl codec.IDL - if err := json.Unmarshal([]byte(rawIDL), &idl); err != nil { - t.Logf("failed to unmarshal test IDL: %s", err.Error()) - t.FailNow() - } - - return idl -} - type modifiedStructWithNestedStruct struct { V uint8 InnerStruct testutils.ObjectRef1 @@ -939,3 +929,13 @@ func (s *skipEventsChainReader) QueryKey(_ context.Context, _ types.BoundContrac s.t.Skip("QueryKey is not yet supported in Solana") return nil, nil } + +func mustUnmarshalIDL(t *testing.T, rawIDL string) codec.IDL { + var idl codec.IDL + if err := json.Unmarshal([]byte(rawIDL), &idl); err != nil { + t.Logf("failed to unmarshal test IDL: %s", err.Error()) + t.FailNow() + } + + return idl +} diff --git a/pkg/solana/chainreader/lookup.go b/pkg/solana/chainreader/lookup.go index 5c7d06241..ccd7b44db 100644 --- a/pkg/solana/chainreader/lookup.go +++ b/pkg/solana/chainreader/lookup.go @@ -7,59 +7,55 @@ import ( ) type readValues struct { - address string - contract string - name namePair -} - -type namePair struct { - onChainName, genericName string + address string + contract string + genericName string } // lookup provides basic utilities for mapping a complete readIdentifier to // finite contract read information type lookup struct { mu sync.RWMutex - // contractReadNames maps a contract name to all available readNames (method, log, event, etc.) - contractReadNames map[string][]namePair + // contractReadNames maps a contract name to all available namePairs (method, log, event, etc.) + contractReadNames map[string][]string // readIdentifiers maps from a complete readIdentifier string to finite read data - // a readIdentifier is a combination of address, contract, and namePair as a concatenated string + // a readIdentifier is a combination of address, contract, and chainSpecificName as a concatenated string readIdentifiers map[string]readValues } func newLookup() *lookup { return &lookup{ - contractReadNames: make(map[string][]namePair), + contractReadNames: make(map[string][]string), readIdentifiers: make(map[string]readValues), } } -func (l *lookup) addReadNameForContract(contract string, name namePair) { +func (l *lookup) addReadNameForContract(contract string, genericName string) { l.mu.Lock() defer l.mu.Unlock() readNames, exists := l.contractReadNames[contract] if !exists { - readNames = []namePair{} + readNames = []string{} } - l.contractReadNames[contract] = append(readNames, name) + l.contractReadNames[contract] = append(readNames, genericName) } func (l *lookup) bindAddressForContract(contract, address string) { l.mu.Lock() defer l.mu.Unlock() - for _, namePair := range l.contractReadNames[contract] { + for _, genericName := range l.contractReadNames[contract] { readIdentifier := types.BoundContract{ Address: address, Name: contract, - }.ReadIdentifier(namePair.onChainName) + }.ReadIdentifier(genericName) l.readIdentifiers[readIdentifier] = readValues{ - address: address, - contract: contract, - name: namePair, + address: address, + contract: contract, + genericName: genericName, } } } @@ -68,11 +64,11 @@ func (l *lookup) unbindAddressForContract(contract, address string) { l.mu.Lock() defer l.mu.Unlock() - for _, namePair := range l.contractReadNames[contract] { + for _, genericName := range l.contractReadNames[contract] { readIdentifier := types.BoundContract{ Address: address, Name: contract, - }.ReadIdentifier(namePair.onChainName) + }.ReadIdentifier(genericName) delete(l.readIdentifiers, readIdentifier) } diff --git a/pkg/solana/codec/codec_entry.go b/pkg/solana/codec/codec_entry.go index 6342055b4..f22b05984 100644 --- a/pkg/solana/codec/codec_entry.go +++ b/pkg/solana/codec/codec_entry.go @@ -22,11 +22,11 @@ type Entry interface { type entry struct { // TODO this might not be needed in the end, it was handy to make tests simpler - offchainName string - onchainName string - reflectType reflect.Type - typeCodec commonencodings.TypeCodec - mod codec.Modifier + genericName string + chainSpecificName string + reflectType reflect.Type + typeCodec commonencodings.TypeCodec + mod codec.Modifier // includeDiscriminator during Encode adds a discriminator to the encoded bytes under an assumption that the provided value didn't have a discriminator. // During Decode includeDiscriminator removes discriminator from bytes under an assumption that the provided struct doesn't need a discriminator. includeDiscriminator bool @@ -95,19 +95,19 @@ func NewEventArgsEntry(offChainName string, idlTypes EventIDLTypes, includeDiscr } func newEntry( - offchainName, onchainName string, + genericName, chainSpecificName string, typeCodec commonencodings.TypeCodec, includeDiscriminator bool, mod codec.Modifier, ) Entry { return &entry{ - offchainName: offchainName, - onchainName: onchainName, + genericName: genericName, + chainSpecificName: chainSpecificName, reflectType: typeCodec.GetType(), typeCodec: typeCodec, mod: ensureModifier(mod), includeDiscriminator: includeDiscriminator, - discriminator: *NewDiscriminator(onchainName), + discriminator: *NewDiscriminator(chainSpecificName), } } @@ -130,8 +130,8 @@ func (e *entry) Encode(value any, into []byte) ([]byte, error) { return []byte{}, nil } } - return nil, fmt.Errorf("%w: cannot encode nil value for offchainName: %q, onchainName: %q", - commontypes.ErrInvalidType, e.offchainName, e.onchainName) + return nil, fmt.Errorf("%w: cannot encode nil value for genericName: %q, chainSpecificName: %q", + commontypes.ErrInvalidType, e.genericName, e.chainSpecificName) } encodedVal, err := e.typeCodec.Encode(value, into) @@ -154,13 +154,13 @@ func (e *entry) Encode(value any, into []byte) ([]byte, error) { func (e *entry) Decode(encoded []byte) (any, []byte, error) { if e.includeDiscriminator { if len(encoded) < discriminatorLength { - return nil, nil, fmt.Errorf("%w: encoded data too short to contain discriminator for offchainName: %q, onchainName: %q", - commontypes.ErrInvalidType, e.offchainName, e.onchainName) + return nil, nil, fmt.Errorf("%w: encoded data too short to contain discriminator for genericName: %q, chainSpecificName: %q", + commontypes.ErrInvalidType, e.genericName, e.chainSpecificName) } if !bytes.Equal(e.discriminator.hashPrefix, encoded[:discriminatorLength]) { - return nil, nil, fmt.Errorf("%w: encoded data has a bad discriminator %v for offchainName: %q, onchainName: %q", - commontypes.ErrInvalidType, encoded[:discriminatorLength], e.offchainName, e.onchainName) + return nil, nil, fmt.Errorf("%w: encoded data has a bad discriminator %v for genericName: %q, chainSpecificName: %q", + commontypes.ErrInvalidType, encoded[:discriminatorLength], e.genericName, e.chainSpecificName) } encoded = encoded[discriminatorLength:] diff --git a/pkg/solana/codec/codec_test.go b/pkg/solana/codec/codec_test.go index 689d545ce..50b0366ac 100644 --- a/pkg/solana/codec/codec_test.go +++ b/pkg/solana/codec/codec_test.go @@ -122,7 +122,7 @@ func (it *codecInterfaceTester) GetCodec(t *testing.T) clcommontypes.Codec { codecEntryCfg := codecConfig.Configs[offChainName] codecEntryCfg.IDL = v.IDL codecEntryCfg.Type = v.ItemType - codecEntryCfg.OnChainName = v.IDLTypeName + codecEntryCfg.ChainSpecificName = v.IDLTypeName if offChainName != NilType { codecEntryCfg.ModifierConfigs = commoncodec.ModifiersConfig{ diff --git a/pkg/solana/codec/decoder.go b/pkg/solana/codec/decoder.go index 242dbc44f..e8af04563 100644 --- a/pkg/solana/codec/decoder.go +++ b/pkg/solana/codec/decoder.go @@ -10,14 +10,14 @@ import ( type Decoder struct { definitions map[string]Entry - codecFromTypeCodec encodings.CodecFromTypeCodec + codecFromTypeCodec encodings.LenientCodecFromTypeCodec } var _ commontypes.Decoder = &Decoder{} func (d *Decoder) Decode(ctx context.Context, raw []byte, into any, itemType string) (err error) { if d.codecFromTypeCodec == nil { - d.codecFromTypeCodec = make(encodings.CodecFromTypeCodec) + d.codecFromTypeCodec = make(encodings.LenientCodecFromTypeCodec) for k, v := range d.definitions { d.codecFromTypeCodec[k] = v } diff --git a/pkg/solana/codec/encoder.go b/pkg/solana/codec/encoder.go index 409fb0013..a33c5f5dd 100644 --- a/pkg/solana/codec/encoder.go +++ b/pkg/solana/codec/encoder.go @@ -10,14 +10,14 @@ import ( type Encoder struct { definitions map[string]Entry - codecFromTypeCodec encodings.CodecFromTypeCodec + codecFromTypeCodec encodings.LenientCodecFromTypeCodec } var _ commontypes.Encoder = &Encoder{} func (e *Encoder) Encode(ctx context.Context, item any, itemType string) (res []byte, err error) { if e.codecFromTypeCodec == nil { - e.codecFromTypeCodec = make(encodings.CodecFromTypeCodec) + e.codecFromTypeCodec = make(encodings.LenientCodecFromTypeCodec) for k, v := range e.definitions { e.codecFromTypeCodec[k] = v } diff --git a/pkg/solana/codec/solana.go b/pkg/solana/codec/solana.go index 2a730ffa2..372e111aa 100644 --- a/pkg/solana/codec/solana.go +++ b/pkg/solana/codec/solana.go @@ -73,7 +73,7 @@ func NewCodec(conf Config) (commontypes.RemoteCodec, error) { return nil, err } - definition, err := FindDefinitionFromIDL(cfg.Type, cfg.OnChainName, idl) + definition, err := FindDefinitionFromIDL(cfg.Type, cfg.ChainSpecificName, idl) if err != nil { return nil, err } @@ -108,32 +108,32 @@ func CreateCodecEntry(idlDefinition interface{}, offChainName string, idl IDL, m return entry, nil } -func FindDefinitionFromIDL(cfgType ChainConfigType, onChainName string, idl IDL) (interface{}, error) { +func FindDefinitionFromIDL(cfgType ChainConfigType, chainSpecificName string, idl IDL) (interface{}, error) { // not the most efficient way to do this, but these slices should always be very, very small switch cfgType { case ChainConfigTypeAccountDef: for i := range idl.Accounts { - if idl.Accounts[i].Name == onChainName { + if idl.Accounts[i].Name == chainSpecificName { return idl.Accounts[i], nil } } - return nil, fmt.Errorf("failed to find account %q in IDL", onChainName) + return nil, fmt.Errorf("failed to find account %q in IDL", chainSpecificName) case ChainConfigTypeInstructionDef: for i := range idl.Instructions { - if idl.Instructions[i].Name == onChainName { + if idl.Instructions[i].Name == chainSpecificName { return idl.Instructions[i], nil } } - return nil, fmt.Errorf("failed to find instruction %q in IDL", onChainName) + return nil, fmt.Errorf("failed to find instruction %q in IDL", chainSpecificName) case ChainConfigTypeEventDef: for i := range idl.Events { - if idl.Events[i].Name == onChainName { + if idl.Events[i].Name == chainSpecificName { return idl.Events[i], nil } } - return nil, fmt.Errorf("failed to find event %q in IDL", onChainName) + return nil, fmt.Errorf("failed to find event %q in IDL", chainSpecificName) } return nil, fmt.Errorf("unknown type: %q", cfgType) } diff --git a/pkg/solana/codec/types.go b/pkg/solana/codec/types.go index e047b36ae..40852398e 100644 --- a/pkg/solana/codec/types.go +++ b/pkg/solana/codec/types.go @@ -16,8 +16,8 @@ type Config struct { } type ChainConfig struct { - IDL string `json:"typeIdl" toml:"typeIdl"` - OnChainName string `json:"onChainName" toml:"onChainName"` + IDL string `json:"typeIdl" toml:"typeIdl"` + ChainSpecificName string `json:"chainSpecificName" toml:"chainSpecificName"` // Type can be Solana Account, Instruction args, or TODO Event Type ChainConfigType `json:"type" toml:"type"` ModifierConfigs commoncodec.ModifiersConfig `json:"modifierConfigs,omitempty" toml:"modifierConfigs,omitempty"`