From 6977063206f0c0045a09fa88fa1c7dfa769ae462 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 8 Dec 2021 10:35:46 +0000 Subject: [PATCH] fixup after rebase --- fastpay/src/client.rs | 4 ++-- fastpay/src/config.rs | 4 ++-- fastpay_core/src/base_types.rs | 21 --------------------- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/fastpay/src/client.rs b/fastpay/src/client.rs index c4e39f6470c99..144cbbe3400d7 100644 --- a/fastpay/src/client.rs +++ b/fastpay/src/client.rs @@ -387,7 +387,7 @@ fn main() { } => { let sender = decode_address(&from).expect("Failed to decode sender's address"); let recipient = decode_address(&to).expect("Failed to decode recipient's address"); - let object_id = decode_object_id(&object_id).unwrap(); + let object_id = ObjectID::from_hex_literal(&object_id).unwrap(); let mut rt = Runtime::new().unwrap(); rt.block_on(async move { @@ -541,7 +541,7 @@ fn main() { let num_accounts: u32 = num; let object_ids = match initial_objects { Some(object_ids) => { - object_ids.into_iter().map(|string| decode_object_id(&string).unwrap()).collect() + object_ids.into_iter().map(|string| ObjectID::from_hex_literal(&string).unwrap()).collect() } None => Vec::new() }; diff --git a/fastpay/src/config.rs b/fastpay/src/config.rs index ded55847bfed4..49fcdf4a58bf4 100644 --- a/fastpay/src/config.rs +++ b/fastpay/src/config.rs @@ -213,7 +213,7 @@ impl InitialStateConfig { failure::bail!("expecting two columns separated with ':'") } let address = decode_address(elements[0])?; - let balance = decode_object_id(elements[1])?; + let balance = ObjectID::from_hex_literal(elements[1])?; accounts.push((address, balance)); } Ok(Self { accounts }) @@ -227,7 +227,7 @@ impl InitialStateConfig { writer, "{}:{}", encode_address(address), - encode_object_id(&object_id) + object_id.to_string(), )?; } Ok(()) diff --git a/fastpay_core/src/base_types.rs b/fastpay_core/src/base_types.rs index 0215ec4674042..9de1e54cffdb0 100644 --- a/fastpay_core/src/base_types.rs +++ b/fastpay_core/src/base_types.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 use crate::error::FastPayError; use std::convert::{TryFrom, TryInto}; -use std::num::ParseIntError; use ed25519_dalek as dalek; use ed25519_dalek::{Signer, Verifier}; @@ -11,7 +10,6 @@ use rand::rngs::OsRng; #[cfg(test)] use rand::Rng; use serde::{Deserialize, Serialize}; -use std::fmt::Write; #[cfg(test)] #[path = "unit_tests/base_types_tests.rs"] @@ -97,25 +95,6 @@ pub fn decode_address(s: &str) -> Result { Ok(PublicKeyBytes(address)) } -pub fn decode_object_id(s: &str) -> Result { - let parsed: Result, ParseIntError> = (0..s.len()) - .step_by(2) - .map(|i| u8::from_str_radix(&s[i..i + 2], 16)) - .collect(); - parsed.map(|vec| { - let result: ObjectID = vec.try_into().unwrap(); - result - }) -} - -pub fn encode_object_id(object_id: &ObjectID) -> String { - let mut s = String::with_capacity(object_id.len() * 2); - for &b in object_id { - write!(&mut s, "{:02x}", b).unwrap(); - } - s -} - #[cfg(test)] pub fn dbg_addr(name: u8) -> FastPayAddress { let addr = [name; dalek::PUBLIC_KEY_LENGTH];