Skip to content

Commit 3c208cd

Browse files
accounts/abi/bind: make it possible to wait for tx hash (#30079)
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]>
1 parent 5c58612 commit 3c208cd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

accounts/abi/bind/util.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ import (
3030
// WaitMined waits for tx to be mined on the blockchain.
3131
// It stops waiting when the context is canceled.
3232
func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) {
33+
return WaitMinedHash(ctx, b, tx.Hash())
34+
}
35+
36+
// WaitMinedHash waits for a transaction with the provided hash to be mined on the blockchain.
37+
// It stops waiting when the context is canceled.
38+
func WaitMinedHash(ctx context.Context, b DeployBackend, hash common.Hash) (*types.Receipt, error) {
3339
queryTicker := time.NewTicker(time.Second)
3440
defer queryTicker.Stop()
3541

36-
logger := log.New("hash", tx.Hash())
42+
logger := log.New("hash", hash)
3743
for {
38-
receipt, err := b.TransactionReceipt(ctx, tx.Hash())
44+
receipt, err := b.TransactionReceipt(ctx, hash)
3945
if err == nil {
4046
return receipt, nil
4147
}
@@ -61,7 +67,13 @@ func WaitDeployed(ctx context.Context, b DeployBackend, tx *types.Transaction) (
6167
if tx.To() != nil {
6268
return common.Address{}, errors.New("tx is not contract creation")
6369
}
64-
receipt, err := WaitMined(ctx, b, tx)
70+
return WaitDeployedHash(ctx, b, tx.Hash())
71+
}
72+
73+
// WaitDeployedHash waits for a contract deployment transaction with the provided hash and returns the on-chain
74+
// contract address when it is mined. It stops waiting when ctx is canceled.
75+
func WaitDeployedHash(ctx context.Context, b DeployBackend, hash common.Hash) (common.Address, error) {
76+
receipt, err := WaitMinedHash(ctx, b, hash)
6577
if err != nil {
6678
return common.Address{}, err
6779
}

0 commit comments

Comments
 (0)