feat: add support for Conway config and params traverse (#521)
Co-authored-by: Clark Alesna <clark_alesna@hotmail.com> Co-authored-by: johnquinnvictaboada <quinnvictaboada@gmail.com>
This commit is contained in:
parent
ae71a53707
commit
19b0ac3072
10 changed files with 800 additions and 19 deletions
|
|
@ -186,6 +186,7 @@ pub enum MultiEraUpdate<'b> {
|
|||
Byron(u64, Box<Cow<'b, byron::UpProp>>),
|
||||
AlonzoCompatible(Box<Cow<'b, alonzo::Update>>),
|
||||
Babbage(Box<Cow<'b, babbage::Update>>),
|
||||
Conway(Box<Cow<'b, conway::Update>>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use pallas_codec::minicbor;
|
|||
use paste::paste;
|
||||
use std::{borrow::Cow, ops::Deref};
|
||||
|
||||
use pallas_primitives::{alonzo, babbage, byron};
|
||||
use pallas_primitives::{alonzo, babbage, byron, conway};
|
||||
|
||||
macro_rules! param_boilerplate {
|
||||
($name:ident: $type_:ty, [$($variant:tt)*]) => {
|
||||
|
|
@ -47,8 +47,12 @@ pub type UnitInterval = alonzo::UnitInterval;
|
|||
pub type Nonce = alonzo::Nonce;
|
||||
pub type ExUnitPrices = alonzo::ExUnitPrices;
|
||||
pub type ExUnits = alonzo::ExUnits;
|
||||
pub type CostMdls = alonzo::CostMdls;
|
||||
pub type AlonzoCostMdls = alonzo::CostMdls;
|
||||
pub type BabbageCostMdls = babbage::CostMdls;
|
||||
pub type ConwayCostMdls = conway::CostMdls;
|
||||
pub type ProtocolVersion = alonzo::ProtocolVersion;
|
||||
pub type PoolVotingThresholds = conway::PoolVotingThresholds;
|
||||
pub type DRepVotingThresholds = conway::DRepVotingThresholds;
|
||||
|
||||
use crate::{Era, MultiEraUpdate};
|
||||
|
||||
|
|
@ -70,13 +74,18 @@ impl<'b> MultiEraUpdate<'b> {
|
|||
let up = Box::new(Cow::Owned(up));
|
||||
Ok(MultiEraUpdate::Babbage(up))
|
||||
}
|
||||
_ => unimplemented!("unimplemented era"),
|
||||
Era::Conway => {
|
||||
let up = minicbor::decode(cbor)?;
|
||||
let up = Box::new(Cow::Owned(up));
|
||||
Ok(MultiEraUpdate::Conway(up))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn encode(&self) -> Vec<u8> {
|
||||
// to_vec is infallible
|
||||
match self {
|
||||
MultiEraUpdate::Conway(x) => minicbor::to_vec(x).unwrap(),
|
||||
MultiEraUpdate::AlonzoCompatible(x) => minicbor::to_vec(x).unwrap(),
|
||||
MultiEraUpdate::Babbage(x) => minicbor::to_vec(x).unwrap(),
|
||||
MultiEraUpdate::Byron(a, b) => minicbor::to_vec((a, b)).unwrap(),
|
||||
|
|
@ -121,6 +130,7 @@ impl<'b> MultiEraUpdate<'b> {
|
|||
MultiEraUpdate::Byron(x, _) => *x,
|
||||
MultiEraUpdate::AlonzoCompatible(x) => x.epoch,
|
||||
MultiEraUpdate::Babbage(x) => x.epoch,
|
||||
MultiEraUpdate::Conway(x) => x.epoch,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -147,6 +157,40 @@ impl<'b> MultiEraUpdate<'b> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn alonzo_first_proposed_cost_models_for_script_languages(&self) -> Option<AlonzoCostMdls> {
|
||||
match self {
|
||||
MultiEraUpdate::AlonzoCompatible(x) => x
|
||||
.proposed_protocol_parameter_updates
|
||||
.first()
|
||||
.and_then(|x| x.1.cost_models_for_script_languages.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn babbage_first_proposed_cost_models_for_script_languages(
|
||||
&self,
|
||||
) -> Option<BabbageCostMdls> {
|
||||
match self {
|
||||
MultiEraUpdate::Babbage(x) => x
|
||||
.proposed_protocol_parameter_updates
|
||||
.first()
|
||||
.and_then(|x| x.1.cost_models_for_script_languages.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn conway_first_proposed_cost_models_for_script_languages(&self) -> Option<ConwayCostMdls> {
|
||||
match self {
|
||||
MultiEraUpdate::Conway(x) => x
|
||||
.proposed_protocol_parameter_updates
|
||||
.first()
|
||||
.and_then(|x| x.1.cost_models_for_script_languages.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
// remaining params are mostly boilerplate code, so we can just generate them
|
||||
|
||||
param_boilerplate!(minfee_a: u32, [AlonzoCompatible Babbage]);
|
||||
|
||||
param_boilerplate!(minfee_b: u32, [AlonzoCompatible Babbage]);
|
||||
|
|
@ -181,9 +225,6 @@ impl<'b> MultiEraUpdate<'b> {
|
|||
|
||||
param_boilerplate!(ada_per_utxo_byte: u64, [AlonzoCompatible Babbage]);
|
||||
|
||||
//param_boilerplate!(cost_models_for_script_languages: CostMdls,
|
||||
// [AlonzoCompatible Babbage]);
|
||||
|
||||
param_boilerplate!(execution_costs: ExUnitPrices, [AlonzoCompatible Babbage]);
|
||||
|
||||
param_boilerplate!(max_tx_ex_units: ExUnits, [AlonzoCompatible Babbage]);
|
||||
|
|
@ -195,4 +236,22 @@ impl<'b> MultiEraUpdate<'b> {
|
|||
param_boilerplate!(collateral_percentage: u32, [AlonzoCompatible Babbage]);
|
||||
|
||||
param_boilerplate!(max_collateral_inputs: u32, [AlonzoCompatible Babbage]);
|
||||
|
||||
param_boilerplate!(pool_voting_thresholds: PoolVotingThresholds, [Conway]);
|
||||
|
||||
param_boilerplate!(drep_voting_thresholds: DRepVotingThresholds, [Conway]);
|
||||
|
||||
param_boilerplate!(min_committee_size: u64, [Conway]);
|
||||
|
||||
param_boilerplate!(committee_term_limit: u64, [Conway]);
|
||||
|
||||
param_boilerplate!(governance_action_validity_period: u64, [Conway]);
|
||||
|
||||
param_boilerplate!(governance_action_deposit: u64, [Conway]);
|
||||
|
||||
param_boilerplate!(drep_deposit: u64, [Conway]);
|
||||
|
||||
param_boilerplate!(drep_inactivity_period: u64, [Conway]);
|
||||
|
||||
param_boilerplate!(minfee_refscript_cost_per_byte: UnitInterval, [Conway]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue