ethapi: make nonce,gas,gasPrice obligatory in signTransaction

This commit is contained in:
Martin Holst Swende 2018-01-26 14:34:44 +01:00
parent a2ccf4f526
commit 9518f94f50
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -381,6 +381,15 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args SendTxArgs, passwd string) (*SignTransactionResult, error) { func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args SendTxArgs, passwd string) (*SignTransactionResult, error) {
// No need to obtain the noncelock mutex, since we won't be sending this // No need to obtain the noncelock mutex, since we won't be sending this
// tx into the transaction pool, but right back to the user // tx into the transaction pool, but right back to the user
if args.Gas == nil {
return nil, fmt.Errorf("gas not specified")
}
if args.GasPrice == nil {
return nil, fmt.Errorf("gasPrice not specified")
}
if args.Nonce == nil {
return nil, fmt.Errorf("nonce not specified")
}
signed, err := s.signTransaction(ctx, args, passwd) signed, err := s.signTransaction(ctx, args, passwd)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1243,11 +1252,14 @@ type SignTransactionResult struct {
// The node needs to have the private key of the account corresponding with // The node needs to have the private key of the account corresponding with
// the given from address and it needs to be unlocked. // the given from address and it needs to be unlocked.
func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) { func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) {
if args.Gas == nil {
return nil, fmt.Errorf("gas not specified")
}
if args.GasPrice == nil {
return nil, fmt.Errorf("gasPrice not specified")
}
if args.Nonce == nil { if args.Nonce == nil {
// Hold the addresse's mutex around signing to prevent concurrent assignment of return nil, fmt.Errorf("nonce not specified")
// the same nonce to multiple accounts.
s.nonceLock.LockAddr(args.From)
defer s.nonceLock.UnlockAddr(args.From)
} }
if err := args.setDefaults(ctx, s.b); err != nil { if err := args.setDefaults(ctx, s.b); err != nil {
return nil, err return nil, err