-
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.
feat: integrate Pallas phase-1 validation function (#127)
Co-authored-by: Maico Leberle <[email protected]>
- Loading branch information
1 parent
bebee58
commit 77f172c
Showing
17 changed files
with
572 additions
and
265 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -12,8 +12,6 @@ authors = ["Santiago Carmuega <[email protected]>"] | |
|
||
|
||
[dependencies] | ||
# pallas = "0.19.0" | ||
# pallas = { path = "../pallas/pallas" } | ||
pallas = { git = "https://github.com/txpipe/pallas.git", features = ["unstable"] } | ||
|
||
gasket = { version = "^0.5", features = ["derive"] } | ||
|
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
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
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,75 @@ | ||
use miette::{Context, IntoDiagnostic}; | ||
use pallas::{ | ||
applying::{validate, Environment, UTxOs}, | ||
ledger::traverse::{Era, MultiEraInput, MultiEraOutput}, | ||
}; | ||
use std::{borrow::Cow, collections::HashMap, path::PathBuf}; | ||
|
||
#[derive(Debug, clap::Args)] | ||
pub struct Args { | ||
#[arg(long, short)] | ||
file: PathBuf, | ||
|
||
#[arg(long, short)] | ||
era: u16, | ||
|
||
#[arg(long, short)] | ||
slot: u64, | ||
} | ||
|
||
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 = HashMap::new(); | ||
ledger | ||
.resolve_inputs_for_tx(&tx, &mut utxos) | ||
.into_diagnostic() | ||
.context("resolving tx inputs")?; | ||
|
||
let mut utxos2 = UTxOs::new(); | ||
|
||
for (ref_, output) in utxos.iter() { | ||
let txin = pallas::ledger::primitives::byron::TxIn::Variant0( | ||
pallas::codec::utils::CborWrap((ref_.0.clone(), ref_.1 as u32)), | ||
); | ||
|
||
let key = MultiEraInput::Byron( | ||
<Box<Cow<'_, pallas::ledger::primitives::byron::TxIn>>>::from(Cow::Owned(txin)), | ||
); | ||
|
||
let era = Era::try_from(output.0) | ||
.into_diagnostic() | ||
.context("parsing era")?; | ||
|
||
let value = MultiEraOutput::decode(era, &output.1) | ||
.into_diagnostic() | ||
.context("decoding utxo")?; | ||
|
||
utxos2.insert(key, value); | ||
} | ||
|
||
let env: Environment = ledger | ||
.get_active_pparams(args.slot) | ||
.into_diagnostic() | ||
.context("resolving pparams")?; | ||
|
||
validate(&tx, &utxos2, &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
Oops, something went wrong.