mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
Merge ee4c97193b into 12eabbd76d
This commit is contained in:
commit
8d0a08b186
6 changed files with 50 additions and 4 deletions
|
|
@ -4,8 +4,10 @@
|
||||||
package {{.Package}}
|
package {{.Package}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
ethereum "github.com/ethereum/go-ethereum"
|
ethereum "github.com/ethereum/go-ethereum"
|
||||||
|
|
@ -27,6 +29,8 @@ var (
|
||||||
_ = types.BloomLookup
|
_ = types.BloomLookup
|
||||||
_ = event.NewSubscription
|
_ = event.NewSubscription
|
||||||
_ = abi.ConvertType
|
_ = abi.ConvertType
|
||||||
|
_ = time.Tick
|
||||||
|
_ = context.Background
|
||||||
)
|
)
|
||||||
|
|
||||||
{{$structs := .Structs}}
|
{{$structs := .Structs}}
|
||||||
|
|
@ -77,7 +81,11 @@ var (
|
||||||
return common.Address{}, nil, nil, errors.New("GetABI returned nil")
|
return common.Address{}, nil, nil, errors.New("GetABI returned nil")
|
||||||
}
|
}
|
||||||
{{range $pattern, $name := .Libraries}}
|
{{range $pattern, $name := .Libraries}}
|
||||||
{{decapitalise $name}}Addr, _, _, _ := Deploy{{capitalise $name}}(auth, backend)
|
{{decapitalise $name}}Addr, tx, _, _ := Deploy{{capitalise $name}}(auth, backend)
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), 5 * time.Second)
|
||||||
|
if err := bind.WaitAccepted(ctx, backend, tx); err != nil {
|
||||||
|
return common.Address{}, nil, nil, err
|
||||||
|
}
|
||||||
{{$contract.Type}}Bin = strings.ReplaceAll({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:])
|
{{$contract.Type}}Bin = strings.ReplaceAll({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:])
|
||||||
{{end}}
|
{{end}}
|
||||||
address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
|
address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,12 @@ func (m *MetaData) GetAbi() (*abi.ABI, error) {
|
||||||
|
|
||||||
// util.go
|
// util.go
|
||||||
|
|
||||||
|
// WaitAccepted waits for a tx to be accepted into the pool.
|
||||||
|
// It stops waiting when the context is canceled.
|
||||||
|
func WaitAccepted(ctx context.Context, b ContractBackend, tx *types.Transaction) error {
|
||||||
|
return bind2.WaitAccepted(ctx, b, tx.Hash())
|
||||||
|
}
|
||||||
|
|
||||||
// WaitMined waits for tx to be mined on the blockchain.
|
// WaitMined waits for tx to be mined on the blockchain.
|
||||||
// It stops waiting when the context is canceled.
|
// It stops waiting when the context is canceled.
|
||||||
func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) {
|
func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) {
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,9 @@ type ContractTransactor interface {
|
||||||
|
|
||||||
// PendingNonceAt retrieves the current pending nonce associated with an account.
|
// PendingNonceAt retrieves the current pending nonce associated with an account.
|
||||||
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
|
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
|
||||||
|
|
||||||
|
// TransactionByHash retrieves the transaction associated with the hash, if it exists in the pool.
|
||||||
|
TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
|
// DeployBackend wraps the operations needed by WaitMined and WaitDeployed.
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,7 @@ func (c *BoundContract) createDynamicTx(opts *TransactOpts, contract *common.Add
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create the transaction
|
// create the transaction
|
||||||
nonce, err := c.getNonce(opts)
|
nonce, err := c.GetNonce(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -365,7 +365,7 @@ func (c *BoundContract) createLegacyTx(opts *TransactOpts, contract *common.Addr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create the transaction
|
// create the transaction
|
||||||
nonce, err := c.getNonce(opts)
|
nonce, err := c.GetNonce(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -402,7 +402,7 @@ func (c *BoundContract) estimateGasLimit(opts *TransactOpts, contract *common.Ad
|
||||||
return c.transactor.EstimateGas(ensureContext(opts.Context), msg)
|
return c.transactor.EstimateGas(ensureContext(opts.Context), msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BoundContract) getNonce(opts *TransactOpts) (uint64, error) {
|
func (c *BoundContract) GetNonce(opts *TransactOpts) (uint64, error) {
|
||||||
if opts.Nonce == nil {
|
if opts.Nonce == nil {
|
||||||
return c.transactor.PendingNonceAt(ensureContext(opts.Context), opts.From)
|
return c.transactor.PendingNonceAt(ensureContext(opts.Context), opts.From)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ func (mt *mockTransactor) SendTransaction(ctx context.Context, tx *types.Transac
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mt *mockTransactor) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error) {
|
||||||
|
return nil, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
type mockCaller struct {
|
type mockCaller struct {
|
||||||
codeAtBlockNumber *big.Int
|
codeAtBlockNumber *big.Int
|
||||||
callContractBlockNumber *big.Int
|
callContractBlockNumber *big.Int
|
||||||
|
|
|
||||||
|
|
@ -75,3 +75,28 @@ func WaitDeployed(ctx context.Context, b DeployBackend, hash common.Hash) (commo
|
||||||
}
|
}
|
||||||
return receipt.ContractAddress, err
|
return receipt.ContractAddress, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WaitAccepted(ctx context.Context, d ContractBackend, txHash common.Hash) error {
|
||||||
|
queryTicker := time.NewTicker(time.Second)
|
||||||
|
defer queryTicker.Stop()
|
||||||
|
logger := log.New("hash", txHash)
|
||||||
|
for {
|
||||||
|
_, _, err := d.TransactionByHash(ctx, txHash)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if errors.Is(err, ethereum.NotFound) { // TODO: check this is emitted
|
||||||
|
logger.Trace("Transaction not yet accepted")
|
||||||
|
} else {
|
||||||
|
logger.Trace("Transaction submission failed", "err", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the next round.
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
case <-queryTicker.C:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue