Skip to content

Commit 417b55b

Browse files
Add eth_feeHistory method to Eth API (#146)
1 parent f073e74 commit 417b55b

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

packages/ethereum/src/Network/Ethereum/Api/Eth.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ module Network.Ethereum.Api.Eth where
1818
import Data.ByteArray.HexString (HexString)
1919
import Data.Solidity.Prim.Address (Address)
2020
import Data.Text (Text)
21-
import Network.Ethereum.Api.Types (Block, BlockT, Call, Change,
22-
DefaultBlock, Filter, Quantity,
23-
SyncingState, Transaction,
24-
TxReceipt)
25-
import Network.JsonRpc.TinyClient (JsonRpc (..))
21+
import Network.Ethereum.Api.Types
22+
( Block
23+
, BlockT
24+
, Call
25+
, Change
26+
, DefaultBlock
27+
, Filter
28+
, Quantity
29+
, SyncingState
30+
, Transaction
31+
, TxReceipt
32+
)
33+
import Network.JsonRpc.TinyClient (JsonRpc(..))
2634

2735
-- | Returns the current ethereum protocol version.
2836
protocolVersion :: JsonRpc m => m Text
@@ -146,6 +154,10 @@ estimateGas :: JsonRpc m => Call -> m Quantity
146154
{-# INLINE estimateGas #-}
147155
estimateGas = remote "eth_estimateGas"
148156

157+
-- | Returns transaction base fee per gas and effective priority fee per gas for the requested/supported block range.
158+
feeHistory :: (JsonRpc m) => Quantity -> DefaultBlock -> [Double] -> m FeeHistory
159+
feeHistory = remote "eth_feeHistory"
160+
149161
-- | Returns information about a block by hash with only hashes of the transactions in it.
150162
getBlockByHashLite :: JsonRpc m => HexString -> m (Maybe (BlockT HexString))
151163
{-# INLINE getBlockByHashLite #-}

packages/ethereum/src/Network/Ethereum/Api/Types.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,23 @@ data BlockT tx = Block
300300

301301
$(deriveJSON (defaultOptions
302302
{ fieldLabelModifier = over _head toLower . drop 5 }) ''BlockT)
303+
304+
--| Fee History information
305+
data FeeHistory
306+
= FeeHistory
307+
{ feeHistoryBaseFeePerBlobGas :: [Quantity]
308+
-- ^ array of block base fees per blob gas.
309+
, feeHistoryBaseFeePerGas :: [Quantity]
310+
-- ^ Array of block base fees per gas.
311+
, feeHistoryBlobGasUsedRatio :: [Rational]
312+
-- ^ Array of block base fees per blob gas.
313+
, feeHistoryGasUsedRatio :: [Rational]
314+
-- ^ Array of block gas used ratios.
315+
, feeHistoryOldestBlock :: Quantity
316+
-- ^ QUANTITY - lowest number block of returned range.
317+
, feeHistoryReward :: [[Quantity]]
318+
-- ^ Two-dimensional array of effective priority fees per gas at the requested block percentiles.
319+
}
320+
deriving (Generic, Show)
321+
322+
$(deriveJSON defaultOptions{fieldLabelModifier = over _head toLower . drop 10} ''FeeHistory)

0 commit comments

Comments
 (0)