Skip to content

Commit bb4b91f

Browse files
authored
Merge pull request #308 from Emurgo/cddl-update-collateral-params
alonzo.cddl minor update
2 parents 8c74ea2 + 4f1df30 commit bb4b91f

File tree

3 files changed

+85
-15
lines changed

3 files changed

+85
-15
lines changed

rust/pkg/cardano_serialization_lib.js.flow

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ declare export function decode_metadatum_to_json_str(
165165
schema: number
166166
): string;
167167

168+
/**
169+
* @param {Transaction} tx
170+
* @param {LinearFee} linear_fee
171+
* @returns {BigNum}
172+
*/
173+
declare export function min_fee(tx: Transaction, linear_fee: LinearFee): BigNum;
174+
168175
/**
169176
* @param {string} password
170177
* @param {string} salt
@@ -189,13 +196,6 @@ declare export function decrypt_with_password(
189196
data: string
190197
): string;
191198

192-
/**
193-
* @param {Transaction} tx
194-
* @param {LinearFee} linear_fee
195-
* @returns {BigNum}
196-
*/
197-
declare export function min_fee(tx: Transaction, linear_fee: LinearFee): BigNum;
198-
199199
/**
200200
*/
201201

@@ -265,14 +265,6 @@ declare export var NetworkIdKind: {|
265265
+Mainnet: 1, // 1
266266
|};
267267

268-
/**
269-
*/
270-
271-
declare export var StakeCredKind: {|
272-
+Key: 0, // 0
273-
+Script: 1, // 1
274-
|};
275-
276268
/**
277269
*/
278270

@@ -330,6 +322,14 @@ declare export var MetadataJsonSchema: {|
330322
+DetailedSchema: 2, // 2
331323
|};
332324

325+
/**
326+
*/
327+
328+
declare export var StakeCredKind: {|
329+
+Key: 0, // 0
330+
+Script: 1, // 1
331+
|};
332+
333333
/**
334334
*/
335335

@@ -3780,6 +3780,26 @@ declare export class ProtocolParamUpdate {
37803780
*/
37813781
max_value_size(): number | void;
37823782

3783+
/**
3784+
* @param {number} collateral_percentage
3785+
*/
3786+
set_collateral_percentage(collateral_percentage: number): void;
3787+
3788+
/**
3789+
* @returns {number | void}
3790+
*/
3791+
collateral_percentage(): number | void;
3792+
3793+
/**
3794+
* @param {number} max_collateral_inputs
3795+
*/
3796+
set_max_collateral_inputs(max_collateral_inputs: number): void;
3797+
3798+
/**
3799+
* @returns {number | void}
3800+
*/
3801+
max_collateral_inputs(): number | void;
3802+
37833803
/**
37843804
* @returns {ProtocolParamUpdate}
37853805
*/

rust/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,8 @@ pub struct ProtocolParamUpdate {
19311931
max_tx_ex_units: Option<ExUnits>,
19321932
max_block_ex_units: Option<ExUnits>,
19331933
max_value_size: Option<u32>,
1934+
collateral_percentage: Option<u32>,
1935+
max_collateral_inputs: Option<u32>,
19341936
}
19351937

19361938
to_from_bytes!(ProtocolParamUpdate);
@@ -2113,6 +2115,22 @@ impl ProtocolParamUpdate {
21132115
self.max_value_size.clone()
21142116
}
21152117

2118+
pub fn set_collateral_percentage(&mut self, collateral_percentage: u32) {
2119+
self.collateral_percentage = Some(collateral_percentage)
2120+
}
2121+
2122+
pub fn collateral_percentage(&self) -> Option<u32> {
2123+
self.collateral_percentage.clone()
2124+
}
2125+
2126+
pub fn set_max_collateral_inputs(&mut self, max_collateral_inputs: u32) {
2127+
self.max_collateral_inputs = Some(max_collateral_inputs)
2128+
}
2129+
2130+
pub fn max_collateral_inputs(&self) -> Option<u32> {
2131+
self.max_collateral_inputs.clone()
2132+
}
2133+
21162134
pub fn new() -> Self {
21172135
Self {
21182136
minfee_a: None,
@@ -2137,6 +2155,8 @@ impl ProtocolParamUpdate {
21372155
max_tx_ex_units: None,
21382156
max_block_ex_units: None,
21392157
max_value_size: None,
2158+
collateral_percentage: None,
2159+
max_collateral_inputs: None,
21402160
}
21412161
}
21422162
}

rust/src/serialization.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,14 @@ impl cbor_event::se::Serialize for ProtocolParamUpdate {
26422642
serializer.write_unsigned_integer(22)?;
26432643
field.serialize(serializer)?;
26442644
}
2645+
if let Some(field) = &self.collateral_percentage {
2646+
serializer.write_unsigned_integer(23)?;
2647+
field.serialize(serializer)?;
2648+
}
2649+
if let Some(field) = &self.max_collateral_inputs {
2650+
serializer.write_unsigned_integer(24)?;
2651+
field.serialize(serializer)?;
2652+
}
26452653
Ok(serializer)
26462654
}
26472655
}
@@ -2673,6 +2681,8 @@ impl Deserialize for ProtocolParamUpdate {
26732681
let mut max_tx_ex_units = None;
26742682
let mut max_block_ex_units = None;
26752683
let mut max_value_size = None;
2684+
let mut collateral_percentage = None;
2685+
let mut max_collateral_inputs = None;
26762686
let mut read = 0;
26772687
while match len { cbor_event::Len::Len(n) => read < n as usize, cbor_event::Len::Indefinite => true, } {
26782688
match raw.cbor_type()? {
@@ -2875,6 +2885,24 @@ impl Deserialize for ProtocolParamUpdate {
28752885
Ok(u32::deserialize(raw)?)
28762886
})().map_err(|e| e.annotate("max_value_size"))?);
28772887
},
2888+
23 => {
2889+
if collateral_percentage.is_some() {
2890+
return Err(DeserializeFailure::DuplicateKey(Key::Uint(23)).into());
2891+
}
2892+
collateral_percentage = Some((|| -> Result<_, DeserializeError> {
2893+
read_len.read_elems(1)?;
2894+
Ok(u32::deserialize(raw)?)
2895+
})().map_err(|e| e.annotate("collateral_percentage"))?);
2896+
},
2897+
24 => {
2898+
if max_collateral_inputs.is_some() {
2899+
return Err(DeserializeFailure::DuplicateKey(Key::Uint(24)).into());
2900+
}
2901+
max_collateral_inputs = Some((|| -> Result<_, DeserializeError> {
2902+
read_len.read_elems(1)?;
2903+
Ok(u32::deserialize(raw)?)
2904+
})().map_err(|e| e.annotate("max_collateral_inputs"))?);
2905+
},
28782906
unknown_key => return Err(DeserializeFailure::UnknownKey(Key::Uint(unknown_key)).into()),
28792907
},
28802908
CBORType::Text => match raw.text()?.as_str() {
@@ -2915,6 +2943,8 @@ impl Deserialize for ProtocolParamUpdate {
29152943
max_tx_ex_units,
29162944
max_block_ex_units,
29172945
max_value_size,
2946+
collateral_percentage,
2947+
max_collateral_inputs,
29182948
})
29192949
})().map_err(|e| e.annotate("ProtocolParamUpdate"))
29202950
}

0 commit comments

Comments
 (0)