diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 16e2bcbde1..36252cbc6d 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -28,6 +28,7 @@ package bind import ( "errors" + "math/big" ethereum "github.com/XinFinOrg/XDPoSChain" "github.com/XinFinOrg/XDPoSChain/accounts/abi" @@ -241,3 +242,27 @@ func DefaultDeployer(opts *TransactOpts, backend ContractBackend) DeployFn { return addr, tx, nil } } + +// DeployerWithNonceAssignment is basically identical to DefaultDeployer, +// but it additionally tracks the nonce to enable automatic assignment. +// +// This is especially useful when deploying multiple contracts +// from the same address — whether they are independent contracts +// or part of a dependency chain that must be deployed in order. +func DeployerWithNonceAssignment(opts *TransactOpts, backend ContractBackend) DeployFn { + var pendingNonce int64 + if opts.Nonce != nil { + pendingNonce = opts.Nonce.Int64() + } + return func(input []byte, deployer []byte) (common.Address, *types.Transaction, error) { + if pendingNonce != 0 { + opts.Nonce = big.NewInt(pendingNonce) + } + addr, tx, err := DeployContract(opts, deployer, backend, input) + if err != nil { + return common.Address{}, nil, err + } + pendingNonce = int64(tx.Nonce() + 1) + return addr, tx, nil + } +}