From 627c35ffe913645a4b7d0b4f4d66c389d7904619 Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Wed, 29 Dec 2021 21:34:18 -0800 Subject: [PATCH 1/2] alonzo.cddl minor update Specs updated in: input-output-hk/cardano-ledger#2590 --- rust/src/lib.rs | 20 ++++++++++++++++++++ rust/src/serialization.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 600d91a4..8b14c93d 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1931,6 +1931,8 @@ pub struct ProtocolParamUpdate { max_tx_ex_units: Option, max_block_ex_units: Option, max_value_size: Option, + collateral_percentage: Option, + max_collateral_inputs: Option, } to_from_bytes!(ProtocolParamUpdate); @@ -2113,6 +2115,22 @@ impl ProtocolParamUpdate { self.max_value_size.clone() } + pub fn set_collateral_percentage(&mut self, collateral_percentage: u32) { + self.collateral_percentage = Some(collateral_percentage) + } + + pub fn collateral_percentage(&self) -> Option { + self.collateral_percentage.clone() + } + + pub fn set_max_collateral_inputs(&mut self, max_collateral_inputs: u32) { + self.max_collateral_inputs = Some(max_collateral_inputs) + } + + pub fn max_collateral_inputs(&self) -> Option { + self.max_collateral_inputs.clone() + } + pub fn new() -> Self { Self { minfee_a: None, @@ -2137,6 +2155,8 @@ impl ProtocolParamUpdate { max_tx_ex_units: None, max_block_ex_units: None, max_value_size: None, + collateral_percentage: None, + max_collateral_inputs: None, } } } diff --git a/rust/src/serialization.rs b/rust/src/serialization.rs index f8bbb8d5..2e4a65db 100644 --- a/rust/src/serialization.rs +++ b/rust/src/serialization.rs @@ -2642,6 +2642,14 @@ impl cbor_event::se::Serialize for ProtocolParamUpdate { serializer.write_unsigned_integer(22)?; field.serialize(serializer)?; } + if let Some(field) = &self.collateral_percentage { + serializer.write_unsigned_integer(23)?; + field.serialize(serializer)?; + } + if let Some(field) = &self.max_collateral_inputs { + serializer.write_unsigned_integer(24)?; + field.serialize(serializer)?; + } Ok(serializer) } } @@ -2673,6 +2681,8 @@ impl Deserialize for ProtocolParamUpdate { let mut max_tx_ex_units = None; let mut max_block_ex_units = None; let mut max_value_size = None; + let mut collateral_percentage = None; + let mut max_collateral_inputs = None; let mut read = 0; while match len { cbor_event::Len::Len(n) => read < n as usize, cbor_event::Len::Indefinite => true, } { match raw.cbor_type()? { @@ -2875,6 +2885,24 @@ impl Deserialize for ProtocolParamUpdate { Ok(u32::deserialize(raw)?) })().map_err(|e| e.annotate("max_value_size"))?); }, + 23 => { + if collateral_percentage.is_some() { + return Err(DeserializeFailure::DuplicateKey(Key::Uint(23)).into()); + } + collateral_percentage = Some((|| -> Result<_, DeserializeError> { + read_len.read_elems(1)?; + Ok(u32::deserialize(raw)?) + })().map_err(|e| e.annotate("collateral_percentage"))?); + }, + 24 => { + if max_collateral_inputs.is_some() { + return Err(DeserializeFailure::DuplicateKey(Key::Uint(24)).into()); + } + max_collateral_inputs = Some((|| -> Result<_, DeserializeError> { + read_len.read_elems(1)?; + Ok(u32::deserialize(raw)?) + })().map_err(|e| e.annotate("max_collateral_inputs"))?); + }, unknown_key => return Err(DeserializeFailure::UnknownKey(Key::Uint(unknown_key)).into()), }, CBORType::Text => match raw.text()?.as_str() { @@ -2915,6 +2943,8 @@ impl Deserialize for ProtocolParamUpdate { max_tx_ex_units, max_block_ex_units, max_value_size, + collateral_percentage, + max_collateral_inputs, }) })().map_err(|e| e.annotate("ProtocolParamUpdate")) } From 625da85171dcf014b8cdb965c1da4354eb0e991d Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Tue, 4 Jan 2022 17:41:53 -0800 Subject: [PATCH 2/2] update flow types --- rust/pkg/cardano_serialization_lib.js.flow | 50 +++++++++++++++------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index 2a66c8ec..9b9bc0b7 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -165,6 +165,13 @@ declare export function decode_metadatum_to_json_str( schema: number ): string; +/** + * @param {Transaction} tx + * @param {LinearFee} linear_fee + * @returns {BigNum} + */ +declare export function min_fee(tx: Transaction, linear_fee: LinearFee): BigNum; + /** * @param {string} password * @param {string} salt @@ -189,13 +196,6 @@ declare export function decrypt_with_password( data: string ): string; -/** - * @param {Transaction} tx - * @param {LinearFee} linear_fee - * @returns {BigNum} - */ -declare export function min_fee(tx: Transaction, linear_fee: LinearFee): BigNum; - /** */ @@ -265,14 +265,6 @@ declare export var NetworkIdKind: {| +Mainnet: 1, // 1 |}; -/** - */ - -declare export var StakeCredKind: {| - +Key: 0, // 0 - +Script: 1, // 1 -|}; - /** */ @@ -330,6 +322,14 @@ declare export var MetadataJsonSchema: {| +DetailedSchema: 2, // 2 |}; +/** + */ + +declare export var StakeCredKind: {| + +Key: 0, // 0 + +Script: 1, // 1 +|}; + /** */ @@ -3780,6 +3780,26 @@ declare export class ProtocolParamUpdate { */ max_value_size(): number | void; + /** + * @param {number} collateral_percentage + */ + set_collateral_percentage(collateral_percentage: number): void; + + /** + * @returns {number | void} + */ + collateral_percentage(): number | void; + + /** + * @param {number} max_collateral_inputs + */ + set_max_collateral_inputs(max_collateral_inputs: number): void; + + /** + * @returns {number | void} + */ + max_collateral_inputs(): number | void; + /** * @returns {ProtocolParamUpdate} */