Move Pubkey into its own module

This commit is contained in:
Greg Fitzgerald 2018-09-26 17:55:36 -06:00
parent c6d7cd2d33
commit b7ae5b712a
37 changed files with 99 additions and 70 deletions

View File

@ -12,7 +12,8 @@ use solana::banking_stage::{BankingStage, NUM_THREADS};
use solana::entry::Entry;
use solana::mint::Mint;
use solana::packet::{to_packets_chunked, PacketRecycler};
use solana::signature::{KeypairUtil, Pubkey, Signature};
use solana::pubkey::Pubkey;
use solana::signature::{KeypairUtil, Signature};
use solana::system_transaction::SystemTransaction;
use solana::transaction::Transaction;
use std::iter;

View File

@ -23,7 +23,7 @@ mod tests {
use super::*;
use bincode::serialize;
use solana::account::Account;
use solana::signature::Pubkey;
use solana::pubkey::Pubkey;
#[test]
fn test_move_funds() {

View File

@ -1,4 +1,4 @@
use signature::Pubkey;
use pubkey::Pubkey;
/// An Account with userdata that is stored on chain
#[derive(Serialize, Deserialize, Debug, Clone, Default)]

View File

@ -17,7 +17,8 @@ use ledger::Block;
use log::Level;
use mint::Mint;
use payment_plan::Payment;
use signature::{Keypair, Pubkey, Signature};
use pubkey::Pubkey;
use signature::{Keypair, Signature};
use std;
use std::collections::{BTreeMap, HashMap, VecDeque};
use std::result;

View File

@ -283,8 +283,9 @@ mod tests {
use entry::Entry;
use ledger::next_entries_mut;
use mint::Mint;
use pubkey::Pubkey;
use service::Service;
use signature::{Keypair, KeypairUtil, Pubkey};
use signature::{Keypair, KeypairUtil};
use std::cmp;
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::{channel, Sender};

View File

@ -5,7 +5,7 @@
use chrono::prelude::*;
use payment_plan::{Payment, Witness};
use signature::Pubkey;
use pubkey::Pubkey;
use std::mem;
/// A data type representing a `Witness` that the payment plan is waiting on.

View File

@ -5,7 +5,7 @@ use budget::Budget;
use budget_instruction::Instruction;
use chrono::prelude::{DateTime, Utc};
use payment_plan::Witness;
use signature::Pubkey;
use pubkey::Pubkey;
use std::io;
use transaction::Transaction;
@ -271,7 +271,8 @@ mod test {
use budget_transaction::BudgetTransaction;
use chrono::prelude::{DateTime, NaiveDate, Utc};
use hash::Hash;
use signature::{GenKeys, Keypair, KeypairUtil, Pubkey};
use pubkey::Pubkey;
use signature::{GenKeys, Keypair, KeypairUtil};
use transaction::Transaction;
#[test]

View File

@ -7,7 +7,8 @@ use budget_program::BudgetState;
use chrono::prelude::*;
use hash::Hash;
use payment_plan::Payment;
use signature::{Keypair, Pubkey};
use pubkey::Pubkey;
use signature::Keypair;
use transaction::Transaction;
pub trait BudgetTransaction {

View File

@ -1,8 +1,8 @@
use crdt::{CrdtError, NodeInfo};
use pubkey::Pubkey;
use rand::distributions::{Distribution, Weighted, WeightedChoice};
use rand::thread_rng;
use result::Result;
use signature::Pubkey;
use std;
use std::collections::HashMap;
@ -192,7 +192,8 @@ impl<'a> ChooseGossipPeerStrategy for ChooseWeightedPeerStrategy<'a> {
mod tests {
use choose_gossip_peer_strategy::{ChooseWeightedPeerStrategy, DEFAULT_WEIGHT};
use logger;
use signature::{Keypair, KeypairUtil, Pubkey};
use pubkey::Pubkey;
use signature::{Keypair, KeypairUtil};
use std;
use std::collections::HashMap;

View File

@ -21,10 +21,11 @@ use ledger::LedgerWindow;
use log::Level;
use netutil::{bind_in_range, bind_to, multi_bind_in_range};
use packet::{to_blob, Blob, BlobRecycler, SharedBlob, BLOB_SIZE};
use pubkey::Pubkey;
use rand::{thread_rng, Rng};
use rayon::prelude::*;
use result::{Error, Result};
use signature::{Keypair, KeypairUtil, Pubkey};
use signature::{Keypair, KeypairUtil};
use std;
use std::collections::HashMap;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
@ -1408,8 +1409,9 @@ mod tests {
use ledger::{LedgerWindow, LedgerWriter};
use logger;
use packet::BlobRecycler;
use pubkey::Pubkey;
use result::Error;
use signature::{Keypair, KeypairUtil, Pubkey};
use signature::{Keypair, KeypairUtil};
use std::fs::remove_dir_all;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::atomic::{AtomicBool, Ordering};

View File

@ -8,8 +8,8 @@ use bincode::{deserialize, serialize};
use bytes::Bytes;
use influx_db_client as influxdb;
use metrics;
use signature::Signature;
use signature::{Keypair, Pubkey};
use pubkey::Pubkey;
use signature::{Keypair, Signature};
use std::io;
use std::io::{Error, ErrorKind};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};

View File

@ -4,7 +4,7 @@ extern crate generic_array;
use account::Account;
use libc;
use libloading;
use signature::Pubkey;
use pubkey::Pubkey;
use std::path::PathBuf;
#[cfg(debug_assertions)]
@ -107,7 +107,7 @@ mod tests {
use super::*;
use account::Account;
use bincode::serialize;
use signature::Pubkey;
use pubkey::Pubkey;
use std::path::Path;
use std::thread;

View File

@ -7,8 +7,8 @@ use budget_transaction::BudgetTransaction;
use hash::Hash;
use packet::{BlobRecycler, SharedBlob, BLOB_DATA_SIZE};
use poh::Poh;
use pubkey::Pubkey;
use rayon::prelude::*;
use signature::Pubkey;
use std::io::Cursor;
use std::net::SocketAddr;
use std::sync::mpsc::{Receiver, Sender};

View File

@ -1,6 +1,6 @@
// Support erasure coding
use packet::{BlobRecycler, SharedBlob, BLOB_DATA_SIZE, BLOB_HEADER_SIZE};
use signature::Pubkey;
use pubkey::Pubkey;
use std::cmp;
use std::mem;
use std::result;
@ -603,8 +603,9 @@ mod test {
use erasure;
use logger;
use packet::{BlobRecycler, BLOB_DATA_SIZE, BLOB_HEADER_SIZE, BLOB_SIZE};
use pubkey::Pubkey;
use rand::{thread_rng, Rng};
use signature::{Keypair, KeypairUtil, Pubkey};
use signature::{Keypair, KeypairUtil};
// use std::sync::{Arc, RwLock};
use window::{index_blobs, WindowSlot};

View File

@ -7,10 +7,11 @@ use drone::DRONE_PORT;
use entry::Entry;
use ledger::read_ledger;
use ncp::Ncp;
use pubkey::Pubkey;
use rpc::{JsonRpcService, RPC_PORT};
use rpu::Rpu;
use service::Service;
use signature::{Keypair, KeypairUtil, Pubkey};
use signature::{Keypair, KeypairUtil};
use std::net::UdpSocket;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::atomic::{AtomicBool, Ordering};

View File

@ -11,9 +11,9 @@ use log::Level::Trace;
#[cfg(test)]
use mint::Mint;
use packet::{self, SharedBlob, BLOB_DATA_SIZE};
use pubkey::Pubkey;
use rayon::prelude::*;
use result::{Error, Result};
use signature::Pubkey;
#[cfg(test)]
use signature::{Keypair, KeypairUtil};
use std::fs::{create_dir_all, remove_dir_all, File, OpenOptions};

View File

@ -41,6 +41,7 @@ pub mod packet;
pub mod payment_plan;
pub mod poh;
pub mod poh_recorder;
pub mod pubkey;
pub mod recvmmsg;
pub mod recycler;
pub mod replicate_stage;

View File

@ -2,8 +2,9 @@
use entry::Entry;
use hash::{hash, Hash};
use pubkey::Pubkey;
use ring::rand::SystemRandom;
use signature::{Keypair, KeypairUtil, Pubkey};
use signature::{Keypair, KeypairUtil};
use system_transaction::SystemTransaction;
use transaction::Transaction;
use untrusted::Input;

View File

@ -7,11 +7,11 @@ use hash::Hash;
#[cfg(test)]
use ledger::{next_entries_mut, Block};
use log::Level;
use pubkey::Pubkey;
use recvmmsg::{recv_mmsg, NUM_RCVMMSGS};
use recycler;
use result::{Error, Result};
use serde::Serialize;
use signature::Pubkey;
use std::fmt;
use std::io;
use std::mem::size_of;

View File

@ -4,7 +4,7 @@
//! `Payment`, the payment is executed.
use chrono::prelude::*;
use signature::Pubkey;
use pubkey::Pubkey;
/// The types of events a payment plan can process.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]

31
src/pubkey.rs Normal file
View File

@ -0,0 +1,31 @@
use bs58;
use generic_array::typenum::U32;
use generic_array::GenericArray;
use std::fmt;
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Pubkey(GenericArray<u8, U32>);
impl Pubkey {
pub fn new(pubkey_vec: &[u8]) -> Self {
Pubkey(GenericArray::clone_from_slice(&pubkey_vec))
}
}
impl AsRef<[u8]> for Pubkey {
fn as_ref(&self) -> &[u8] {
&self.0[..]
}
}
impl fmt::Debug for Pubkey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
}
}
impl fmt::Display for Pubkey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
}
}

View File

@ -2,7 +2,8 @@
use account::Account;
use hash::Hash;
use signature::{Pubkey, Signature};
use pubkey::Pubkey;
use signature::Signature;
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]

View File

@ -6,8 +6,9 @@ use bincode::deserialize;
use bs58;
use jsonrpc_core::*;
use jsonrpc_http_server::*;
use pubkey::Pubkey;
use service::Service;
use signature::{Pubkey, Signature};
use signature::Signature;
use std::mem;
use std::net::{SocketAddr, UdpSocket};
use std::result;

View File

@ -1,8 +1,9 @@
//! The `signature` module provides functionality for public, and private keys.
use bs58;
use generic_array::typenum::{U32, U64};
use generic_array::typenum::U64;
use generic_array::GenericArray;
use pubkey::Pubkey;
use rand::{ChaChaRng, Rng, SeedableRng};
use rayon::prelude::*;
use ring::signature::Ed25519KeyPair;
@ -14,32 +15,6 @@ use std::fs::File;
use untrusted::Input;
pub type Keypair = Ed25519KeyPair;
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Pubkey(GenericArray<u8, U32>);
impl Pubkey {
pub fn new(pubkey_vec: &[u8]) -> Self {
Pubkey(GenericArray::clone_from_slice(&pubkey_vec))
}
}
impl AsRef<[u8]> for Pubkey {
fn as_ref(&self) -> &[u8] {
&self.0[..]
}
}
impl fmt::Debug for Pubkey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
}
}
impl fmt::Display for Pubkey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
}
}
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Signature(GenericArray<u8, U64>);
@ -89,7 +64,7 @@ impl KeypairUtil for Ed25519KeyPair {
/// Return the public key for the given keypair
fn pubkey(&self) -> Pubkey {
Pubkey(GenericArray::clone_from_slice(self.public_key_bytes()))
Pubkey::new(self.public_key_bytes())
}
}

