Skip to content

Commit

Permalink
internal/ethapi: address review concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman authored and karalabe committed Jun 1, 2021
1 parent 3946fa3 commit 88caa9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1473,11 +1473,11 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, has
return nil, err
}
if tx != nil {
block, err := s.b.BlockByHash(ctx, blockHash)
header, err := s.b.HeaderByHash(ctx, blockHash)
if err != nil {
return nil, err
}
return newRPCTransaction(tx, blockHash, blockNumber, index, block.BaseFee()), nil
return newRPCTransaction(tx, blockHash, blockNumber, index, header.BaseFee), nil
}
// No finalized transaction, try to retrieve it from the pool
if tx := s.b.GetPoolTransaction(hash); tx != nil {
Expand Down
27 changes: 17 additions & 10 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func (arg *TransactionArgs) data() []byte {

// setDefaults fills in default values for unspecified tx fields.
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
if args.GasPrice != nil && (args.FeeCap != nil || args.Tip != nil) {
return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
}
// After london, default to 1559 unless gasPrice is set
if b.ChainConfig().IsLondon(b.CurrentBlock().Number()) && args.GasPrice == nil {
if args.Tip == nil {
tip, err := b.SuggestTip(ctx)
Expand All @@ -92,6 +96,9 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
// Don't let tip exceed feeCap.
args.FeeCap = (*hexutil.Big)(math.BigMax(args.FeeCap.ToInt(), args.Tip.ToInt()))
} else {
if args.FeeCap != nil || args.Tip != nil {
return errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet")
}
if args.GasPrice == nil {
price, err := b.SuggestPrice(ctx)
if err != nil {
Expand Down Expand Up @@ -221,16 +228,7 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
Data: args.data(),
AccessList: al,
}
case args.AccessList == nil:
data = &types.LegacyTx{
To: args.To,
Nonce: uint64(*args.Nonce),
Gas: uint64(*args.Gas),
GasPrice: (*big.Int)(args.GasPrice),
Value: (*big.Int)(args.Value),
Data: args.data(),
}
default:
case args.AccessList != nil:
data = &types.AccessListTx{
To: args.To,
ChainID: (*big.Int)(args.ChainID),
Expand All @@ -241,6 +239,15 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
Data: args.data(),
AccessList: *args.AccessList,
}
default:
data = &types.LegacyTx{
To: args.To,
Nonce: uint64(*args.Nonce),
Gas: uint64(*args.Gas),
GasPrice: (*big.Int)(args.GasPrice),
Value: (*big.Int)(args.Value),
Data: args.data(),
}
}
return types.NewTx(data)
}

0 comments on commit 88caa9e

Please sign in to comment.