Skip to content

Commit

Permalink
internal/ethapi: fix transaction APIs (ethereum#23179)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Jun 19, 2024
1 parent 905f8bf commit ece6c90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,15 @@ func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args Transactio
if args.Gas == nil {
return nil, errors.New("gas not specified")
}
if args.GasPrice == nil {
return nil, errors.New("gasPrice not specified")
if args.GasPrice == nil && (args.MaxFeePerGas == nil || args.MaxPriorityFeePerGas == nil) {
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
}
if args.Nonce == nil {
return nil, errors.New("nonce not specified")
}
// Before actually sign the transaction, ensure the transaction fee is reasonable.
if err := checkTxFee(args.GasPrice.ToInt(), uint64(*args.Gas), s.b.RPCTxFeeCap()); err != nil {
tx := args.toTransaction()
if err := checkTxFee(tx.GasPrice(), tx.Gas(), s.b.RPCTxFeeCap()); err != nil {
return nil, err
}
signed, err := s.signTransaction(ctx, &args, passwd)
Expand Down Expand Up @@ -2368,8 +2369,9 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Tra
return SubmitTransaction(ctx, s.b, signed)
}

// FillTransaction fills the defaults (nonce, gas, gasPrice) on a given unsigned transaction,
// and returns it to the caller for further processing (signing + broadcast)
// FillTransaction fills the defaults (nonce, gas, gasPrice or 1559 fields)
// on a given unsigned transaction, and returns it to the caller for further
// processing (signing + broadcast).
func (s *PublicTransactionPoolAPI) FillTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) {
// Set some sanity defaults and terminate on failure
if err := args.setDefaults(ctx, s.b); err != nil {
Expand Down Expand Up @@ -3271,8 +3273,8 @@ func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args Tra
if args.Gas == nil {
return nil, errors.New("gas not specified")
}
if args.GasPrice == nil {
return nil, errors.New("gasPrice not specified")
if args.GasPrice == nil && (args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil) {
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
}
if args.Nonce == nil {
return nil, errors.New("nonce not specified")
Expand All @@ -3281,14 +3283,15 @@ func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args Tra
return nil, err
}
// Before actually sign the transaction, ensure the transaction fee is reasonable.
if err := checkTxFee(args.GasPrice.ToInt(), uint64(*args.Gas), s.b.RPCTxFeeCap()); err != nil {
tx := args.toTransaction()
if err := checkTxFee(tx.GasPrice(), tx.Gas(), s.b.RPCTxFeeCap()); err != nil {
return nil, err
}
tx, err := s.sign(args.from(), args.toTransaction())
signed, err := s.sign(args.from(), tx)
if err != nil {
return nil, err
}
data, err := tx.MarshalBinary()
data, err := signed.MarshalBinary()
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type TransactionArgs struct {
Data *hexutil.Bytes `json:"data"`
Input *hexutil.Bytes `json:"input"`

// For non-legacy transactions
// Introduced by AccessListTxType transaction.
AccessList *types.AccessList `json:"accessList,omitempty"`
ChainID *hexutil.Big `json:"chainId,omitempty"`
}
Expand Down

0 comments on commit ece6c90

Please sign in to comment.