expose tx simulation with simulate cli command
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Cardano smart contract toolchain
|
||||
#[derive(Parser)]
|
||||
@@ -26,36 +25,13 @@ pub enum TxCommand {
|
||||
cbor: bool,
|
||||
#[clap(short, long)]
|
||||
resolved_inputs: PathBuf,
|
||||
#[clap(short, long)]
|
||||
slot_length: u64,
|
||||
#[clap(short, long)]
|
||||
zero_time: u64,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ResolvedInputOld {
|
||||
pub input: Input,
|
||||
pub output: Output,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Input {
|
||||
pub tx_hash: String,
|
||||
pub index: u64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Output {
|
||||
pub address: String,
|
||||
pub value: (u64, HashMap<String, HashMap<String, u64>>),
|
||||
pub datum: Option<OutputDatum>,
|
||||
pub script: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum OutputDatum {
|
||||
DatumHash(String),
|
||||
Datum(String),
|
||||
}
|
||||
|
||||
/// Commands for working with Untyped Plutus Core
|
||||
#[derive(Subcommand)]
|
||||
pub enum UplcCommand {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::{
|
||||
fmt::Write as _,
|
||||
fs::{self},
|
||||
fs::{self, File},
|
||||
io::BufReader,
|
||||
};
|
||||
|
||||
use pallas_traverse::{Era, MultiEraTx};
|
||||
@@ -8,6 +9,8 @@ use uplc::{
|
||||
ast::{DeBruijn, FakeNamedDeBruijn, Name, NamedDeBruijn, Program, Term},
|
||||
machine::cost_model::ExBudget,
|
||||
parser,
|
||||
transaction_eval::eval_tx,
|
||||
transaction_eval::script_context::{ResolvedInput, SlotConfig},
|
||||
};
|
||||
|
||||
mod args;
|
||||
@@ -22,7 +25,9 @@ fn main() -> anyhow::Result<()> {
|
||||
TxCommand::Simulate {
|
||||
input,
|
||||
cbor,
|
||||
resolved_inputs: _,
|
||||
resolved_inputs,
|
||||
slot_length,
|
||||
zero_time,
|
||||
} => {
|
||||
let tx_bytes = if cbor {
|
||||
fs::read(input)?
|
||||
@@ -37,7 +42,18 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
println!("Simulating: {}", tx.hash());
|
||||
|
||||
|
||||
if let Some(tx_babbage) = tx.as_babbage() {
|
||||
let file = File::open(&resolved_inputs)?;
|
||||
let reader = BufReader::new(file);
|
||||
let resolved_inputs: Vec<ResolvedInput> = serde_json::from_reader(reader)?;
|
||||
|
||||
let slot_config = SlotConfig {
|
||||
zero_time,
|
||||
slot_length,
|
||||
};
|
||||
|
||||
eval_tx(tx_babbage, &resolved_inputs, &slot_config)?;
|
||||
}
|
||||
}
|
||||
},
|
||||
Args::Uplc(uplc_cmd) => match uplc_cmd {
|
||||
|
||||
Reference in New Issue
Block a user