-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more progress in evaluating a real tx
- Loading branch information
Showing
3 changed files
with
79 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(), | ||
} | ||
} |