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
use crate::types::{Address, Bytes, CallRequest, H256, U256};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct SignedData {
pub message: Vec<u8>,
#[serde(rename = "messageHash")]
pub message_hash: H256,
pub v: u8,
pub r: H256,
pub s: H256,
pub signature: Bytes,
}
#[derive(Clone, Debug, PartialEq)]
pub struct TransactionParameters {
pub nonce: Option<U256>,
pub to: Option<Address>,
pub gas: U256,
pub gas_price: Option<U256>,
pub value: U256,
pub data: Bytes,
pub chain_id: Option<u64>,
}
const TRANSACTION_DEFAULT_GAS: U256 = U256([100_000, 0, 0, 0]);
impl Default for TransactionParameters {
fn default() -> Self {
TransactionParameters {
nonce: None,
to: None,
gas: TRANSACTION_DEFAULT_GAS,
gas_price: None,
value: U256::zero(),
data: Bytes::default(),
chain_id: None,
}
}
}
impl From<CallRequest> for TransactionParameters {
fn from(call: CallRequest) -> Self {
TransactionParameters {
nonce: None,
to: call.to,
gas: call.gas.unwrap_or(TRANSACTION_DEFAULT_GAS),
gas_price: call.gas_price,
value: call.value.unwrap_or_default(),
data: call.data.unwrap_or_default(),
chain_id: None,
}
}
}
impl Into<CallRequest> for TransactionParameters {
fn into(self) -> CallRequest {
CallRequest {
from: None,
to: self.to,
gas: Some(self.gas),
gas_price: self.gas_price,
value: Some(self.value),
data: Some(self.data),
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct SignedTransaction {
pub message_hash: H256,
pub v: u64,
pub r: H256,
pub s: H256,
pub raw_transaction: Bytes,
pub transaction_hash: H256,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn verify_transaction_default_gas() {
assert_eq!(TRANSACTION_DEFAULT_GAS, U256::from(100_000));
}
}