Skip to content

Commit

Permalink
fixup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkuo committed Dec 8, 2021
1 parent f878477 commit 6977063
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
4 changes: 2 additions & 2 deletions fastpay/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
};
Expand Down
4 changes: 2 additions & 2 deletions fastpay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -227,7 +227,7 @@ impl InitialStateConfig {
writer,
"{}:{}",
encode_address(address),
encode_object_id(&object_id)
object_id.to_string(),
)?;
}
Ok(())
Expand Down
21 changes: 0 additions & 21 deletions fastpay_core/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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"]
Expand Down Expand Up @@ -97,25 +95,6 @@ pub fn decode_address(s: &str) -> Result<PublicKeyBytes, failure::Error> {
Ok(PublicKeyBytes(address))
}

pub fn decode_object_id(s: &str) -> Result<ObjectID, ParseIntError> {
let parsed: Result<Vec<u8>, 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];
Expand Down

0 comments on commit 6977063

Please sign in to comment.