-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
196 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# `eval` command | ||
|
||
The `eval` is an utility for evaluating transactions. It takes tx data from an external source and uses the current ledger state to evaluate phase-1 validation rules. | ||
|
||
## Usage | ||
|
||
To execute the evaluation, run the following command from your terminal: | ||
|
||
```bash | ||
dolos eval --file <FILE> --era <ERA> --magic <MAGIC> --slot <SLOT> | ||
``` | ||
|
||
The args should be interpreted as: | ||
|
||
- `--file <FILE>`: the path to the file containing the tx data as hex-encoded cbor. | ||
- `--era <ERA>`: the id of the era that should be used to interpret the transaction data. | ||
- `--magic <MAGIC>`: the protocol magic of the network. | ||
- `--slot <SLOT>`: the slot that should be used for retrieving protocol parameters. |
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use miette::{Context, IntoDiagnostic}; | ||
use pallas::{ | ||
applying::{validate, Environment, UTxOs}, | ||
ledger::{ | ||
primitives::byron::TxIn, | ||
traverse::{Era, MultiEraInput, MultiEraOutput, MultiEraTx}, | ||
}, | ||
}; | ||
use std::path::PathBuf; | ||
|
||
use dolos::storage::applydb::ApplyDB; | ||
|
||
#[derive(Debug, clap::Args)] | ||
pub struct Args { | ||
#[arg(long, short)] | ||
file: PathBuf, | ||
|
||
#[arg(long, short)] | ||
era: u16, | ||
|
||
#[arg(long, short)] | ||
magic: u32, | ||
|
||
#[arg(long, short)] | ||
slot: u64, | ||
} | ||
|
||
type ResolveInputs = Vec<(TxIn, Vec<u8>)>; | ||
|
||
pub fn resolve_inputs(tx: &MultiEraTx<'_>, ledger: &ApplyDB) -> miette::Result<ResolveInputs> { | ||
let mut set = vec![]; | ||
|
||
for input in tx.inputs() { | ||
let hash = input.hash(); | ||
let idx = input.index(); | ||
|
||
let bytes = ledger | ||
.get_utxo(*hash, idx) | ||
.into_diagnostic() | ||
.context("fetching utxo from ledger")? | ||
.ok_or(miette::miette!("utxo not found"))?; | ||
|
||
//TODO: allow to pass extra utxos manually, to mimic what happens when | ||
// consuming utxos from the same block; | ||
|
||
let txin = pallas::ledger::primitives::byron::TxIn::Variant0( | ||
pallas::codec::utils::CborWrap((*hash, idx as u32)), | ||
); | ||
|
||
set.push((txin, bytes)); | ||
} | ||
|
||
Ok(set) | ||
} | ||
|
||
pub fn run(config: &super::Config, args: &Args) -> miette::Result<()> { | ||
crate::common::setup_tracing(&config.logging)?; | ||
|
||
let (_, _, ledger) = crate::common::open_data_stores(config)?; | ||
|
||
let cbor = std::fs::read_to_string(&args.file) | ||
.into_diagnostic() | ||
.context("reading tx from file")?; | ||
|
||
let cbor = hex::decode(&cbor) | ||
.into_diagnostic() | ||
.context("decoding hex content from file")?; | ||
|
||
let era = Era::try_from(args.era).unwrap(); | ||
|
||
let tx = pallas::ledger::traverse::MultiEraTx::decode_for_era(era, &cbor) | ||
.into_diagnostic() | ||
.context("decoding tx cbor")?; | ||
|
||
let mut utxos: UTxOs = UTxOs::new(); | ||
let resolved = resolve_inputs(&tx, &ledger)?; | ||
|
||
for (input, output) in resolved.iter() { | ||
let key = MultiEraInput::from_byron(&input); | ||
|
||
let value = MultiEraOutput::decode(Era::Byron, &output) | ||
.into_diagnostic() | ||
.context("decoding utxo cbor")?; | ||
|
||
utxos.insert(key, value); | ||
} | ||
|
||
let env: Environment = ApplyDB::mk_environment(args.slot, args.magic) | ||
.into_diagnostic() | ||
.context("resolving pparams")?; | ||
|
||
validate(&tx, &utxos, &env).unwrap(); | ||
|
||
Ok(()) | ||
} |
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