1use crate::methods;
2use std::thread;
3use jsonrpc_http_server::jsonrpc_core::{IoHandler, Value, Params};
4use jsonrpc_http_server::ServerBuilder;
5
6pub struct Entry {
7 addr: String,
8}
9
10impl Clone for Entry {
11 fn clone(&self) -> Entry {
12 Entry {
13 addr: self.addr.clone(),
14 }
15 }
16}
17
18impl Entry {
19 pub fn new(addr: &str) -> Self {
20 Entry {
21 addr: String::from(addr),
22 }
23 }
24
25 pub fn serve_silent(self) {
26 thread::spawn(move || self.serve());
27 }
28
29 pub fn serve(self) {
30 let server = ServerBuilder::new(self.setup_methods())
31 .threads(3)
32 .start_http(&self.addr.parse().unwrap())
33 .unwrap();
34
35 server.wait();
36 }
37
38 fn setup_methods(&self) -> IoHandler {
39 let mut io = IoHandler::default();
40
41 io.add_method(methods::WEB3_CLIENT_VERSION, |_params: Params| async {
42 Ok(Value::String("Mist/v0.9.3/darwin/go1.4.1".to_owned()))
43 });
44
45 io.add_method(methods::WEB3_SHA3, |_params: Params| async {
46 Ok(Value::String("0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad".to_owned()))
47 });
48
49 io.add_method(methods::NET_VERSION, |_params: Params| async {
50 Ok(Value::String("3".to_owned()))
51 });
52
53 io.add_method(methods::NET_PEER_COUNT, |_params: Params| async {
54 Ok(Value::String("0x2".to_owned()))
55 });
56
57 io.add_method(methods::NET_LISTENING, |_params: Params| async {
58 Ok(Value::Bool(true))
59 });
60
61 io.add_method(methods::ETH_PROTOCOL_VERSION, |_params: Params| async {
62 Ok(Value::String("54".to_owned()))
63 });
64
65 io.add_method(methods::ETH_SYNCING, |_params: Params| async {
66 let mut data = jsonrpc_core::serde_json::Map::new();
67 data.insert("startingBlock".to_string(), Value::String("0x384".to_owned()));
68 data.insert("currentBlock".to_string(), Value::String("0x386".to_owned()));
69 data.insert("highestBlock".to_string(), Value::String("0x454".to_owned()));
70
71 Ok(Value::Object(data))
72 });
73
74 io.add_method(methods::ETH_COINBASE, |_params: Params| async {
75 Ok(Value::String("0x407d73d8a49eeb85d32cf465507dd71d507100c1".to_owned()))
76 });
77
78 io.add_method(methods::ETH_MINING, |_params: Params| async {
79 Ok(Value::Bool(true))
80 });
81
82 io.add_method(methods::ETH_HASHRATE, |_params: Params| async {
83 Ok(Value::String("0x38a".to_owned()))
84 });
85
86 io.add_method(methods::ETH_GAS_PRICE, |_params: Params| async {
87 Ok(Value::String("0x1dfd14000".to_owned()))
88 });
89
90 io.add_method(methods::ETH_ACCOUNTS, |_params: Params| async {
91 Ok(Value::Array(vec![Value::String("0x407d73d8a49eeb85d32cf465507dd71d507100c1".to_owned())]))
92 });
93
94 io.add_method(methods::ETH_BLOCK_NUMBER, |_params: Params| async {
95 Ok(Value::String("0x4b7".to_owned()))
96 });
97
98 io.add_method(methods::ETH_GET_BALANCE, |_params: Params| async {
99 Ok(Value::String("0x0234c8a3397aab58".to_owned()))
100 });
101
102 io.add_method(methods::ETH_GET_STORAGE_AT, |_params: Params| async {
103 Ok(Value::String("0x000000000000000000000000000000000000000000000000000000000000162e".to_owned()))
104 });
105
106 io.add_method(methods::ETH_GET_TRANSACTION_COUNT, |_params: Params| async {
107 Ok(Value::String("0x1".to_owned()))
108 });
109
110 io.add_method(methods::ETH_GET_BLOCK_TRANSACTION_COUNT_BY_HASH, |_params: Params| async {
111 Ok(Value::String("0xb".to_owned()))
112 });
113
114 io.add_method(methods::ETH_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER, |_params: Params| async {
115 Ok(Value::String("0xa".to_owned()))
116 });
117
118 io.add_method(methods::ETH_GET_UNCLE_COUNT_BY_BLOCK_HASH, |_params: Params| async {
119 Ok(Value::String("0x1".to_owned()))
120 });
121
122 io.add_method(methods::ETH_GET_UNCLE_COUNT_BY_BLOCK_NUMBER, |_params: Params| async {
123 Ok(Value::String("0x1".to_owned()))
124 });
125
126 io.add_method(methods::ETH_GET_CODE, |_params: Params| async {
127 Ok(Value::String("0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056".to_owned()))
128 });
129
130 io.add_method(methods::ETH_SIGN, |_params: Params| async {
131 Ok(Value::String("0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b".to_owned()))
132 });
133
134 io.add_method(methods::ETH_SIGN_TRANSACTION, |_params: Params| async {
135 Ok(Value::String("0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b".to_owned()))
136 });
137
138 io.add_method(methods::ETH_SEND_TRANSACTION, |_params: Params| async {
139 Ok(Value::String("0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331".to_owned()))
140 });
141
142 io.add_method(methods::ETH_SEND_RAW_TRANSACTION, |_params: Params| async {
143 Ok(Value::String("0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331".to_owned()))
144 });
145
146 io.add_method(methods::ETH_CALL, |_params: Params| async {
147 Ok(Value::String("0x".to_owned()))
148 });
149
150 io.add_method(methods::ETH_ESTIMATE_GAS, |_params: Params| async {
151 Ok(Value::String("0x5208".to_owned()))
152 });
153
154 io.add_method(methods::ETH_GET_BLOCK_BY_HASH, |_params: Params| async {
155 let mut data = jsonrpc_core::serde_json::Map::new();
156 data.insert("difficulty".to_string(), Value::String("0x4ea3f27bc".to_owned()));
157 data.insert("extraData".to_string(), Value::String("0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32".to_owned()));
158 data.insert("gasLimit".to_string(), Value::String("0x1388".to_owned()));
159 data.insert("gasUsed".to_string(), Value::String("0x0".to_owned()));
160 data.insert("hash".to_string(), Value::String("0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae".to_owned()));
161 data.insert("logsBloom".to_string(), Value::String("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".to_owned()));
162 data.insert("miner".to_string(), Value::String("0xbb7b8287f3f0a933474a79eae42cbca977791171".to_owned()));
163 data.insert("mixHash".to_string(), Value::String("0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843".to_owned()));
164 data.insert("nonce".to_string(), Value::String("0x689056015818adbe".to_owned()));
165 data.insert("number".to_string(), Value::String("0x1b4".to_owned()));
166 data.insert("parentHash".to_string(), Value::String("0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54".to_owned()));
167 data.insert("receiptsRoot".to_string(), Value::String("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_owned()));
168 data.insert("sha3Uncles".to_string(), Value::String("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".to_owned()));
169 data.insert("size".to_string(), Value::String("0x220".to_owned()));
170 data.insert("stateRoot".to_string(), Value::String("0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d".to_owned()));
171 data.insert("timestamp".to_string(), Value::String("0x55ba467c".to_owned()));
172 data.insert("totalDifficulty".to_string(), Value::String("0x78ed983323d".to_owned()));
173 data.insert("transactions".to_string(), Value::Array(vec![]));
174 data.insert("transactionsRoot".to_string(), Value::String("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_owned()));
175 data.insert("uncles".to_string(), Value::Array(vec![]));
176
177 Ok(Value::Object(data))
178 });
179
180 io.add_method(methods::ETH_GET_BLOCK_BY_NUMBER, |_params: Params| async {
181 let mut data = jsonrpc_core::serde_json::Map::new();
182 data.insert("difficulty".to_string(), Value::String("0x4ea3f27bc".to_owned()));
183 data.insert("extraData".to_string(), Value::String("0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32".to_owned()));
184 data.insert("gasLimit".to_string(), Value::String("0x1388".to_owned()));
185 data.insert("gasUsed".to_string(), Value::String("0x0".to_owned()));
186 data.insert("hash".to_string(), Value::String("0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae".to_owned()));
187 data.insert("logsBloom".to_string(), Value::String("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".to_owned()));
188 data.insert("miner".to_string(), Value::String("0xbb7b8287f3f0a933474a79eae42cbca977791171".to_owned()));
189 data.insert("mixHash".to_string(), Value::String("0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843".to_owned()));
190 data.insert("nonce".to_string(), Value::String("0x689056015818adbe".to_owned()));
191 data.insert("number".to_string(), Value::String("0x1b4".to_owned()));
192 data.insert("parentHash".to_string(), Value::String("0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54".to_owned()));
193 data.insert("receiptsRoot".to_string(), Value::String("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_owned()));
194 data.insert("sha3Uncles".to_string(), Value::String("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".to_owned()));
195 data.insert("size".to_string(), Value::String("0x220".to_owned()));
196 data.insert("stateRoot".to_string(), Value::String("0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d".to_owned()));
197 data.insert("timestamp".to_string(), Value::String("0x55ba467c".to_owned()));
198 data.insert("totalDifficulty".to_string(), Value::String("0x78ed983323d".to_owned()));
199 data.insert("transactions".to_string(), Value::Array(vec![]));
200 data.insert("transactionsRoot".to_string(), Value::String("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_owned()));
201 data.insert("uncles".to_string(), Value::Array(vec![]));
202
203 Ok(Value::Object(data))
204 });
205
206 io.add_method(methods::ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX, |_params: Params| async {
207 let mut data = jsonrpc_core::serde_json::Map::new();
208 data.insert("difficulty".to_string(), Value::String("0x4ea3f27bc".to_owned()));
209 data.insert("extraData".to_string(), Value::String("0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32".to_owned()));
210 data.insert("gasLimit".to_string(), Value::String("0x1388".to_owned()));
211 data.insert("gasUsed".to_string(), Value::String("0x0".to_owned()));
212 data.insert("hash".to_string(), Value::String("0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae".to_owned()));
213 data.insert("logsBloom".to_string(), Value::String("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".to_owned()));
214 data.insert("miner".to_string(), Value::String("0xbb7b8287f3f0a933474a79eae42cbca977791171".to_owned()));
215 data.insert("mixHash".to_string(), Value::String("0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843".to_owned()));
216 data.insert("nonce".to_string(), Value::String("0x689056015818adbe".to_owned()));
217 data.insert("number".to_string(), Value::String("0x1b4".to_owned()));
218 data.insert("parentHash".to_string(), Value::String("0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54".to_owned()));
219 data.insert("receiptsRoot".to_string(), Value::String("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_owned()));
220 data.insert("sha3Uncles".to_string(), Value::String("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".to_owned()));
221 data.insert("size".to_string(), Value::String("0x220".to_owned()));
222 data.insert("stateRoot".to_string(), Value::String("0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d".to_owned()));
223 data.insert("timestamp".to_string(), Value::String("0x55ba467c".to_owned()));
224 data.insert("totalDifficulty".to_string(), Value::String("0x78ed983323d".to_owned()));
225 data.insert("transactions".to_string(), Value::Array(vec![]));
226 data.insert("transactionsRoot".to_string(), Value::String("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_owned()));
227 data.insert("uncles".to_string(), Value::Array(vec![]));
228
229 Ok(Value::Object(data))
230 });
231
232 io.add_method(methods::ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX, |_params: Params| async {
233 let mut data = jsonrpc_core::serde_json::Map::new();
234 data.insert("difficulty".to_string(), Value::String("0x4ea3f27bc".to_owned()));
235 data.insert("extraData".to_string(), Value::String("0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32".to_owned()));
236 data.insert("gasLimit".to_string(), Value::String("0x1388".to_owned()));
237 data.insert("gasUsed".to_string(), Value::String("0x0".to_owned()));
238 data.insert("hash".to_string(), Value::String("0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae".to_owned()));
239 data.insert("logsBloom".to_string(), Value::String("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".to_owned()));
240 data.insert("miner".to_string(), Value::String("0xbb7b8287f3f0a933474a79eae42cbca977791171".to_owned()));
241 data.insert("mixHash".to_string(), Value::String("0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843".to_owned()));
242 data.insert("nonce".to_string(), Value::String("0x689056015818adbe".to_owned()));
243 data.insert("number".to_string(), Value::String("0x1b4".to_owned()));
244 data.insert("parentHash".to_string(), Value::String("0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54".to_owned()));
245 data.insert("receiptsRoot".to_string(), Value::String("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_owned()));
246 data.insert("sha3Uncles".to_string(), Value::String("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".to_owned()));
247 data.insert("size".to_string(), Value::String("0x220".to_owned()));
248 data.insert("stateRoot".to_string(), Value::String("0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d".to_owned()));
249 data.insert("timestamp".to_string(), Value::String("0x55ba467c".to_owned()));
250 data.insert("totalDifficulty".to_string(), Value::String("0x78ed983323d".to_owned()));
251 data.insert("transactions".to_string(), Value::Array(vec![]));
252 data.insert("transactionsRoot".to_string(), Value::String("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_owned()));
253 data.insert("uncles".to_string(), Value::Array(vec![]));
254
255 Ok(Value::Object(data))
256 });
257
258 io.add_method(methods::ETH_GET_TRANSACTION_BY_HASH, |_params: Params| async {
259 let mut data = jsonrpc_core::serde_json::Map::new();
260 data.insert("blockHash".to_string(), Value::String("0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2".to_owned()));
261 data.insert("blockNumber".to_string(), Value::String("0x5daf3b".to_owned()));
262 data.insert("from".to_string(), Value::String("0xa7d9ddbe1f17865597fbd27ec712455208b6b76d".to_owned()));
263 data.insert("gas".to_string(), Value::String("0xc350".to_owned()));
264 data.insert("gasPrice".to_string(), Value::String("0x4a817c800".to_owned()));
265 data.insert("hash".to_string(), Value::String("0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b".to_owned()));
266 data.insert("input".to_string(), Value::String("0x68656c6c6f21".to_owned()));
267 data.insert("nonce".to_string(), Value::String("0x15".to_owned()));
268 data.insert("to".to_string(), Value::String("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb".to_owned()));
269 data.insert("transactionIndex".to_string(), Value::String("0x41".to_owned()));
270 data.insert("value".to_string(), Value::String("0xf3dbb76162000".to_owned()));
271 data.insert("v".to_string(), Value::String("0x25".to_owned()));
272 data.insert("r".to_string(), Value::String("0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea".to_owned()));
273 data.insert("s".to_string(), Value::String("0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c".to_owned()));
274 data.insert("value".to_string(), Value::String("0xf3dbb76162000".to_owned()));
275
276 Ok(Value::Object(data))
277 });
278
279 io.add_method(methods::ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX, |_params: Params| async {
280 let mut data = jsonrpc_core::serde_json::Map::new();
281 data.insert("blockHash".to_string(), Value::String("0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2".to_owned()));
282 data.insert("blockNumber".to_string(), Value::String("0x5daf3b".to_owned()));
283 data.insert("from".to_string(), Value::String("0xa7d9ddbe1f17865597fbd27ec712455208b6b76d".to_owned()));
284 data.insert("gas".to_string(), Value::String("0xc350".to_owned()));
285 data.insert("gasPrice".to_string(), Value::String("0x4a817c800".to_owned()));
286 data.insert("hash".to_string(), Value::String("0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b".to_owned()));
287 data.insert("input".to_string(), Value::String("0x68656c6c6f21".to_owned()));
288 data.insert("nonce".to_string(), Value::String("0x15".to_owned()));
289 data.insert("to".to_string(), Value::String("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb".to_owned()));
290 data.insert("transactionIndex".to_string(), Value::String("0x41".to_owned()));
291 data.insert("value".to_string(), Value::String("0xf3dbb76162000".to_owned()));
292 data.insert("v".to_string(), Value::String("0x25".to_owned()));
293 data.insert("r".to_string(), Value::String("0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea".to_owned()));
294 data.insert("s".to_string(), Value::String("0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c".to_owned()));
295 data.insert("value".to_string(), Value::String("0xf3dbb76162000".to_owned()));
296
297 Ok(Value::Object(data))
298 });
299
300 io.add_method(methods::ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX, |_params: Params| async {
301 let mut data = jsonrpc_core::serde_json::Map::new();
302 data.insert("blockHash".to_string(), Value::String("0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2".to_owned()));
303 data.insert("blockNumber".to_string(), Value::String("0x5daf3b".to_owned()));
304 data.insert("from".to_string(), Value::String("0xa7d9ddbe1f17865597fbd27ec712455208b6b76d".to_owned()));
305 data.insert("gas".to_string(), Value::String("0xc350".to_owned()));
306 data.insert("gasPrice".to_string(), Value::String("0x4a817c800".to_owned()));
307 data.insert("hash".to_string(), Value::String("0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b".to_owned()));
308 data.insert("input".to_string(), Value::String("0x68656c6c6f21".to_owned()));
309 data.insert("nonce".to_string(), Value::String("0x15".to_owned()));
310 data.insert("to".to_string(), Value::String("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb".to_owned()));
311 data.insert("transactionIndex".to_string(), Value::String("0x41".to_owned()));
312 data.insert("value".to_string(), Value::String("0xf3dbb76162000".to_owned()));
313 data.insert("v".to_string(), Value::String("0x25".to_owned()));
314 data.insert("r".to_string(), Value::String("0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea".to_owned()));
315 data.insert("s".to_string(), Value::String("0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c".to_owned()));
316 data.insert("value".to_string(), Value::String("0xf3dbb76162000".to_owned()));
317
318 Ok(Value::Object(data))
319 });
320
321 io.add_method(methods::ETH_GET_TRANSACTION_RECEIPT, |_params: Params| async {
322 let mut data = jsonrpc_core::serde_json::Map::new();
323 data.insert("transactionHash".to_string(), Value::String("0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238".to_owned()));
324 data.insert("transactionIndex".to_string(), Value::String("0x1".to_owned()));
325 data.insert("blockNumber".to_string(), Value::String("0xb".to_owned()));
326 data.insert("blockHash".to_string(), Value::String("0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b".to_owned()));
327 data.insert("cumulativeGasUsed".to_string(), Value::String("0x33bc".to_owned()));
328 data.insert("gasUsed".to_string(), Value::String("0x4dc".to_owned()));
329 data.insert("contractAddress".to_string(), Value::String("0xb60e8dd61c5d32be8058bb8eb970870f07233155".to_owned()));
330 data.insert("logs".to_string(), Value::Array(vec![Value::String("...".to_owned())]));
331 data.insert("logsBloom".to_string(), Value::String("0x00...0".to_owned()));
332 data.insert("status".to_string(), Value::String("0x1".to_owned()));
333
334 Ok(Value::Object(data))
335 });
336
337 io.add_method(methods::ETH_GET_COMPILERS, |_params: Params| async {
338 Ok(Value::Array(vec![Value::String("solidity".to_owned()), Value::String("lll".to_owned()), Value::String("serpent".to_owned())]))
339 });
340
341 io.add_method(methods::ETH_COMPILE_LLL, |_params: Params| async {
342 Ok(Value::String("0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056".to_owned()))
343 });
344
345 io.add_method(methods::ETH_COMPILE_SOLIDITY, |_params: Params| async {
346 let mut data = jsonrpc_core::serde_json::Map::new();
347 data.insert("code".to_string(), Value::String("0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056".to_owned()));
348
349 let mut info = jsonrpc_core::serde_json::Map::new();
350 info.insert("source".to_string(), Value::String("contract test {\n function multiply(uint a) constant returns(uint d) {\n return a * 7;\n }\n}\n".to_owned()));
351 info.insert("language".to_string(), Value::String("Solidity".to_owned()));
352 info.insert("languageVersion".to_string(), Value::String("0".to_owned()));
353 info.insert("compilerVersion".to_string(), Value::String("0.9.19".to_owned()));
354
355 let mut abi_definition = jsonrpc_core::serde_json::Map::new();
356 abi_definition.insert("constant".to_string(), Value::Bool(true));
357 abi_definition.insert("name".to_string(), Value::String("multiply".to_owned()));
358 abi_definition.insert("type".to_string(), Value::String("function".to_owned()));
359
360 let mut inputs = jsonrpc_core::serde_json::Map::new();
361 inputs.insert("name".to_string(), Value::String("a".to_owned()));
362 inputs.insert("type".to_string(), Value::String("uint256".to_owned()));
363
364 let mut outputs = jsonrpc_core::serde_json::Map::new();
365 outputs.insert("name".to_string(), Value::String("d".to_owned()));
366 outputs.insert("type".to_string(), Value::String("uint256".to_owned()));
367
368 abi_definition.insert("inputs".to_string(), Value::Array(vec![Value::Object(inputs)]));
369 abi_definition.insert("outputs".to_string(), Value::Array(vec![Value::Object(outputs)]));
370 info.insert("abiDefinition".to_string(), Value::Array(vec![Value::Object(abi_definition)]));
371 data.insert("info".to_string(), Value::Object(info));
372
373 Ok(Value::Object(data))
374 });
375
376 io.add_method(methods::ETH_COMPILE_SERPENT, |_params: Params| async {
377 Ok(Value::String("0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056".to_owned()))
378 });
379
380 io.add_method(methods::ETH_NEW_FILTER, |_params: Params| async {
381 Ok(Value::String("0x1".to_owned()))
382 });
383
384 io.add_method(methods::ETH_NEW_BLOCK_FILTER, |_params: Params| async {
385 Ok(Value::String("0x1".to_owned()))
386 });
387
388 io.add_method(methods::ETH_NEW_PENDING_TRANSACTION_FILTER, |_params: Params| async {
389 Ok(Value::String("0x1".to_owned()))
390 });
391
392 io.add_method(methods::ETH_UNINSTALL_FILTER, |_params: Params| async {
393 Ok(Value::Bool(true))
394 });
395
396 io.add_method(methods::ETH_GET_FILTER_CHANGES, |_params: Params| async {
397 let mut data = jsonrpc_core::serde_json::Map::new();
398 data.insert("logIndex".to_string(), Value::String("0x1".to_owned()));
399 data.insert("blockNumber".to_string(), Value::String("0x1b4".to_owned()));
400 data.insert("blockHash".to_string(), Value::String("0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d".to_owned()));
401 data.insert("transactionHash".to_string(), Value::String("0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf".to_owned()));
402 data.insert("transactionIndex".to_string(), Value::String("0x0".to_owned()));
403 data.insert("address".to_string(), Value::String("0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d".to_owned()));
404 data.insert("data".to_string(), Value::String("0x0000000000000000000000000000000000000000000000000000000000000000".to_owned()));
405 data.insert("topics".to_string(), Value::Array(vec![Value::String("0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5".to_owned())]));
406
407 Ok(Value::Array(vec![Value::Object(data)]))
408 });
409
410 io.add_method(methods::ETH_GET_FILTER_LOGS, |_params: Params| async {
411 let mut data = jsonrpc_core::serde_json::Map::new();
412 data.insert("logIndex".to_string(), Value::String("0x1".to_owned()));
413 data.insert("blockNumber".to_string(), Value::String("0x1b4".to_owned()));
414 data.insert("blockHash".to_string(), Value::String("0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d".to_owned()));
415 data.insert("transactionHash".to_string(), Value::String("0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf".to_owned()));
416 data.insert("transactionIndex".to_string(), Value::String("0x0".to_owned()));
417 data.insert("address".to_string(), Value::String("0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d".to_owned()));
418 data.insert("data".to_string(), Value::String("0x0000000000000000000000000000000000000000000000000000000000000000".to_owned()));
419 data.insert("topics".to_string(), Value::Array(vec![Value::String("0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5".to_owned())]));
420
421 Ok(Value::Array(vec![Value::Object(data)]))
422 });
423
424 io.add_method(methods::ETH_GET_FILTER_LOGS, |_params: Params| async {
425 let mut data = jsonrpc_core::serde_json::Map::new();
426 data.insert("logIndex".to_string(), Value::String("0x1".to_owned()));
427 data.insert("blockNumber".to_string(), Value::String("0x1b4".to_owned()));
428 data.insert("blockHash".to_string(), Value::String("0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d".to_owned()));
429 data.insert("transactionHash".to_string(), Value::String("0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf".to_owned()));
430 data.insert("transactionIndex".to_string(), Value::String("0x0".to_owned()));
431 data.insert("address".to_string(), Value::String("0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d".to_owned()));
432 data.insert("data".to_string(), Value::String("0x0000000000000000000000000000000000000000000000000000000000000000".to_owned()));
433 data.insert("topics".to_string(), Value::Array(vec![Value::String("0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5".to_owned())]));
434
435 Ok(Value::Array(vec![Value::Object(data)]))
436 });
437
438 io.add_method(methods::ETH_GET_WORK, |_params: Params| async {
439 Ok(Value::Array(vec![Value::String("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef".to_owned()), Value::String("0x5EED00000000000000000000000000005EED0000000000000000000000000000".to_owned()), Value::String("0xd1ff1c01710000000000000000000000d1ff1c01710000000000000000000000".to_owned())]))
440 });
441
442 io.add_method(methods::ETH_SUBMIT_WORK, |_params: Params| async {
443 Ok(Value::Bool(true))
444 });
445
446 io.add_method(methods::ETH_SUBMIT_HASHRATE, |_params: Params| async {
447 Ok(Value::Bool(true))
448 });
449
450 io.add_method(methods::DB_PUT_STRING, |_params: Params| async {
451 Ok(Value::Bool(true))
452 });
453
454 io.add_method(methods::DB_GET_STRING, |_params: Params| async {
455 Ok(Value::String("myString".to_owned()))
456 });
457
458 io.add_method(methods::DB_PUT_HEX, |_params: Params| async {
459 Ok(Value::Bool(true))
460 });
461
462 io.add_method(methods::DB_GET_HEX, |_params: Params| async {
463 Ok(Value::String("0x68656c6c6f20776f726c64".to_owned()))
464 });
465
466 io.add_method(methods::SHH_POST, |_params: Params| async {
467 Ok(Value::Bool(true))
468 });
469
470 io.add_method(methods::DB_GET_HEX, |_params: Params| async {
471 Ok(Value::String("2".to_owned()))
472 });
473
474 io.add_method(methods::SHH_NEW_IDENTITY, |_params: Params| async {
475 Ok(Value::String("0xc931d93e97ab07fe42d923478ba2465f283f440fd6cabea4dd7a2c807108f651b7135d1d6ca9007d5b68aa497e4619ac10aa3b27726e1863c1fd9b570d99bbaf".to_owned()))
476 });
477
478 io.add_method(methods::SHH_HAS_IDENTITY, |_params: Params| async {
479 Ok(Value::Bool(true))
480 });
481
482 io.add_method(methods::SHH_NEW_GROUP, |_params: Params| async {
483 Ok(Value::String("0xc65f283f440fd6cabea4dd7a2c807108f651b7135d1d6ca90931d93e97ab07fe42d923478ba2407d5b68aa497e4619ac10aa3b27726e1863c1fd9b570d99bbaf".to_owned()))
484 });
485
486 io.add_method(methods::SHH_ADD_TO_GROUP, |_params: Params| async {
487 Ok(Value::Bool(true))
488 });
489
490 io.add_method(methods::SHH_NEW_FILTER, |_params: Params| async {
491 Ok(Value::String("0x7".to_owned()))
492 });
493
494 io.add_method(methods::SHH_UNINSTALL_FILTER, |_params: Params| async {
495 Ok(Value::Bool(true))
496 });
497
498 io.add_method(methods::SHH_GET_FILTER_CHANGES, |_params: Params| async {
499 let mut data = jsonrpc_core::serde_json::Map::new();
500 data.insert("hash".to_string(), Value::String("0x33eb2da77bf3527e28f8bf493650b1879b08c4f2a362beae4ba2f71bafcd91f9".to_owned()));
501 data.insert("from".to_string(), Value::String("0x3ec052fc33..".to_owned()));
502 data.insert("to".to_string(), Value::String("0x87gdf76g8d7fgdfg...".to_owned()));
503 data.insert("expiry".to_string(), Value::String("0x54caa50a".to_owned()));
504 data.insert("sent".to_string(), Value::String("0x54ca9ea2".to_owned()));
505 data.insert("ttl".to_string(), Value::String("0x64".to_owned()));
506 data.insert("topics".to_string(), Value::Array(vec![Value::String("0x6578616d".to_owned())]));
507 data.insert("payload".to_string(), Value::String("0x7b2274797065223a226d657373616765222c2263686...".to_owned()));
508 data.insert("workProved".to_string(), Value::String("0x0".to_owned()));
509
510 Ok(Value::Array(vec![Value::Object(data)]))
511 });
512
513 io.add_method(methods::SHH_GET_MESSAGES, |_params: Params| async {
514 let mut data = jsonrpc_core::serde_json::Map::new();
515 data.insert("hash".to_string(), Value::String("0x33eb2da77bf3527e28f8bf493650b1879b08c4f2a362beae4ba2f71bafcd91f9".to_owned()));
516 data.insert("from".to_string(), Value::String("0x3ec052fc33..".to_owned()));
517 data.insert("to".to_string(), Value::String("0x87gdf76g8d7fgdfg...".to_owned()));
518 data.insert("expiry".to_string(), Value::String("0x54caa50a".to_owned()));
519 data.insert("sent".to_string(), Value::String("0x54ca9ea2".to_owned()));
520 data.insert("ttl".to_string(), Value::String("0x64".to_owned()));
521 data.insert("topics".to_string(), Value::Array(vec![Value::String("0x6578616d".to_owned())]));
522 data.insert("payload".to_string(), Value::String("0x7b2274797065223a226d657373616765222c2263686...".to_owned()));
523 data.insert("workProved".to_string(), Value::String("0x0".to_owned()));
524
525 Ok(Value::Array(vec![Value::Object(data)]))
526 });
527
528 io
529 }
530}
531
532#[cfg(test)]
533mod tests {
534 use super::*;
535 use std::collections::HashMap;
536
537 #[test]
538 fn test_web3_client_version() {
539 Entry::new("127.0.0.1:8545").serve_silent();
540
541 let mut map = HashMap::new();
542 map.insert("jsonrpc", "2.0");
543 map.insert("method", "web3_clientVersion");
544 map.insert("params", "0x7");
545 map.insert("id", "73");
546
547 let client = reqwest::blocking::Client::new();
548
549 let res = client.post("http://127.0.0.1:8545")
550 .json(&map)
551 .send();
552
553 match res {
554 Ok(data) => {
555 match data.text() {
556 Ok(t) => {
557 assert_eq!(String::from(r#"{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid request"},"id":"73"}"#.to_owned()+"\n"), t);
558 },
559 Err(err) => println!("{}", err),
560 }
561 },
562 Err(err) => println!("{}", err),
563 }
564 }
565}