Replace pub field with AsRef impl
This commit is contained in:
		| @@ -8,7 +8,6 @@ extern crate serde_json; | |||||||
| extern crate solana; | extern crate solana; | ||||||
|  |  | ||||||
| use clap::{App, Arg, SubCommand}; | use clap::{App, Arg, SubCommand}; | ||||||
| use generic_array::GenericArray; |  | ||||||
| use solana::client::mk_client; | use solana::client::mk_client; | ||||||
| use solana::crdt::NodeInfo; | use solana::crdt::NodeInfo; | ||||||
| use solana::drone::DRONE_PORT; | use solana::drone::DRONE_PORT; | ||||||
| @@ -182,7 +181,7 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> { | |||||||
|                     display_actions(); |                     display_actions(); | ||||||
|                     Err(WalletError::BadParameter("Invalid public key".to_string()))?; |                     Err(WalletError::BadParameter("Invalid public key".to_string()))?; | ||||||
|                 } |                 } | ||||||
|                 PublicKey(GenericArray::clone_from_slice(&pubkey_vec)) |                 PublicKey::new(&pubkey_vec) | ||||||
|             } else { |             } else { | ||||||
|                 id.pubkey() |                 id.pubkey() | ||||||
|             }; |             }; | ||||||
|   | |||||||
| @@ -136,7 +136,7 @@ pub struct NodeInfo { | |||||||
| } | } | ||||||
|  |  | ||||||
| fn make_debug_id(key: &PublicKey) -> u64 { | 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]); |     let mut rdr = Cursor::new(&buf[..8]); | ||||||
|     rdr.read_u64::<LittleEndian>() |     rdr.read_u64::<LittleEndian>() | ||||||
|         .expect("rdr.read_u64 in fn debug_id") |         .expect("rdr.read_u64 in fn debug_id") | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ impl Ncp { | |||||||
|         let (request_sender, request_receiver) = channel(); |         let (request_sender, request_receiver) = channel(); | ||||||
|         trace!( |         trace!( | ||||||
|             "Ncp: id: {:?}, listening on: {:?}", |             "Ncp: id: {:?}, listening on: {:?}", | ||||||
|             &crdt.read().unwrap().me.0[..4], |             &crdt.read().unwrap().me.as_ref()[..4], | ||||||
|             gossip_listen_socket.local_addr().unwrap() |             gossip_listen_socket.local_addr().unwrap() | ||||||
|         ); |         ); | ||||||
|         let t_receiver = streamer::blob_receiver( |         let t_receiver = streamer::blob_receiver( | ||||||
|   | |||||||
| @@ -18,7 +18,19 @@ use untrusted::Input; | |||||||
|  |  | ||||||
| pub type KeyPair = Ed25519KeyPair; | pub type KeyPair = Ed25519KeyPair; | ||||||
| #[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] | #[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 { | impl fmt::Debug for PublicKey { | ||||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||||
|   | |||||||
| @@ -192,7 +192,7 @@ impl Transaction { | |||||||
|     /// Verify only the transaction signature. |     /// Verify only the transaction signature. | ||||||
|     pub fn verify_sig(&self) -> bool { |     pub fn verify_sig(&self) -> bool { | ||||||
|         warn!("transaction signature verification called"); |         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. |     /// Verify only the payment plan. | ||||||
| @@ -319,7 +319,7 @@ mod tests { | |||||||
|         let tx_bytes = serialize(&tx).unwrap(); |         let tx_bytes = serialize(&tx).unwrap(); | ||||||
|         assert_matches!(memfind(&tx_bytes, &sign_data), Some(SIGNED_DATA_OFFSET)); |         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.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] |     #[test] | ||||||
|   | |||||||
| @@ -101,7 +101,7 @@ fn gossip_star() { | |||||||
|             let mut yd = yv.table[&yv.me].clone(); |             let mut yd = yv.table[&yv.me].clone(); | ||||||
|             yd.version = 0; |             yd.version = 0; | ||||||
|             xv.insert(&yd); |             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(); |             let xv = listen[0].0.read().unwrap(); | ||||||
|             xv.table[&xv.me].clone() |             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) { |         for n in 0..(num - 1) { | ||||||
|             let y = (n + 1) % listen.len(); |             let y = (n + 1) % listen.len(); | ||||||
|             let mut yv = listen[y].0.write().unwrap(); |             let mut yv = listen[y].0.write().unwrap(); | ||||||
|             yv.insert(&xd); |             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] | ||||||
|  |             ); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user