Skip to content

Commit

Permalink
accounts/abi/bind: make it possible to wait for tx hash (#30079)
Browse files Browse the repository at this point in the history
This change adds methods which makes it possible for to wait for a transaction with a specific hash when deploying contracts during abi bind interaction.

---------

Co-authored-by: Marius van der Wijden <[email protected]>
  • Loading branch information
mask-pp and MariusVanDerWijden authored Dec 17, 2024
1 parent 5c58612 commit 3c208cd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions accounts/abi/bind/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ import (
// WaitMined waits for tx to be mined on the blockchain.
// It stops waiting when the context is canceled.
func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) {
return WaitMinedHash(ctx, b, tx.Hash())
}

// WaitMinedHash waits for a transaction with the provided hash to be mined on the blockchain.
// It stops waiting when the context is canceled.
func WaitMinedHash(ctx context.Context, b DeployBackend, hash common.Hash) (*types.Receipt, error) {
queryTicker := time.NewTicker(time.Second)
defer queryTicker.Stop()

logger := log.New("hash", tx.Hash())
logger := log.New("hash", hash)
for {
receipt, err := b.TransactionReceipt(ctx, tx.Hash())
receipt, err := b.TransactionReceipt(ctx, hash)
if err == nil {
return receipt, nil
}
Expand All @@ -61,7 +67,13 @@ func WaitDeployed(ctx context.Context, b DeployBackend, tx *types.Transaction) (
if tx.To() != nil {
return common.Address{}, errors.New("tx is not contract creation")
}
receipt, err := WaitMined(ctx, b, tx)
return WaitDeployedHash(ctx, b, tx.Hash())
}

// WaitDeployedHash waits for a contract deployment transaction with the provided hash and returns the on-chain
// contract address when it is mined. It stops waiting when ctx is canceled.
func WaitDeployedHash(ctx context.Context, b DeployBackend, hash common.Hash) (common.Address, error) {
receipt, err := WaitMinedHash(ctx, b, hash)
if err != nil {
return common.Address{}, err
}
Expand Down

0 comments on commit 3c208cd

Please sign in to comment.