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
166
use serde::{Deserialize, Serialize};
use std::fmt;

#[derive(Serialize, Deserialize, Debug)]
pub struct ValidateAddress {
    #[serde(rename(deserialize = "isvalid"))]
    pub is_valid: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Etherscan<T> {
    pub status: String,
    pub message: String,
    pub result: T,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct EvmBalance {
    pub account: String,
    pub balance: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct EvmPrice {
    pub ethbtc: String,
    pub ethbtc_timestamp: String,
    pub ethusd: String,
    pub ethusd_timestamp: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct EvmTransaction {
    #[serde(rename = "blockNumber")]
    pub block_number: String,
    #[serde(rename = "timeStamp")]
    pub time_stamp: String,
    pub hash: String,
    pub nonce: String,
    #[serde(rename = "blockHash")]
    pub block_hash: String,
    #[serde(rename = "transactionIndex")]
    pub transaction_index: String,
    pub from: String,
    pub to: String,
    pub value: String,
    pub gas: String,
    #[serde(rename = "gasPrice")]
    pub gas_price: String,
    #[serde(rename = "isError")]
    pub is_error: String,
    pub txreceipt_status: String,
    pub input: String,
    #[serde(rename = "contractAddress")]
    pub contract_address: String,
    #[serde(rename = "cumulativeGasUsed")]
    pub cumulative_gas_used: String,
    #[serde(rename = "gasUsed")]
    pub gas_used: String,
    pub confirmations: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct EvmTransactionHash {
    #[serde(rename = "blockHash")]
    pub block_hash: String,
    #[serde(rename = "blockNumber")]
    pub block_number: String,
    pub from: String,
    pub gas: String,
    #[serde(rename = "gasPrice")]
    pub gas_price: String,
    pub hash: String,
    pub input: String,
    pub nonce: String,
    pub to: String,
    #[serde(rename = "transactionIndex")]
    pub transaction_index: String,
    pub value: String,
    pub v: String,
    pub r: String,
    pub s: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct EvmTransactionnReceipt {
    #[serde(rename = "blockHash")]
    pub block_hash: String,
    #[serde(rename = "blockNumber")]
    pub block_number: String,
    #[serde(rename = "contractAddress")]
    pub contract_address: Option<serde_json::Value>,
    #[serde(rename = "cumulativeGasUsed")]
    pub cumulative_gas_used: String,
    pub from: String,
    #[serde(rename = "gasUsed")]
    pub gas_used: String,
    #[serde(rename = "Ethlogs")]
    pub ethlogs: Vec<EvmLog>,
    #[serde(rename = "logsBloom")]
    pub logs_bloom: String,
    pub root: String,
    pub to: String,
    #[serde(rename = "transactionHash")]
    pub transaction_hash: String,
    #[serde(rename = "transactionIndex")]
    pub transaction_index: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct EvmLog {
    pub address: String,
    pub topics: Vec<String>,
    pub data: String,
    #[serde(rename = "blockNumber")]
    pub block_number: String,
    #[serde(rename = "transactionHash")]
    pub transaction_hash: String,
    #[serde(rename = "transactionIndex")]
    pub transaction_index: String,
    #[serde(rename = "blockHash")]
    pub block_hash: String,
    #[serde(rename = "logIndex")]
    pub log_index: String,
    pub removed: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct EvmBlockByNumber {
    pub difficulty: String,
    #[serde(rename = "extraData")]
    pub extra_data: String,
    #[serde(rename = "gasLimit")]
    pub gas_limit: String,
    #[serde(rename = "gasUsed")]
    pub gas_used: String,
    pub hash: String,
    #[serde(rename = "logsBloom")]
    pub logs_bloom: String,
    pub miner: String,
    #[serde(rename = "mixHash")]
    pub mix_hash: String,
    pub nonce: String,
    pub number: String,
    #[serde(rename = "parentHash")]
    pub parent_hash: String,
    #[serde(rename = "receiptsRoot")]
    pub receipts_root: String,
    #[serde(rename = "sha3Uncles")]
    pub sha3_uncles: String,
    pub size: String,
    #[serde(rename = "stateRoot")]
    pub state_root: String,
    pub timestamp: String,
    #[serde(rename = "totalDifficulty")]
    pub total_difficulty: Option<serde_json::Value>,
    #[serde(rename = "transactionsRoot")]
    pub transactions_root: String,
    pub uncles: Vec<Option<serde_json::Value>>,
}

impl fmt::Display for EvmPrice {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let to_json = serde_json::to_string(self);
        write!(f, "{}", to_json.unwrap())
    }
}