Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alonzo.cddl minor update #308

Merged
merged 4 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions rust/pkg/cardano_serialization_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

/**
*/

Expand Down Expand Up @@ -265,14 +265,6 @@ declare export var NetworkIdKind: {|
+Mainnet: 1, // 1
|};

/**
*/

declare export var StakeCredKind: {|
+Key: 0, // 0
+Script: 1, // 1
|};

/**
*/

Expand Down Expand Up @@ -330,6 +322,14 @@ declare export var MetadataJsonSchema: {|
+DetailedSchema: 2, // 2
|};

/**
*/

declare export var StakeCredKind: {|
+Key: 0, // 0
+Script: 1, // 1
|};

/**
*/

Expand Down Expand Up @@ -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}
*/
Expand Down
20 changes: 20 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,8 @@ pub struct ProtocolParamUpdate {
max_tx_ex_units: Option<ExUnits>,
max_block_ex_units: Option<ExUnits>,
max_value_size: Option<u32>,
collateral_percentage: Option<u32>,
max_collateral_inputs: Option<u32>,
}

to_from_bytes!(ProtocolParamUpdate);
Expand Down Expand Up @@ -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<u32> {
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<u32> {
self.max_collateral_inputs.clone()
}

pub fn new() -> Self {
Self {
minfee_a: None,
Expand All @@ -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,
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions rust/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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()? {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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"))
}
Expand Down