From f7a0ad47e1acf2cac553d9ba2ba9913774cc9b69 Mon Sep 17 00:00:00 2001 From: Linfeng Liang Date: Thu, 21 Jun 2018 14:40:31 +0800 Subject: [PATCH] accounts/abi, mobile: use EIP155Signer for new txs Fix #16484. --- accounts/abi/bind/base.go | 16 ++++++++++++---- mobile/bind.go | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index 83ad1c8ae7fc..4955d37f7f94 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -45,9 +45,10 @@ type CallOpts struct { // TransactOpts is the collection of authorization data required to create a // valid Ethereum transaction. 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) + 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 } diff --git a/mobile/bind.go b/mobile/bind.go index d6e621a258fd..544b42e1c482 100644 --- a/mobile/bind.go +++ b/mobile/bind.go @@ -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) }