Move Network, Magic, and magics to zebra-chain
This commit is contained in:
parent
14120cf828
commit
b68e1e2d55
|
@ -2057,6 +2057,7 @@ dependencies = [
|
|||
"redjubjub",
|
||||
"ripemd160",
|
||||
"secp256k1",
|
||||
"serde",
|
||||
"sha2",
|
||||
"thiserror",
|
||||
]
|
||||
|
|
|
@ -16,6 +16,7 @@ hex = "0.4"
|
|||
lazy_static = "1.4.0"
|
||||
ripemd160 = "0.8.0"
|
||||
secp256k1 = "0.17.2"
|
||||
serde = { version = "1", features = ["serde_derive"] }
|
||||
sha2 = "0.8"
|
||||
thiserror = "1"
|
||||
# ZF deps
|
||||
|
|
|
@ -10,9 +10,11 @@ use sha2::Sha256;
|
|||
#[cfg(test)]
|
||||
use proptest_derive::Arbitrary;
|
||||
|
||||
use crate::serialization::{SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||
|
||||
use crate::types::Script;
|
||||
use crate::{
|
||||
network::Network,
|
||||
serialization::{SerializationError, ZcashDeserialize, ZcashSerialize},
|
||||
types::Script,
|
||||
};
|
||||
|
||||
/// A hash of a redeem script, as used in transparent
|
||||
/// 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
|
||||
///
|
||||
/// In Bitcoin a single byte is used for the version field identifying
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
#![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_chain")]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde;
|
||||
|
||||
mod merkle_tree;
|
||||
mod sha256d_writer;
|
||||
|
||||
|
@ -11,6 +14,7 @@ pub mod addresses;
|
|||
pub mod block;
|
||||
pub mod equihash_solution;
|
||||
pub mod keys;
|
||||
pub mod network;
|
||||
pub mod note_commitment_tree;
|
||||
pub mod note_encryption;
|
||||
pub mod proofs;
|
||||
|
|
|
@ -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.
|
||||
#[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]);
|
||||
}
|
|
@ -15,6 +15,17 @@ use crate::serialization::{
|
|||
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).
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
pub struct Sha256dChecksum(pub [u8; 4]);
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use crate::network::Network;
|
||||
use zebra_chain::network::Network;
|
||||
|
||||
/// Configuration for networking code.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
|
|
|
@ -40,15 +40,6 @@ pub const CURRENT_VERSION: Version = Version(170_009);
|
|||
/// The minimum version supported for peer connections.
|
||||
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)]
|
||||
mod tests {
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
#![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")]
|
||||
#![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_network")]
|
||||
|
||||
#![deny(missing_docs)]
|
||||
// Tracing causes false positives on this lint:
|
||||
// https://github.com/tokio-rs/tracing/issues/553
|
||||
|
@ -54,7 +53,6 @@ mod address_book;
|
|||
mod config;
|
||||
mod constants;
|
||||
mod meta_addr;
|
||||
mod network;
|
||||
mod peer;
|
||||
mod peer_set;
|
||||
mod policies;
|
||||
|
@ -71,5 +69,5 @@ pub use crate::{
|
|||
|
||||
/// Types used in the definition of [`Request`] and [`Response`] messages.
|
||||
pub mod types {
|
||||
pub use crate::{meta_addr::MetaAddr, network::Network, protocol::types::PeerServices};
|
||||
pub use crate::{meta_addr::MetaAddr, protocol::types::PeerServices};
|
||||
}
|
||||
|
|
|
@ -10,14 +10,15 @@ use tokio_util::codec::{Decoder, Encoder};
|
|||
|
||||
use zebra_chain::{
|
||||
block::{Block, BlockHeaderHash},
|
||||
network::Network,
|
||||
serialization::{
|
||||
ReadZcashExt, SerializationError as Error, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
||||
},
|
||||
transaction::Transaction,
|
||||
types::{BlockHeight, Sha256dChecksum},
|
||||
types::{BlockHeight, Magic, Sha256dChecksum},
|
||||
};
|
||||
|
||||
use crate::{constants, types::Network};
|
||||
use crate::constants;
|
||||
|
||||
use super::{
|
||||
message::{Message, RejectReason},
|
||||
|
|
|
@ -3,17 +3,6 @@ use std::fmt;
|
|||
#[cfg(test)]
|
||||
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.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Version(pub u32);
|
||||
|
|
Loading…
Reference in New Issue