fix SendTransaction signature in go-ethereum (#355)
I created a separate method SendTransactionWithPassphrase which accepts passphrase as a second argument. It's an exact copy of SendTransaction except for calling wallet.SignTxWithPassphrase.
This commit is contained in:
parent
6d9f5d2e2a
commit
750612f2bc
|
@ -206,7 +206,7 @@ func (s *BackendTestSuite) TestCallRPC() {
|
||||||
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}],"id":1}`,
|
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}],"id":1}`,
|
||||||
func(resultJSON string) {
|
func(resultJSON string) {
|
||||||
log.Info("eth_sendTransaction")
|
log.Info("eth_sendTransaction")
|
||||||
s.T().Log("GOT: ", resultJSON)
|
s.NotContains(resultJSON, "error")
|
||||||
progress <- struct{}{}
|
progress <- struct{}{}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -1180,9 +1180,10 @@ func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
|
||||||
return tx.Hash(), nil
|
return tx.Hash(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendTransaction creates a transaction by unpacking queued transaction, signs it and submits to the
|
// SendTransactionWithPassphrase creates a transaction by unpacking queued transaction, signs it and submits to the
|
||||||
// transaction pool.
|
// transaction pool.
|
||||||
func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args SendTxArgs, passphrase string) (common.Hash, error) {
|
// @Status
|
||||||
|
func (s *PublicTransactionPoolAPI) SendTransactionWithPassphrase(ctx context.Context, args SendTxArgs, passphrase string) (common.Hash, error) {
|
||||||
// Set some sanity defaults and terminate on failure
|
// Set some sanity defaults and terminate on failure
|
||||||
if err := args.setDefaults(ctx, s.b); err != nil {
|
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
|
@ -1221,6 +1222,47 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
|
||||||
return submitTransaction(ctx, s.b, signed)
|
return submitTransaction(ctx, s.b, signed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendTransaction creates a transaction by unpacking queued transaction, signs it and submits to the
|
||||||
|
// transaction pool.
|
||||||
|
func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args SendTxArgs) (common.Hash, error) {
|
||||||
|
// Set some sanity defaults and terminate on failure
|
||||||
|
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||||
|
return common.Hash{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look up the wallet containing the requested signer
|
||||||
|
account := accounts.Account{Address: args.From}
|
||||||
|
|
||||||
|
wallet, err := s.b.AccountManager().Find(account)
|
||||||
|
if err != nil {
|
||||||
|
return common.Hash{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if args.Nonce == nil {
|
||||||
|
// Hold the addresse's mutex around signing to prevent concurrent assignment of
|
||||||
|
// the same nonce to multiple accounts.
|
||||||
|
s.nonceLock.LockAddr(args.From)
|
||||||
|
defer s.nonceLock.UnlockAddr(args.From)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set some sanity defaults and terminate on failure
|
||||||
|
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||||
|
return common.Hash{}, err
|
||||||
|
}
|
||||||
|
// Assemble the transaction and sign with the wallet
|
||||||
|
tx := args.toTransaction()
|
||||||
|
|
||||||
|
var chainID *big.Int
|
||||||
|
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
|
||||||
|
chainID = config.ChainId
|
||||||
|
}
|
||||||
|
signed, err := wallet.SignTx(account, tx, chainID)
|
||||||
|
if err != nil {
|
||||||
|
return common.Hash{}, err
|
||||||
|
}
|
||||||
|
return submitTransaction(ctx, s.b, signed)
|
||||||
|
}
|
||||||
|
|
||||||
// SendRawTransaction will add the signed transaction to the transaction pool.
|
// SendRawTransaction will add the signed transaction to the transaction pool.
|
||||||
// The sender is responsible for signing the transaction and using the correct nonce.
|
// The sender is responsible for signing the transaction and using the correct nonce.
|
||||||
func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (string, error) {
|
func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (string, error) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (b *StatusBackend) AccountManager() *status.AccountManager {
|
||||||
return b.am
|
return b.am
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendTransaction wraps call to PublicTransactionPoolAPI.SendTransaction
|
// SendTransaction wraps call to PublicTransactionPoolAPI.SendTransactionWithPassphrase
|
||||||
func (b *StatusBackend) SendTransaction(ctx context.Context, args status.SendTxArgs, passphrase string) (common.Hash, error) {
|
func (b *StatusBackend) SendTransaction(ctx context.Context, args status.SendTxArgs, passphrase string) (common.Hash, error) {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
|
@ -57,7 +57,7 @@ func (b *StatusBackend) SendTransaction(ctx context.Context, args status.SendTxA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.txapi.SendTransaction(ctx, SendTxArgs(args), passphrase)
|
return b.txapi.SendTransactionWithPassphrase(ctx, SendTxArgs(args), passphrase)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EstimateGas uses underlying blockchain API to obtain gas for a given tx arguments
|
// EstimateGas uses underlying blockchain API to obtain gas for a given tx arguments
|
||||||
|
|
Loading…
Reference in New Issue