Skip to content

Commit

Permalink
simplify encoding and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Dec 14, 2024
1 parent ca79f42 commit 3fa5274
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
8 changes: 8 additions & 0 deletions pallas-traverse/src/redeemers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;

use pallas_codec::minicbor;
use pallas_primitives::{alonzo, conway};

use crate::MultiEraRedeemer;
Expand Down Expand Up @@ -78,4 +79,11 @@ impl<'b> MultiEraRedeemer<'b> {
})),
)
}

pub fn encode(&self) -> Vec<u8> {
match self {
MultiEraRedeemer::AlonzoCompatible(x) => minicbor::to_vec(x).unwrap(),
MultiEraRedeemer::Conway(k, v) => minicbor::to_vec((k, v)).unwrap(),
}
}
}
17 changes: 4 additions & 13 deletions pallas-utxorpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, ops::Deref};

use pallas_codec::{minicbor, utils::KeyValuePairs};
use pallas_codec::utils::KeyValuePairs;
use pallas_crypto::hash::Hash;
use pallas_primitives::{alonzo, babbage, conway};
use pallas_traverse as trv;
Expand Down Expand Up @@ -62,24 +62,15 @@ impl<C: LedgerContext> Mapper<C> {
}

pub fn map_redeemer(&self, x: &trv::MultiEraRedeemer) -> u5c::Redeemer {
let cbor = match x {
trv::MultiEraRedeemer::AlonzoCompatible(_) => {
minicbor::to_vec(x.as_alonzo()).unwrap()
}
trv::MultiEraRedeemer::Conway(_,_) => {
minicbor::to_vec(x.as_conway()).unwrap()
}
_ => todo!(),
};
u5c::Redeemer {
purpose: self.map_purpose(&x.tag()).into(),
payload: self.map_plutus_datum(x.data()).into(),
index: x.index().into(),
ex_units: Some(u5c::ExUnits{
ex_units: Some(u5c::ExUnits {
steps: x.ex_units().steps as u64,
memory: x.ex_units().mem as u64
memory: x.ex_units().mem as u64,
}),
original_cbor: cbor.into()
original_cbor: x.encode().into(),
}
}

Expand Down
34 changes: 34 additions & 0 deletions test_data/u5c1.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"inputs": [
{
"redeemer": {
"exUnits": {
"memory": "2893153",
"steps": "1254988362"
},
"originalCbor": "hAAAGgAtxsCCGgAsJWEaSs2aSg==",
"payload": {
"bigInt": {
"int": "3000000"
Expand All @@ -33,6 +38,12 @@
},
{
"redeemer": {
"exUnits": {
"memory": "29039",
"steps": "9759373"
},
"index": 1,
"originalCbor": "hAAB2HmAghlxbxoAlOqN",
"payload": {
"constr": {
"tag": 121
Expand All @@ -45,6 +56,12 @@
{
"outputIndex": 2,
"redeemer": {
"exUnits": {
"memory": "23776",
"steps": "8949203"
},
"index": 2,
"originalCbor": "hAAC2HmAghlc4BoAiI3T",
"payload": {
"constr": {
"tag": 121
Expand Down Expand Up @@ -1384,6 +1401,12 @@
},
{
"redeemer": {
"exUnits": {
"memory": "862260",
"steps": "283080173"
},
"index": 1,
"originalCbor": "hAAB2HmAghoADSg0GhDfde0=",
"payload": {
"constr": {
"tag": 121
Expand Down Expand Up @@ -2018,6 +2041,12 @@
},
{
"redeemer": {
"exUnits": {
"memory": "312977",
"steps": "151500123"
},
"index": 1,
"originalCbor": "hAAB2HqfUCgL7p8Ifi1y1Y0n3fHPaAb/ghoABMaRGgkHtVs=",
"payload": {
"constr": {
"fields": [
Expand All @@ -2043,6 +2072,11 @@
],
"policyId": "J5+ELDPu2QVLnjxwzWo7MimCWcJLeLiVy0HZGg==",
"redeemer": {
"exUnits": {
"memory": "56931",
"steps": "22622736"
},
"originalCbor": "hAEA2HmAghneYxoBWTIQ",
"payload": {
"constr": {
"tag": 121
Expand Down

0 comments on commit 3fa5274

Please sign in to comment.