From 744c3884e0a23c294331ef5bdfbc5d5a10e2ebb2 Mon Sep 17 00:00:00 2001 From: Supun Induwara Date: Mon, 6 Jan 2025 17:36:23 +0530 Subject: [PATCH] Fixed #422 Add `isTxIdHex` to `SimpleTxManager` constructor Introduce `isTxIdHex` to handle tx ID formats in transaction receipt retrieval. Updated relevant function signatures and logic to support this flag and added necessary changes across dependent tests and usages. --- chainio/clients/builder.go | 2 +- chainio/txmgr/simple.go | 21 +++++++++++++++------ signerv2/kms_signer_test.go | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/chainio/clients/builder.go b/chainio/clients/builder.go index 3f7311dc..1d1ea785 100644 --- a/chainio/clients/builder.go +++ b/chainio/clients/builder.go @@ -159,7 +159,7 @@ func BuildAll( if err != nil { return nil, utils.WrapError("Failed to create transaction sender", err) } - txMgr := txmgr.NewSimpleTxManager(pkWallet, ethHttpClient, logger, addr) + txMgr := txmgr.NewSimpleTxManager(pkWallet, ethHttpClient, logger, addr, true) // creating AVS clients: Reader and Writer avsRegistryChainReader, avsRegistryChainSubscriber, avsRegistryChainWriter, avsRegistryContractBindings, err := avsregistry.BuildClients( diff --git a/chainio/txmgr/simple.go b/chainio/txmgr/simple.go index 6c732ad2..0da1f772 100644 --- a/chainio/txmgr/simple.go +++ b/chainio/txmgr/simple.go @@ -35,6 +35,7 @@ type SimpleTxManager struct { logger logging.Logger sender common.Address gasLimitMultiplier float64 + isTxIdHex bool } var _ TxManager = (*SimpleTxManager)(nil) @@ -46,6 +47,7 @@ func NewSimpleTxManager( client ethBackend, logger logging.Logger, sender common.Address, + isTxIdHex bool, ) *SimpleTxManager { return &SimpleTxManager{ wallet: wallet, @@ -53,6 +55,7 @@ func NewSimpleTxManager( logger: logger, sender: sender, gasLimitMultiplier: FallbackGasLimitMultiplier, + isTxIdHex: isTxIdHex, } } @@ -74,7 +77,7 @@ func (m *SimpleTxManager) Send( waitForReceipt bool, ) (*types.Receipt, error) { - r, err := m.send(ctx, tx) + r, txID, err := m.send(ctx, tx) if err != nil { return nil, errors.Join(errors.New("send: failed to estimate gas and nonce"), err) } @@ -82,7 +85,13 @@ func (m *SimpleTxManager) Send( return r, nil } - receipt, err := m.waitForReceipt(ctx, r.TxHash.Hex()) + var receipt *types.Receipt + if m.isTxIdHex { + receipt, err = m.waitForReceipt(ctx, r.TxHash.Hex()) + } else { + receipt, err = m.waitForReceipt(ctx, txID) + } + if err != nil { log.Info("Transaction receipt not found", "err", err) return nil, err @@ -91,14 +100,14 @@ func (m *SimpleTxManager) Send( return receipt, nil } -func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*types.Receipt, error) { +func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*types.Receipt, string, error) { // Estimate gas and nonce // can't print tx hash in logs because the tx changes below when we complete and sign it // so the txHash is meaningless at this point m.logger.Debug("Estimating gas and nonce") tx, err := m.estimateGasAndNonce(ctx, tx) if err != nil { - return nil, err + return nil, "", err } bumpedGasTx := &types.DynamicFeeTx{ To: tx.To(), @@ -111,11 +120,11 @@ func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*typ } txID, err := m.wallet.SendTransaction(ctx, types.NewTx(bumpedGasTx)) if err != nil { - return nil, errors.Join(errors.New("send: failed to estimate gas and nonce"), err) + return nil, "", errors.Join(errors.New("send: failed to estimate gas and nonce"), err) } return &types.Receipt{ TxHash: common.HexToHash(txID), - }, nil + }, txID, nil } func NoopSigner(addr common.Address, tx *types.Transaction) (*types.Transaction, error) { diff --git a/signerv2/kms_signer_test.go b/signerv2/kms_signer_test.go index 8dd09124..ad3c0ef0 100644 --- a/signerv2/kms_signer_test.go +++ b/signerv2/kms_signer_test.go @@ -124,7 +124,7 @@ func TestSignTransactionWithKmsSigner(t *testing.T) { pkWallet, err := wallet.NewPrivateKeyWallet(ethClient, signer, keyAddr, logger) assert.Nil(t, err) assert.NotNil(t, pkWallet) - txMgr := txmgr.NewSimpleTxManager(pkWallet, ethClient, logger, keyAddr) + txMgr := txmgr.NewSimpleTxManager(pkWallet, ethClient, logger, keyAddr, false) assert.NotNil(t, txMgr) receipt, err := txMgr.Send(context.Background(), gtypes.NewTx(>ypes.DynamicFeeTx{ ChainID: &testData.Input.ChainID,