Output addresses with checksum.

This commit is contained in:
chriseth 2022-12-24 16:02:30 +01:00
parent 404ceb39b9
commit 7821daf532
4 changed files with 11 additions and 6 deletions

View file

@ -7,6 +7,7 @@ default-run = "server"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
eth_checksum = "0.1.2"
json = "^0.12.4" json = "^0.12.4"
num-bigint = "^0.4.3" num-bigint = "^0.4.3"
serde = { version = "1.0.149", features = ["serde_derive"] } serde = { version = "1.0.149", features = ["serde_derive"] }

View file

@ -99,9 +99,9 @@ fn main() {
maxFlowValue: flow.to_decimal(), maxFlowValue: flow.to_decimal(),
transferSteps: transfers.iter().enumerate().map(|(i, e)| { transferSteps: transfers.iter().enumerate().map(|(i, e)| {
json::object!{ json::object!{
from: e.from.to_string(), from: e.from.to_checksummed_hex(),
to: e.to.to_string(), to: e.to.to_checksummed_hex(),
token: e.token.to_string(), token: e.token.to_checksummed_hex(),
value: e.capacity.to_decimal(), value: e.capacity.to_decimal(),
step: i, step: i,
} }

View file

@ -166,9 +166,9 @@ fn compute_transfer(
flow: flow.to_string(), flow: flow.to_string(),
final: max_distance.is_none(), final: max_distance.is_none(),
transfers: transfers.into_iter().map(|e| json::object! { transfers: transfers.into_iter().map(|e| json::object! {
from: e.from.to_string(), from: e.from.to_checksummed_hex(),
to: e.to.to_string(), to: e.to.to_checksummed_hex(),
token_owner: e.token.to_string(), token_owner: e.token.to_checksummed_hex(),
value: e.capacity.to_string() value: e.capacity.to_string()
}).collect::<Vec<_>>(), }).collect::<Vec<_>>(),
}, },

View file

@ -11,6 +11,10 @@ impl Address {
pub fn to_bytes(self) -> [u8; 20] { pub fn to_bytes(self) -> [u8; 20] {
self.0 self.0
} }
pub fn to_checksummed_hex(&self) -> String {
eth_checksum::checksum(&self.to_string())
}
} }
impl Debug for Address { impl Debug for Address {