Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.

Commit f1ac9f0

Browse files
authored
Merge pull request #37 from input-output-hk/decode-signed-tx
add debug command to decode signed transaction
2 parents 5331afb + 1262f96 commit f1ac9f0

File tree

4 files changed

+62
-34
lines changed

4 files changed

+62
-34
lines changed

src/debug/mod.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cardano::{address::{ExtendedAddr, StakeDistribution}, util::{base58, hex, try_from_slice::{TryFromSlice}}, hash};
22
use cardano_storage::utxo;
3-
use utils::term::Term;
4-
use std::io::{self, Read};
3+
use utils::term::{emoji, Term, style::Style};
4+
use std::{io::{self, Read}, str::FromStr};
55
use exe_common::parse_genesis_data;
66

77
pub fn command_address( mut term: Term
@@ -61,3 +61,27 @@ pub fn decode_utxos() {
6161
io::stdin().read_to_end(&mut data).expect("Cannot read stdin.");
6262
println!("{:?}", utxo::decode_utxo_file(&mut &data[..]).unwrap());
6363
}
64+
65+
pub fn decode_signed_tx() {
66+
let mut data = String::new();
67+
io::stdin().read_to_string(&mut data).expect("Cannot read stdin.");
68+
69+
let bytes = base64::decode(&data).unwrap();
70+
let txaux : cardano::tx::TxAux = cbor_event::de::RawCbor::from(&bytes).deserialize_complete().unwrap();
71+
72+
println!("inputs({})", txaux.tx.inputs.len());
73+
for ((i, input), witness) in txaux.tx.inputs.iter().enumerate().zip(txaux.witness.iter()) {
74+
let signature_ok = witness.verify_tx(Default::default(), &txaux.tx);
75+
let valid = if signature_ok {
76+
emoji::CHECK_MARK
77+
} else {
78+
emoji::CHECK_MARK
79+
};
80+
println!(" - input ({}) {}.{} {}", i, style!(&input.id), style!(&input.index), valid);
81+
}
82+
83+
println!("outputs({}):", txaux.tx.outputs.len());
84+
for (i, output) in txaux.tx.outputs.iter().enumerate() {
85+
println!(" - output ({}) {} {}", i, style!(&output.address), style!(&output.value));
86+
}
87+
}

src/lib.rs

-28
This file was deleted.

src/main.rs

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
use std::path::PathBuf;
22

33
extern crate dirs;
4-
extern crate cardano_cli;
5-
extern crate cardano;
64
#[macro_use]
75
extern crate log;
86
extern crate env_logger;
97

10-
use self::cardano_cli::utils::term;
11-
use self::cardano_cli::{blockchain, wallet, transaction, debug};
8+
extern crate cryptoxide;
9+
extern crate cbor_event;
10+
extern crate cardano;
11+
extern crate exe_common;
12+
extern crate cardano_storage;
13+
extern crate storage_units;
14+
15+
extern crate console;
16+
extern crate dialoguer;
17+
extern crate indicatif;
18+
19+
#[macro_use]
20+
extern crate serde_derive;
21+
extern crate serde;
22+
extern crate serde_yaml;
23+
extern crate serde_json;
24+
extern crate rand;
25+
extern crate humantime;
26+
extern crate base64;
27+
28+
#[macro_use]
29+
mod utils;
30+
mod blockchain;
31+
mod wallet;
32+
mod transaction;
33+
mod debug;
34+
35+
use utils::term;
1236

1337
#[macro_use]
1438
extern crate clap;
@@ -1128,6 +1152,9 @@ fn subcommand_debug<'a>(mut term: term::Term, _rootdir: PathBuf, matches: &ArgMa
11281152
("decode-utxos", Some(_)) => {
11291153
debug::decode_utxos();
11301154
},
1155+
("decode-signed-tx", Some(_)) => {
1156+
debug::decode_signed_tx();
1157+
},
11311158
_ => {
11321159
term.error(matches.usage()).unwrap();
11331160
::std::process::exit(1)
@@ -1162,4 +1189,7 @@ fn debug_commands_definition<'a, 'b>() -> App<'a, 'b> {
11621189
.subcommand(SubCommand::with_name("decode-utxos")
11631190
.about("decode and dump a UTXO delta file")
11641191
)
1192+
.subcommand(SubCommand::with_name("decode-signed-tx")
1193+
.about("decode a signed transaction (TxAux)")
1194+
)
11651195
}

src/utils/term/emoji.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ use console::{Emoji};
44

55
pub static PACKAGE: Emoji = Emoji("📦", " ");
66
pub static WARN: Emoji = Emoji("⚠️", " ");
7+
pub static CHECK_MARK: Emoji = Emoji("✓", "OK");
8+
pub static CROSS_MARK: Emoji = Emoji("❌", "FAILED");

0 commit comments

Comments
 (0)