Make imports in core crate more Rust 2018 idiomatic (#3112)

We use crate renaming to remove grin prefix, as  result imports for util and keychain crates start with crate::
which looks like a part of the current crate. This PR fixes it.
Also some small improvements were made.
If this approach works I'll replicate it to other crates.
This commit is contained in:
hashmap 2019-11-14 16:27:30 +01:00 committed by Quentin Le Sceller
parent 928097ad62
commit 43bd5a56ff
32 changed files with 133 additions and 181 deletions

View file

@ -10,7 +10,7 @@ workspace = ".."
edition = "2018" edition = "2018"
[dependencies] [dependencies]
blake2-rfc = "0.2" blake2 = { package = "blake2-rfc", version = "0.2"}
byteorder = "1" byteorder = "1"
croaring = "0.3.9" croaring = "0.3.9"
enum_primitive = "0.1" enum_primitive = "0.1"
@ -29,8 +29,8 @@ log = "0.4"
chrono = { version = "0.4.4", features = ["serde"] } chrono = { version = "0.4.4", features = ["serde"] }
zeroize = "0.9" zeroize = "0.9"
grin_keychain = { path = "../keychain", version = "3.0.0-alpha.1" } keychain = { package = "grin_keychain", path = "../keychain", version = "3.0.0-alpha.1" }
grin_util = { path = "../util", version = "3.0.0-alpha.1" } util = { package = "grin_util", path = "../util", version = "3.0.0-alpha.1" }
[dev-dependencies] [dev-dependencies]
serde_json = "1" serde_json = "1"

View file

@ -18,12 +18,11 @@
//! enough, consensus-relevant constants and short functions should be kept //! enough, consensus-relevant constants and short functions should be kept
//! here. //! here.
use std::cmp::{max, min};
use crate::core::block::HeaderVersion; use crate::core::block::HeaderVersion;
use crate::core::hash::{Hash, ZERO_HASH}; use crate::core::hash::{Hash, ZERO_HASH};
use crate::global; use crate::global;
use crate::pow::Difficulty; use crate::pow::Difficulty;
use std::cmp::{max, min};
/// A grin is divisible to 10^9, following the SI prefixes /// A grin is divisible to 10^9, following the SI prefixes
pub const GRIN_BASE: u64 = 1_000_000_000; pub const GRIN_BASE: u64 = 1_000_000_000;

View file

@ -26,8 +26,7 @@ pub mod transaction;
pub mod verifier_cache; pub mod verifier_cache;
use crate::consensus::GRIN_BASE; use crate::consensus::GRIN_BASE;
use util::secp::pedersen::Commitment;
use crate::util::secp::pedersen::Commitment;
pub use self::block::*; pub use self::block::*;
pub use self::block_sums::*; pub use self::block_sums::*;

View file

@ -14,15 +14,6 @@
//! Blocks and blockheaders //! Blocks and blockheaders
use crate::util::RwLock;
use chrono::naive::{MAX_DATE, MIN_DATE};
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
use chrono::Duration;
use std::collections::HashSet;
use std::fmt;
use std::iter::FromIterator;
use std::sync::Arc;
use crate::consensus::{self, reward, REWARD}; use crate::consensus::{self, reward, REWARD};
use crate::core::committed::{self, Committed}; use crate::core::committed::{self, Committed};
use crate::core::compact_block::{CompactBlock, CompactBlockBody}; use crate::core::compact_block::{CompactBlock, CompactBlockBody};
@ -32,12 +23,19 @@ use crate::core::{
transaction, Commitment, Input, KernelFeatures, Output, Transaction, TransactionBody, TxKernel, transaction, Commitment, Input, KernelFeatures, Output, Transaction, TransactionBody, TxKernel,
Weighting, Weighting,
}; };
use crate::global; use crate::global;
use crate::keychain::{self, BlindingFactor};
use crate::pow::{verify_size, Difficulty, Proof, ProofOfWork}; use crate::pow::{verify_size, Difficulty, Proof, ProofOfWork};
use crate::ser::{self, FixedLength, PMMRable, Readable, Reader, Writeable, Writer}; use crate::ser::{self, FixedLength, PMMRable, Readable, Reader, Writeable, Writer};
use crate::util::{secp, static_secp_instance}; use chrono::naive::{MAX_DATE, MIN_DATE};
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
use chrono::Duration;
use keychain::{self, BlindingFactor};
use std::collections::HashSet;
use std::fmt;
use std::iter::FromIterator;
use std::sync::Arc;
use util::RwLock;
use util::{secp, static_secp_instance};
/// Errors thrown by Block validation /// Errors thrown by Block validation
#[derive(Debug, Clone, Eq, PartialEq, Fail)] #[derive(Debug, Clone, Eq, PartialEq, Fail)]

View file

@ -17,8 +17,8 @@
use crate::core::committed::Committed; use crate::core::committed::Committed;
use crate::ser::{self, Readable, Reader, Writeable, Writer}; use crate::ser::{self, Readable, Reader, Writeable, Writer};
use crate::util::secp::pedersen::Commitment; use util::secp::pedersen::Commitment;
use crate::util::secp_static; use util::secp_static;
/// The output_sum and kernel_sum for a given block. /// The output_sum and kernel_sum for a given block.
/// This is used to validate the next block being processed by applying /// This is used to validate the next block being processed by applying

