-
Notifications
You must be signed in to change notification settings - Fork 31
/
ethereum_api.go
51 lines (42 loc) · 1.45 KB
/
ethereum_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package rpcapi
import (
"context"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)
type EthereumAPI struct {
we *Services
}
func NewEthereumAPI(we *Services,
) *EthereumAPI {
return &EthereumAPI{we}
}
func (api *EthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) {
return UnauthenticatedTenRPCCall[hexutil.Big](ctx, api.we, &CacheCfg{CacheType: LatestBatch}, "eth_gasPrice")
}
func (api *EthereumAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) {
return UnauthenticatedTenRPCCall[hexutil.Big](ctx, api.we, &CacheCfg{CacheType: LatestBatch}, "eth_maxPriorityFeePerGas")
}
type FeeHistoryResult struct {
OldestBlock *hexutil.Big `json:"oldestBlock"`
Reward [][]*hexutil.Big `json:"reward,omitempty"`
BaseFee []*hexutil.Big `json:"baseFeePerGas,omitempty"`
GasUsedRatio []float64 `json:"gasUsedRatio"`
}
func (api *EthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*FeeHistoryResult, error) {
return UnauthenticatedTenRPCCall[FeeHistoryResult](
ctx,
api.we,
&CacheCfg{CacheTypeDynamic: func() CacheStrategy {
return cacheBlockNumber(lastBlock)
}},
"eth_feeHistory",
blockCount,
lastBlock,
rewardPercentiles,
)
}
func (api *EthereumAPI) Syncing() (interface{}, error) {
return nil, rpcNotImplemented
}