feat: move input from json to helper method
This commit is contained in:
parent
3cb24a1d00
commit
8620332b75
|
@ -20,16 +20,21 @@ pub enum Args {
|
||||||
pub enum TxCommand {
|
pub enum TxCommand {
|
||||||
/// Simulate a transaction by evaluating it's script
|
/// Simulate a transaction by evaluating it's script
|
||||||
Simulate {
|
Simulate {
|
||||||
|
/// A file containing cbor hex
|
||||||
input: PathBuf,
|
input: PathBuf,
|
||||||
|
|
||||||
|
/// Toggle whether input is raw cbor or a hex string
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
cbor: bool,
|
cbor: bool,
|
||||||
|
|
||||||
|
/// Json file containing resolved inputs
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
resolved_inputs: PathBuf,
|
resolved_inputs: PathBuf,
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
slot_length: u64,
|
slot_length: u64,
|
||||||
#[clap(short, long)]
|
#[clap(long)]
|
||||||
zero_time: u64,
|
zero_time: u64,
|
||||||
#[clap(short, long)]
|
#[clap(long)]
|
||||||
zero_slot: u64,
|
zero_slot: u64,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
use std::{
|
use std::{fmt::Write as _, fs};
|
||||||
fmt::Write as _,
|
|
||||||
fs::{self, File},
|
|
||||||
io::BufReader,
|
|
||||||
};
|
|
||||||
|
|
||||||
use pallas_traverse::{Era, MultiEraTx};
|
use pallas_traverse::{Era, MultiEraTx};
|
||||||
use uplc::{
|
use uplc::{
|
||||||
|
@ -46,9 +42,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
println!("Simulating: {}", tx.hash());
|
println!("Simulating: {}", tx.hash());
|
||||||
|
|
||||||
if let Some(tx_babbage) = tx.as_babbage() {
|
if let Some(tx_babbage) = tx.as_babbage() {
|
||||||
let file = File::open(&resolved_inputs)?;
|
let resolved_inputs = ResolvedInput::from_json(&resolved_inputs)?;
|
||||||
let reader = BufReader::new(file);
|
|
||||||
let resolved_inputs: Vec<ResolvedInput> = serde_json::from_reader(reader)?;
|
|
||||||
|
|
||||||
let slot_config = SlotConfig {
|
let slot_config = SlotConfig {
|
||||||
zero_time,
|
zero_time,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{DeBruijn, FakeNamedDeBruijn, NamedDeBruijn, Program},
|
ast::{FakeNamedDeBruijn, NamedDeBruijn, Program},
|
||||||
machine::cost_model::ExBudget,
|
machine::cost_model::ExBudget,
|
||||||
PlutusData,
|
PlutusData,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::{fs::File, io::BufReader, path::PathBuf};
|
||||||
|
|
||||||
use pallas_codec::utils::KeyValuePairs;
|
use pallas_codec::utils::KeyValuePairs;
|
||||||
use pallas_crypto::hash::Hash;
|
use pallas_crypto::hash::Hash;
|
||||||
use pallas_primitives::babbage::{
|
use pallas_primitives::babbage::{
|
||||||
|
@ -14,6 +16,26 @@ pub struct ResolvedInput {
|
||||||
pub output: TransactionOutput,
|
pub output: TransactionOutput,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
#[error("{0}")]
|
||||||
|
File(#[from] std::io::Error),
|
||||||
|
#[error("{0}")]
|
||||||
|
Serde(#[from] serde_json::error::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ResolvedInput {
|
||||||
|
pub fn from_json(file: &PathBuf) -> Result<Vec<Self>, Error> {
|
||||||
|
let file = File::open(file)?;
|
||||||
|
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
let resolved_inputs: Vec<ResolvedInput> = serde_json::from_reader(reader)?;
|
||||||
|
|
||||||
|
Ok(resolved_inputs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct TxInInfo {
|
pub struct TxInInfo {
|
||||||
pub out_ref: TransactionInput,
|
pub out_ref: TransactionInput,
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub trait ToPlutusData {
|
||||||
fn to_plutus_data(&self) -> PlutusData;
|
fn to_plutus_data(&self) -> PlutusData;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct MintValue {
|
pub struct MintValue {
|
||||||
pub mint_value: Mint,
|
pub mint_value: Mint,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue