Skip to content

Commit

Permalink
chore(interop): update u5c spec to v0.8.0 (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jul 28, 2024
1 parent c7f2240 commit 3dbd582
Show file tree
Hide file tree
Showing 4 changed files with 1,294 additions and 444 deletions.
2 changes: 1 addition & 1 deletion pallas-network/src/miniprotocols/blockfetch/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Server {
/// # Arguments
///
/// * `blocks` - Ordered list of block bodies corresponding to the client's
/// requested range.
/// requested range.
pub async fn send_block_range(&mut self, blocks: Vec<Body>) -> Result<(), ServerError> {
if blocks.is_empty() {
self.send_no_blocks().await
Expand Down
2 changes: 1 addition & 1 deletion pallas-utxorpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pallas-primitives = { version = "=0.29.0", path = "../pallas-primitives" }
pallas-codec = { version = "=0.29.0", path = "../pallas-codec" }
pallas-crypto = { version = "=0.29.0", path = "../pallas-crypto" }

utxorpc-spec = { version = "0.7.0" }
utxorpc-spec = { version = "0.8.0" }

[dev-dependencies]
hex = "0.4.3"
Expand Down
39 changes: 29 additions & 10 deletions pallas-utxorpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<C: LedgerContext> Mapper<C> {
pub fn map_redeemer(&self, x: &trv::MultiEraRedeemer) -> u5c::Redeemer {
u5c::Redeemer {
purpose: self.map_purpose(&x.tag()).into(),
datum: self.map_plutus_datum(x.data()).into(),
payload: self.map_plutus_datum(x.data()).into(),
}
}

Expand Down Expand Up @@ -112,6 +112,24 @@ impl<C: LedgerContext> Mapper<C> {
}
}

pub fn map_tx_datum(&self, x: &trv::MultiEraOutput) -> u5c::Datum {
u5c::Datum {
hash: match x.datum() {
Some(babbage::PseudoDatumOption::Data(x)) => x.original_hash().to_vec().into(),
Some(babbage::PseudoDatumOption::Hash(x)) => x.to_vec().into(),
_ => vec![].into(),
},
payload: match x.datum() {
Some(babbage::PseudoDatumOption::Data(x)) => self.map_plutus_datum(&x.0).into(),
_ => None,
},
original_cbor: match x.datum() {
Some(babbage::PseudoDatumOption::Data(x)) => x.raw_cbor().to_vec().into(),
_ => vec![].into(),
},
}
}

pub fn map_tx_output(&self, x: &trv::MultiEraOutput) -> u5c::TxOutput {
u5c::TxOutput {
address: x.address().map(|a| a.to_vec()).unwrap_or_default().into(),
Expand All @@ -124,15 +142,7 @@ impl<C: LedgerContext> Mapper<C> {
.iter()
.map(|x| self.map_policy_assets(x))
.collect(),
datum: match x.datum() {
Some(babbage::PseudoDatumOption::Data(x)) => self.map_plutus_datum(&x.0).into(),
_ => None,
},
datum_hash: match x.datum() {
Some(babbage::PseudoDatumOption::Data(x)) => x.original_hash().to_vec().into(),
Some(babbage::PseudoDatumOption::Hash(x)) => x.to_vec().into(),
_ => vec![].into(),
},
datum: self.map_tx_datum(x).into(),
script: match x.script_ref() {
Some(conway::PseudoScript::NativeScript(x)) => u5c::Script {
script: u5c::script::Script::Native(Self::map_native_script(&x)).into(), /* */
Expand Down Expand Up @@ -669,6 +679,15 @@ mod tests {
let cbor = hex::decode(block_str).unwrap();
let block = pallas_traverse::MultiEraBlock::decode(&cbor).unwrap();
let current = serde_json::json!(mapper.map_block(&block));

// un-comment the following to generate a new snapshot

// std::fs::write(
// "new_snapshot.json",
// serde_json::to_string_pretty(&current).unwrap(),
// )
// .unwrap();

let expected: serde_json::Value = serde_json::from_str(&json_str).unwrap();

assert_eq!(expected, current)
Expand Down
Loading

0 comments on commit 3dbd582

Please sign in to comment.