Skip to content

Commit

Permalink
Merge branch 'master' into upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
teghnet authored May 23, 2022
2 parents 21aded5 + ca8871b commit af742b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: go

go:
- "1.9.x"
- "1.10.x"
- "master"

script:
Expand Down
19 changes: 9 additions & 10 deletions hdwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (w *Wallet) SignHash(account accounts.Account, hash []byte) ([]byte, error)
}

// SignTxEIP155 implements accounts.Wallet, which allows the account to sign an ERC-20 transaction.
func (w *Wallet) SignTxEIP155(account accounts.Account, tx *types.Transaction, chainID, baseFee *big.Int) (*types.Transaction, error) {
func (w *Wallet) SignTxEIP155(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
w.stateLock.RLock() // Comms have own mutex, this is for the state fields
defer w.stateLock.RUnlock()

Expand All @@ -245,18 +245,18 @@ func (w *Wallet) SignTxEIP155(account accounts.Account, tx *types.Transaction, c
return nil, err
}

signer := types.NewEIP155Signer(chainID)
// Sign the transaction and verify the sender to avoid hardware fault surprises
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
signedTx, err := types.SignTx(tx, signer, privateKey)
if err != nil {
return nil, err
}

msg, err := signedTx.AsMessage(types.NewEIP155Signer(chainID), baseFee)
sender, err := types.Sender(signer, signedTx)
if err != nil {
return nil, err
}

sender := msg.From()
if sender != account.Address {
return nil, fmt.Errorf("signer mismatch: expected %s, got %s", account.Address.Hex(), sender.Hex())
}
Expand All @@ -265,7 +265,7 @@ func (w *Wallet) SignTxEIP155(account accounts.Account, tx *types.Transaction, c
}

// SignTx implements accounts.Wallet, which allows the account to sign an Ethereum transaction.
func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID, baseFee *big.Int) (*types.Transaction, error) {
func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
w.stateLock.RLock() // Comms have own mutex, this is for the state fields
defer w.stateLock.RUnlock()

Expand All @@ -282,18 +282,17 @@ func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID

signer := types.LatestSignerForChainID(chainID)

// Sign the transaction and verify the sender to avoid hardware fault surprises
// Sign the transaction and verify the sender to avoid hardware fault surprises
signedTx, err := types.SignTx(tx, signer, privateKey)
if err != nil {
return nil, err
}

msg, err := signedTx.AsMessage(signer, baseFee)
sender, err := types.Sender(signer, signedTx)
if err != nil {
return nil, err
}

sender := msg.From()
if sender != account.Address {
return nil, fmt.Errorf("signer mismatch: expected %s, got %s", account.Address.Hex(), sender.Hex())
}
Expand All @@ -310,8 +309,8 @@ func (w *Wallet) SignHashWithPassphrase(account accounts.Account, passphrase str

// SignTxWithPassphrase implements accounts.Wallet, attempting to sign the given
// transaction with the given account using passphrase as extra authentication.
func (w *Wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID, baseFee *big.Int) (*types.Transaction, error) {
return w.SignTx(account, tx, baseFee, chainID)
func (w *Wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
return w.SignTx(account, tx, chainID)
}

// PrivateKey returns the ECDSA private key of the account.
Expand Down
9 changes: 6 additions & 3 deletions hdwallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"testing"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -64,6 +65,8 @@ func TestWallet(t *testing.T) {
if err != nil {
t.Error(err)
}
// Check that Wallet implements the accounts.Wallet interface.
var _ accounts.Wallet = wallet

path, err := ParseDerivationPath("m/44'/60'/0'/0/0")
if err != nil {
Expand Down Expand Up @@ -163,7 +166,7 @@ func TestWallet(t *testing.T) {

tx := types.NewTransaction(nonce, toAddress, value, gasLimit, gasPrice, data)

signedTx, err := wallet.SignTx(account, tx, nil, nil)
signedTx, err := wallet.SignTx(account, tx, nil)
if err != nil {
t.Error(err)
}
Expand All @@ -179,15 +182,15 @@ func TestWallet(t *testing.T) {
t.Error("expected s value")
}

signedTx2, err := wallet.SignTxWithPassphrase(account, "", tx, nil, nil)
signedTx2, err := wallet.SignTxWithPassphrase(account, "", tx, nil)
if err != nil {
t.Error(err)
}
if signedTx.Hash() != signedTx2.Hash() {
t.Error("expected match")
}

signedTx3, err := wallet.SignTxEIP155(account, tx, big.NewInt(42), big.NewInt(10))
signedTx3, err := wallet.SignTxEIP155(account, tx, big.NewInt(42))
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit af742b3

Please sign in to comment.