kill some bs58 (#4316)

* kill some bs58

* fixup
This commit is contained in:
Rob Walker 2019-05-16 21:43:18 -07:00 committed by GitHub
parent 41156da4ca
commit 39e85a3e53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 29 deletions

View File

@ -655,8 +655,7 @@ mod tests {
fn test_get_recent_blockhash() { fn test_get_recent_blockhash() {
let rpc_client = RpcClient::new_mock("succeeds".to_string()); let rpc_client = RpcClient::new_mock("succeeds".to_string());
let vec = bs58::decode(PUBKEY).into_vec().unwrap(); let expected_blockhash: Hash = PUBKEY.parse().unwrap();
let expected_blockhash = Hash::new(&vec);
let (blockhash, _fee_calculator) = rpc_client.get_recent_blockhash().expect("blockhash ok"); let (blockhash, _fee_calculator) = rpc_client.get_recent_blockhash().expect("blockhash ok");
assert_eq!(blockhash, expected_blockhash); assert_eq!(blockhash, expected_blockhash);
@ -711,10 +710,9 @@ mod tests {
let key = Keypair::new(); let key = Keypair::new();
let to = Pubkey::new_rand(); let to = Pubkey::new_rand();
let vec = bs58::decode("HUu3LwEzGRsUkuJS121jzkPJW39Kq62pXCTmTa1F9jDL") let blockhash: Hash = "HUu3LwEzGRsUkuJS121jzkPJW39Kq62pXCTmTa1F9jDL"
.into_vec() .parse()
.unwrap(); .unwrap();
let blockhash = Hash::new(&vec);
let prev_tx = system_transaction::create_user_account(&key, &to, 50, blockhash, 0); 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); let mut tx = system_transaction::create_user_account(&key, &to, 50, blockhash, 0);

View File

@ -154,13 +154,11 @@ mod tests {
let mut hasher = Hasher::default(); let mut hasher = Hasher::default();
hasher.hash(&buf[..size]); hasher.hash(&buf[..size]);
use bs58;
// golden needs to be updated if blob stuff changes.... // golden needs to be updated if blob stuff changes....
let golden = Hash::new( let golden: Hash = "5Pz5KQyNht2nqkJhVd8F9zTFxzoDvbQSzaxQbtCPiyCo"
&bs58::decode("5Pz5KQyNht2nqkJhVd8F9zTFxzoDvbQSzaxQbtCPiyCo") .parse()
.into_vec() .unwrap();
.unwrap(),
);
assert_eq!(hasher.result(), golden); assert_eq!(hasher.result(), golden);
remove_file(out_path).unwrap(); remove_file(out_path).unwrap();
} }

View File

@ -35,10 +35,7 @@ fn test_rpc_send_tx() {
.send() .send()
.unwrap(); .unwrap();
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap(); let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
let blockhash_vec = bs58::decode(json["result"][0].as_str().unwrap()) let blockhash: Hash = json["result"][0].as_str().unwrap().parse().unwrap();
.into_vec()
.unwrap();
let blockhash = Hash::new(&blockhash_vec);
info!("blockhash: {:?}", blockhash); info!("blockhash: {:?}", blockhash);
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 0); let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 0);

View File

@ -1,4 +1,3 @@
use bs58;
use chrono::prelude::*; use chrono::prelude::*;
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use log::*; use log::*;
@ -33,7 +32,7 @@ use std::io::Read;
use std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; 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 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)) Ok(WalletCommand::Cancel(process_id))
} }
("confirm", Some(confirm_matches)) => { ("confirm", Some(confirm_matches)) => {
let signatures = bs58::decode(confirm_matches.value_of("signature").unwrap()) match confirm_matches.value_of("signature").unwrap().parse() {
.into_vec() Ok(signature) => Ok(WalletCommand::Confirm(signature)),
.expect("base58-encoded signature"); _ => {
eprintln!("{}", confirm_matches.usage());
if signatures.len() == mem::size_of::<Signature>() { Err(WalletError::BadParameter("Invalid signature".to_string()))
let signature = Signature::new(&signatures); }
Ok(WalletCommand::Confirm(signature))
} else {
eprintln!("{}", confirm_matches.usage());
Err(WalletError::BadParameter("Invalid signature".to_string()))
} }
} }
("create-vote-account", Some(matches)) => { ("create-vote-account", Some(matches)) => {
@ -1725,8 +1720,8 @@ mod tests {
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
let program_id_vec = bs58::decode(program_id).into_vec().unwrap();
assert_eq!(program_id_vec.len(), mem::size_of::<Pubkey>()); assert!(program_id.parse::<Pubkey>().is_ok());
// Failure cases // Failure cases
config.rpc_client = Some(RpcClient::new_mock("airdrop".to_string())); config.rpc_client = Some(RpcClient::new_mock("airdrop".to_string()));