mobile: use EIP155 signer (#14817)

* mobile: Use EIP155Signer - closes #14762

* mobile: Correctly fall back on HomesteadSigner when no chainID is passed in
This commit is contained in:
ligi 2017-07-17 13:31:26 +02:00 committed by Péter Szilágyi
parent b95c2b58f0
commit cf5d4b5541
1 changed files with 10 additions and 5 deletions

View File

@ -265,10 +265,11 @@ func (tx *Transaction) GetSigHash() *Hash { return &Hash{tx.tx.SigHash(types.Hom
func (tx *Transaction) GetCost() *BigInt { return &BigInt{tx.tx.Cost()} } func (tx *Transaction) GetCost() *BigInt { return &BigInt{tx.tx.Cost()} }
func (tx *Transaction) GetFrom(chainID *BigInt) (address *Address, _ error) { func (tx *Transaction) GetFrom(chainID *BigInt) (address *Address, _ error) {
if chainID == nil { // Null passed from mobile app var signer types.Signer = types.HomesteadSigner{}
chainID = new(BigInt) if chainID != nil {
signer = types.NewEIP155Signer(chainID.bigint)
} }
from, err := types.Sender(types.NewEIP155Signer(chainID.bigint), tx.tx) from, err := types.Sender(signer, tx.tx)
return &Address{from}, err return &Address{from}, err
} }
@ -279,8 +280,12 @@ func (tx *Transaction) GetTo() *Address {
return nil return nil
} }
func (tx *Transaction) WithSignature(sig []byte) (signedTx *Transaction, _ error) { func (tx *Transaction) WithSignature(sig []byte, chainID *BigInt) (signedTx *Transaction, _ error) {
rawTx, err := tx.tx.WithSignature(types.HomesteadSigner{}, sig) var signer types.Signer = types.HomesteadSigner{}
if chainID != nil {
signer = types.NewEIP155Signer(chainID.bigint)
}
rawTx, err := tx.tx.WithSignature(signer, sig)
return &Transaction{rawTx}, err return &Transaction{rawTx}, err
} }