Skip to content

Commit

Permalink
feat: fill in cert redeemers
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Jul 15, 2024
1 parent bb30164 commit 4a12d53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pallas-traverse/src/witnesses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ impl<'b> MultiEraTx<'b> {
})
}

pub fn find_certificate_redeemer(&self, certificate_order: u32) -> Option<MultiEraRedeemer> {
self.redeemers().into_iter().find(|r| {
r.tag() == pallas_primitives::conway::RedeemerTag::Cert
&& r.index() == certificate_order
})
}

pub fn plutus_v2_scripts(&self) -> &[PlutusV2Script] {
match self {
Self::Byron(_) => &[],
Expand Down
19 changes: 15 additions & 4 deletions pallas-utxorpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ impl<C: LedgerContext> Mapper<C> {
}
}

pub fn map_cert(&self, x: &trv::MultiEraCert) -> u5c::Certificate {
pub fn map_cert(
&self,
x: &trv::MultiEraCert,
tx: &trv::MultiEraTx,
order: u32,
) -> u5c::Certificate {
let inner = match x.as_alonzo().unwrap() {
babbage::Certificate::StakeRegistration(a) => {
u5c::certificate::Certificate::StakeRegistration(self.map_stake_credential(a))
Expand Down Expand Up @@ -279,15 +284,16 @@ impl<C: LedgerContext> Mapper<C> {

u5c::Certificate {
certificate: inner.into(),
redeemer: None, // TODO
redeemer: tx
.find_certificate_redeemer(order)
.map(|r| self.map_redeemer(&r)),
}
}

pub fn map_withdrawals(
&self,
x: &(&[u8], u64),
tx: &trv::MultiEraTx,
// lexicographical order of the input we're mapping
order: u32,
) -> u5c::Withdrawal {
u5c::Withdrawal {
Expand Down Expand Up @@ -542,7 +548,12 @@ impl<C: LedgerContext> Mapper<C> {
.map(|(order, i)| self.map_tx_input(i, tx, order as u32, &resolved))
.collect(),
outputs: tx.outputs().iter().map(|x| self.map_tx_output(x)).collect(),
certificates: tx.certs().iter().map(|x| self.map_cert(x)).collect(),
certificates: tx
.certs()
.iter()
.enumerate()
.map(|(order, x)| self.map_cert(x, tx, order as u32))
.collect(),
withdrawals: tx
.withdrawals_sorted_set()
.iter()
Expand Down

0 comments on commit 4a12d53

Please sign in to comment.