From 7cc160e1fde3efbedc72ee72b65cc50d69cd0196 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 19 Jul 2024 11:38:11 +0200 Subject: [PATCH] accounts/abi/bind: add WaitMinedHash and WaitDeployedHash --- accounts/abi/bind/util.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/accounts/abi/bind/util.go b/accounts/abi/bind/util.go index 0d298eed3f..c83116e9a1 100644 --- a/accounts/abi/bind/util.go +++ b/accounts/abi/bind/util.go @@ -29,7 +29,13 @@ 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, hash common.Hash) (*types.Receipt, error) { +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() @@ -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.Hash()) + 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 }