From e82e8e2cdb6b1f454ba9d3b5d014ebf2e6bea663 Mon Sep 17 00:00:00 2001 From: sara Date: Thu, 18 Apr 2024 16:00:46 -0300 Subject: [PATCH] feat: ppt params interfaces adapted to new updates in pallas --- napi-pallas/Cargo.toml | 2 +- napi-pallas/index.d.ts | 21 ++++-- napi-pallas/src/lib.rs | 45 ++++++----- napi-pallas/src/validations/alonzo.rs | 86 ++++++++++++++++----- napi-pallas/src/validations/babbage.rs | 92 ++++++++++++++++++----- napi-pallas/src/validations/byron.rs | 26 +++++-- napi-pallas/src/validations/shelley_ma.rs | 61 +++++++++++---- napi-pallas/src/validations/validate.rs | 2 +- web/app/components.tsx | 18 ++++- web/app/interfaces.ts | 2 +- web/app/routes/tx.tsx | 89 ++++++++++++---------- web/app/utils.ts | 71 +++++++++++++++++ 12 files changed, 380 insertions(+), 135 deletions(-) create mode 100644 web/app/utils.ts diff --git a/napi-pallas/Cargo.toml b/napi-pallas/Cargo.toml index 8b53243..3d38211 100644 --- a/napi-pallas/Cargo.toml +++ b/napi-pallas/Cargo.toml @@ -12,7 +12,7 @@ hex = "0.4.3" # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix napi = { version = "2.12.2", default-features = false, features = ["napi4"] } napi-derive = "2.12.2" -pallas = { git = "https://github.com/txpipe/pallas.git", rev = "2f97cbe" , features = ["unstable"]} +pallas = { git = "https://github.com/txpipe/pallas.git", rev = "9f5713c" , features = ["unstable"]} [build-dependencies] napi-build = "2.0.1" diff --git a/napi-pallas/index.d.ts b/napi-pallas/index.d.ts index 7fe8517..947a5d1 100644 --- a/napi-pallas/index.d.ts +++ b/napi-pallas/index.d.ts @@ -31,17 +31,24 @@ export interface ValidationContext { poolDeposit: number eMax: number nOpt: number - a0: number - rho: number - tau: number - decentralisationParam: number - extraEntropy: number + a0Numerator: number + a0Denominator: number + rhoNumerator: number + rhoDenominator: number + tauNumerator: number + tauDenominator: number + decentralisationParamNumerator: number + decentralisationParamDenominator: number + extraEntropyNumerator: number + extraEntropyDenominator: number protocolMajorVer: number protocolMinorVer: number minUtxo: number minPoolCost: number - priceMem: number - priceStep: number + priceMemNumerator: number + priceMemDenominator: number + priceStepNumerator: number + priceStepDenominator: number maxTxExMem: number maxTxExSteps: number maxBlockExMem: number diff --git a/napi-pallas/src/lib.rs b/napi-pallas/src/lib.rs index a018745..09b7a8a 100644 --- a/napi-pallas/src/lib.rs +++ b/napi-pallas/src/lib.rs @@ -13,40 +13,47 @@ mod validations; #[derive(Default)] #[napi(object)] pub struct ValidationContext { - pub epoch: i64, - pub min_fee_a: i64, - pub min_fee_b: i64, - pub max_block_size: i64, - pub max_tx_size: i64, - pub max_block_header_size: i64, + pub epoch: u32, + pub min_fee_a: u32, + pub min_fee_b: u32, + pub max_block_size: u32, + pub max_tx_size: u32, + pub max_block_header_size: u32, pub key_deposit: i64, pub pool_deposit: i64, pub e_max: i64, - pub n_opt: i64, - pub a0: i64, - pub rho: i64, - pub tau: i64, - pub decentralisation_param: i64, - pub extra_entropy: i64, + pub n_opt: u32, + pub a0_numerator: i64, + pub a0_denominator: i64, + pub rho_numerator: i64, + pub rho_denominator: i64, + pub tau_numerator: i64, + pub tau_denominator: i64, + pub decentralisation_param_numerator: i64, + pub decentralisation_param_denominator: i64, + pub extra_entropy_numerator: u32, + pub extra_entropy_denominator: u32, pub protocol_major_ver: i64, pub protocol_minor_ver: i64, pub min_utxo: i64, pub min_pool_cost: i64, - pub price_mem: i64, - pub price_step: i64, + pub price_mem_numerator: i64, + pub price_mem_denominator: i64, + pub price_step_numerator: i64, + pub price_step_denominator: i64, pub max_tx_ex_mem: u32, pub max_tx_ex_steps: i64, - pub max_block_ex_mem: i64, + pub max_block_ex_mem: u32, pub max_block_ex_steps: i64, - pub max_val_size: i64, - pub collateral_percent: i64, - pub max_collateral_inputs: i64, + pub max_val_size: u32, + pub collateral_percent: u32, + pub max_collateral_inputs: u32, pub coins_per_utxo_size: i64, pub coins_per_utxo_word: i64, pub network: String, pub era: String, - pub block_slot: i64, + pub block_slot: u32, } #[derive(Default)] diff --git a/napi-pallas/src/validations/alonzo.rs b/napi-pallas/src/validations/alonzo.rs index a6a7e79..2fff5de 100644 --- a/napi-pallas/src/validations/alonzo.rs +++ b/napi-pallas/src/validations/alonzo.rs @@ -6,18 +6,22 @@ use pallas::{ check_preservation_of_value, check_script_data_hash, check_tx_ex_units, check_tx_size, check_tx_validity_interval, check_witness_set, }, - utils::{get_alonzo_comp_tx_size, AlonzoProtParams, FeePolicy}, - Environment, MultiEraProtParams, UTxOs, + utils::{get_alonzo_comp_tx_size, AlonzoProtParams}, + Environment, MultiEraProtocolParameters, UTxOs, + }, + ledger::primitives::{ + alonzo::{ExUnitPrices, Language, MintedTx, TransactionBody}, + conway::{ExUnits, Nonce, NonceVariant, RationalNumber}, }, - ledger::primitives::alonzo::{MintedTx, TransactionBody}, }; use crate::{Validation, ValidationContext, Validations}; use super::validate::set_description; +use pallas::codec::utils::KeyValuePairs; // & The following validation requires the size and the protocol params -fn validate_alonzo_tx_size(size: &Option, prot_pps: &AlonzoProtParams) -> Validation { +fn validate_alonzo_tx_size(size: &Option, prot_pps: &AlonzoProtParams) -> Validation { match size { Some(size_value) => { let res = check_tx_size(&size_value, &prot_pps); @@ -206,7 +210,7 @@ fn validate_alonzo_witness_set(mtx_a: &MintedTx, utxos: &UTxOs) -> Validation { // & The following validation requires the transaction, its utxos and the protocol params fn validate_alonzo_fee(mtx_a: &MintedTx, utxos: &UTxOs, prot_pps: &AlonzoProtParams) -> Validation { let tx_body: &TransactionBody = &mtx_a.transaction_body; - let size: &Option = &get_alonzo_comp_tx_size(tx_body); + let size: &Option = &get_alonzo_comp_tx_size(tx_body); match size { Some(size_value) => { let res = check_fee(tx_body, size_value, mtx_a, utxos, prot_pps); @@ -231,21 +235,65 @@ fn validate_alonzo_fee(mtx_a: &MintedTx, utxos: &UTxOs, prot_pps: &AlonzoProtPar pub fn validate_alonzo(mtx_a: &MintedTx, context: ValidationContext) -> Validations { let tx_body: &TransactionBody = &mtx_a.transaction_body; - let size: &Option = &get_alonzo_comp_tx_size(tx_body); + let size: &Option = &get_alonzo_comp_tx_size(tx_body); let prot_params = AlonzoProtParams { - fee_policy: FeePolicy { - summand: context.min_fee_b as u64, - multiplier: context.min_fee_a as u64, + minfee_a: context.min_fee_a, + minfee_b: context.min_fee_b, + max_block_body_size: context.max_block_size, + max_transaction_size: context.max_tx_size, + max_block_header_size: context.max_block_header_size, + key_deposit: context.key_deposit as u64, + pool_deposit: context.pool_deposit as u64, + maximum_epoch: context.e_max as u64, + desired_number_of_stake_pools: context.n_opt, + pool_pledge_influence: RationalNumber { + numerator: context.a0_numerator as u64, + denominator: context.a0_denominator as u64, + }, + expansion_rate: RationalNumber { + numerator: context.rho_numerator as u64, + denominator: context.rho_denominator as u64, + }, + treasury_growth_rate: RationalNumber { + numerator: context.tau_numerator as u64, + denominator: context.tau_denominator as u64, + }, + decentralization_constant: RationalNumber { + numerator: context.decentralisation_param_numerator as u64, + denominator: context.decentralisation_param_denominator as u64, + }, + extra_entropy: Nonce { + variant: NonceVariant::NeutralNonce, + hash: None, + }, + protocol_version: ( + context.protocol_minor_ver as u64, + context.protocol_major_ver as u64, + ), + min_pool_cost: context.min_pool_cost as u64, + cost_models_for_script_languages: KeyValuePairs::Def(vec![(Language::PlutusV1, vec![])]), + ada_per_utxo_byte: context.coins_per_utxo_size as u64, + execution_costs: ExUnitPrices { + mem_price: RationalNumber { + numerator: context.price_mem_numerator as u64, + denominator: context.price_mem_denominator as u64, + }, + step_price: RationalNumber { + numerator: context.price_step_numerator as u64, + denominator: context.price_step_denominator as u64, + }, + }, + max_tx_ex_units: ExUnits { + mem: context.max_tx_ex_mem, + steps: context.max_tx_ex_steps as u64, + }, + max_block_ex_units: ExUnits { + mem: context.max_block_ex_mem, + steps: context.max_block_ex_steps as u64, }, - max_tx_size: context.max_tx_size as u64, - max_block_ex_mem: context.max_block_ex_mem as u64, - max_block_ex_steps: context.max_block_ex_steps as u64, - max_tx_ex_mem: context.max_tx_ex_mem, - max_tx_ex_steps: context.max_tx_ex_steps as u64, - max_val_size: context.max_val_size as u64, - collateral_percent: context.collateral_percent as u64, - max_collateral_inputs: context.max_collateral_inputs as u64, - coins_per_utxo_word: context.coins_per_utxo_word as u64, + max_value_size: context.max_val_size, + collateral_percentage: context.collateral_percent, + max_collateral_inputs: context.max_collateral_inputs, }; let mut magic = 764824073; // For mainnet @@ -261,7 +309,7 @@ pub fn validate_alonzo(mtx_a: &MintedTx, context: ValidationContext) -> Validati } let env: Environment = Environment { - prot_params: MultiEraProtParams::Alonzo(prot_params.clone()), + prot_params: MultiEraProtocolParameters::Alonzo(prot_params.clone()), prot_magic: magic, block_slot: context.block_slot as u64, network_id: net_id, diff --git a/napi-pallas/src/validations/babbage.rs b/napi-pallas/src/validations/babbage.rs index 4328816..716fe86 100644 --- a/napi-pallas/src/validations/babbage.rs +++ b/napi-pallas/src/validations/babbage.rs @@ -7,10 +7,17 @@ use pallas::{ check_preservation_of_value, check_script_data_hash, check_tx_ex_units, check_tx_size, check_tx_validity_interval, check_well_formedness, check_witness_set, }, - utils::{get_babbage_tx_size, BabbageProtParams, FeePolicy}, - Environment, MultiEraProtParams, UTxOs, + utils::{get_babbage_tx_size, BabbageProtParams}, + Environment, MultiEraProtocolParameters, UTxOs, + }, + ledger::{ + primitives::{ + alonzo::ExUnitPrices, + babbage::{CostMdls, MintedTransactionBody, MintedTx as BabbageMintedTx}, + conway::{Nonce, NonceVariant, RationalNumber}, + }, + traverse::update::ExUnits, }, - ledger::primitives::babbage::{MintedTransactionBody, MintedTx as BabbageMintedTx}, }; use super::validate::set_description; @@ -115,7 +122,7 @@ fn validate_babbage_tx_ex_units(mtx: &BabbageMintedTx, prot_pps: &BabbageProtPar } // &The following validation also requires the tx size -fn validate_babbage_tx_size(size: &Option, prot_pps: &BabbageProtParams) -> Validation { +fn validate_babbage_tx_size(size: &Option, prot_pps: &BabbageProtParams) -> Validation { match size { Some(size_value) => { let res = check_tx_size(size_value, prot_pps); @@ -142,7 +149,7 @@ fn validate_babbage_tx_size(size: &Option, prot_pps: &BabbageProtParams) -> // &The following validation also requires the tx utxos fn validate_babbage_fee( mtx: &BabbageMintedTx, - size: &Option, + size: &Option, utxos: &UTxOs, prot_pps: &BabbageProtParams, ) -> Validation { @@ -282,21 +289,68 @@ fn validate_babbage_network_id(mtx: &BabbageMintedTx, network_id: u8) -> Validat pub fn validate_babbage(mtx_b: &BabbageMintedTx, context: ValidationContext) -> Validations { let tx_body: &MintedTransactionBody = &mtx_b.transaction_body.clone(); - let size: &Option = &get_babbage_tx_size(tx_body); + let size: &Option = &get_babbage_tx_size(tx_body); let prot_params = BabbageProtParams { - fee_policy: FeePolicy { - summand: context.min_fee_b as u64, - multiplier: context.min_fee_a as u64, + minfee_a: context.min_fee_a, + minfee_b: context.min_fee_b, + max_block_body_size: context.max_block_size, + max_transaction_size: context.max_tx_size, + max_block_header_size: context.max_block_header_size, + key_deposit: context.key_deposit as u64, + pool_deposit: context.pool_deposit as u64, + maximum_epoch: context.e_max as u64, + desired_number_of_stake_pools: context.n_opt, + pool_pledge_influence: RationalNumber { + numerator: context.a0_numerator as u64, + denominator: context.a0_denominator as u64, // ? + }, + expansion_rate: RationalNumber { + numerator: context.rho_numerator as u64, + denominator: context.rho_denominator as u64, // ? + }, + treasury_growth_rate: RationalNumber { + numerator: context.tau_numerator as u64, + denominator: context.tau_denominator as u64, // ? + }, + decentralization_constant: RationalNumber { + numerator: context.decentralisation_param_numerator as u64, + denominator: context.decentralisation_param_denominator as u64, // ? + }, + extra_entropy: Nonce { + variant: NonceVariant::NeutralNonce, + hash: None, + }, + protocol_version: ( + context.protocol_minor_ver as u64, + context.protocol_major_ver as u64, + ), + min_pool_cost: context.min_pool_cost as u64, + cost_models_for_script_languages: CostMdls { + plutus_v1: None, + plutus_v2: None, + }, + ada_per_utxo_byte: context.coins_per_utxo_size as u64, + execution_costs: ExUnitPrices { + mem_price: RationalNumber { + numerator: context.price_mem_numerator as u64, + denominator: context.price_mem_denominator as u64, // ? + }, + step_price: RationalNumber { + numerator: context.price_step_numerator as u64, + denominator: context.price_step_denominator as u64, // ? + }, + }, + max_tx_ex_units: ExUnits { + mem: context.max_tx_ex_mem, + steps: context.max_tx_ex_steps as u64, + }, + max_block_ex_units: ExUnits { + mem: context.max_block_ex_mem, + steps: context.max_block_ex_steps as u64, }, - max_tx_size: context.max_tx_size as u64, - max_block_ex_mem: context.max_block_ex_mem as u64, - max_block_ex_steps: context.max_block_ex_steps as u64, - max_tx_ex_mem: context.max_tx_ex_mem, - max_tx_ex_steps: context.max_tx_ex_steps as u64, - max_val_size: context.max_val_size as u64, - collateral_percent: context.collateral_percent as u64, - max_collateral_inputs: context.max_collateral_inputs as u64, - coins_per_utxo_word: context.coins_per_utxo_word as u64, + max_value_size: context.max_val_size, + collateral_percentage: context.collateral_percent, + max_collateral_inputs: context.max_collateral_inputs, }; let mut magic = 764824073; // For mainnet @@ -312,7 +366,7 @@ pub fn validate_babbage(mtx_b: &BabbageMintedTx, context: ValidationContext) -> } let env: Environment = Environment { - prot_params: MultiEraProtParams::Babbage(prot_params.clone()), + prot_params: MultiEraProtocolParameters::Babbage(prot_params.clone()), prot_magic: magic, block_slot: context.block_slot as u64, network_id: net_id, diff --git a/napi-pallas/src/validations/byron.rs b/napi-pallas/src/validations/byron.rs index 47bb4be..bee436d 100644 --- a/napi-pallas/src/validations/byron.rs +++ b/napi-pallas/src/validations/byron.rs @@ -1,11 +1,11 @@ -use crate::{Validation, ValidationContext, Validations}; +use crate::{Validation, Validations}; use pallas::{ applying::{ byron::{ check_fees, check_ins_in_utxos, check_ins_not_empty, check_outs_have_lovelace, check_outs_not_empty, check_size, check_witnesses, }, - utils::{ByronProtParams, FeePolicy}, + utils::ByronProtParams, UTxOs, }, codec::minicbor::encode, @@ -120,15 +120,25 @@ fn validate_byron_fees( .with_description(description); } -pub fn validate_byron(mtxp: &MintedTxPayload, context: ValidationContext) -> Validations { +pub fn validate_byron(mtxp: &MintedTxPayload) -> Validations { let tx: &Tx = &mtxp.transaction; let size: &u64 = &get_tx_size(&tx); let prot_pps: ByronProtParams = ByronProtParams { - fee_policy: FeePolicy { - summand: context.min_fee_b as u64, - multiplier: context.min_fee_a as u64, - }, - max_tx_size: context.max_tx_size as u64, + script_version: 0, + slot_duration: 20000, + max_block_size: 2000000, + max_header_size: 2000000, + max_tx_size: 4096, + max_proposal_size: 700, + mpc_thd: 20000000000000, + heavy_del_thd: 300000000000, + update_vote_thd: 1000000000000, + update_proposal_thd: 100000000000000, + update_implicit: 10000, + soft_fork_rule: (900000000000000, 600000000000000, 50000000000000), + summand: 155381, + multiplier: 44, + unlock_stake_epoch: 18446744073709551615, }; let out = Validations::new() diff --git a/napi-pallas/src/validations/shelley_ma.rs b/napi-pallas/src/validations/shelley_ma.rs index 37869bf..64bf861 100644 --- a/napi-pallas/src/validations/shelley_ma.rs +++ b/napi-pallas/src/validations/shelley_ma.rs @@ -5,12 +5,15 @@ use pallas::{ check_minting, check_network_id, check_preservation_of_value, check_ttl, check_tx_size, check_witnesses, }, - utils::{get_alonzo_comp_tx_size, FeePolicy, ShelleyProtParams}, - Environment, MultiEraProtParams, UTxOs, + utils::{get_alonzo_comp_tx_size, ShelleyProtParams}, + Environment, MultiEraProtocolParameters, UTxOs, }, ledger::{ - primitives::alonzo::{MintedTx, MintedWitnessSet, TransactionBody}, - traverse::Era, + primitives::{ + alonzo::{MintedTx, MintedWitnessSet, TransactionBody}, + conway::{NonceVariant, RationalNumber}, + }, + traverse::{update::Nonce, Era}, }, }; @@ -19,7 +22,7 @@ use crate::{Validation, ValidationContext, Validations}; use super::validate::set_description; // & The following validation requires the size and the protocol parameters -fn validate_byron_ma_size(size: &Option, prot_pps: &ShelleyProtParams) -> Validation { +fn validate_shelley_ma_tx_size(size: &Option, prot_pps: &ShelleyProtParams) -> Validation { match size { Some(size_value) => { let res = check_tx_size(&size_value, &prot_pps); @@ -83,7 +86,7 @@ fn validate_shelley_ma_min_lovelace( prot_pps: &ShelleyProtParams, ) -> Validation { let tx_body = &mtx_sma.transaction_body; - let res = check_min_lovelace(&tx_body, &prot_pps, &Era::Shelley); + let res = check_min_lovelace(&tx_body, &prot_pps); let description = set_description( &res, "All transaction outputs contain Lovelace values not under the minimum.".to_string(), @@ -97,7 +100,7 @@ fn validate_shelley_ma_min_lovelace( // & The following validations require the transaction the size and the protocol parameters fn validate_shelley_ma_fees( mtx_sma: &MintedTx, - size: &Option, + size: &Option, prot_pps: &ShelleyProtParams, ) -> Validation { match size { @@ -207,14 +210,42 @@ pub fn validate_shelley_ma( ) -> Validations { let tx_body: &TransactionBody = &mtx_sma.transaction_body; let tx_wits: &MintedWitnessSet = &mtx_sma.transaction_witness_set; - let size: &Option = &get_alonzo_comp_tx_size(tx_body); + let size: &Option = &get_alonzo_comp_tx_size(tx_body); let prot_params = ShelleyProtParams { - fee_policy: FeePolicy { - summand: context.min_fee_b as u64, - multiplier: context.min_fee_a as u64, + minfee_a: context.min_fee_a, + minfee_b: context.min_fee_b, + max_block_body_size: context.max_block_size, + max_transaction_size: context.max_tx_size, + max_block_header_size: context.max_block_header_size, + key_deposit: context.key_deposit as u64, + pool_deposit: context.pool_deposit as u64, + maximum_epoch: context.e_max as u64, + desired_number_of_stake_pools: context.n_opt, + pool_pledge_influence: RationalNumber { + numerator: context.a0_numerator as u64, + denominator: context.a0_denominator as u64, // ? + }, + expansion_rate: RationalNumber { + numerator: context.rho_numerator as u64, + denominator: context.rho_denominator as u64, // ? + }, + treasury_growth_rate: RationalNumber { + numerator: context.tau_numerator as u64, + denominator: context.tau_denominator as u64, // ? + }, + decentralization_constant: RationalNumber { + numerator: context.decentralisation_param_numerator as u64, + denominator: context.decentralisation_param_denominator as u64, // ? + }, + extra_entropy: Nonce { + variant: NonceVariant::NeutralNonce, + hash: None, }, - max_tx_size: context.max_tx_size as u64, - min_lovelace: 2000000, + protocol_version: ( + context.protocol_minor_ver as u64, + context.protocol_major_ver as u64, + ), + min_utxo_value: context.min_utxo as u64, }; let mut magic = 764824073; // For mainnet @@ -230,14 +261,14 @@ pub fn validate_shelley_ma( } let env: Environment = Environment { - prot_params: MultiEraProtParams::Shelley(prot_params.clone()), + prot_params: MultiEraProtocolParameters::Shelley(prot_params.clone()), prot_magic: magic, block_slot: context.block_slot as u64, network_id: net_id, }; let out = Validations::new() .with_era("Shelley Mary Allegra".to_string()) - .add_new_validation(validate_byron_ma_size(&size, &prot_params)) + .add_new_validation(validate_shelley_ma_tx_size(size, &prot_params)) .add_new_validation(validate_shelley_ma_ins_not_empty(&mtx_sma)) .add_new_validation(validate_shelley_ma_metadata(&mtx_sma)) .add_new_validation(validate_shelley_ma_minting(&mtx_sma)) diff --git a/napi-pallas/src/validations/validate.rs b/napi-pallas/src/validations/validate.rs index 6212e18..026e47d 100644 --- a/napi-pallas/src/validations/validate.rs +++ b/napi-pallas/src/validations/validate.rs @@ -18,7 +18,7 @@ pub fn set_description(res: &Result<(), ValidationError>, success: String) -> St pub fn validate(mtx: &MultiEraTx<'_>, context: ValidationContext) -> Validations { match &mtx { - MultiEraTx::Byron(mtxp) => validate_byron(&mtxp, context), + MultiEraTx::Byron(mtxp) => validate_byron(&mtxp), MultiEraTx::AlonzoCompatible(mtx_sma, Era::Shelley) => { validate_shelley_ma(&mtx_sma, &Era::Shelley, context) } diff --git a/web/app/components.tsx b/web/app/components.tsx index 51e2f71..bda7c9b 100644 --- a/web/app/components.tsx +++ b/web/app/components.tsx @@ -3,12 +3,14 @@ import { PropsWithChildren, useEffect, useState } from "react"; import { DataProps, EraType, + Eras, IContext, IValidation, NetworkType, ProtocolType, TabType, } from "./interfaces"; +import { ByronPptParams } from "./utils"; export type TopicMeta = { title: string; @@ -329,7 +331,7 @@ export function ConfigsModal({ hover:bg-info-400 hover:bg-pink-400 border-2 sm:w-auto rounded-lg py-2 tracking-wide w-full border-blue-950 shadow-black rounded-b-xl border-b-8 appearance-none text-black placeholder-gray-400 mt-3`} > - Submit + Submit & Dissect @@ -364,6 +366,9 @@ function Tabs({ setOtherContext({ ...otherContext, blockSlot: Number(value) }); }; + const isByron = otherContext.selectedEra === Eras.Byron; + const paramsList = isByron ? ByronPptParams : protocolParams; + return (
@@ -386,7 +391,7 @@ function Tabs({ selected === TabType.ProtocolParameters ? "block" : "hidden" }`} > - {protocolParams.map((param, index) => ( + {paramsList.map((param, index) => (
))} diff --git a/web/app/interfaces.ts b/web/app/interfaces.ts index e762030..639f704 100644 --- a/web/app/interfaces.ts +++ b/web/app/interfaces.ts @@ -19,7 +19,7 @@ export interface DataProps extends server.Section { export interface ProtocolType { name: string; - value: number | null; + value: number; } export const TabType = { diff --git a/web/app/routes/tx.tsx b/web/app/routes/tx.tsx index e933412..a64646d 100644 --- a/web/app/routes/tx.tsx +++ b/web/app/routes/tx.tsx @@ -4,6 +4,7 @@ import { useState } from "react"; import SettingsIcon from "../../public/settings.svg"; import { Button, ConfigsModal, RootSection, logCuriosity } from "../components"; import { DataProps, IContext, IValidation, ProtocolType } from "../interfaces"; +import { decimalToFraction, initialProtPps } from "../utils"; import * as server from "./tx.server"; import TOPICS from "./tx.topics"; @@ -19,6 +20,26 @@ export async function action({ request }: ActionFunctionArgs) { const raw = formData.get("raw"); const era = formData.get("Era"); const net = formData.get("Network"); + const [a0Numerator, a0Denominator] = decimalToFraction( + Number(formData.get("A0")) + ); + const [rhoNumerator, rhoDenominator] = decimalToFraction( + Number(formData.get("Rho")) + ); + const [tauNumerator, tauDenominator] = decimalToFraction( + Number(formData.get("Tau")) + ); + const [decentralisationParamNumerator, decentralisationParamDenominator] = + decimalToFraction(Number(formData.get("Decentralisation_param"))); + const [extraEntropyNumerator, extraEntropyDenominator] = decimalToFraction( + Number(formData.get("Extra_entropy")) + ); + const [priceMemNumerator, priceMemDenominator] = decimalToFraction( + Number(formData.get("Price_mem")) + ); + const [priceStepNumerator, priceStepDenominator] = decimalToFraction( + Number(formData.get("Price_step")) + ); if (raw) { const { section, validations } = server.safeParseTx(raw.toString(), { @@ -32,17 +53,24 @@ export async function action({ request }: ActionFunctionArgs) { poolDeposit: Number(formData.get("Pool_deposit")), eMax: Number(formData.get("E_max")), nOpt: Number(formData.get("N_opt")), - a0: Number(formData.get("A0")), - rho: Number(formData.get("Rho")), - tau: Number(formData.get("Tau")), - decentralisationParam: Number(formData.get("Decentralisation_param")), - extraEntropy: Number(formData.get("Extra_entropy")), + a0Numerator: a0Numerator, + a0Denominator: a0Denominator, + rhoNumerator: rhoNumerator, + rhoDenominator: rhoDenominator, + tauNumerator: tauNumerator, + tauDenominator: tauDenominator, + decentralisationParamNumerator: decentralisationParamNumerator, + decentralisationParamDenominator: decentralisationParamDenominator, + extraEntropyNumerator: extraEntropyNumerator, + extraEntropyDenominator: extraEntropyDenominator, protocolMajorVer: Number(formData.get("Protocol_major_ver")), protocolMinorVer: Number(formData.get("Protocol_minor_ver")), minUtxo: Number(formData.get("Min_utxo")), minPoolCost: Number(formData.get("Min_pool_cost")), - priceMem: Number(formData.get("Price_mem")), - priceStep: Number(formData.get("Price_step")), + priceMemNumerator: priceMemNumerator, + priceMemDenominator: priceMemDenominator, + priceStepNumerator: priceStepNumerator, + priceStepDenominator: priceStepDenominator, maxTxExMem: Number(formData.get("Max_tx_ex_mem")), maxTxExSteps: Number(formData.get("Max_tx_ex_steps")), maxBlockExMem: Number(formData.get("Max_block_ex_mem")), @@ -74,7 +102,19 @@ function ExampleCard(props: { title: string; address: string }) { className="border-2 rounded-lg p-4 shadow bg-gray-100 cursor-pointer flex flex-col w-full h-full text-left" >

{props.title}

- + + + + + {initialProtPps.map((param) => ( + + ))} {props.address.substring(0, 30)}... @@ -83,39 +123,6 @@ function ExampleCard(props: { title: string; address: string }) { ); } -const initialProtPps: ProtocolType[] = [ - { name: "Epoch", value: 478 }, - { name: "Min_fee_a", value: 44 }, - { name: "Min_fee_b", value: 155381 }, - { name: "Max_block_size", value: 90112 }, - { name: "Max_tx_size", value: 16384 }, - { name: "Max_block_header_size", value: 1100 }, - { name: "Key_deposit", value: 2000000 }, - { name: "Pool_deposit", value: 500000000 }, - { name: "E_max", value: 18 }, - { name: "N_opt", value: 500 }, - { name: "A0", value: 0.3 }, - { name: "Rho", value: 0.003 }, - { name: "Tau", value: 0.2 }, - { name: "Decentralisation_param", value: 0 }, - { name: "Extra_entropy", value: null }, - { name: "Protocol_major_ver", value: 8 }, - { name: "Protocol_minor_ver", value: 0 }, - { name: "Min_utxo", value: 4310 }, - { name: "Min_pool_cost", value: 170000000 }, - { name: "Price_mem", value: 0.0577 }, - { name: "Price_step", value: 0.0000721 }, - { name: "Max_tx_ex_mem", value: 14000000 }, - { name: "Max_tx_ex_steps", value: 10000000000 }, - { name: "Max_block_ex_mem", value: 62000000 }, - { name: "Max_block_ex_steps", value: 20000000000 }, - { name: "Max_val_size", value: 5000 }, - { name: "Collateral_percent", value: 150 }, - { name: "Max_collateral_inputs", value: 3 }, - { name: "Coins_per_utxo_size", value: 4310 }, - { name: "Coins_per_utxo_word", value: 4310 }, -]; - export default function Index() { const data: DataProps | undefined = useActionData(); const [modalOpen, setModalOpen] = useState(false); diff --git a/web/app/utils.ts b/web/app/utils.ts new file mode 100644 index 0000000..c52c8fd --- /dev/null +++ b/web/app/utils.ts @@ -0,0 +1,71 @@ +import { ProtocolType } from "./interfaces"; + +export const initialProtPps: ProtocolType[] = [ + { name: "Epoch", value: 478 }, + { name: "Min_fee_a", value: 44 }, + { name: "Min_fee_b", value: 155381 }, + { name: "Max_block_size", value: 90112 }, + { name: "Max_tx_size", value: 16384 }, + { name: "Max_block_header_size", value: 1100 }, + { name: "Key_deposit", value: 2000000 }, + { name: "Pool_deposit", value: 500000000 }, + { name: "E_max", value: 18 }, + { name: "N_opt", value: 500 }, + { name: "A0", value: 0.3 }, + { name: "Rho", value: 0.003 }, + { name: "Tau", value: 0.2 }, + { name: "Decentralisation_param", value: 0 }, + { name: "Extra_entropy", value: 0 }, + { name: "Protocol_major_ver", value: 8 }, + { name: "Protocol_minor_ver", value: 0 }, + { name: "Min_utxo", value: 4310 }, + { name: "Min_pool_cost", value: 170000000 }, + { name: "Price_mem", value: 0.0577 }, + { name: "Price_step", value: 0.0000721 }, + { name: "Max_tx_ex_mem", value: 14000000 }, + { name: "Max_tx_ex_steps", value: 10000000000 }, + { name: "Max_block_ex_mem", value: 62000000 }, + { name: "Max_block_ex_steps", value: 20000000000 }, + { name: "Max_val_size", value: 5000 }, + { name: "Collateral_percent", value: 150 }, + { name: "Max_collateral_inputs", value: 3 }, + { name: "Coins_per_utxo_size", value: 4310 }, + { name: "Coins_per_utxo_word", value: 4310 }, +]; + +export const ByronPptParams = [ + { name: "Script_version", value: "0 " }, + { name: "Slot_duration", value: "20000 " }, + { name: "Max_block_size", value: "2000000 " }, + { name: "Max_header_size", value: "2000000 " }, + { name: "Max_tx_size", value: "4096 " }, + { name: "Max_proposal_size", value: "700 " }, + { name: "Mpc_thd", value: "20000000000000 " }, + { name: "Heavy_del_thd", value: "300000000000 " }, + { name: "Update_vote_thd", value: "1000000000000 " }, + { name: "Update_proposal_thd", value: "100000000000000 " }, + { name: "Update_implicit", value: "10000 " }, + { + name: "Soft_fork_rule", + value: "(900000000000000, 600000000000000, 50000000000000)", + }, + { name: "Summand", value: "155381 " }, + { name: "Multiplier", value: "44 " }, + { name: "Unlock_stake_epoch", value: "18446744073709551615" }, +]; + +export function decimalToFraction(decimal: number): [number, number] { + let numerator = decimal; + let denominator = 1; + let prevNumerator = 0; + let prevDenominator = 1; + + while (Math.abs(numerator - prevNumerator) > 6) { + prevNumerator = numerator; + prevDenominator = denominator; + numerator = Math.floor(numerator); + denominator = 1 / (decimal - numerator); + } + + return [prevNumerator, prevDenominator]; +}