diff --git a/pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go b/pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go index 697d74a44d..7a24c0dce2 100644 --- a/pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go +++ b/pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go @@ -450,37 +450,37 @@ type fakeContractWriter struct { cr *fakeContractReader } -func (f *fakeContractWriter) SubmitTransaction(_ context.Context, contractName, method string, args any, transactionID string, toAddress string, meta *types.TxMeta, value *big.Int) error { - contractID := toAddress + "-" + contractName - switch method { +func (f *fakeContractWriter) SubmitTransaction(_ context.Context, req types.SubmitTransactionRequest) error { + contractID := req.ToAddress + "-" + req.ContractName + switch req.Method { case MethodSettingStruct: - v, ok := args.(TestStruct) + v, ok := req.Args.(TestStruct) if !ok { - return fmt.Errorf("unexpected type %T", args) + return fmt.Errorf("unexpected type %T", req.Args) } f.cr.SetTestStructLatestValue(contractID, &v) case MethodSettingUint64: - v, ok := args.(PrimitiveArgs) + v, ok := req.Args.(PrimitiveArgs) if !ok { - return fmt.Errorf("unexpected type %T", args) + return fmt.Errorf("unexpected type %T", req.Args) } f.cr.SetUintLatestValue(contractID, v.Value, ExpectedGetLatestValueArgs{}) case MethodTriggeringEvent: - if err := f.cr.triggers.RecordEvent(contractID, args, primitives.Unconfirmed, EventName); err != nil { + if err := f.cr.triggers.RecordEvent(contractID, req.Args, primitives.Unconfirmed, EventName); err != nil { return fmt.Errorf("failed to record event: %w", err) } case MethodTriggeringEventWithDynamicTopic: - if err := f.cr.triggers.RecordEvent(contractID, args, primitives.Unconfirmed, DynamicTopicEventName); err != nil { + if err := f.cr.triggers.RecordEvent(contractID, req.Args, primitives.Unconfirmed, DynamicTopicEventName); err != nil { return fmt.Errorf("failed to record event: %w", err) } case "batchContractWrite": - v, ok := args.(BatchCallEntry) + v, ok := req.Args.(BatchCallEntry) if !ok { - return fmt.Errorf("unexpected type %T", args) + return fmt.Errorf("unexpected type %T", req.Args) } f.cr.SetBatchLatestValues(v) default: - return fmt.Errorf("unsupported method: %s", method) + return fmt.Errorf("unsupported method: %s", req.Method) } return nil diff --git a/pkg/loop/internal/relayer/pluginprovider/contractwriter/contract_writer.go b/pkg/loop/internal/relayer/pluginprovider/contractwriter/contract_writer.go index eca3a69555..5467e3ac01 100644 --- a/pkg/loop/internal/relayer/pluginprovider/contractwriter/contract_writer.go +++ b/pkg/loop/internal/relayer/pluginprovider/contractwriter/contract_writer.go @@ -45,23 +45,23 @@ func WithClientEncoding(version codecpb.EncodingVersion) ClientOpt { } } -func (c *Client) SubmitTransaction(ctx context.Context, contractName, method string, params any, transactionID, toAddress string, meta *types.TxMeta, value *big.Int) error { - versionedParams, err := codecpb.EncodeVersionedBytes(params, c.encodeWith) +func (c *Client) SubmitTransaction(ctx context.Context, req types.SubmitTransactionRequest) error { + versionedParams, err := codecpb.EncodeVersionedBytes(req.Args, c.encodeWith) if err != nil { return err } - req := pb.SubmitTransactionRequest{ - ContractName: contractName, - Method: method, + pbReq := pb.SubmitTransactionRequest{ + ContractName: req.ContractName, + Method: req.Method, Params: versionedParams, - TransactionId: transactionID, - ToAddress: toAddress, - Meta: TxMetaToProto(meta), - Value: pb.NewBigIntFromInt(value), + TransactionId: req.TransactionID, + ToAddress: req.ToAddress, + Meta: TxMetaToProto(req.Meta), + Value: pb.NewBigIntFromInt(req.Value), } - _, err = c.grpc.SubmitTransaction(ctx, &req) + _, err = c.grpc.SubmitTransaction(ctx, &pbReq) if err != nil { return net.WrapRPCErr(err) } @@ -153,7 +153,15 @@ func (s *Server) SubmitTransaction(ctx context.Context, req *pb.SubmitTransactio return nil, err } - err := s.impl.SubmitTransaction(ctx, req.ContractName, req.Method, params, req.TransactionId, req.ToAddress, TxMetaFromProto(req.Meta), req.Value.Int()) + err := s.impl.SubmitTransaction(ctx, types.SubmitTransactionRequest{ + ContractName: req.ContractName, + Method: req.Method, + Args: params, + TransactionID: req.TransactionId, + ToAddress: req.ToAddress, + Meta: TxMetaFromProto(req.Meta), + Value: req.Value.Int(), + }) if err != nil { return nil, err } diff --git a/pkg/types/contract_writer.go b/pkg/types/contract_writer.go index d8e4ea291b..07f9ca6e5c 100644 --- a/pkg/types/contract_writer.go +++ b/pkg/types/contract_writer.go @@ -14,14 +14,25 @@ const ( // IdempotencyKey is generated by SubmitTransaction caller to prevent double sending or to track transaction status type IdempotencyKey = string +// SubmitTransactionRequest contains parameters for submitting a transaction. +type SubmitTransactionRequest struct { + ContractName string + Method string + Args any + TransactionID IdempotencyKey + ToAddress string + Meta *TxMeta + Value *big.Int +} + type ContractWriter interface { services.Service // SubmitTransaction packs and broadcasts a transaction to the underlying chain contract. // - // - `args` should be any object which maps a set of method param into the contract and method specific method params. - // - `transactionID` will be used by the underlying TXM as an idempotency key, and unique reference to track transaction attempts. - SubmitTransaction(ctx context.Context, contractName, method string, args any, transactionID IdempotencyKey, toAddress string, meta *TxMeta, value *big.Int) error + // - `req.Args` should be any object which maps a set of method param into the contract and method specific method params. + // - `req.TransactionID` will be used by the underlying TXM as an idempotency key, and unique reference to track transaction attempts. + SubmitTransaction(ctx context.Context, req SubmitTransactionRequest) error // GetTransactionStatus returns the current status of a transaction in the underlying chain's TXM. GetTransactionStatus(ctx context.Context, transactionID IdempotencyKey) (TransactionStatus, error) diff --git a/pkg/types/interfacetests/utils.go b/pkg/types/interfacetests/utils.go index 4c8610b462..758550cc04 100644 --- a/pkg/types/interfacetests/utils.go +++ b/pkg/types/interfacetests/utils.go @@ -89,7 +89,12 @@ func RunTestsInParallel[T TestingT[T]](t T, tester BasicTester[T], tests []Testc func batchContractWrite[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], cw types.ContractWriter, boundContracts []types.BoundContract, batchCallEntry BatchCallEntry, mockRun bool) { // This is necessary because the mock helper function requires the entire batchCallEntry rather than an individual testStruct if mockRun { - err := cw.SubmitTransaction(t.Context(), AnyContractName, "batchContractWrite", batchCallEntry, "", "", nil, big.NewInt(0)) + err := cw.SubmitTransaction(t.Context(), types.SubmitTransactionRequest{ + ContractName: AnyContractName, + Method: "batchContractWrite", + Args: batchCallEntry, + Value: big.NewInt(0), + }) require.NoError(t, err) return } @@ -115,7 +120,14 @@ func batchContractWrite[T TestingT[T]](t T, tester ChainComponentsInterfaceTeste func SubmitTransactionToCW[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], cw types.ContractWriter, method string, args any, contract types.BoundContract, status types.TransactionStatus) string { tester.DirtyContracts() txID := uuid.New().String() - err := cw.SubmitTransaction(t.Context(), contract.Name, method, args, txID, contract.Address, nil, big.NewInt(0)) + err := cw.SubmitTransaction(t.Context(), types.SubmitTransactionRequest{ + ContractName: contract.Name, + Method: method, + Args: args, + TransactionID: txID, + ToAddress: contract.Address, + Value: big.NewInt(0), + }) require.NoError(t, err) err = WaitForTransactionStatus(t, tester, cw, txID, status, false)