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 {
|
||||
/// Simulate a transaction by evaluating it's script
|
||||
Simulate {
|
||||
/// A file containing cbor hex
|
||||
input: PathBuf,
|
||||
|
||||
/// Toggle whether input is raw cbor or a hex string
|
||||
#[clap(short, long)]
|
||||
cbor: bool,
|
||||
|
||||
/// Json file containing resolved inputs
|
||||
#[clap(short, long)]
|
||||
resolved_inputs: PathBuf,
|
||||
#[clap(short, long)]
|
||||
slot_length: u64,
|
||||
#[clap(short, long)]
|
||||
#[clap(long)]
|
||||
zero_time: u64,
|
||||
#[clap(short, long)]
|
||||
#[clap(long)]
|
||||
zero_slot: u64,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
use std::{
|
||||
fmt::Write as _,
|
||||
fs::{self, File},
|
||||
io::BufReader,
|
||||
};
|
||||
use std::{fmt::Write as _, fs};
|
||||
|
||||
use pallas_traverse::{Era, MultiEraTx};
|
||||
use uplc::{
|
||||
|
@ -46,9 +42,7 @@ 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 resolved_inputs = ResolvedInput::from_json(&resolved_inputs)?;
|
||||
|
||||
let slot_config = SlotConfig {
|
||||
zero_time,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
ast::{DeBruijn, FakeNamedDeBruijn, NamedDeBruijn, Program},
|
||||
ast::{FakeNamedDeBruijn, NamedDeBruijn, Program},
|
||||
machine::cost_model::ExBudget,
|
||||
PlutusData,
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::{fs::File, io::BufReader, path::PathBuf};
|
||||
|
||||
use pallas_codec::utils::KeyValuePairs;
|
||||
use pallas_crypto::hash::Hash;
|
||||
use pallas_primitives::babbage::{
|
||||
|
@ -14,6 +16,26 @@ pub struct ResolvedInput {
|
|||
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)]
|
||||
pub struct TxInInfo {
|
||||
pub out_ref: TransactionInput,
|
||||
|
|
|
@ -43,7 +43,7 @@ pub trait ToPlutusData {
|
|||
fn to_plutus_data(&self) -> PlutusData;
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct MintValue {
|
||||
pub mint_value: Mint,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue