Replace pub field with AsRef impl

This commit is contained in:
Tyera Eulberg 2018-07-31 15:50:09 -06:00 committed by Grimes
parent fda3b9bbd4
commit 7ff721e563
6 changed files with 25 additions and 10 deletions

View File

@ -8,7 +8,6 @@ extern crate serde_json;
extern crate solana;
use clap::{App, Arg, SubCommand};
use generic_array::GenericArray;
use solana::client::mk_client;
use solana::crdt::NodeInfo;
use solana::drone::DRONE_PORT;
@ -182,7 +181,7 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
display_actions();
Err(WalletError::BadParameter("Invalid public key".to_string()))?;
}
PublicKey(GenericArray::clone_from_slice(&pubkey_vec))
PublicKey::new(&pubkey_vec)
} else {
id.pubkey()
};

View File

@ -136,7 +136,7 @@ pub struct NodeInfo {
}
fn make_debug_id(key: &PublicKey) -> u64 {
let buf: &[u8] = &key.0;
let buf: &[u8] = &key.as_ref();
let mut rdr = Cursor::new(&buf[..8]);
rdr.read_u64::<LittleEndian>()
.expect("rdr.read_u64 in fn debug_id")

View File

@ -28,7 +28,7 @@ impl Ncp {
let (request_sender, request_receiver) = channel();
trace!(
"Ncp: id: {:?}, listening on: {:?}",
&crdt.read().unwrap().me.0[..4],
&crdt.read().unwrap().me.as_ref()[..4],
gossip_listen_socket.local_addr().unwrap()
);
let t_receiver = streamer::blob_receiver(

View File

@ -18,7 +18,19 @@ use untrusted::Input;
pub type KeyPair = Ed25519KeyPair;
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct PublicKey(pub GenericArray<u8, U32>);
pub struct PublicKey(GenericArray<u8, U32>);
impl PublicKey {
pub fn new(pubkey_vec: &[u8]) -> Self {
PublicKey(GenericArray::clone_from_slice(&pubkey_vec))
}
}
impl AsRef<GenericArray<u8, U32>> for PublicKey {
fn as_ref(&self) -> &GenericArray<u8, U32> {
&self.0
}
}
impl fmt::Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

View File

@ -192,7 +192,7 @@ impl Transaction {
/// Verify only the transaction signature.
pub fn verify_sig(&self) -> bool {
warn!("transaction signature verification called");
self.sig.verify(&self.from.0, &self.get_sign_data())
self.sig.verify(&self.from.as_ref(), &self.get_sign_data())
}
/// Verify only the payment plan.
@ -319,7 +319,7 @@ mod tests {
let tx_bytes = serialize(&tx).unwrap();
assert_matches!(memfind(&tx_bytes, &sign_data), Some(SIGNED_DATA_OFFSET));
assert_matches!(memfind(&tx_bytes, &tx.sig), Some(SIG_OFFSET));
assert_matches!(memfind(&tx_bytes, &tx.from.0), Some(PUB_KEY_OFFSET));
assert_matches!(memfind(&tx_bytes, &tx.from.as_ref()), Some(PUB_KEY_OFFSET));
}
#[test]

View File

@ -101,7 +101,7 @@ fn gossip_star() {
let mut yd = yv.table[&yv.me].clone();
yd.version = 0;
xv.insert(&yd);
trace!("star leader {:?}", &xv.me.0[..4]);
trace!("star leader {:?}", &xv.me.as_ref()[..4]);
}
});
}
@ -116,12 +116,16 @@ fn gossip_rstar() {
let xv = listen[0].0.read().unwrap();
xv.table[&xv.me].clone()
};
trace!("rstar leader {:?}", &xd.id.0[..4]);
trace!("rstar leader {:?}", &xd.id.as_ref()[..4]);
for n in 0..(num - 1) {
let y = (n + 1) % listen.len();
let mut yv = listen[y].0.write().unwrap();
yv.insert(&xd);
trace!("rstar insert {:?} into {:?}", &xd.id.0[..4], &yv.me.0[..4]);
trace!(
"rstar insert {:?} into {:?}",
&xd.id.as_ref()[..4],
&yv.me.as_ref()[..4]
);
}
});
}