From 7821daf532f973459d68cc59a23d7e2577c607c0 Mon Sep 17 00:00:00 2001 From: chriseth Date: Sat, 24 Dec 2022 16:02:30 +0100 Subject: [PATCH] Output addresses with checksum. --- Cargo.toml | 1 + src/bin/cli.rs | 6 +++--- src/server.rs | 6 +++--- src/types/address.rs | 4 ++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 54c40bb..e2ae8bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ default-run = "server" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +eth_checksum = "0.1.2" json = "^0.12.4" num-bigint = "^0.4.3" serde = { version = "1.0.149", features = ["serde_derive"] } diff --git a/src/bin/cli.rs b/src/bin/cli.rs index 3d0940b..2655519 100644 --- a/src/bin/cli.rs +++ b/src/bin/cli.rs @@ -99,9 +99,9 @@ fn main() { maxFlowValue: flow.to_decimal(), transferSteps: transfers.iter().enumerate().map(|(i, e)| { json::object!{ - from: e.from.to_string(), - to: e.to.to_string(), - token: e.token.to_string(), + from: e.from.to_checksummed_hex(), + to: e.to.to_checksummed_hex(), + token: e.token.to_checksummed_hex(), value: e.capacity.to_decimal(), step: i, } diff --git a/src/server.rs b/src/server.rs index 5f08574..872b724 100644 --- a/src/server.rs +++ b/src/server.rs @@ -166,9 +166,9 @@ fn compute_transfer( flow: flow.to_string(), final: max_distance.is_none(), transfers: transfers.into_iter().map(|e| json::object! { - from: e.from.to_string(), - to: e.to.to_string(), - token_owner: e.token.to_string(), + from: e.from.to_checksummed_hex(), + to: e.to.to_checksummed_hex(), + token_owner: e.token.to_checksummed_hex(), value: e.capacity.to_string() }).collect::>(), }, diff --git a/src/types/address.rs b/src/types/address.rs index 9b352a6..0a38580 100644 --- a/src/types/address.rs +++ b/src/types/address.rs @@ -11,6 +11,10 @@ impl Address { pub fn to_bytes(self) -> [u8; 20] { self.0 } + + pub fn to_checksummed_hex(&self) -> String { + eth_checksum::checksum(&self.to_string()) + } } impl Debug for Address {