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

Multi-Era expanded functionality + Shelley Metadata set fix #272

Merged
merged 3 commits into from
Nov 14, 2023
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
2 changes: 1 addition & 1 deletion chain/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ cbor_event = "2.4.0"
wasm-bindgen = { version = "=0.2.83", features = ["serde-serialize"] }
linked-hash-map = "0.5.3"
serde_json = "1.0.57"
serde-wasm-bindgen = "0.4.5"
serde-wasm-bindgen = "0.4.5"
44 changes: 0 additions & 44 deletions cip25/wasm/package.json

This file was deleted.

10 changes: 10 additions & 0 deletions core/rust/src/ordered_hash_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::hash::{Hash, Hasher};
use std::iter::FromIterator;

// allowing this since PartialEq equality here still implies hash equality
#[allow(clippy::derived_hash_with_manual_eq)]
Expand Down Expand Up @@ -105,3 +106,12 @@ where
std::collections::BTreeMap::<K, V>::is_referenceable()
}
}

impl<K, V> FromIterator<(K, V)> for OrderedHashMap<K, V>
where
K: Hash + Eq + Ord,
{
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
Self(linked_hash_map::LinkedHashMap::from_iter(iter))
}
}
1 change: 1 addition & 0 deletions multi-era/rust/src/allegra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

pub mod cbor_encodings;
pub mod serialization;
pub mod utils;

