@@ -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.
3232func 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