diff --git a/pallas-configs/src/lib.rs b/pallas-configs/src/lib.rs index a000d3c..154a7b2 100644 --- a/pallas-configs/src/lib.rs +++ b/pallas-configs/src/lib.rs @@ -1,3 +1,4 @@ //! Genesis data structs and utilities pub mod byron; +pub mod shelley; diff --git a/pallas-configs/src/shelley.rs b/pallas-configs/src/shelley.rs new file mode 100644 index 0000000..a29a50c --- /dev/null +++ b/pallas-configs/src/shelley.rs @@ -0,0 +1,103 @@ +use serde::Deserialize; +use std::collections::HashMap; + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct GenDelegs { + pub delegate: Option, + pub vrf: Option, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ProtocolVersion { + pub minor: Option, + pub major: Option, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ExtraEntropy { + pub tag: Option, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ProtocolParams { + pub protocol_version: Option, + pub decentralisation_param: Option, + pub e_max: Option, + pub extra_entropy: Option, + pub max_tx_size: Option, + pub max_block_body_size: Option, + pub max_block_header_size: Option, + pub min_fee_a: Option, + pub min_fee_b: Option, + pub min_u_tx_o_value: Option, + pub pool_deposit: Option, + pub min_pool_cost: Option, + pub key_deposit: Option, + pub n_opt: Option, + pub rho: Option, + pub tau: Option, + pub a0: Option, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Staking { + pub pools: Option>, + pub stake: Option>, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct GenesisFile { + pub active_slots_coeff: Option, + pub epoch_length: Option, + pub gen_delegs: Option>, + pub initial_funds: Option>, + pub max_kes_evolutions: Option, + pub max_lovelace_supply: Option, + pub network_id: Option, + pub network_magic: Option, + pub protocol_params: Option, + pub security_param: Option, + pub slot_length: Option, + pub slots_per_kes_period: Option, + pub staking: Option, + pub system_start: Option, + pub update_quorum: Option, +} + +pub fn from_file(path: &std::path::Path) -> Result { + let file = std::fs::File::open(path)?; + let reader = std::io::BufReader::new(file); + let parsed: GenesisFile = serde_json::from_reader(reader)?; + + Ok(parsed) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn load_test_data_config(network: &str) -> GenesisFile { + let path = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()) + .join("..") + .join("test_data") + .join(format!("{network}-shelley-genesis.json")); + + from_file(&path).unwrap() + } + + #[test] + fn test_preview_json_loads() { + load_test_data_config("preview"); + } + + #[test] + fn test_mainnet_json_loads() { + load_test_data_config("mainnet"); + } +} diff --git a/test_data/mainnet-shelley-genesis.json b/test_data/mainnet-shelley-genesis.json new file mode 100644 index 0000000..e8cc20d --- /dev/null +++ b/test_data/mainnet-shelley-genesis.json @@ -0,0 +1,68 @@ +{ + "activeSlotsCoeff": 0.05, + "protocolParams": { + "protocolVersion": { + "minor": 0, + "major": 2 + }, + "decentralisationParam": 1, + "eMax": 18, + "extraEntropy": { + "tag": "NeutralNonce" + }, + "maxTxSize": 16384, + "maxBlockBodySize": 65536, + "maxBlockHeaderSize": 1100, + "minFeeA": 44, + "minFeeB": 155381, + "minUTxOValue": 1000000, + "poolDeposit": 500000000, + "minPoolCost": 340000000, + "keyDeposit": 2000000, + "nOpt": 150, + "rho": 0.003, + "tau": 0.20, + "a0": 0.3 + }, + "genDelegs": { + "ad5463153dc3d24b9ff133e46136028bdc1edbb897f5a7cf1b37950c": { + "delegate": "d9e5c76ad5ee778960804094a389f0b546b5c2b140a62f8ec43ea54d", + "vrf": "64fa87e8b29a5b7bfbd6795677e3e878c505bc4a3649485d366b50abadec92d7" + }, + "b9547b8a57656539a8d9bc42c008e38d9c8bd9c8adbb1e73ad529497": { + "delegate": "855d6fc1e54274e331e34478eeac8d060b0b90c1f9e8a2b01167c048", + "vrf": "66d5167a1f426bd1adcc8bbf4b88c280d38c148d135cb41e3f5a39f948ad7fcc" + }, + "60baee25cbc90047e83fd01e1e57dc0b06d3d0cb150d0ab40bbfead1": { + "delegate": "7f72a1826ae3b279782ab2bc582d0d2958de65bd86b2c4f82d8ba956", + "vrf": "c0546d9aa5740afd569d3c2d9c412595cd60822bb6d9a4e8ce6c43d12bd0f674" + }, + "f7b341c14cd58fca4195a9b278cce1ef402dc0e06deb77e543cd1757": { + "delegate": "69ae12f9e45c0c9122356c8e624b1fbbed6c22a2e3b4358cf0cb5011", + "vrf": "6394a632af51a32768a6f12dac3485d9c0712d0b54e3f389f355385762a478f2" + }, + "162f94554ac8c225383a2248c245659eda870eaa82d0ef25fc7dcd82": { + "delegate": "4485708022839a7b9b8b639a939c85ec0ed6999b5b6dc651b03c43f6", + "vrf": "aba81e764b71006c515986bf7b37a72fbb5554f78e6775f08e384dbd572a4b32" + }, + "2075a095b3c844a29c24317a94a643ab8e22d54a3a3a72a420260af6": { + "delegate": "6535db26347283990a252313a7903a45e3526ec25ddba381c071b25b", + "vrf": "fcaca997b8105bd860876348fc2c6e68b13607f9bbd23515cd2193b555d267af" + }, + "268cfc0b89e910ead22e0ade91493d8212f53f3e2164b2e4bef0819b": { + "delegate": "1d4f2e1fda43070d71bb22a5522f86943c7c18aeb4fa47a362c27e23", + "vrf": "63ef48bc5355f3e7973100c371d6a095251c80ceb40559f4750aa7014a6fb6db" + } + }, + "updateQuorum": 5, + "networkId": "Mainnet", + "initialFunds": {}, + "maxLovelaceSupply": 45000000000000000, + "networkMagic": 764824073, + "epochLength": 432000, + "systemStart": "2017-09-23T21:44:51Z", + "slotsPerKESPeriod": 129600, + "slotLength": 1, + "maxKESEvolutions": 62, + "securityParam": 2160 +} diff --git a/test_data/preview-shelley-genesis.json b/test_data/preview-shelley-genesis.json new file mode 100644 index 0000000..20abba3 --- /dev/null +++ b/test_data/preview-shelley-genesis.json @@ -0,0 +1,68 @@ +{ + "activeSlotsCoeff": 0.05, + "epochLength": 86400, + "genDelegs": { + "12b0f443d02861948a0fce9541916b014e8402984c7b83ad70a834ce": { + "delegate": "7c54a168c731f2f44ced620f3cca7c2bd90731cab223d5167aa994e6", + "vrf": "62d546a35e1be66a2b06e29558ef33f4222f1c466adbb59b52d800964d4e60ec" + }, + "3df542796a64e399b60c74acfbdb5afa1e114532fa36b46d6368ef3a": { + "delegate": "c44bc2f3cc7e98c0f227aa399e4035c33c0d775a0985875fff488e20", + "vrf": "4f9d334decadff6eba258b2df8ae1f02580a2628bce47ae7d957e1acd3f42a3c" + }, + "93fd5083ff20e7ab5570948831730073143bea5a5d5539852ed45889": { + "delegate": "82a02922f10105566b70366b07c758c8134fa91b3d8ae697dfa5e8e0", + "vrf": "8a57e94a9b4c65ec575f35d41edb1df399fa30fdf10775389f5d1ef670ca3f9f" + }, + "a86cab3ea72eabb2e8aafbbf4abbd2ba5bdfd04eea26a39b126a78e4": { + "delegate": "10257f6d3bae913514bdc96c9170b3166bf6838cca95736b0e418426", + "vrf": "1b54aad6b013145a0fc74bb5c2aa368ebaf3999e88637d78e09706d0cc29874a" + }, + "b799804a28885bd49c0e1b99d8b3b26de0fac17a5cf651ecf0c872f0": { + "delegate": "ebe606e22d932d51be2c1ce87e7d7e4c9a7d1f7df4a5535c29e23d22", + "vrf": "b3fc06a1f8ee69ff23185d9af453503be8b15b2652e1f9fb7c3ded6797a2d6f9" + }, + "d125812d6ab973a2c152a0525b7fd32d36ff13555a427966a9cac9b1": { + "delegate": "e302198135fb5b00bfe0b9b5623426f7cf03179ab7ba75f945d5b79b", + "vrf": "b45ca2ed95f92248fa0322ce1fc9f815a5a5aa2f21f1adc2c42c4dccfc7ba631" + }, + "ef27651990a26449a40767d5e06cdef1670a3f3ff4b951d385b51787": { + "delegate": "0e0b11e80d958732e587585d30978d683a061831d1b753878f549d05", + "vrf": "b860ec844f6cd476c4fabb4aa1ca72d5c74d82f3835aed3c9515a35b6e048719" + } + }, + "initialFunds": {}, + "maxKESEvolutions": 62, + "maxLovelaceSupply": 45000000000000000, + "networkId": "Testnet", + "networkMagic": 2, + "protocolParams": { + "protocolVersion": { + "minor": 0, + "major": 6 + }, + "decentralisationParam": 1, + "eMax": 18, + "extraEntropy": { + "tag": "NeutralNonce" + }, + "maxTxSize": 16384, + "maxBlockBodySize": 65536, + "maxBlockHeaderSize": 1100, + "minFeeA": 44, + "minFeeB": 155381, + "minUTxOValue": 1000000, + "poolDeposit": 500000000, + "minPoolCost": 340000000, + "keyDeposit": 2000000, + "nOpt": 150, + "rho": 0.003, + "tau": 0.20, + "a0": 0.3 + }, + "securityParam": 432, + "slotLength": 1, + "slotsPerKESPeriod": 129600, + "systemStart": "2022-10-25T00:00:00Z", + "updateQuorum": 5 +}