github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/accounts/abi/bind/util.go (about) 1 package bind 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/neatio-net/neatio/chain/core/types" 9 "github.com/neatio-net/neatio/chain/log" 10 "github.com/neatio-net/neatio/utilities/common" 11 ) 12 13 func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) { 14 queryTicker := time.NewTicker(time.Second) 15 defer queryTicker.Stop() 16 17 logger := log.New("hash", tx.Hash()) 18 for { 19 receipt, err := b.TransactionReceipt(ctx, tx.Hash()) 20 if receipt != nil { 21 return receipt, nil 22 } 23 if err != nil { 24 logger.Trace("Receipt retrieval failed", "err", err) 25 } else { 26 logger.Trace("Transaction not yet mined") 27 } 28 29 select { 30 case <-ctx.Done(): 31 return nil, ctx.Err() 32 case <-queryTicker.C: 33 } 34 } 35 } 36 37 func WaitDeployed(ctx context.Context, b DeployBackend, tx *types.Transaction) (common.Address, error) { 38 if tx.To() != nil { 39 return common.Address{}, fmt.Errorf("tx is not contract creation") 40 } 41 receipt, err := WaitMined(ctx, b, tx) 42 if err != nil { 43 return common.Address{}, err 44 } 45 if receipt.ContractAddress == (common.Address{}) { 46 return common.Address{}, fmt.Errorf("zero address") 47 } 48 49 code, err := b.CodeAt(ctx, receipt.ContractAddress, nil) 50 if err == nil && len(code) == 0 { 51 err = ErrNoCodeAfterDeploy 52 } 53 return receipt.ContractAddress, err 54 }