Skip to content

Commit

Permalink
Add isQuorum parameter to SignTx.
Browse files Browse the repository at this point in the history
  • Loading branch information
joelburget committed Aug 24, 2017
1 parent 39fc09e commit bd88b3e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type Wallet interface {
// about which fields or actions are needed. The user may retry by providing
// the needed details via SignTxWithPassphrase, or by other means (e.g. unlock
// the account in a keystore).
SignTx(account Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
SignTx(account Account, tx *types.Transaction, chainID *big.Int, isQuorum bool) (*types.Transaction, error)

// SignHashWithPassphrase requests the wallet to sign the given hash with the
// given passphrase as extra authentication information.
Expand Down
4 changes: 2 additions & 2 deletions accounts/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (ks *KeyStore) SignHash(a accounts.Account, hash []byte) ([]byte, error) {
}

// SignTx signs the given transaction with the requested account.
func (ks *KeyStore) SignTx(a accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
func (ks *KeyStore) SignTx(a accounts.Account, tx *types.Transaction, chainID *big.Int, isQuorum bool) (*types.Transaction, error) {
// Look up the key to sign with and abort if it cannot be found
ks.mu.RLock()
defer ks.mu.RUnlock()
Expand All @@ -278,7 +278,7 @@ func (ks *KeyStore) SignTx(a accounts.Account, tx *types.Transaction, chainID *b
return nil, ErrLocked
}
// Depending on the presence of the chain ID, sign with EIP155 or homestead
if chainID != nil { // && !params.IsQuorum {
if chainID != nil && !isQuorum {
return types.SignTx(tx, types.NewEIP155Signer(chainID), unlockedKey.PrivateKey)
}
return types.SignTx(tx, types.HomesteadSigner{}, unlockedKey.PrivateKey)
Expand Down
4 changes: 2 additions & 2 deletions accounts/keystore/keystore_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (w *keystoreWallet) SignHash(account accounts.Account, hash []byte) ([]byte
// with the given account. If the wallet does not wrap this particular account,
// an error is returned to avoid account leakage (even though in theory we may
// be able to sign via our shared keystore backend).
func (w *keystoreWallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
func (w *keystoreWallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int, isQuorum bool) (*types.Transaction, error) {
// Make sure the requested account is contained within
if account.Address != w.account.Address {
return nil, accounts.ErrUnknownAccount
Expand All @@ -107,7 +107,7 @@ func (w *keystoreWallet) SignTx(account accounts.Account, tx *types.Transaction,
return nil, accounts.ErrUnknownAccount
}
// Account seems valid, request the keystore to sign
return w.keystore.SignTx(account, tx, chainID)
return w.keystore.SignTx(account, tx, chainID, isQuorum)
}

// SignHashWithPassphrase implements accounts.Wallet, attempting to sign the
Expand Down
9 changes: 7 additions & 2 deletions accounts/usbwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sync"
"time"

"errors"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -508,10 +509,14 @@ func (w *wallet) SignHash(account accounts.Account, hash []byte) ([]byte, error)
// Note, if the version of the Ethereum application running on the Ledger wallet is
// too old to sign EIP-155 transactions, but such is requested nonetheless, an error
// will be returned opposed to silently signing in Homestead mode.
func (w *wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
func (w *wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int, isQuorum bool) (*types.Transaction, error) {
w.stateLock.RLock() // Comms have own mutex, this is for the state fields
defer w.stateLock.RUnlock()

if isQuorum {
return nil, errors.New("Signing Quorum transactions with a USB wallet not yet supported")
}

// If the wallet is closed, abort
if w.device == nil {
return nil, accounts.ErrWalletClosed
Expand Down Expand Up @@ -558,5 +563,5 @@ func (w *wallet) SignHashWithPassphrase(account accounts.Account, passphrase str
// transaction with the given account using passphrase as extra authentication.
// Since USB wallets don't rely on passphrases, these are silently ignored.
func (w *wallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
return w.SignTx(account, tx, chainID)
return w.SignTx(account, tx, chainID, false)
}
8 changes: 6 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,12 @@ func (s *PublicTransactionPoolAPI) sign(addr common.Address, tx *types.Transacti
}
// Request the wallet to sign the transaction
var chainID *big.Int
isQuorum := false
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
chainID = config.ChainId
isQuorum = true
}
return wallet.SignTx(account, tx, chainID)
return wallet.SignTx(account, tx, chainID, isQuorum)
}

// SendTxArgs represents the arguments to sumbit a new transaction into the transaction pool.
Expand Down Expand Up @@ -1155,10 +1157,12 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
tx := args.toTransaction()

var chainID *big.Int
isQuorum := false
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
chainID = config.ChainId
isQuorum = true
}
signed, err := wallet.SignTx(account, tx, chainID)
signed, err := wallet.SignTx(account, tx, chainID, isQuorum)
if err != nil {
return common.Hash{}, err
}
Expand Down

0 comments on commit bd88b3e

Please sign in to comment.