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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use jsonrpc_core::{BoxFuture, Result};
use jsonrpc_derive::rpc;
use zksync_types::{
    api::{BlockIdVariant, BlockNumber, Transaction, TransactionReceipt, TransactionVariant},
    transaction_request::CallRequest,
    web3::{Bytes, FeeHistory, Index, SyncState},
    Address, H256, U256, U64,
};
use zksync_web3_decl::types::{Block, Filter, FilterChanges, Log};

#[rpc]
pub trait EthNamespaceT {
    #[rpc(name = "eth_blockNumber")]
    fn get_block_number(&self) -> BoxFuture<Result<U64>>;

    #[rpc(name = "eth_chainId")]
    fn chain_id(&self) -> BoxFuture<Result<U64>>;

    #[rpc(name = "eth_call")]
    fn call(&self, req: CallRequest, block: Option<BlockIdVariant>) -> BoxFuture<Result<Bytes>>;

    #[rpc(name = "eth_estimateGas")]
    fn estimate_gas(
        &self,
        req: CallRequest,
        _block: Option<BlockNumber>,
    ) -> BoxFuture<Result<U256>>;

    #[rpc(name = "eth_gasPrice")]
    fn gas_price(&self) -> BoxFuture<Result<U256>>;

    #[rpc(name = "eth_newFilter")]
    fn new_filter(&self, filter: Filter) -> BoxFuture<Result<U256>>;

    #[rpc(name = "eth_newBlockFilter")]
    fn new_block_filter(&self) -> BoxFuture<Result<U256>>;

    #[rpc(name = "eth_uninstallFilter")]
    fn uninstall_filter(&self, idx: U256) -> BoxFuture<Result<bool>>;

    #[rpc(name = "eth_newPendingTransactionFilter")]
    fn new_pending_transaction_filter(&self) -> BoxFuture<Result<U256>>;

    #[rpc(name = "eth_getLogs")]
    fn get_logs(&self, filter: Filter) -> BoxFuture<Result<Vec<Log>>>;

    #[rpc(name = "eth_getFilterLogs")]
    fn get_filter_logs(&self, filter_index: U256) -> BoxFuture<Result<FilterChanges>>;

    #[rpc(name = "eth_getFilterChanges")]
    fn get_filter_changes(&self, filter_index: U256) -> BoxFuture<Result<FilterChanges>>;

    #[rpc(name = "eth_getBalance")]
    fn get_balance(
        &self,
        address: Address,
        block: Option<BlockIdVariant>,
    ) -> BoxFuture<Result<U256>>;

    #[rpc(name = "eth_getBlockByNumber")]
    fn get_block_by_number(
        &self,
        block_number: BlockNumber,
        full_transactions: bool,
    ) -> BoxFuture<Result<Option<Block<TransactionVariant>>>>;

    #[rpc(name = "eth_getBlockByHash")]
    fn get_block_by_hash(
        &self,
        hash: H256,
        full_transactions: bool,
    ) -> BoxFuture<Result<Option<Block<TransactionVariant>>>>;

    #[rpc(name = "eth_getBlockTransactionCountByNumber")]
    fn get_block_transaction_count_by_number(
        &self,
        block_number: BlockNumber,
    ) -> BoxFuture<Result<Option<U256>>>;

    #[rpc(name = "eth_getBlockTransactionCountByHash")]
    fn get_block_transaction_count_by_hash(
        &self,
        block_hash: H256,
    ) -> BoxFuture<Result<Option<U256>>>;

    #[rpc(name = "eth_getCode")]
    fn get_code(&self, address: Address, block: Option<BlockIdVariant>)
        -> BoxFuture<Result<Bytes>>;

    #[rpc(name = "eth_getStorageAt")]
    fn get_storage(
        &self,
        address: Address,
        idx: U256,
        block: Option<BlockIdVariant>,
    ) -> BoxFuture<Result<H256>>;

    #[rpc(name = "eth_getTransactionCount")]
    fn get_transaction_count(
        &self,
        address: Address,
        block: Option<BlockIdVariant>,
    ) -> BoxFuture<Result<U256>>;

    #[rpc(name = "eth_getTransactionByHash")]
    fn get_transaction_by_hash(&self, hash: H256) -> BoxFuture<Result<Option<Transaction>>>;

    #[rpc(name = "eth_getTransactionByBlockHashAndIndex")]
    fn get_transaction_by_block_hash_and_index(
        &self,
        block_hash: H256,
        index: Index,
    ) -> BoxFuture<Result<Option<Transaction>>>;

    #[rpc(name = "eth_getTransactionByBlockNumberAndIndex")]
    fn get_transaction_by_block_number_and_index(
        &self,
        block_number: BlockNumber,
        index: Index,
    ) -> BoxFuture<Result<Option<Transaction>>>;

    #[rpc(name = "eth_getTransactionReceipt")]
    fn get_transaction_receipt(&self, hash: H256) -> BoxFuture<Result<Option<TransactionReceipt>>>;

    #[rpc(name = "eth_protocolVersion")]
    fn protocol_version(&self) -> BoxFuture<Result<String>>;

    #[rpc(name = "eth_sendRawTransaction")]
    fn send_raw_transaction(&self, tx_bytes: Bytes) -> BoxFuture<Result<H256>>;

    #[rpc(name = "eth_syncing")]
    fn syncing(&self) -> BoxFuture<Result<SyncState>>;

    #[rpc(name = "eth_accounts")]
    fn accounts(&self) -> BoxFuture<Result<Vec<Address>>>;

    #[rpc(name = "eth_coinbase")]
    fn coinbase(&self) -> BoxFuture<Result<Address>>;

    #[rpc(name = "eth_getCompilers")]
    fn compilers(&self) -> BoxFuture<Result<Vec<String>>>;

    #[rpc(name = "eth_hashrate")]
    fn hashrate(&self) -> BoxFuture<Result<U256>>;

    #[rpc(name = "eth_getUncleCountByBlockHash")]
    fn get_uncle_count_by_block_hash(&self, hash: H256) -> BoxFuture<Result<Option<U256>>>;

    #[rpc(name = "eth_getUncleCountByBlockNumber")]
    fn get_uncle_count_by_block_number(
        &self,
        number: BlockNumber,
    ) -> BoxFuture<Result<Option<U256>>>;

    #[rpc(name = "eth_mining")]
    fn mining(&self) -> BoxFuture<Result<bool>>;

    #[rpc(name = "eth_feeHistory")]
    fn fee_history(
        &self,
        block_count: U64,
        newest_block: BlockNumber,
        reward_percentiles: Vec<f32>,
    ) -> BoxFuture<Result<FeeHistory>>;
}