accounts/abi, mobile: use EIP155Signer for new txs

Fix #16484.
This commit is contained in:
Linfeng Liang 2018-06-21 14:40:31 +08:00
parent 61a5976368
commit f7a0ad47e1
No known key found for this signature in database
GPG key ID: 09F1C130287F5D93
2 changed files with 14 additions and 4 deletions

View file

@ -48,6 +48,7 @@ type TransactOpts struct {
From common.Address // Ethereum account to send the transaction from
Nonce *big.Int // Nonce to use for the transaction execution (nil = use pending state)
Signer SignerFn // Method to use for signing the transaction (mandatory)
ChainId *big.Int // Chain id to use for signing the transaction (nil = use Homestead signer)
Value *big.Int // Funds to transfer along along the transaction (nil = 0 = no funds)
GasPrice *big.Int // Gas price to use for the transaction execution (nil = gas price oracle)
@ -234,7 +235,14 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
if opts.Signer == nil {
return nil, errors.New("no signer to authorize the transaction with")
}
signedTx, err := opts.Signer(types.HomesteadSigner{}, opts.From, rawTx)
var signer types.Signer
if opts.ChainId == nil {
signer = types.HomesteadSigner{}
} else {
signer = types.NewEIP155Signer(opts.ChainId)
}
signedTx, err := opts.Signer(signer, opts.From, rawTx)
if err != nil {
return nil, err
}

View file

@ -75,6 +75,7 @@ type TransactOpts struct {
func (opts *TransactOpts) GetFrom() *Address { return &Address{opts.opts.From} }
func (opts *TransactOpts) GetNonce() int64 { return opts.opts.Nonce.Int64() }
func (opts *TransactOpts) GetChainId() *BigInt { return &BigInt{opts.opts.ChainId} }
func (opts *TransactOpts) GetValue() *BigInt { return &BigInt{opts.opts.Value} }
func (opts *TransactOpts) GetGasPrice() *BigInt { return &BigInt{opts.opts.GasPrice} }
func (opts *TransactOpts) GetGasLimit() int64 { return int64(opts.opts.GasLimit) }
@ -97,6 +98,7 @@ func (opts *TransactOpts) SetSigner(s Signer) {
return sig.tx, nil
}
}
func (opts *TransactOpts) SetChainId(chainId *BigInt) { opts.opts.ChainId = chainId.bigint }
func (opts *TransactOpts) SetValue(value *BigInt) { opts.opts.Value = value.bigint }
func (opts *TransactOpts) SetGasPrice(price *BigInt) { opts.opts.GasPrice = price.bigint }
func (opts *TransactOpts) SetGasLimit(limit int64) { opts.opts.GasLimit = uint64(limit) }