sidan_csl_rs/core/utils/
redeemer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use cardano_serialization_lib::JsError;
use model::{Redeemer, RedeemerTag};

use crate::*;

use super::to_bignum;

pub fn to_csl_redeemer(
    redeemer_tag: RedeemerTag,
    redeemer: Redeemer,
    index: u64,
) -> Result<csl::Redeemer, JsError> {
    let csl_redeemer_tag = match redeemer_tag {
        RedeemerTag::Spend => csl::RedeemerTag::new_spend(),
        RedeemerTag::Mint => csl::RedeemerTag::new_mint(),
        RedeemerTag::Cert => csl::RedeemerTag::new_cert(),
        RedeemerTag::Reward => csl::RedeemerTag::new_reward(),
        RedeemerTag::Vote => csl::RedeemerTag::new_vote(),
        RedeemerTag::Propose => csl::RedeemerTag::new_voting_proposal(),
    };
    Ok(csl::Redeemer::new(
        &csl_redeemer_tag,
        &to_bignum(index),
        &csl::PlutusData::from_hex(&redeemer.data)?,
        &csl::ExUnits::new(
            &to_bignum(redeemer.ex_units.mem),
            &to_bignum(redeemer.ex_units.steps),
        ),
    ))
}