View file

@ -14,13 +14,12 @@
//! The Committed trait and associated errors. //! The Committed trait and associated errors.
use crate::keychain;
use crate::keychain::BlindingFactor;
use crate::util::secp::key::SecretKey;
use crate::util::secp::pedersen::Commitment;
use crate::util::{secp, secp_static, static_secp_instance};
use failure::Fail; use failure::Fail;
use keychain;
use keychain::BlindingFactor;
use util::secp::key::SecretKey;
use util::secp::pedersen::Commitment;
use util::{secp, secp_static, static_secp_instance};
/// Errors from summing and verifying kernel excesses via committed trait. /// Errors from summing and verifying kernel excesses via committed trait.
#[derive(Debug, Clone, PartialEq, Eq, Fail)] #[derive(Debug, Clone, PartialEq, Eq, Fail)]

View file

@ -14,13 +14,12 @@
//! Compact Blocks. //! Compact Blocks.
use rand::{thread_rng, Rng};
use crate::core::block::{Block, BlockHeader, Error, UntrustedBlockHeader}; use crate::core::block::{Block, BlockHeader, Error, UntrustedBlockHeader};
use crate::core::hash::{DefaultHashable, Hashed}; use crate::core::hash::{DefaultHashable, Hashed};
use crate::core::id::ShortIdentifiable; use crate::core::id::ShortIdentifiable;
use crate::core::{Output, ShortId, TxKernel}; use crate::core::{Output, ShortId, TxKernel};
use crate::ser::{self, read_multi, Readable, Reader, VerifySortedAndUnique, Writeable, Writer}; use crate::ser::{self, read_multi, Readable, Reader, VerifySortedAndUnique, Writeable, Writer};
use rand::{thread_rng, Rng};
/// Container for full (full) outputs and kernels and kern_ids for a compact block. /// Container for full (full) outputs and kernels and kern_ids for a compact block.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View file

@ -17,18 +17,16 @@
//! Primary hash function used in the protocol //! Primary hash function used in the protocol
//! //!
use crate::ser::{
self, AsFixedBytes, Error, FixedLength, ProtocolVersion, Readable, Reader, Writeable, Writer,
};
use blake2::blake2b::Blake2b;
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use std::cmp::min; use std::cmp::min;
use std::convert::AsRef; use std::convert::AsRef;
use std::ops::Add; use std::ops::Add;
use std::{fmt, ops}; use std::{fmt, ops};
use util;
use crate::blake2::blake2b::Blake2b;
use crate::ser::{
self, AsFixedBytes, Error, FixedLength, ProtocolVersion, Readable, Reader, Writeable, Writer,
};
use crate::util;
/// A hash consisting of all zeroes, used as a sentinel. No known preimage. /// A hash consisting of all zeroes, used as a sentinel. No known preimage.
pub const ZERO_HASH: Hash = Hash([0; 32]); pub const ZERO_HASH: Hash = Hash([0; 32]);
@ -251,7 +249,7 @@ impl<D: DefaultHashable, E: DefaultHashable> DefaultHashable for (D, E) {}
impl<D: DefaultHashable, E: DefaultHashable, F: DefaultHashable> DefaultHashable for (D, E, F) {} impl<D: DefaultHashable, E: DefaultHashable, F: DefaultHashable> DefaultHashable for (D, E, F) {}
/// Implement Hashed trait for external types here /// Implement Hashed trait for external types here
impl DefaultHashable for crate::util::secp::pedersen::RangeProof {} impl DefaultHashable for util::secp::pedersen::RangeProof {}
impl DefaultHashable for Vec<u8> {} impl DefaultHashable for Vec<u8> {}
impl DefaultHashable for u8 {} impl DefaultHashable for u8 {}
impl DefaultHashable for u64 {} impl DefaultHashable for u64 {}

View file

@ -14,15 +14,12 @@
//! short ids for compact blocks //! short ids for compact blocks
use std::cmp::min;
use std::cmp::Ordering;
use byteorder::{ByteOrder, LittleEndian};
use siphasher::sip::SipHasher24;
use crate::core::hash::{DefaultHashable, Hash, Hashed}; use crate::core::hash::{DefaultHashable, Hash, Hashed};
use crate::ser::{self, Readable, Reader, Writeable, Writer}; use crate::ser::{self, Readable, Reader, Writeable, Writer};
use crate::util; use byteorder::{ByteOrder, LittleEndian};
use siphasher::sip::SipHasher24;
use std::cmp::{min, Ordering};
use util;
/// The size of a short id used to identify inputs|outputs|kernels (6 bytes) /// The size of a short id used to identify inputs|outputs|kernels (6 bytes)
pub const SHORT_ID_SIZE: usize = 6; pub const SHORT_ID_SIZE: usize = 6;

View file

@ -18,7 +18,7 @@ use crate::core::hash::Hash;
use crate::core::pmmr; use crate::core::pmmr;
use crate::ser; use crate::ser;
use crate::ser::{PMMRIndexHashable, Readable, Reader, Writeable, Writer}; use crate::ser::{PMMRIndexHashable, Readable, Reader, Writeable, Writer};
use crate::util; use util;
/// Merkle proof errors. /// Merkle proof errors.
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]

View file

