all: rename internal 1559 gas fields, add support for graphql (#23010)

* all: rename internal 1559 gas fields, add support for graphql

* cmd/evm/testdata, core: use public 1559 gas names on API surfaces
This commit is contained in:
Péter Szilágyi
2021-06-08 13:05:41 +03:00
committed by GitHub
parent 248572ee54
commit c503f98f6d
27 changed files with 329 additions and 262 deletions

View File

@ -21,12 +21,14 @@ import (
"context"
"errors"
"fmt"
"math/big"
"strconv"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
@ -218,7 +220,50 @@ func (t *Transaction) GasPrice(ctx context.Context) (hexutil.Big, error) {
if err != nil || tx == nil {
return hexutil.Big{}, err
}
return hexutil.Big(*tx.GasPrice()), nil
switch tx.Type() {
case types.AccessListTxType:
return hexutil.Big(*tx.GasPrice()), nil
case types.DynamicFeeTxType:
if t.block != nil {
if baseFee, _ := t.block.BaseFeePerGas(ctx); baseFee != nil {
// price = min(tip, gasFeeCap - baseFee) + baseFee
return (hexutil.Big)(*math.BigMin(new(big.Int).Add(tx.GasTipCap(), baseFee.ToInt()), tx.GasFeeCap())), nil
}
}
return hexutil.Big(*tx.GasPrice()), nil
default:
return hexutil.Big(*tx.GasPrice()), nil
}
}
func (t *Transaction) MaxFeePerGas(ctx context.Context) (*hexutil.Big, error) {
tx, err := t.resolve(ctx)
if err != nil || tx == nil {
return nil, err
}
switch tx.Type() {
case types.AccessListTxType:
return nil, nil
case types.DynamicFeeTxType:
return (*hexutil.Big)(tx.GasFeeCap()), nil
default:
return nil, nil
}
}
func (t *Transaction) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) {
tx, err := t.resolve(ctx)
if err != nil || tx == nil {
return nil, err
}
switch tx.Type() {
case types.AccessListTxType:
return nil, nil
case types.DynamicFeeTxType:
return (*hexutil.Big)(tx.GasTipCap()), nil
default:
return nil, nil
}
}
func (t *Transaction) Value(ctx context.Context) (hexutil.Big, error) {
@ -517,6 +562,17 @@ func (b *Block) GasUsed(ctx context.Context) (Long, error) {
return Long(header.GasUsed), nil
}
func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
header, err := b.resolveHeader(ctx)
if err != nil {
return nil, err
}
if header.BaseFee == nil {
return nil, nil
}
return (*hexutil.Big)(header.BaseFee), nil
}
func (b *Block) Parent(ctx context.Context) (*Block, error) {
// If the block header hasn't been fetched, and we'll need it, fetch it.
if b.numberOrHash == nil && b.header == nil {
@ -833,12 +889,14 @@ func (b *Block) Account(ctx context.Context, args struct {
// CallData encapsulates arguments to `call` or `estimateGas`.
// All arguments are optional.
type CallData struct {
From *common.Address // The Ethereum address the call is from.
To *common.Address // The Ethereum address the call is to.
Gas *hexutil.Uint64 // The amount of gas provided for the call.
GasPrice *hexutil.Big // The price of each unit of gas, in wei.
Value *hexutil.Big // The value sent along with the call.
Data *hexutil.Bytes // Any data sent with the call.
From *common.Address // The Ethereum address the call is from.
To *common.Address // The Ethereum address the call is to.
Gas *hexutil.Uint64 // The amount of gas provided for the call.
GasPrice *hexutil.Big // The price of each unit of gas, in wei.
MaxFeePerGas *hexutil.Big // The max price of each unit of gas, in wei (1559).
MaxPriorityFeePerGas *hexutil.Big // The max tip of each unit of gas, in wei (1559).
Value *hexutil.Big // The value sent along with the call.
Data *hexutil.Bytes // Any data sent with the call.
}
// CallResult encapsulates the result of an invocation of the `call` accessor.