From 7052c72d8c96a3128fb9f4bce0ac02db42158327 Mon Sep 17 00:00:00 2001 From: Silas Lenihan Date: Thu, 9 Jan 2025 15:51:29 -0500 Subject: [PATCH] Updated SubmitTransaction to apply input modifications to args before lookups --- pkg/solana/chainwriter/chain_writer.go | 28 +++++++++++++++------ pkg/solana/chainwriter/chain_writer_test.go | 20 +++++++++++---- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/pkg/solana/chainwriter/chain_writer.go b/pkg/solana/chainwriter/chain_writer.go index e02148d89..c262625ad 100644 --- a/pkg/solana/chainwriter/chain_writer.go +++ b/pkg/solana/chainwriter/chain_writer.go @@ -30,8 +30,9 @@ type SolanaChainWriterService struct { ge fees.Estimator config ChainWriterConfig - parsed *codec.ParsedTypes - encoder types.Encoder + parsed *codec.ParsedTypes + encoder types.Encoder + modifiers map[string]commoncodec.Modifier services.StateMachine } @@ -63,12 +64,13 @@ type MethodConfig struct { func NewSolanaChainWriterService(logger logger.Logger, reader client.Reader, txm txm.TxManager, ge fees.Estimator, config ChainWriterConfig) (*SolanaChainWriterService, error) { w := SolanaChainWriterService{ - lggr: logger, - reader: reader, - txm: txm, - ge: ge, - config: config, - parsed: &codec.ParsedTypes{EncoderDefs: map[string]codec.Entry{}, DecoderDefs: map[string]codec.Entry{}}, + lggr: logger, + reader: reader, + txm: txm, + ge: ge, + config: config, + parsed: &codec.ParsedTypes{EncoderDefs: map[string]codec.Entry{}, DecoderDefs: map[string]codec.Entry{}}, + modifiers: make(map[string]commoncodec.Modifier), } if err := w.parsePrograms(config); err != nil { @@ -99,6 +101,7 @@ func (s *SolanaChainWriterService) parsePrograms(config ChainWriterConfig) error if err != nil { return fmt.Errorf("failed to create input modifications for method %s.%s, error: %w", program, method, err) } + s.modifiers[codec.WrapItemType(true, program, method, "")] = inputMod input, err := codec.CreateCodecEntry(idlDef, methodConfig.ChainSpecificName, idl, inputMod) if err != nil { @@ -258,6 +261,15 @@ func (s *SolanaChainWriterService) SubmitTransaction(ctx context.Context, contra encodedPayload, err := s.encoder.Encode(ctx, args, codec.WrapItemType(true, contractName, method, "")) + modifier, exists := s.modifiers[codec.WrapItemType(true, contractName, method, "")] + if exists { + // apply codec modifiers to args before doing address lookups + args, err = modifier.TransformToOnChain(args, "") + if err != nil { + return errorWithDebugID(fmt.Errorf("error transforming input args: %w", err), debugID) + } + } + if err != nil { return errorWithDebugID(fmt.Errorf("error encoding transaction payload: %w", err), debugID) } diff --git a/pkg/solana/chainwriter/chain_writer_test.go b/pkg/solana/chainwriter/chain_writer_test.go index f113f33da..97c74085c 100644 --- a/pkg/solana/chainwriter/chain_writer_test.go +++ b/pkg/solana/chainwriter/chain_writer_test.go @@ -16,6 +16,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec" "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" @@ -429,7 +430,10 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { "contract_reader_interface": { Methods: map[string]chainwriter.MethodConfig{ "initializeLookupTable": { - FromAddress: admin.String(), + FromAddress: admin.String(), + InputModifications: commoncodec.ModifiersConfig{ + &commoncodec.RenameModifierConfig{Fields: map[string]string{"Lookup": "LookupTable"}}, + }, ChainSpecificName: "initializeLookupTable", LookupTables: chainwriter.LookupTables{ DerivedLookupTables: []chainwriter.DerivedLookupTable{ @@ -557,10 +561,16 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { return true }), &txID, mock.Anything).Return(nil).Once() - args := Arguments{ - LookupTable: account2, - Seed1: seed1, - Seed2: seed2, + type ArgumentsOffChain struct { + Lookup solana.PublicKey + Seed1 []byte + Seed2 []byte + } + + args := ArgumentsOffChain{ + Lookup: account2, + Seed1: seed1, + Seed2: seed2, } submitErr := cw.SubmitTransaction(ctx, "contract_reader_interface", "initializeLookupTable", args, txID, programID.String(), nil, nil)