Skip to content

Commit

Permalink
Fixed Layr-Labs#422 : Add IsHexTxID method to determine TxID format i…
Browse files Browse the repository at this point in the history
…n wallets

This change introduces an IsHexTxID method to the Wallet interface, with implementations for privateKeyWallet, fireblocksWallet, and MockWallet. The method is used to handle differing TxID formats (hexadecimal or custom) when processing transaction receipts. Adjustments were made to the SimpleTxManager to incorporate this new method for better compatibility.
  • Loading branch information
induwarabas committed Jan 6, 2025
1 parent fce9e63 commit 0b191d0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions chainio/clients/mocks/wallet.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions chainio/clients/wallet/fireblocks_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func NewFireblocksWallet(
}, nil
}

func (t *fireblocksWallet) IsHexTxID() bool {
return false
}

func (t *fireblocksWallet) getAccount(ctx context.Context) (*fireblocks.VaultAccount, error) {
if t.account == nil {
accounts, err := t.fireblocksClient.ListVaultAccounts(ctx)
Expand Down
4 changes: 4 additions & 0 deletions chainio/clients/wallet/privatekey_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func NewPrivateKeyWallet(
}, nil
}

func (t *privateKeyWallet) IsHexTxID() bool {
return true
}

func (t *privateKeyWallet) SendTransaction(ctx context.Context, tx *types.Transaction) (TxID, error) {

t.logger.Debug("Getting signer for tx")
Expand Down
4 changes: 4 additions & 0 deletions chainio/clients/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ type Wallet interface {
GetTransactionReceipt(ctx context.Context, txID TxID) (*types.Receipt, error)
// SenderAddress returns the address of the wallet
SenderAddress(ctx context.Context) (common.Address, error)

// IsHexTxID returns true if the transaction ID (TxID) is represented as a hexadecimal string; otherwise, false.
// Some wallets use custom formats like uuid for representing the TxID instead of raw hex
IsHexTxID() bool
}
18 changes: 12 additions & 6 deletions chainio/txmgr/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ 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)
}
if !waitForReceipt {
return r, nil
}

receipt, err := m.waitForReceipt(ctx, r.TxHash.Hex())
var receipt *types.Receipt
if m.wallet.IsHexTxID() {
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
Expand All @@ -91,14 +97,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(),
Expand All @@ -111,11 +117,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) {
Expand Down

0 comments on commit 0b191d0

Please sign in to comment.