From bd88b3e41622a10fae05a7f3338a559aff820a16 Mon Sep 17 00:00:00 2001 From: Joel Burget Date: Thu, 17 Aug 2017 11:51:11 -0400 Subject: [PATCH] Add isQuorum parameter to SignTx. --- accounts/accounts.go | 2 +- accounts/keystore/keystore.go | 4 ++-- accounts/keystore/keystore_wallet.go | 4 ++-- accounts/usbwallet/wallet.go | 9 +++++++-- internal/ethapi/api.go | 8 ++++++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/accounts/accounts.go b/accounts/accounts.go index 76951e1a42a60..6b23d1d7b0f21 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -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. diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index 22536e623f735..10c0db70ffa7c 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -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() @@ -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) diff --git a/accounts/keystore/keystore_wallet.go b/accounts/keystore/keystore_wallet.go index 758fdfe364386..6f809a9bfb246 100644 --- a/accounts/keystore/keystore_wallet.go +++ b/accounts/keystore/keystore_wallet.go @@ -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 @@ -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 diff --git a/accounts/usbwallet/wallet.go b/accounts/usbwallet/wallet.go index 8b3b5a522402e..8dbcc646a02e1 100644 --- a/accounts/usbwallet/wallet.go +++ b/accounts/usbwallet/wallet.go @@ -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" @@ -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 @@ -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) } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 04cab733759ab..9b44c92085f8d 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -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. @@ -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 }