View File

@ -43,8 +43,9 @@ pub fn init() {
}
fn verify_packet(packet: &Packet) -> u8 {
use pubkey::Pubkey;
use ring::signature;
use signature::{Pubkey, Signature};
use signature::Signature;
use untrusted;
let msg_start = TX_OFFSET + SIGNED_DATA_OFFSET;

View File

@ -4,7 +4,7 @@
use account::Account;
use bincode::deserialize;
use signature::Pubkey;
use pubkey::Pubkey;
use transaction::Transaction;
#[derive(Serialize, Deserialize, Debug, Clone)]

View File

@ -3,7 +3,7 @@
use account::Account;
use bincode::deserialize;
use dynamic_program::DynamicProgram;
use signature::Pubkey;
use pubkey::Pubkey;
use std::collections::HashMap;
use std::sync::RwLock;
use transaction::Transaction;
@ -101,7 +101,8 @@ mod test {
use bincode::serialize;
use dynamic_program::KeyedAccount;
use hash::Hash;
use signature::{Keypair, KeypairUtil, Pubkey};
use pubkey::Pubkey;
use signature::{Keypair, KeypairUtil};
use std::collections::HashMap;
use std::sync::RwLock;
use std::thread;

View File

@ -2,7 +2,8 @@
use bincode::serialize;
use hash::Hash;
use signature::{Keypair, KeypairUtil, Pubkey};
use pubkey::Pubkey;
use signature::{Keypair, KeypairUtil};
use system_program::SystemProgram;
use transaction::Transaction;

View File

@ -10,9 +10,10 @@ use crdt::{Crdt, CrdtError, NodeInfo};
use hash::Hash;
use log::Level;
use ncp::Ncp;
use pubkey::Pubkey;
use request::{Request, Response};
use result::{Error, Result};
use signature::{Keypair, Pubkey, Signature};
use signature::{Keypair, Signature};
use std;
use std::collections::HashMap;
use std::io;

View File

@ -1,8 +1,8 @@
//! tic-tac-toe program
use account::Account;
use pubkey::Pubkey;
use serde_cbor;
use signature::Pubkey;
use std;
use transaction::Transaction;

View File

@ -2,7 +2,8 @@
use bincode::serialize;
use hash::{Hash, Hasher};
use signature::{Keypair, KeypairUtil, Pubkey, Signature};
use pubkey::Pubkey;
use signature::{Keypair, KeypairUtil, Signature};
use std::mem::size_of;
pub const SIGNED_DATA_OFFSET: usize = size_of::<Signature>();

View File

@ -10,8 +10,9 @@ use influx_db_client as influxdb;
use log::Level;
use metrics;
use packet::{BlobRecycler, SharedBlob};
use pubkey::Pubkey;
use result::Result;
use signature::{Keypair, Pubkey};
use signature::Keypair;
use std::result;
use std::sync::atomic::AtomicUsize;
use std::sync::{Arc, RwLock};

View File

@ -8,12 +8,13 @@ use crdt::NodeInfo;
use drone::DroneRequest;
use fullnode::Config;
use hash::Hash;
use pubkey::Pubkey;
use reqwest;
use reqwest::header::CONTENT_TYPE;
use ring::rand::SystemRandom;
use ring::signature::Ed25519KeyPair;
use serde_json::{self, Value};
use signature::{Keypair, KeypairUtil, Pubkey, Signature};
use signature::{Keypair, KeypairUtil, Signature};
use std::fs::{self, File};
use std::io::prelude::*;
use std::io::{Error, ErrorKind, Write};

View File

@ -8,8 +8,8 @@ use erasure;
use ledger::{reconstruct_entries_from_blobs, Block};
use log::Level;
use packet::{BlobRecycler, SharedBlob};
use pubkey::Pubkey;
use result::Result;
use signature::Pubkey;
use std::cmp;
use std::mem;
use std::net::SocketAddr;
@ -450,7 +450,7 @@ pub fn new_window_from_entries(
#[cfg(test)]
mod test {
use packet::{Blob, BlobRecycler, Packet, Packets, PACKET_DATA_SIZE};
use signature::Pubkey;
use pubkey::Pubkey;
use std::io;
use std::io::Write;
use std::net::UdpSocket;

View File

@ -5,9 +5,9 @@ use crdt::{Crdt, NodeInfo};
use entry::EntrySender;
use log::Level;
use packet::{BlobRecycler, SharedBlob};
use pubkey::Pubkey;
use rand::{thread_rng, Rng};
use result::{Error, Result};
use signature::Pubkey;
use std::net::UdpSocket;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::mpsc::RecvTimeoutError;

View File

@ -299,8 +299,9 @@ mod tests {
use entry::Entry;
use hash::Hash;
use ledger::{genesis, next_entries_mut, read_ledger};
use pubkey::Pubkey;
use service::Service;
use signature::{Keypair, KeypairUtil, Pubkey};
use signature::{Keypair, KeypairUtil};
use std::fs::remove_dir_all;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::{Arc, RwLock};

View File

@ -13,9 +13,10 @@ use solana::ledger::{read_ledger, LedgerWriter};
use solana::logger;
use solana::mint::Mint;
use solana::ncp::Ncp;
use solana::pubkey::Pubkey;
use solana::result;
use solana::service::Service;
use solana::signature::{Keypair, KeypairUtil, Pubkey};
use solana::signature::{Keypair, KeypairUtil};
use solana::thin_client::ThinClient;
use solana::timing::{duration_as_ms, duration_as_s};
use solana::window::{default_window, WINDOW_SIZE};