Move Network, Magic, and magics to zebra-chain

This commit is contained in:
Deirdre Connolly 2020-03-10 19:44:19 -04:00 committed by Deirdre Connolly
parent 14120cf828
commit b68e1e2d55
11 changed files with 39 additions and 40 deletions

1
Cargo.lock generated
View File

@ -2057,6 +2057,7 @@ dependencies = [
"redjubjub", "redjubjub",
"ripemd160", "ripemd160",
"secp256k1", "secp256k1",
"serde",
"sha2", "sha2",
"thiserror", "thiserror",
] ]

View File

@ -16,6 +16,7 @@ hex = "0.4"
lazy_static = "1.4.0" lazy_static = "1.4.0"
ripemd160 = "0.8.0" ripemd160 = "0.8.0"
secp256k1 = "0.17.2" secp256k1 = "0.17.2"
serde = { version = "1", features = ["serde_derive"] }
sha2 = "0.8" sha2 = "0.8"
thiserror = "1" thiserror = "1"
# ZF deps # ZF deps

View File

@ -10,9 +10,11 @@ use sha2::Sha256;
#[cfg(test)] #[cfg(test)]
use proptest_derive::Arbitrary; use proptest_derive::Arbitrary;
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}; use crate::{
network::Network,
use crate::types::Script; serialization::{SerializationError, ZcashDeserialize, ZcashSerialize},
types::Script,
};
/// A hash of a redeem script, as used in transparent /// A hash of a redeem script, as used in transparent
/// pay-to-script-hash and pay-to-publickey-hash addresses. /// pay-to-script-hash and pay-to-publickey-hash addresses.
@ -42,16 +44,6 @@ impl fmt::Debug for AddressPayloadHash {
} }
} }
/// An enum describing the possible network choices.
// XXX Stolen from zebra-network for now.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum Network {
/// The production mainnet.
Mainnet,
/// The testnet.
Testnet,
}
/// Transparent Zcash Addresses /// Transparent Zcash Addresses
/// ///
/// In Bitcoin a single byte is used for the version field identifying /// In Bitcoin a single byte is used for the version field identifying

View File

@ -4,6 +4,9 @@
#![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_chain")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_chain")]
#![deny(missing_docs)] #![deny(missing_docs)]
#[macro_use]
extern crate serde;
mod merkle_tree; mod merkle_tree;
mod sha256d_writer; mod sha256d_writer;
@ -11,6 +14,7 @@ pub mod addresses;
pub mod block; pub mod block;
pub mod equihash_solution; pub mod equihash_solution;
pub mod keys; pub mod keys;
pub mod network;
pub mod note_commitment_tree; pub mod note_commitment_tree;
pub mod note_encryption; pub mod note_encryption;
pub mod proofs; pub mod proofs;

View File

@ -1,4 +1,6 @@
use crate::{constants::magics, protocol::external::types::Magic}; //! Network-specific types.
use crate::types::Magic;
/// An enum describing the possible network choices. /// An enum describing the possible network choices.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
@ -18,3 +20,12 @@ impl Network {
} }
} }
} }
/// Magic numbers used to identify different Zcash networks.
pub mod magics {
use super::*;
/// The production mainnet.
pub const MAINNET: Magic = Magic([0x24, 0xe9, 0x27, 0x64]);
/// The testnet.
pub const TESTNET: Magic = Magic([0xfa, 0x1a, 0xf9, 0xbf]);
}

View File

@ -15,6 +15,17 @@ use crate::serialization::{
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize, ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
}; };
/// A magic number identifying the network.
#[derive(Copy, Clone, Eq, PartialEq)]
#[cfg_attr(test, derive(Arbitrary))]
pub struct Magic(pub [u8; 4]);
impl fmt::Debug for Magic {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("Magic").field(&hex::encode(&self.0)).finish()
}
}
/// A 4-byte checksum using truncated double-SHA256 (two rounds of SHA256). /// A 4-byte checksum using truncated double-SHA256 (two rounds of SHA256).
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq)]
pub struct Sha256dChecksum(pub [u8; 4]); pub struct Sha256dChecksum(pub [u8; 4]);

View File

@ -4,7 +4,7 @@ use std::{
time::Duration, time::Duration,
}; };
use crate::network::Network; use zebra_chain::network::Network;
/// Configuration for networking code. /// Configuration for networking code.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]

View File

@ -40,15 +40,6 @@ pub const CURRENT_VERSION: Version = Version(170_009);
/// The minimum version supported for peer connections. /// The minimum version supported for peer connections.
pub const MIN_VERSION: Version = Version(170_009); pub const MIN_VERSION: Version = Version(170_009);
/// Magic numbers used to identify different Zcash networks.
pub mod magics {
use super::*;
/// The production mainnet.
pub const MAINNET: Magic = Magic([0x24, 0xe9, 0x27, 0x64]);
/// The testnet.
pub const TESTNET: Magic = Magic([0xfa, 0x1a, 0xf9, 0xbf]);
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@ -28,7 +28,6 @@
#![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")]
#![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_network")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_network")]
#![deny(missing_docs)] #![deny(missing_docs)]
// Tracing causes false positives on this lint: // Tracing causes false positives on this lint:
// https://github.com/tokio-rs/tracing/issues/553 // https://github.com/tokio-rs/tracing/issues/553
@ -54,7 +53,6 @@ mod address_book;
mod config; mod config;
mod constants; mod constants;
mod meta_addr; mod meta_addr;
mod network;
mod peer; mod peer;
mod peer_set; mod peer_set;
mod policies; mod policies;
@ -71,5 +69,5 @@ pub use crate::{
/// Types used in the definition of [`Request`] and [`Response`] messages. /// Types used in the definition of [`Request`] and [`Response`] messages.
pub mod types { pub mod types {
pub use crate::{meta_addr::MetaAddr, network::Network, protocol::types::PeerServices}; pub use crate::{meta_addr::MetaAddr, protocol::types::PeerServices};
} }

View File

@ -10,14 +10,15 @@ use tokio_util::codec::{Decoder, Encoder};
use zebra_chain::{ use zebra_chain::{
block::{Block, BlockHeaderHash}, block::{Block, BlockHeaderHash},
network::Network,
serialization::{ serialization::{
ReadZcashExt, SerializationError as Error, WriteZcashExt, ZcashDeserialize, ZcashSerialize, ReadZcashExt, SerializationError as Error, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
}, },
transaction::Transaction, transaction::Transaction,
types::{BlockHeight, Sha256dChecksum}, types::{BlockHeight, Magic, Sha256dChecksum},
}; };
use crate::{constants, types::Network}; use crate::constants;
use super::{ use super::{
message::{Message, RejectReason}, message::{Message, RejectReason},

View File

@ -3,17 +3,6 @@ use std::fmt;
#[cfg(test)] #[cfg(test)]
use proptest_derive::Arbitrary; use proptest_derive::Arbitrary;
/// A magic number identifying the network.
#[derive(Copy, Clone, Eq, PartialEq)]
#[cfg_attr(test, derive(Arbitrary))]
pub struct Magic(pub [u8; 4]);
impl fmt::Debug for Magic {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("Magic").field(&hex::encode(&self.0)).finish()
}
}
/// A protocol version number. /// A protocol version number.
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Version(pub u32); pub struct Version(pub u32);