@ -17,23 +17,23 @@
use crate::core::hash::{DefaultHashable, Hashed}; use crate::core::hash::{DefaultHashable, Hashed};
use crate::core::verifier_cache::VerifierCache; use crate::core::verifier_cache::VerifierCache;
use crate::core::{committed, Committed}; use crate::core::{committed, Committed};
use crate::keychain::{self, BlindingFactor};
use crate::libtx::secp_ser; use crate::libtx::secp_ser;
use crate::ser::{ use crate::ser::{
self, read_multi, FixedLength, PMMRable, ProtocolVersion, Readable, Reader, self, read_multi, FixedLength, PMMRable, ProtocolVersion, Readable, Reader,
VerifySortedAndUnique, Writeable, Writer, VerifySortedAndUnique, Writeable, Writer,
}; };
use crate::util;
use crate::util::secp;
use crate::util::secp::pedersen::{Commitment, RangeProof};
use crate::util::static_secp_instance;
use crate::util::RwLock;
use crate::{consensus, global}; use crate::{consensus, global};
use enum_primitive::FromPrimitive; use enum_primitive::FromPrimitive;
use keychain::{self, BlindingFactor};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::sync::Arc; use std::sync::Arc;
use std::{error, fmt}; use std::{error, fmt};
use util;
use util::secp;
use util::secp::pedersen::{Commitment, RangeProof};
use util::static_secp_instance;
use util::RwLock;
/// Various tx kernel variants. /// Various tx kernel variants.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
@ -1584,8 +1584,8 @@ mod test {
use super::*; use super::*;
use crate::core::hash::Hash; use crate::core::hash::Hash;
use crate::core::id::{ShortId, ShortIdentifiable}; use crate::core::id::{ShortId, ShortIdentifiable};
use crate::keychain::{ExtKeychain, Keychain, SwitchCommitmentType}; use keychain::{ExtKeychain, Keychain, SwitchCommitmentType};
use crate::util::secp; use util::secp;
#[test] #[test]
fn test_kernel_ser_deser() { fn test_kernel_ser_deser() {

View file

@ -15,10 +15,9 @@
//! VerifierCache trait for batch verifying outputs and kernels. //! VerifierCache trait for batch verifying outputs and kernels.
//! We pass a "caching verifier" into the block validation processing with this. //! We pass a "caching verifier" into the block validation processing with this.
use lru_cache::LruCache;
use crate::core::hash::{Hash, Hashed}; use crate::core::hash::{Hash, Hashed};
use crate::core::{Output, TxKernel}; use crate::core::{Output, TxKernel};
use lru_cache::LruCache;
/// Verifier cache for caching expensive verification results. /// Verifier cache for caching expensive verification results.
/// Specifically the following - /// Specifically the following -

View file

@ -19,17 +19,15 @@
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
use chrono::prelude::{TimeZone, Utc};
use crate::core; use crate::core;
use crate::pow::{Difficulty, Proof, ProofOfWork};
use crate::util;
use crate::util::secp::constants::SINGLE_BULLET_PROOF_SIZE;
use crate::util::secp::pedersen::{Commitment, RangeProof};
use crate::util::secp::Signature;
use crate::core::hash::Hash; use crate::core::hash::Hash;
use crate::keychain::BlindingFactor; use crate::pow::{Difficulty, Proof, ProofOfWork};
use chrono::prelude::{TimeZone, Utc};
use keychain::BlindingFactor;
use util;
use util::secp::constants::SINGLE_BULLET_PROOF_SIZE;
use util::secp::pedersen::{Commitment, RangeProof};
use util::secp::Signature;
/// Genesis block definition for development networks. The proof of work size /// Genesis block definition for development networks. The proof of work size
/// is small enough to mine it on the fly, so it does not contain its own /// is small enough to mine it on the fly, so it does not contain its own

View file

@ -26,11 +26,12 @@ use crate::core::block::HeaderVersion;
use crate::pow::{ use crate::pow::{
self, new_cuckaroo_ctx, new_cuckarood_ctx, new_cuckatoo_ctx, EdgeType, PoWContext, self, new_cuckaroo_ctx, new_cuckarood_ctx, new_cuckatoo_ctx, EdgeType, PoWContext,
}; };
use util::RwLock;
/// An enum collecting sets of parameters used throughout the /// An enum collecting sets of parameters used throughout the
/// code wherever mining is needed. This should allow for /// code wherever mining is needed. This should allow for
/// different sets of parameters for different purposes, /// different sets of parameters for different purposes,
/// e.g. CI, User testing, production values /// e.g. CI, User testing, production values
use crate::util::RwLock;
/// Define these here, as they should be developer-set, not really tweakable /// Define these here, as they should be developer-set, not really tweakable
/// by users /// by users

View file

@ -21,22 +21,18 @@
#![deny(unused_mut)] #![deny(unused_mut)]
#![warn(missing_docs)] #![warn(missing_docs)]
use blake2_rfc as blake2;
#[macro_use] #[macro_use]
extern crate enum_primitive; extern crate enum_primitive;
use grin_keychain as keychain;
use grin_util as util;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
extern crate serde; use serde;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
use failure; use failure;
#[macro_use] #[macro_use]
extern crate failure_derive; extern crate failure_derive;
extern crate zeroize;
#[macro_use] #[macro_use]
pub mod macros; pub mod macros;

View file

@ -16,12 +16,11 @@
//! This module interfaces into the underlying //! This module interfaces into the underlying
//! [Rust Aggsig library](https://github.com/mimblewimble/rust-secp256k1-zkp/blob/master/src/aggsig.rs) //! [Rust Aggsig library](https://github.com/mimblewimble/rust-secp256k1-zkp/blob/master/src/aggsig.rs)
use crate::keychain::{BlindingFactor, Identifier, Keychain};
use crate::libtx::error::{Error, ErrorKind}; use crate::libtx::error::{Error, ErrorKind};
use crate::util::secp::key::{PublicKey, SecretKey}; use keychain::{BlindingFactor, Identifier, Keychain, SwitchCommitmentType};
use crate::util::secp::pedersen::Commitment; use util::secp::key::{PublicKey, SecretKey};
use crate::util::secp::{self, aggsig, Message, Secp256k1, Signature}; use util::secp::pedersen::Commitment;
use grin_keychain::SwitchCommitmentType; use util::secp::{self, aggsig, Message, Secp256k1, Signature};
/// Creates a new secure nonce (as a SecretKey), guaranteed to be usable during /// Creates a new secure nonce (as a SecretKey), guaranteed to be usable during
/// aggsig creation. /// aggsig creation.
@ -34,7 +33,6 @@ use grin_keychain::SwitchCommitmentType;
/// ///
/// ``` /// ```
/// # extern crate grin_core as core; /// # extern crate grin_core as core;
/// # extern crate grin_util as util;
/// use core::libtx::aggsig; /// use core::libtx::aggsig;
/// use util::secp::{ContextFlag, Secp256k1}; /// use util::secp::{ContextFlag, Secp256k1};
/// let secp = Secp256k1::with_caps(ContextFlag::SignOnly); /// let secp = Secp256k1::with_caps(ContextFlag::SignOnly);
@ -68,7 +66,6 @@ pub fn create_secnonce(secp: &Secp256k1) -> Result<SecretKey, Error> {
/// ///
/// ``` /// ```
/// # extern crate grin_core as core; /// # extern crate grin_core as core;
/// # extern crate grin_util as util;
/// # extern crate rand; /// # extern crate rand;
/// use rand::thread_rng; /// use rand::thread_rng;
/// use core::libtx::aggsig; /// use core::libtx::aggsig;
@ -139,7 +136,6 @@ pub fn calculate_partial_sig(
/// ///
/// ``` /// ```
/// # extern crate grin_core as core; /// # extern crate grin_core as core;
/// # extern crate grin_util as util;
/// # extern crate rand; /// # extern crate rand;
/// use rand::thread_rng; /// use rand::thread_rng;
/// use core::libtx::aggsig; /// use core::libtx::aggsig;
@ -223,9 +219,7 @@ pub fn verify_partial_sig(
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # extern crate grin_util as util;
/// # extern crate grin_core as core; /// # extern crate grin_core as core;
/// # extern crate grin_keychain as keychain;
/// use core::consensus::reward; /// use core::consensus::reward;
/// use util::secp::key::{PublicKey, SecretKey}; /// use util::secp::key::{PublicKey, SecretKey};
/// use util::secp::{ContextFlag, Secp256k1}; /// use util::secp::{ContextFlag, Secp256k1};
@ -291,9 +285,7 @@ where
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # extern crate grin_util as util;
/// # extern crate grin_core as core; /// # extern crate grin_core as core;
/// # extern crate grin_keychain as keychain;
/// use core::consensus::reward; /// use core::consensus::reward;
/// use core::libtx::{aggsig, proof}; /// use core::libtx::{aggsig, proof};
/// use util::secp::key::{PublicKey, SecretKey}; /// use util::secp::key::{PublicKey, SecretKey};
@ -367,7 +359,6 @@ pub fn verify_single_from_commit(
/// ///
/// ``` /// ```
/// # extern crate grin_core as core; /// # extern crate grin_core as core;
/// # extern crate grin_util as util;
/// # extern crate rand; /// # extern crate rand;
/// use rand::thread_rng; /// use rand::thread_rng;
/// use core::libtx::aggsig; /// use core::libtx::aggsig;

View file

@ -32,10 +32,9 @@
//! ) //! )
use crate::core::{Input, KernelFeatures, Output, OutputFeatures, Transaction, TxKernel}; use crate::core::{Input, KernelFeatures, Output, OutputFeatures, Transaction, TxKernel};
use crate::keychain::{BlindSum, BlindingFactor, Identifier, Keychain};
use crate::libtx::proof::{self, ProofBuild}; use crate::libtx::proof::{self, ProofBuild};
use crate::libtx::{aggsig, Error}; use crate::libtx::{aggsig, Error};
use grin_keychain::SwitchCommitmentType; use keychain::{BlindSum, BlindingFactor, Identifier, Keychain, SwitchCommitmentType};
/// Context information available to transaction combinators. /// Context information available to transaction combinators.
pub struct Context<'a, K, B> pub struct Context<'a, K, B>
@ -247,14 +246,14 @@ where
// Just a simple test, most exhaustive tests in the core. // Just a simple test, most exhaustive tests in the core.
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::util::RwLock;
use std::sync::Arc; use std::sync::Arc;
use util::RwLock;
use super::*; use super::*;
use crate::core::transaction::Weighting; use crate::core::transaction::Weighting;
use crate::core::verifier_cache::{LruVerifierCache, VerifierCache}; use crate::core::verifier_cache::{LruVerifierCache, VerifierCache};
use crate::keychain::{ExtKeychain, ExtKeychainPath};
use crate::libtx::ProofBuilder; use crate::libtx::ProofBuilder;
use keychain::{ExtKeychain, ExtKeychainPath};
fn verifier_cache() -> Arc<RwLock<dyn VerifierCache>> { fn verifier_cache() -> Arc<RwLock<dyn VerifierCache>> {
Arc::new(RwLock::new(LruVerifierCache::new())) Arc::new(RwLock::new(LruVerifierCache::new()))

View file

@ -13,12 +13,11 @@
// limitations under the License. // limitations under the License.
//! libtx specific errors //! libtx specific errors
use failure::{Backtrace, Context, Fail};
use std::fmt::{self, Display};
use crate::core::transaction; use crate::core::transaction;
use crate::keychain; use failure::{Backtrace, Context, Fail};
use crate::util::secp; use keychain;
use std::fmt::{self, Display};
use util::secp;
/// Lib tx error definition /// Lib tx error definition
#[derive(Debug)] #[derive(Debug)]

View file

@ -14,15 +14,15 @@
//! Rangeproof library functions //! Rangeproof library functions
use crate::blake2::blake2b::blake2b;
use crate::keychain::extkey_bip32::BIP32GrinHasher;
use crate::keychain::{Identifier, Keychain, SwitchCommitmentType, ViewKey};
use crate::libtx::error::{Error, ErrorKind}; use crate::libtx::error::{Error, ErrorKind};
use crate::util::secp::key::SecretKey; use blake2::blake2b::blake2b;
use crate::util::secp::pedersen::{Commitment, ProofMessage, RangeProof}; use keychain::extkey_bip32::BIP32GrinHasher;
use crate::util::secp::{self, Secp256k1}; use keychain::{Identifier, Keychain, SwitchCommitmentType, ViewKey};
use crate::zeroize::Zeroize;
use std::convert::TryFrom; use std::convert::TryFrom;
use util::secp::key::SecretKey;
use util::secp::pedersen::{Commitment, ProofMessage, RangeProof};
use util::secp::{self, Secp256k1};
use zeroize::Zeroize;
/// Create a bulletproof /// Create a bulletproof
pub fn create<K, B>( pub fn create<K, B>(
@ -440,8 +440,8 @@ impl ProofBuild for ViewKey {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::keychain::ExtKeychain; use keychain::ChildNumber;
use grin_keychain::ChildNumber; use keychain::ExtKeychain;
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
#[test] #[test]

View file

@ -16,14 +16,13 @@
//! reward. //! reward.
use crate::consensus::reward; use crate::consensus::reward;
use crate::core::{KernelFeatures, Output, OutputFeatures, TxKernel}; use crate::core::{KernelFeatures, Output, OutputFeatures, TxKernel};
use crate::keychain::{Identifier, Keychain};
use crate::libtx::error::Error; use crate::libtx::error::Error;
use crate::libtx::{ use crate::libtx::{
aggsig, aggsig,
proof::{self, ProofBuild}, proof::{self, ProofBuild},
}; };
use crate::util::{secp, static_secp_instance}; use keychain::{Identifier, Keychain, SwitchCommitmentType};
use grin_keychain::SwitchCommitmentType; use util::{secp, static_secp_instance};
/// output a reward output /// output a reward output
pub fn output<K, B>( pub fn output<K, B>(

View file

@ -14,16 +14,16 @@
//! Sane serialization & deserialization of cryptographic structs into hex //! Sane serialization & deserialization of cryptographic structs into hex
use crate::keychain::BlindingFactor; use keychain::BlindingFactor;
use crate::serde::{Deserialize, Deserializer, Serializer}; use serde::{Deserialize, Deserializer, Serializer};
use crate::util::secp::pedersen::{Commitment, RangeProof}; use util::secp::pedersen::{Commitment, RangeProof};
use crate::util::{from_hex, to_hex}; use util::{from_hex, to_hex};
/// Serializes a secp PublicKey to and from hex /// Serializes a secp PublicKey to and from hex
pub mod pubkey_serde { pub mod pubkey_serde {
use crate::serde::{Deserialize, Deserializer, Serializer}; use serde::{Deserialize, Deserializer, Serializer};
use crate::util::secp::key::PublicKey; use util::secp::key::PublicKey;
use crate::util::{from_hex, static_secp_instance, to_hex}; use util::{from_hex, static_secp_instance, to_hex};
/// ///
pub fn serialize<S>(key: &PublicKey, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(key: &PublicKey, serializer: S) -> Result<S::Ok, S::Error>
@ -55,8 +55,8 @@ pub mod pubkey_serde {
/// Serializes an Option<secp::Signature> to and from hex /// Serializes an Option<secp::Signature> to and from hex
pub mod option_sig_serde { pub mod option_sig_serde {
use crate::serde::{Deserialize, Deserializer, Serializer}; use crate::serde::{Deserialize, Deserializer, Serializer};
use crate::util::{from_hex, secp, static_secp_instance, to_hex};
use serde::de::Error; use serde::de::Error;
use util::{from_hex, secp, static_secp_instance, to_hex};
/// ///
pub fn serialize<S>(sig: &Option<secp::Signature>, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(sig: &Option<secp::Signature>, serializer: S) -> Result<S::Ok, S::Error>
@ -93,14 +93,13 @@ pub mod option_sig_serde {
None => Ok(None), None => Ok(None),
}) })
} }
} }
/// Serializes an Option<secp::SecretKey> to and from hex /// Serializes an Option<secp::SecretKey> to and from hex
pub mod option_seckey_serde { pub mod option_seckey_serde {
use crate::serde::{Deserialize, Deserializer, Serializer}; use crate::serde::{Deserialize, Deserializer, Serializer};
use crate::util::{from_hex, secp, static_secp_instance, to_hex};
use serde::de::Error; use serde::de::Error;
use util::{from_hex, secp, static_secp_instance, to_hex};
/// ///
pub fn serialize<S>( pub fn serialize<S>(
@ -141,8 +140,8 @@ pub mod option_seckey_serde {
/// Serializes a secp::Signature to and from hex /// Serializes a secp::Signature to and from hex
pub mod sig_serde { pub mod sig_serde {
use crate::serde::{Deserialize, Deserializer, Serializer}; use crate::serde::{Deserialize, Deserializer, Serializer};
use crate::util::{from_hex, secp, static_secp_instance, to_hex};
use serde::de::Error; use serde::de::Error;
use util::{from_hex, secp, static_secp_instance, to_hex};
/// ///
pub fn serialize<S>(sig: &secp::Signature, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(sig: &secp::Signature, serializer: S) -> Result<S::Ok, S::Error>
@ -175,9 +174,9 @@ pub mod sig_serde {
/// Serializes an Option<secp::Commitment> to and from hex /// Serializes an Option<secp::Commitment> to and from hex
pub mod option_commitment_serde { pub mod option_commitment_serde {
use crate::serde::{Deserialize, Deserializer, Serializer}; use crate::serde::{Deserialize, Deserializer, Serializer};
use crate::util::secp::pedersen::Commitment;
use crate::util::{from_hex, to_hex};
use serde::de::Error; use serde::de::Error;
use util::secp::pedersen::Commitment;
use util::{from_hex, to_hex};
/// ///
pub fn serialize<S>(commit: &Option<Commitment>, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(commit: &Option<Commitment>, serializer: S) -> Result<S::Ok, S::Error>
@ -202,7 +201,6 @@ pub mod option_commitment_serde {
None => Ok(None), None => Ok(None),
}) })
} }
} }
/// Creates a BlindingFactor from a hex string /// Creates a BlindingFactor from a hex string
pub fn blind_from_hex<'de, D>(deserializer: D) -> Result<BlindingFactor, D::Error> pub fn blind_from_hex<'de, D>(deserializer: D) -> Result<BlindingFactor, D::Error>
@ -350,9 +348,9 @@ pub mod opt_string_or_u64 {
mod test { mod test {
use super::*; use super::*;
use crate::libtx::aggsig; use crate::libtx::aggsig;
use crate::util::secp::key::{PublicKey, SecretKey}; use util::secp::key::{PublicKey, SecretKey};
use crate::util::secp::{Message, Signature}; use util::secp::{Message, Signature};
use crate::util::static_secp_instance; use util::static_secp_instance;
use serde_json; use serde_json;

View file

@ -28,6 +28,11 @@
#![deny(unused_mut)] #![deny(unused_mut)]
#![warn(missing_docs)] #![warn(missing_docs)]
pub use self::common::EdgeType;
pub use self::types::*;
use crate::core::{Block, BlockHeader};
use crate::genesis;
use crate::global;
use chrono; use chrono;
use num; use num;
@ -42,17 +47,11 @@ pub mod lean;
mod siphash; mod siphash;
mod types; mod types;
use crate::core::{Block, BlockHeader};
use crate::genesis;
use crate::global;
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
pub use self::common::EdgeType;
pub use self::types::*;
pub use crate::pow::cuckaroo::{new_cuckaroo_ctx, CuckarooContext}; pub use crate::pow::cuckaroo::{new_cuckaroo_ctx, CuckarooContext};
pub use crate::pow::cuckarood::{new_cuckarood_ctx, CuckaroodContext}; pub use crate::pow::cuckarood::{new_cuckarood_ctx, CuckaroodContext};
pub use crate::pow::cuckatoo::{new_cuckatoo_ctx, CuckatooContext}; pub use crate::pow::cuckatoo::{new_cuckatoo_ctx, CuckatooContext};
pub use crate::pow::error::Error; pub use crate::pow::error::Error;
use chrono::prelude::{DateTime, NaiveDateTime, Utc};
const MAX_SOLS: u32 = 10; const MAX_SOLS: u32 = 10;

View file

@ -14,12 +14,11 @@
//! Common types and traits for cuckoo family of solvers //! Common types and traits for cuckoo family of solvers
use crate::blake2::blake2b::blake2b;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use crate::pow::error::{Error, ErrorKind}; use crate::pow::error::{Error, ErrorKind};
use crate::pow::num::{PrimInt, ToPrimitive}; use crate::pow::num::{PrimInt, ToPrimitive};
use crate::pow::siphash::siphash24; use crate::pow::siphash::siphash24;
use blake2::blake2b::blake2b;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt; use std::fmt;
use std::hash::Hash; use std::hash::Hash;
use std::io::Cursor; use std::io::Cursor;

View file

@ -12,16 +12,14 @@
// limitations under the License. // limitations under the License.
//! Implementation of Cuckatoo Cycle designed by John Tromp. //! Implementation of Cuckatoo Cycle designed by John Tromp.
use std::mem;
use byteorder::{BigEndian, WriteBytesExt};
use croaring::Bitmap;
use crate::global; use crate::global;
use crate::pow::common::{CuckooParams, EdgeType, Link}; use crate::pow::common::{CuckooParams, EdgeType, Link};
use crate::pow::error::{Error, ErrorKind}; use crate::pow::error::{Error, ErrorKind};
use crate::pow::{PoWContext, Proof}; use crate::pow::{PoWContext, Proof};
use crate::util; use byteorder::{BigEndian, WriteBytesExt};
use croaring::Bitmap;
use std::mem;
use util;
struct Graph<T> struct Graph<T>
where where

View file

@ -12,23 +12,20 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use crate::consensus::{graph_weight, MIN_DIFFICULTY, SECOND_POW_EDGE_BITS};
use crate::core::hash::{DefaultHashable, Hashed};
use crate::global;
use crate::pow::common::EdgeType;
use crate::pow::error::Error;
use crate::ser::{self, FixedLength, Readable, Reader, Writeable, Writer};
use rand::{thread_rng, Rng};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
/// Types for a Cuck(at)oo proof of work and its encapsulation as a fully usable /// Types for a Cuck(at)oo proof of work and its encapsulation as a fully usable
/// proof of work within a block header. /// proof of work within a block header.
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::ops::{Add, Div, Mul, Sub}; use std::ops::{Add, Div, Mul, Sub};
use std::{fmt, iter}; use std::{fmt, iter};
use rand::{thread_rng, Rng};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use crate::consensus::{graph_weight, MIN_DIFFICULTY, SECOND_POW_EDGE_BITS};
use crate::core::hash::{DefaultHashable, Hashed};
use crate::global;
use crate::ser::{self, FixedLength, Readable, Reader, Writeable, Writer};
use crate::pow::common::EdgeType;
use crate::pow::error::Error;
/// Generic trait for a solver/verifier providing common interface into Cuckoo-family PoW /// Generic trait for a solver/verifier providing common interface into Cuckoo-family PoW
/// Mostly used for verification, but also for test mining if necessary /// Mostly used for verification, but also for test mining if necessary
pub trait PoWContext<T> pub trait PoWContext<T>

View file

@ -21,20 +21,20 @@
use crate::core::hash::{DefaultHashable, Hash, Hashed}; use crate::core::hash::{DefaultHashable, Hash, Hashed};
use crate::global::PROTOCOL_VERSION; use crate::global::PROTOCOL_VERSION;
use crate::keychain::{BlindingFactor, Identifier, IDENTIFIER_SIZE};
use crate::util::secp::constants::{
AGG_SIGNATURE_SIZE, COMPRESSED_PUBLIC_KEY_SIZE, MAX_PROOF_SIZE, PEDERSEN_COMMITMENT_SIZE,
SECRET_KEY_SIZE,
};
use crate::util::secp::key::PublicKey;
use crate::util::secp::pedersen::{Commitment, RangeProof};
use crate::util::secp::Signature;
use crate::util::secp::{ContextFlag, Secp256k1};
use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; use byteorder::{BigEndian, ByteOrder, ReadBytesExt};
use keychain::{BlindingFactor, Identifier, IDENTIFIER_SIZE};
use std::fmt::{self, Debug}; use std::fmt::{self, Debug};
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::marker; use std::marker;
use std::{cmp, error}; use std::{cmp, error};
use util::secp::constants::{
AGG_SIGNATURE_SIZE, COMPRESSED_PUBLIC_KEY_SIZE, MAX_PROOF_SIZE, PEDERSEN_COMMITMENT_SIZE,
SECRET_KEY_SIZE,
};
use util::secp::key::PublicKey;
use util::secp::pedersen::{Commitment, RangeProof};
use util::secp::Signature;
use util::secp::{ContextFlag, Secp256k1};
/// Possible errors deriving from serializing or deserializing. /// Possible errors deriving from serializing or deserializing.
#[derive(Clone, Eq, PartialEq, Debug)] #[derive(Clone, Eq, PartialEq, Debug)]
@ -916,17 +916,17 @@ impl AsFixedBytes for crate::core::hash::Hash {
32 32
} }
} }
impl AsFixedBytes for crate::util::secp::pedersen::RangeProof { impl AsFixedBytes for util::secp::pedersen::RangeProof {
fn len(&self) -> usize { fn len(&self) -> usize {
self.plen self.plen
} }
} }
impl AsFixedBytes for crate::util::secp::Signature { impl AsFixedBytes for util::secp::Signature {
fn len(&self) -> usize { fn len(&self) -> usize {
64 64
} }
} }
impl AsFixedBytes for crate::util::secp::pedersen::Commitment { impl AsFixedBytes for util::secp::pedersen::Commitment {
fn len(&self) -> usize { fn len(&self) -> usize {
PEDERSEN_COMMITMENT_SIZE PEDERSEN_COMMITMENT_SIZE
} }
@ -936,7 +936,7 @@ impl AsFixedBytes for BlindingFactor {
SECRET_KEY_SIZE SECRET_KEY_SIZE
} }
} }
impl AsFixedBytes for crate::keychain::Identifier { impl AsFixedBytes for keychain::Identifier {
fn len(&self) -> usize { fn len(&self) -> usize {
IDENTIFIER_SIZE IDENTIFIER_SIZE
} }

View file

@ -27,15 +27,13 @@ use crate::core::core::{
use crate::core::libtx::build::{self, input, output}; use crate::core::libtx::build::{self, input, output};
use crate::core::libtx::ProofBuilder; use crate::core::libtx::ProofBuilder;
use crate::core::{global, ser}; use crate::core::{global, ser};
use crate::keychain::{BlindingFactor, ExtKeychain, Keychain};
use crate::util::secp;
use crate::util::RwLock;
use chrono::Duration; use chrono::Duration;
use grin_core as core; use grin_core as core;
use grin_core::global::ChainTypes; use grin_core::global::ChainTypes;
use grin_keychain as keychain; use keychain::{BlindingFactor, ExtKeychain, Keychain};
use grin_util as util;
use std::sync::Arc; use std::sync::Arc;
use util::secp;
use util::RwLock;
fn verifier_cache() -> Arc<RwLock<dyn VerifierCache>> { fn verifier_cache() -> Arc<RwLock<dyn VerifierCache>> {
Arc::new(RwLock::new(LruVerifierCache::new())) Arc::new(RwLock::new(LruVerifierCache::new()))

View file

@ -14,7 +14,6 @@
//! Common test functions //! Common test functions
use crate::keychain::{Identifier, Keychain};
use grin_core::core::{Block, BlockHeader, KernelFeatures, Transaction}; use grin_core::core::{Block, BlockHeader, KernelFeatures, Transaction};
use grin_core::libtx::{ use grin_core::libtx::{
build::{self, input, output}, build::{self, input, output},
@ -22,7 +21,7 @@ use grin_core::libtx::{
reward, reward,
}; };
use grin_core::pow::Difficulty; use grin_core::pow::Difficulty;
use grin_keychain as keychain; use keychain::{Identifier, Keychain};
// utility producing a transaction with 2 inputs and a single outputs // utility producing a transaction with 2 inputs and a single outputs
pub fn tx2i1o() -> Transaction { pub fn tx2i1o() -> Transaction {

View file

@ -26,14 +26,12 @@ use self::core::core::{
use self::core::libtx::build::{self, initial_tx, input, output, with_excess}; use self::core::libtx::build::{self, initial_tx, input, output, with_excess};
use self::core::libtx::ProofBuilder; use self::core::libtx::ProofBuilder;
use self::core::ser; use self::core::ser;
use self::keychain::{BlindingFactor, ExtKeychain, Keychain};
use self::util::static_secp_instance;
use self::util::RwLock;
use crate::common::{new_block, tx1i1o, tx1i2o, tx2i1o}; use crate::common::{new_block, tx1i1o, tx1i2o, tx2i1o};
use grin_core as core; use grin_core as core;
use grin_keychain as keychain; use keychain::{BlindingFactor, ExtKeychain, Keychain};
use grin_util as util;
use std::sync::Arc; use std::sync::Arc;
use util::static_secp_instance;
use util::RwLock;
#[test] #[test]
fn simple_tx_ser() { fn simple_tx_ser() {

View file

@ -19,9 +19,8 @@ pub mod common;
use self::core::core::{Output, OutputFeatures}; use self::core::core::{Output, OutputFeatures};
use self::core::libtx::proof; use self::core::libtx::proof;
use self::core::ser; use self::core::ser;
use self::keychain::{ExtKeychain, Keychain};
use grin_core as core; use grin_core as core;
use grin_keychain as keychain; use keychain::{ExtKeychain, Keychain};
#[test] #[test]
fn test_output_ser_deser() { fn test_output_ser_deser() {

View file

@ -17,12 +17,10 @@ pub mod common;
use self::core::core::verifier_cache::{LruVerifierCache, VerifierCache}; use self::core::core::verifier_cache::{LruVerifierCache, VerifierCache};
use self::core::core::{Output, OutputFeatures}; use self::core::core::{Output, OutputFeatures};
use self::core::libtx::proof; use self::core::libtx::proof;
use self::keychain::{ExtKeychain, Keychain, SwitchCommitmentType};
use self::util::RwLock;
use grin_core as core; use grin_core as core;
use grin_keychain as keychain; use keychain::{ExtKeychain, Keychain, SwitchCommitmentType};
use grin_util as util;
use std::sync::Arc; use std::sync::Arc;
use util::RwLock;
fn verifier_cache() -> Arc<RwLock<dyn VerifierCache>> { fn verifier_cache() -> Arc<RwLock<dyn VerifierCache>> {
Arc::new(RwLock::new(LruVerifierCache::new())) Arc::new(RwLock::new(LruVerifierCache::new()))

View file

@ -25,8 +25,6 @@ extern crate serde_derive;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
extern crate sha2;
mod base58; mod base58;
pub mod extkey_bip32; pub mod extkey_bip32;
pub mod mnemonic; pub mod mnemonic;