use crate::shelley::{
GenesisKeyDelegation, ShelleyHeader, ShelleyTransactionOutput, ShelleyUpdate,
Expand Down
22 changes: 22 additions & 0 deletions multi-era/rust/src/allegra/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use cml_chain::{auxdata::AuxiliaryData, transaction::TransactionWitnessSet};

use super::{AllegraAuxiliaryData, AllegraTransactionWitnessSet};

impl From<AllegraAuxiliaryData> for AuxiliaryData {
fn from(aux: AllegraAuxiliaryData) -> Self {
match aux {
AllegraAuxiliaryData::Shelley(md) => AuxiliaryData::new_shelley(md),
AllegraAuxiliaryData::ShelleyMA(md) => AuxiliaryData::new_shelley_m_a(md),
}
}
}

impl From<AllegraTransactionWitnessSet> for TransactionWitnessSet {
fn from(wits: AllegraTransactionWitnessSet) -> Self {
let mut new_wits = TransactionWitnessSet::new();
new_wits.vkeywitnesses = wits.vkeywitnesses;
new_wits.native_scripts = wits.native_scripts;
new_wits.bootstrap_witnesses = wits.bootstrap_witnesses;
new_wits
}
}
4 changes: 2 additions & 2 deletions multi-era/rust/src/alonzo/cbor_encodings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ pub struct AlonzoProtocolParamUpdateEncoding {
pub execution_costs_key_encoding: Option<cbor_event::Sz>,
pub max_tx_ex_units_key_encoding: Option<cbor_event::Sz>,
pub max_block_ex_units_key_encoding: Option<cbor_event::Sz>,
pub max_encoding: Option<cbor_event::Sz>,
pub max_key_encoding: Option<cbor_event::Sz>,
pub max_value_size_encoding: Option<cbor_event::Sz>,
pub max_value_size_key_encoding: Option<cbor_event::Sz>,
pub collateral_percentage_encoding: Option<cbor_event::Sz>,
pub collateral_percentage_key_encoding: Option<cbor_event::Sz>,
pub max_collateral_inputs_encoding: Option<cbor_event::Sz>,
Expand Down
5 changes: 3 additions & 2 deletions multi-era/rust/src/alonzo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

pub mod cbor_encodings;
pub mod serialization;
pub mod utils;

use cml_core::Int;

Expand Down Expand Up @@ -144,7 +145,7 @@ pub struct AlonzoProtocolParamUpdate {
pub execution_costs: Option<ExUnitPrices>,
pub max_tx_ex_units: Option<ExUnits>,
pub max_block_ex_units: Option<ExUnits>,
pub max: Option<u64>,
pub max_value_size: Option<u64>,
pub collateral_percentage: Option<u64>,
pub max_collateral_inputs: Option<u64>,
#[serde(skip)]
Expand Down Expand Up @@ -175,7 +176,7 @@ impl AlonzoProtocolParamUpdate {
execution_costs: None,
max_tx_ex_units: None,
max_block_ex_units: None,
max: None,
max_value_size: None,
collateral_percentage: None,
max_collateral_inputs: None,
encodings: None,
Expand Down
34 changes: 17 additions & 17 deletions multi-era/rust/src/alonzo/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ impl Serialize for AlonzoProtocolParamUpdate {
} + match &self.max_block_ex_units {
Some(_) => 1,
None => 0,
} + match &self.max {
} + match &self.max_value_size {
Some(_) => 1,
None => 0,
} + match &self.collateral_percentage {
Expand Down Expand Up @@ -897,7 +897,7 @@ impl Serialize for AlonzoProtocolParamUpdate {
} + match &self.max_block_ex_units {
Some(_) => 1,
None => 0,
} + match &self.max {
} + match &self.max_value_size {
Some(_) => 1,
None => 0,
} + match &self.collateral_percentage {
Expand Down Expand Up @@ -1364,14 +1364,14 @@ impl Serialize for AlonzoProtocolParamUpdate {
}
}
21 => {
if let Some(field) = &self.max {
if let Some(field) = &self.max_value_size {
serializer.write_unsigned_integer_sz(
22u64,
fit_sz(
22u64,
self.encodings
.as_ref()
.map(|encs| encs.max_key_encoding)
.map(|encs| encs.max_value_size_key_encoding)
.unwrap_or_default(),
force_canonical,
),
Expand All @@ -1382,7 +1382,7 @@ impl Serialize for AlonzoProtocolParamUpdate {
*field,
self.encodings
.as_ref()
.map(|encs| encs.max_encoding)
.map(|encs| encs.max_value_size_encoding)
.unwrap_or_default(),
force_canonical,
),
Expand Down Expand Up @@ -1512,9 +1512,9 @@ impl Deserialize for AlonzoProtocolParamUpdate {
let mut max_tx_ex_units = None;
let mut max_block_ex_units_key_encoding = None;
let mut max_block_ex_units = None;
let mut max_encoding = None;
let mut max_key_encoding = None;
let mut max = None;
let mut max_value_size_encoding = None;
let mut max_value_size_key_encoding = None;
let mut max_value_size = None;
let mut collateral_percentage_encoding = None;
let mut collateral_percentage_key_encoding = None;
let mut collateral_percentage = None;
Expand Down Expand Up @@ -1849,20 +1849,20 @@ impl Deserialize for AlonzoProtocolParamUpdate {
orig_deser_order.push(20);
}
(22, key_enc) => {
if max.is_some() {
if max_value_size.is_some() {
return Err(DeserializeFailure::DuplicateKey(Key::Uint(22)).into());
}
let (tmp_max, tmp_max_encoding) =
let (tmp_max_value_size, tmp_max_value_size_encoding) =
(|| -> Result<_, DeserializeError> {
read_len.read_elems(1)?;
raw.unsigned_integer_sz()
.map(|(x, enc)| (x, Some(enc)))
.map_err(Into::<DeserializeError>::into)
})()
.map_err(|e| e.annotate("max"))?;
max = Some(tmp_max);
max_encoding = tmp_max_encoding;
max_key_encoding = Some(key_enc);
.map_err(|e| e.annotate("max_value_size"))?;
max_value_size = Some(tmp_max_value_size);
max_value_size_encoding = tmp_max_value_size_encoding;
max_value_size_key_encoding = Some(key_enc);
orig_deser_order.push(21);
}
(23, key_enc) => {
Expand Down Expand Up @@ -1946,7 +1946,7 @@ impl Deserialize for AlonzoProtocolParamUpdate {
execution_costs,
max_tx_ex_units,
max_block_ex_units,
max,
max_value_size,
collateral_percentage,
max_collateral_inputs,
encodings: Some(AlonzoProtocolParamUpdateEncoding {
Expand Down Expand Up @@ -1984,8 +1984,8 @@ impl Deserialize for AlonzoProtocolParamUpdate {
execution_costs_key_encoding,
max_tx_ex_units_key_encoding,
max_block_ex_units_key_encoding,
max_key_encoding,
max_encoding,
max_value_size_key_encoding,
max_value_size_encoding,
collateral_percentage_key_encoding,
collateral_percentage_encoding,
max_collateral_inputs_key_encoding,
Expand Down
35 changes: 35 additions & 0 deletions multi-era/rust/src/alonzo/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use cml_chain::{
auxdata::{AuxiliaryData, ConwayFormatAuxData},
transaction::TransactionWitnessSet,
};

use super::{AlonzoAuxiliaryData, AlonzoTransactionWitnessSet};

impl From<AlonzoAuxiliaryData> for AuxiliaryData {
fn from(aux: AlonzoAuxiliaryData) -> Self {
match aux {
AlonzoAuxiliaryData::Shelley(md) => AuxiliaryData::new_shelley(md.clone()),
AlonzoAuxiliaryData::ShelleyMA(md) => AuxiliaryData::new_shelley_m_a(md.clone()),
AlonzoAuxiliaryData::Alonzo(md) => AuxiliaryData::new_conway({
let mut conway = ConwayFormatAuxData::new();
conway.metadata = md.metadata.clone();
conway.native_scripts = md.native_scripts.clone();
conway.plutus_v1_scripts = md.plutus_v1_scripts.clone();
conway
}),
}
}
}

impl From<AlonzoTransactionWitnessSet> for TransactionWitnessSet {
fn from(wits: AlonzoTransactionWitnessSet) -> Self {
let mut new_wits = TransactionWitnessSet::new();
new_wits.vkeywitnesses = wits.vkeywitnesses;
new_wits.native_scripts = wits.native_scripts;
new_wits.bootstrap_witnesses = wits.bootstrap_witnesses;
new_wits.redeemers = wits.redeemers;
new_wits.plutus_datums = wits.plutus_datums;
new_wits.plutus_v1_scripts = wits.plutus_v1_scripts;
new_wits
}
}
1 change: 1 addition & 0 deletions multi-era/rust/src/babbage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

pub mod cbor_encodings;
pub mod serialization;
pub mod utils;

use crate::allegra::AllegraCertificate;
use crate::shelley::ProtocolVersionStruct;
Expand Down
72 changes: 72 additions & 0 deletions multi-era/rust/src/babbage/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use cml_chain::{
auxdata::{AuxiliaryData, ConwayFormatAuxData},
transaction::TransactionWitnessSet,
Script,
};

use super::{BabbageAuxiliaryData, BabbageScript, BabbageTransactionWitnessSet};

impl From<BabbageScript> for Script {
fn from(script: BabbageScript) -> Script {
match script {
BabbageScript::Native {
script,
len_encoding,
tag_encoding,
} => Script::Native {
script,
len_encoding,
tag_encoding,
},
BabbageScript::PlutusV1 {
script,
len_encoding,
tag_encoding,
} => Script::PlutusV1 {
script,
len_encoding,
tag_encoding,
},
BabbageScript::PlutusV2 {
script,
len_encoding,
tag_encoding,
} => Script::PlutusV2 {
script,
len_encoding,
tag_encoding,
},
}
}
}

impl From<BabbageAuxiliaryData> for AuxiliaryData {
fn from(aux: BabbageAuxiliaryData) -> Self {
match aux {
BabbageAuxiliaryData::Shelley(md) => AuxiliaryData::new_shelley(md.clone()),
BabbageAuxiliaryData::ShelleyMA(md) => AuxiliaryData::new_shelley_m_a(md.clone()),
BabbageAuxiliaryData::Babbage(md) => AuxiliaryData::new_conway({
let mut conway = ConwayFormatAuxData::new();
conway.metadata = md.metadata.clone();
conway.native_scripts = md.native_scripts.clone();
conway.plutus_v1_scripts = md.plutus_v1_scripts.clone();
conway.plutus_v2_scripts = md.plutus_v2_scripts.clone();
conway
}),
}
}
}

impl From<BabbageTransactionWitnessSet> for TransactionWitnessSet {
fn from(wits: BabbageTransactionWitnessSet) -> Self {
let mut new_wits = TransactionWitnessSet::new();
new_wits.vkeywitnesses = wits.vkeywitnesses;
new_wits.native_scripts = wits.native_scripts;
new_wits.bootstrap_witnesses = wits.bootstrap_witnesses;
new_wits.redeemers = wits.redeemers;
new_wits.plutus_datums = wits.plutus_datums;
new_wits.plutus_v1_scripts = wits.plutus_v1_scripts;
new_wits.plutus_v2_scripts = wits.plutus_v2_scripts;
new_wits
}
}
3 changes: 2 additions & 1 deletion multi-era/rust/src/byron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod transaction;
pub mod update;
pub mod utils;

use cml_crypto::TransactionHash;
pub use utils::*;

pub type ByronBlockId = Blake2b256;
Expand All @@ -29,7 +30,7 @@ impl ByronSlotId {
}
}

pub type ByronTxId = Blake2b256;
pub type ByronTxId = TransactionHash;

pub type ByronUpdateId = Blake2b256;

Expand Down
4 changes: 2 additions & 2 deletions multi-era/rust/src/byron/transaction/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cbor_event::de::Deserializer;
use cbor_event::se::{Serialize, Serializer};
use cml_core::error::*;
use cml_core::serialization::*;
use cml_crypto::RawBytesEncoding;
use cml_crypto::{RawBytesEncoding, TransactionHash};
use std::io::{BufRead, Seek, SeekFrom, Write};

impl cbor_event::se::Serialize for ByronPkWitness {
Expand Down Expand Up @@ -703,7 +703,7 @@ impl Deserialize for ByronTxOutPtr {
.bytes()
.map_err(Into::<DeserializeError>::into)
.and_then(|bytes| {
Blake2b256::from_raw_bytes(&bytes)
TransactionHash::from_raw_bytes(&bytes)
.map_err(|e| DeserializeFailure::InvalidStructure(Box::new(e)).into())
})
.map_err(|e: DeserializeError| e.annotate("byron_tx_id"))?;
Expand Down
Loading
Loading