Skip to content

Commit

Permalink
more progress in evaluating a real tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercurial committed Oct 31, 2024
1 parent 8e4ddc7 commit 5e53c96
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/serve/grpc/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use pallas::ledger::primitives::conway::{
DatumHash, MintedTx, NativeScript, PlutusData, PlutusV1Script, PlutusV2Script, PlutusV3Script,
PseudoScript, ScriptHash, TransactionInput, TransactionOutput,
};
use pallas::ledger::traverse::{ComputeHash, MultiEraTx, OriginalHash};
use pallas::ledger::traverse::{wellknown, ComputeHash, MultiEraTx, OriginalHash};
use std::collections::{HashMap, HashSet};
use std::pin::Pin;
use tokio_stream::wrappers::BroadcastStream;
Expand Down
4 changes: 2 additions & 2 deletions src/uplc/script_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ pub fn get_redeemers_info<'a>(
.redeemer
.as_deref()
.map(|m| {
let redeemers_map = match m {
let redeemers = match m {
pallas::ledger::primitives::conway::Redeemers::List(arr) => arr
.deref()
.iter()
Expand All @@ -730,7 +730,7 @@ pub fn get_redeemers_info<'a>(
pallas::ledger::primitives::conway::Redeemers::Map(arr) => arr.deref().clone(),
};

redeemers_map
redeemers
.iter()
.sorted_by(|a, b| sort_redeemers(&a.0, &b.0))
.map(|(redeemer_key, redeemer_value)| {
Expand Down
103 changes: 76 additions & 27 deletions src/uplc/tx.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,85 @@
use super::script_context::TxInInfo;
use std::ops::Deref;

use super::{error::Error, script_context::{find_script, DataLookupTable, ResolvedInput, ScriptVersion, SlotConfig, TxInfoV3}};
use pallas::{
codec::minicbor::{self, to_vec, Encode},
codec::minicbor::to_vec,
interop::utxorpc::spec::query::any_chain_params::Params,
ledger::{primitives::PlutusData, traverse::MultiEraTx},
ledger::primitives::{
conway::{MintedTx, Redeemer, Redeemers, RedeemersKey, RedeemersValue},
PlutusData,
},
};
use uplc::{bumpalo::Bump, data::PlutusData as PragmaPlutusData};

pub fn map_pragma_data_to_pallas_data<'a>(
arena: &'a Bump,
data: PlutusData,
) -> &'a PragmaPlutusData<'a> {
pub fn map_pragma_data_to_pallas_data(arena: &Bump, data: PlutusData) -> &PragmaPlutusData<'_> {
let bytes = to_vec(&data).expect("failed to encode data");
PragmaPlutusData::from_cbor(arena, &bytes).expect("failed to decode data")
}

// pub fn eval_tx(tx: MultiEraTx, protocol_params: Params, resolved_inputs: Vec<TxInInfo>) {
// let redeemers = tx.redeemers();

// let results = redeemers
// .iter()
// .map(|r| match r {
// pallas::ledger::traverse::MultiEraRedeemer::AlonzoCompatible(r) => match r.tag {
// pallas::ledger::primitives::alonzo::RedeemerTag::Spend => {
// let redeemer_index = r.index;
// let redeemer_data = r.data;
// }
// pallas::ledger::primitives::alonzo::RedeemerTag::Mint => todo!(),
// pallas::ledger::primitives::alonzo::RedeemerTag::Cert => todo!(),
// pallas::ledger::primitives::alonzo::RedeemerTag::Reward => todo!(),
// },
// pallas::ledger::traverse::MultiEraRedeemer::Conway(r_keys, r_values) => todo!(),
// _ => todo!(),
// })
// .collect();
// }
pub fn eval_tx(
tx: &MintedTx,
protocol_params: Params,
utxos: &[ResolvedInput],
slot_config: &SlotConfig,
) {
let lookup_table = DataLookupTable::from_transaction(tx, utxos);

let redeemers = tx
.transaction_witness_set
.redeemer
.as_ref()
.unwrap()
.deref();
let redeemers = match redeemers {
Redeemers::List(arr) => arr
.deref()
.iter()
.map(|r| {
(
RedeemersKey {
tag: r.tag,
index: r.index,
},
RedeemersValue {
data: r.data.clone(),
ex_units: r.ex_units,
},
)
})
.collect(),
Redeemers::Map(arr) => arr.deref().clone(),
};
let redeemers = redeemers
.iter()
.map(|(k, v)| Redeemer {
tag: k.tag,
index: k.index,
data: v.data.clone(),
ex_units: v.ex_units,
})
.collect::<Vec<_>>();

redeemers.iter().for_each(|redeemer| {
eval_redeemer(redeemer, tx, utxos, slot_config, &lookup_table);
});
}

pub fn eval_redeemer(
redeemer: &Redeemer,
tx: &MintedTx,
utxos: &[ResolvedInput],
slot_config: &SlotConfig,
lookup_table: &DataLookupTable,
) -> Result<(), Error> {
let tx_info = TxInfoV3::from_transaction(tx, utxos, slot_config).unwrap();

match find_script(redeemer, tx, utxos, lookup_table)? {
(ScriptVersion::Native(_), _) => Err(Error::NativeScriptPhaseTwo),

(ScriptVersion::V1(script), datum) => todo!(),

(ScriptVersion::V2(script), datum) => todo!(),

(ScriptVersion::V3(script), datum) => todo!(),
}
}

0 comments on commit 5e53c96

Please sign in to comment.