Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman committed Sep 8, 2023
1 parent aed9ee3 commit d66e08f
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,26 @@ func (e *Eth) getGasPrice() (uint64, error) {
return common.Max(e.priceLimit, avgGasPrice), nil
}

// fillTransactionGasPrice fills transaction gas price if no provided
func (e *Eth) fillTransactionGasPrice(tx *types.Transaction) error {
if tx.GetGasPrice(e.store.GetBaseFee()).BitLen() > 0 {
return nil
}

estimatedGasPrice, err := e.getGasPrice()
if err != nil {
return err
}

if tx.Type == types.DynamicFeeTx {
tx.GasFeeCap = new(big.Int).SetUint64(estimatedGasPrice)
} else {
tx.GasPrice = new(big.Int).SetUint64(estimatedGasPrice)
}

return nil
}

type overrideAccount struct {
Nonce *argUint64 `json:"nonce"`
Code *argBytes `json:"code"`
Expand Down Expand Up @@ -477,17 +497,8 @@ func (e *Eth) Call(arg *txnArgs, filter BlockNumberOrHash, apiOverride *stateOve
}

// Force transaction gas price if empty
if transaction.GetGasPrice(e.store.GetBaseFee()).BitLen() == 0 {
estimatedGasPrice, err := e.getGasPrice()
if err != nil {
return nil, err
}

if transaction.Type == types.DynamicFeeTx {
transaction.GasFeeCap = new(big.Int).SetUint64(estimatedGasPrice)
} else {
transaction.GasPrice = new(big.Int).SetUint64(estimatedGasPrice)
}
if err = e.fillTransactionGasPrice(transaction); err != nil {
return nil, err
}

var override types.StateOverride
Expand Down Expand Up @@ -536,17 +547,8 @@ func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error
}

// Force transaction gas price if empty
if transaction.GetGasPrice(e.store.GetBaseFee()).BitLen() == 0 {
estimatedGasPrice, err := e.getGasPrice()
if err != nil {
return nil, err
}

if transaction.Type == types.DynamicFeeTx {
transaction.GasFeeCap = new(big.Int).SetUint64(estimatedGasPrice)
} else {
transaction.GasPrice = new(big.Int).SetUint64(estimatedGasPrice)
}
if err = e.fillTransactionGasPrice(transaction); err != nil {
return nil, err
}

forksInTime := e.store.GetForksInTime(header.Number)
Expand Down

0 comments on commit d66e08f

Please sign in to comment.