From 39e85a3e5301aa5d889e0d9ea0d642e67193ca92 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Thu, 16 May 2019 21:43:18 -0700 Subject: [PATCH] kill some bs58 (#4316) * kill some bs58 * fixup --- client/src/rpc_client.rs | 8 +++----- core/src/chacha.rs | 10 ++++------ core/tests/rpc.rs | 5 +---- wallet/src/wallet.rs | 23 +++++++++-------------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index b020f2e1ed..4363d9f53f 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -655,8 +655,7 @@ mod tests { fn test_get_recent_blockhash() { let rpc_client = RpcClient::new_mock("succeeds".to_string()); - let vec = bs58::decode(PUBKEY).into_vec().unwrap(); - let expected_blockhash = Hash::new(&vec); + let expected_blockhash: Hash = PUBKEY.parse().unwrap(); let (blockhash, _fee_calculator) = rpc_client.get_recent_blockhash().expect("blockhash ok"); assert_eq!(blockhash, expected_blockhash); @@ -711,10 +710,9 @@ mod tests { let key = Keypair::new(); let to = Pubkey::new_rand(); - let vec = bs58::decode("HUu3LwEzGRsUkuJS121jzkPJW39Kq62pXCTmTa1F9jDL") - .into_vec() + let blockhash: Hash = "HUu3LwEzGRsUkuJS121jzkPJW39Kq62pXCTmTa1F9jDL" + .parse() .unwrap(); - let blockhash = Hash::new(&vec); let prev_tx = system_transaction::create_user_account(&key, &to, 50, blockhash, 0); let mut tx = system_transaction::create_user_account(&key, &to, 50, blockhash, 0); diff --git a/core/src/chacha.rs b/core/src/chacha.rs index 1ca2db1473..0a0882d5d8 100644 --- a/core/src/chacha.rs +++ b/core/src/chacha.rs @@ -154,13 +154,11 @@ mod tests { let mut hasher = Hasher::default(); hasher.hash(&buf[..size]); - use bs58; // golden needs to be updated if blob stuff changes.... - let golden = Hash::new( - &bs58::decode("5Pz5KQyNht2nqkJhVd8F9zTFxzoDvbQSzaxQbtCPiyCo") - .into_vec() - .unwrap(), - ); + let golden: Hash = "5Pz5KQyNht2nqkJhVd8F9zTFxzoDvbQSzaxQbtCPiyCo" + .parse() + .unwrap(); + assert_eq!(hasher.result(), golden); remove_file(out_path).unwrap(); } diff --git a/core/tests/rpc.rs b/core/tests/rpc.rs index 0931795023..e3b8f9472f 100644 --- a/core/tests/rpc.rs +++ b/core/tests/rpc.rs @@ -35,10 +35,7 @@ fn test_rpc_send_tx() { .send() .unwrap(); let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap(); - let blockhash_vec = bs58::decode(json["result"][0].as_str().unwrap()) - .into_vec() - .unwrap(); - let blockhash = Hash::new(&blockhash_vec); + let blockhash: Hash = json["result"][0].as_str().unwrap().parse().unwrap(); info!("blockhash: {:?}", blockhash); let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 0); diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index 8fbc8206ac..7714f27f7d 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -1,4 +1,3 @@ -use bs58; use chrono::prelude::*; use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; use log::*; @@ -33,7 +32,7 @@ use std::io::Read; use std::net::{IpAddr, SocketAddr}; use std::thread::sleep; use std::time::Duration; -use std::{error, fmt, mem}; +use std::{error, fmt}; const USERDATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE @@ -169,16 +168,12 @@ pub fn parse_command( Ok(WalletCommand::Cancel(process_id)) } ("confirm", Some(confirm_matches)) => { - let signatures = bs58::decode(confirm_matches.value_of("signature").unwrap()) - .into_vec() - .expect("base58-encoded signature"); - - if signatures.len() == mem::size_of::() { - let signature = Signature::new(&signatures); - Ok(WalletCommand::Confirm(signature)) - } else { - eprintln!("{}", confirm_matches.usage()); - Err(WalletError::BadParameter("Invalid signature".to_string())) + match confirm_matches.value_of("signature").unwrap().parse() { + Ok(signature) => Ok(WalletCommand::Confirm(signature)), + _ => { + eprintln!("{}", confirm_matches.usage()); + Err(WalletError::BadParameter("Invalid signature".to_string())) + } } } ("create-vote-account", Some(matches)) => { @@ -1725,8 +1720,8 @@ mod tests { .unwrap() .as_str() .unwrap(); - let program_id_vec = bs58::decode(program_id).into_vec().unwrap(); - assert_eq!(program_id_vec.len(), mem::size_of::()); + + assert!(program_id.parse::().is_ok()); // Failure cases config.rpc_client = Some(RpcClient::new_mock("airdrop".to_string()));