feat: add a new subcommand for tx simulation
This commit is contained in:
@@ -13,4 +13,7 @@ authors = ["Lucas Rosa <x@rvcas.dev>", "Kasey White <kwhitemsg@gmail.com>"]
|
||||
[dependencies]
|
||||
anyhow = "1.0.57"
|
||||
clap = { version = "3.1.14", features = ["derive"] }
|
||||
hex = "0.4.3"
|
||||
pallas-primitives = "0.13.2"
|
||||
pallas-traverse = "0.13.2"
|
||||
uplc = { path = '../uplc', version = "0.0.12" }
|
||||
|
||||
@@ -7,11 +7,25 @@ use clap::{Parser, Subcommand};
|
||||
#[clap(version, about, long_about = None)]
|
||||
#[clap(propagate_version = true)]
|
||||
pub enum Args {
|
||||
/// A subcommand for working with transactions
|
||||
#[clap(subcommand)]
|
||||
Tx(TxCommand),
|
||||
/// A subcommand for working with Untyped Plutus Core
|
||||
#[clap(subcommand)]
|
||||
Uplc(UplcCommand),
|
||||
}
|
||||
|
||||
/// Commands for working with transactions
|
||||
#[derive(Subcommand)]
|
||||
pub enum TxCommand {
|
||||
/// Simulate a transaction by evaluating it's script
|
||||
Simulate {
|
||||
input: PathBuf,
|
||||
#[clap(short, long)]
|
||||
cbor: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// Commands for working with Untyped Plutus Core
|
||||
#[derive(Subcommand)]
|
||||
pub enum UplcCommand {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::{fmt::Write as _, fs};
|
||||
|
||||
use pallas_traverse::{Era, MultiEraTx};
|
||||
use uplc::{
|
||||
ast::{DeBruijn, FakeNamedDeBruijn, Name, NamedDeBruijn, Program, Term},
|
||||
machine::cost_model::ExBudget,
|
||||
@@ -8,13 +9,29 @@ use uplc::{
|
||||
|
||||
mod args;
|
||||
|
||||
use args::{Args, UplcCommand};
|
||||
use args::{Args, TxCommand, UplcCommand};
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let args = Args::default();
|
||||
|
||||
match args {
|
||||
Args::Uplc(uplc) => match uplc {
|
||||
Args::Tx(tx_cmd) => match tx_cmd {
|
||||
TxCommand::Simulate { input, cbor } => {
|
||||
let tx_bytes = if cbor {
|
||||
fs::read(input)?
|
||||
} else {
|
||||
let cbor_hex = fs::read_to_string(input)?;
|
||||
|
||||
hex::decode(cbor_hex)?
|
||||
};
|
||||
|
||||
let tx = MultiEraTx::decode(Era::Alonzo, &tx_bytes)
|
||||
.or_else(|_| MultiEraTx::decode(Era::Byron, &tx_bytes))?;
|
||||
|
||||
println!("{:?}", tx);
|
||||
}
|
||||
},
|
||||
Args::Uplc(uplc_cmd) => match uplc_cmd {
|
||||
UplcCommand::Flat { input, print, out } => {
|
||||
let code = std::fs::read_to_string(&input)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user