Skip to content

Commit

Permalink
feat: add preview and preprod chains (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas authored Aug 28, 2022
1 parent 7acf717 commit 798c41b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 26 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["Santiago Carmuega <santiago@carmuega.me>"]


[dependencies]
pallas = "0.13.0"
pallas = "0.13.2"
# pallas = { path = "../pallas/pallas" }
# pallas = { git = "https://github.com/txpipe/pallas.git" }
hex = "0.4.3"
Expand All @@ -22,7 +22,10 @@ clap = { version = "3.2.6", features = ["derive"] }
log = "0.4.14"
env_logger = "0.9.0"
merge = "0.1.0"
config = { version = "0.13.0", default-features = false, features = ["toml", "json"] }
config = { version = "0.13.0", default-features = false, features = [
"toml",
"json",
] }
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
minicbor = "0.14.1"
Expand Down
4 changes: 4 additions & 0 deletions src/bin/scrolls/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::console;
pub enum ChainConfig {
Mainnet,
Testnet,
PreProd,
Preview,
Custom(crosscut::ChainWellKnownInfo),
}

Expand All @@ -24,6 +26,8 @@ impl From<ChainConfig> for crosscut::ChainWellKnownInfo {
match other {
ChainConfig::Mainnet => crosscut::ChainWellKnownInfo::mainnet(),
ChainConfig::Testnet => crosscut::ChainWellKnownInfo::testnet(),
ChainConfig::PreProd => crosscut::ChainWellKnownInfo::preprod(),
ChainConfig::Preview => crosscut::ChainWellKnownInfo::testnet(),
ChainConfig::Custom(x) => x,
}
}
Expand Down
55 changes: 54 additions & 1 deletion src/crosscut/args.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use pallas::network::miniprotocols::{Point, MAINNET_MAGIC, TESTNET_MAGIC};
use pallas::network::miniprotocols::{
Point,
MAINNET_MAGIC,
TESTNET_MAGIC,
// PREVIEW_MAGIC, PRE_PRODUCTION_MAGIC,
};
use serde::{Deserialize, Serialize};
use std::{ops::Deref, str::FromStr};

use crate::Error;

// TODO: use from pallas once available
pub const PRE_PRODUCTION_MAGIC: u64 = 1;
pub const PREVIEW_MAGIC: u64 = 2;

/// A serialization-friendly chain Point struct using a hex-encoded hash
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum PointArg {
Expand Down Expand Up @@ -86,6 +95,8 @@ impl FromStr for MagicArg {
let m = match s {
"testnet" => MagicArg(TESTNET_MAGIC),
"mainnet" => MagicArg(MAINNET_MAGIC),
"preview" => MagicArg(PREVIEW_MAGIC),
"preprod" => MagicArg(PRE_PRODUCTION_MAGIC),
_ => MagicArg(u64::from_str(s).map_err(|_| "can't parse magic value")?),
};

Expand Down Expand Up @@ -205,12 +216,54 @@ impl ChainWellKnownInfo {
}
}

pub fn preview() -> Self {
ChainWellKnownInfo {
magic: PREVIEW_MAGIC,
byron_epoch_length: 432000,
byron_slot_length: 20,
byron_known_slot: 0,
byron_known_hash: "".to_string(),
byron_known_time: 1660003200,
shelley_epoch_length: 432000,
shelley_slot_length: 1,
shelley_known_slot: 25260,
shelley_known_hash: "cac921895ef5f2e85f7e6e6b51b663ab81b3605cd47d6b6d66e8e785e5c65011"
.to_string(),
shelley_known_time: 1660003200,
address_network_id: 0,
adahandle_policy: "".to_string(),
}
}

/// Hardcoded values for the "pre-prod" testnet
pub fn preprod() -> Self {
ChainWellKnownInfo {
magic: PRE_PRODUCTION_MAGIC,
byron_epoch_length: 432000,
byron_slot_length: 20,
byron_known_slot: 0,
byron_known_hash: "9ad7ff320c9cf74e0f5ee78d22a85ce42bb0a487d0506bf60cfb5a91ea4497d2"
.to_string(),
byron_known_time: 1654041600,
shelley_epoch_length: 432000,
shelley_slot_length: 1,
shelley_known_slot: 86400,
shelley_known_hash: "c4a1595c5cc7a31eda9e544986fe9387af4e3491afe0ca9a80714f01951bbd5c"
.to_string(),
shelley_known_time: 1654041600,
address_network_id: 0,
adahandle_policy: "".to_string(),
}
}

/// Uses the value of the magic to return either mainnet or testnet
/// hardcoded values.
pub fn try_from_magic(magic: u64) -> Result<ChainWellKnownInfo, Error> {
match magic {
MAINNET_MAGIC => Ok(Self::mainnet()),
TESTNET_MAGIC => Ok(Self::testnet()),
PREVIEW_MAGIC => Ok(Self::preview()),
PRE_PRODUCTION_MAGIC => Ok(Self::preprod()),
_ => Err(Error::ConfigError(
"can't infer well-known chain infro from specified magic".into(),
)),
Expand Down

0 comments on commit 798c41b

Please # to comment.