Skip to content

Commit

Permalink
accounts/abi, mobile: use EIP155Signer for new txs
Browse files Browse the repository at this point in the history
  • Loading branch information
dinstein committed Jun 21, 2018
1 parent 61a5976 commit f7a0ad4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions mobile/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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) }
Expand Down

0 comments on commit f7a0ad4

Please sign in to comment.