Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,023 changes: 534 additions & 489 deletions Cargo.lock

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ keywords = ["cardano", "blockchain", "wallet"]
categories = ["command-line-utilities", "blockchain", "cardano", "wallet"]

[dependencies]
tx3-lang = "0.11.5"
tx3-cardano = "0.11.5"
tx3-sdk = "^0"
# tx3-lang = "0.12.0"
# tx3-cardano = "0.12.0"
# tx3-sdk = "^0"

# tx3-lang = { git = "https://github.com/tx3-lang/tx3.git" }
# tx3-cardano = { git = "https://github.com/tx3-lang/tx3.git" }
# tx3-sdk = { git = "https://github.com/tx3-lang/rust-sdk.git" }
tx3-lang = { git = "https://github.com/tx3-lang/tx3.git" }
tx3-cardano = { git = "https://github.com/tx3-lang/tx3.git" }
tx3-sdk = { git = "https://github.com/tx3-lang/rust-sdk.git" }

# tx3-lang = { path = "../../tx3-lang/tx3/crates/tx3-lang" }
# tx3-cardano = { path = "../../tx3-lang/tx3/crates/tx3-cardano" }
# tx3-sdk = { path = "../../tx3-lang/rust-sdk/sdk" }

utxorpc = { git = "https://github.com/utxorpc/rust-sdk" }
# utxorpc = "0.10.0"
# utxorpc = { path = "../../../utxorpc/rust-sdk" }
# utxorpc = { git = "https://github.com/utxorpc/rust-sdk" }
utxorpc = "0.12.0"
# utxorpc = { path = "../../utxorpc/rust-sdk" }

bech32 = "0.9.1"
bip39 = { version = "2.0.0", features = ["rand_core"] }
Expand All @@ -44,8 +44,8 @@ inquire = "0.7.4"
jsonrpsee = { version = "0", features = ["client"] }
pallas = { version = "1.0.0-alpha.2", features = ["hardano"] }
prost = "0.13.5"
rand = "0.8.5"
rand_core = { version = "0.6.4" }
rand = "0.9.2"
rand_core = { version = "0.9.3" }
ratatui = "0.29.0"
serde = { version = "1.0.217", features = ["derive"] }
serde_with = "3.12.0"
Expand Down Expand Up @@ -74,4 +74,11 @@ lto = "thin"
[workspace.metadata.release]
push = false
publish = false
pre-release-hook = ["git", "cliff", "-o", "CHANGELOG.md", "--tag", "{{version}}"]
pre-release-hook = [
"git",
"cliff",
"-o",
"CHANGELOG.md",
"--tag",
"{{version}}",
]
54 changes: 25 additions & 29 deletions src/explorer/widgets/tabs/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,35 +625,31 @@ impl TxView {
.collect()
}

pub fn from_any_chain_tx(any_chain_tx: &query::AnyChainTx) -> Option<Self> {
let chain = any_chain_tx.chain.as_ref()?;
let block_ref = any_chain_tx.block_ref.as_ref()?;

match chain {
query::any_chain_tx::Chain::Cardano(tx) => {
let hash = hex::encode(&tx.hash);
let certs = tx.certificates.len();
let assets = tx.outputs.iter().map(|o| o.assets.len()).sum();
let amount_ada = tx.outputs.iter().map(|o| o.coin).sum();
let datum = tx
.outputs
.iter()
.any(|o| o.datum.as_ref().is_some_and(|d| !d.hash.is_empty()));

Some(TxView {
hash,
certs,
assets,
amount_ada,
datum,
// TODO: improve to not clone the whole tx
tx: Some(tx.clone()),
block_slot: block_ref.slot,
block_height: block_ref.height,
block_hash: hex::encode(&block_ref.hash),
})
}
}
pub fn from_any_chain_tx(tx: &utxorpc::ChainTx<utxorpc::spec::cardano::Tx>) -> Option<Self> {
let block_ref = tx.block_ref.as_ref()?;
let tx = tx.parsed.as_ref()?;

let hash = hex::encode(&tx.hash);
let certs = tx.certificates.len();
let assets = tx.outputs.iter().map(|o| o.assets.len()).sum();
let amount_ada = tx.outputs.iter().map(|o| o.coin).sum();
let datum = tx
.outputs
.iter()
.any(|o| o.datum.as_ref().is_some_and(|d| !d.hash.is_empty()));

Some(TxView {
hash,
certs,
assets,
amount_ada,
datum,
// TODO: improve to not clone the whole tx
tx: Some(tx.clone()),
block_slot: block_ref.slot,
block_height: block_ref.height,
block_hash: hex::encode(&block_ref.hash),
})
}
}

Expand Down
43 changes: 15 additions & 28 deletions src/provider/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use pallas::ledger::addresses::Address;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use utxorpc::{
spec::{
query::{any_utxo_pattern::UtxoPattern, AnyChainTx, ReadTxRequest},
sync::{AnyChainBlock, BlockRef, FetchBlockRequest},
},
CardanoQueryClient, CardanoSubmitClient, CardanoSyncClient, ClientBuilder, InnerService,
spec::{query::any_utxo_pattern::UtxoPattern, sync::BlockRef},
CardanoQueryClient, CardanoSubmitClient, CardanoSyncClient, ChainBlock, ChainTx, ClientBuilder,
InnerService,
};

use crate::{
Expand Down Expand Up @@ -290,7 +288,10 @@ impl Provider {
Ok(client.submit(tx, vec![]).await?)
}

pub async fn fetch_block(&self, refs: Vec<(Vec<u8>, u64)>) -> Result<Vec<AnyChainBlock>> {
pub async fn fetch_block(
&self,
refs: Vec<(Vec<u8>, u64)>,
) -> Result<Vec<ChainBlock<utxorpc::spec::cardano::Block>>> {
let mut client: utxorpc::CardanoSyncClient = self.client().await?;

let refs = refs
Expand All @@ -302,34 +303,20 @@ impl Provider {
})
.collect();

let request = FetchBlockRequest {
r#ref: refs,
..Default::default()
};
let response = client
.fetch_block(request)
.await
.map_err(|err| anyhow::Error::msg(format!("Fetch block. {}", err.code())))?
.into_inner();
let response = client.fetch_block(refs).await?;

Ok(response.block)
Ok(response)
}

pub async fn fetch_tx(&self, hash: Vec<u8>) -> Result<Option<AnyChainTx>> {
pub async fn fetch_tx(
&self,
hash: Vec<u8>,
) -> Result<Option<ChainTx<utxorpc::spec::cardano::Tx>>> {
let mut client: utxorpc::CardanoQueryClient = self.client().await?;

let request = ReadTxRequest {
hash: hash.into(),
..Default::default()
};

let response = client
.read_tx(request)
.await
.map_err(|err| anyhow::Error::msg(format!("Fetch transaction. {}", err.code())))?
.into_inner();
let response = client.read_tx(hash.into()).await?;

Ok(response.tx)
Ok(response)
}
}

Expand Down
95 changes: 49 additions & 46 deletions src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ use anyhow::Result;
use clap::{command, Parser, Subcommand};
use comfy_table::Table;
use tracing::instrument;
use utxorpc::spec::{cardano::Tx, query, sync};
use utxorpc::{
spec::{
cardano::Tx,
query::{self},
},
ChainBlock,
};

use crate::output::OutputFormatter;

Expand Down Expand Up @@ -32,7 +38,7 @@ pub async fn run(args: Args, ctx: &mut crate::Context) -> Result<()> {
}
}

fn cardano_tx_table(block_hash: Vec<u8>, tx: &[Tx]) -> Table {
fn cardano_tx_table(block_hash: Option<Vec<u8>>, tx: &[Tx]) -> Table {
let mut table = Table::new();
table.set_header(vec![
"Block",
Expand All @@ -45,12 +51,10 @@ fn cardano_tx_table(block_hash: Vec<u8>, tx: &[Tx]) -> Table {
"Datum",
]);

let block_hash = hex::encode(block_hash);
let block_hash_trucated = format!(
"{}...{}",
&block_hash[..4],
&block_hash[block_hash.len() - 4..]
);
let block_hash = block_hash
.map(|b| hex::encode(b))
.map(|x| format!("{}...{}", &x[..4], &x[x.len() - 4..]))
.unwrap_or_default();

for (i, tx) in tx.iter().enumerate() {
let hash = hex::encode(&tx.hash);
Expand All @@ -71,7 +75,7 @@ fn cardano_tx_table(block_hash: Vec<u8>, tx: &[Tx]) -> Table {
};

table.add_row(vec![
&block_hash_trucated,
&block_hash,
&i.to_string(),
&hash,
&inputs.to_string(),
Expand All @@ -85,28 +89,31 @@ fn cardano_tx_table(block_hash: Vec<u8>, tx: &[Tx]) -> Table {
table
}

impl OutputFormatter for Vec<sync::AnyChainBlock> {
impl OutputFormatter for Vec<ChainBlock<utxorpc::spec::cardano::Block>> {
fn to_table(&self) {
for block in self {
if let Some(chain) = &block.chain {
match chain {
sync::any_chain_block::Chain::Cardano(block) => {
if block.header.is_none() {
return;
}
let header = block.header.as_ref().unwrap();
if let Some(body) = &block.body {
let table = cardano_tx_table(header.hash.clone().into(), &body.tx);
println!("{table}");
}
}
if let Some(block) = &block.parsed {
if block.header.is_none() {
return;
}

let header = block.header.as_ref().unwrap();

if let Some(body) = &block.body {
let table = cardano_tx_table(Some(header.hash.clone().into()), &body.tx);
println!("{table}");
}
}
}
}

fn to_json(&self) {
let result = serde_json::to_value(self);
let blocks = self
.iter()
.flat_map(|x| x.parsed.as_ref())
.collect::<Vec<_>>();

let result = serde_json::to_value(blocks);
if let Err(err) = result {
eprintln!("{err}");
return;
Expand All @@ -130,7 +137,8 @@ impl OutputFormatter for Vec<query::AnyChainBlock> {
}
let header = block.header.as_ref().unwrap();
if let Some(body) = &block.body {
let table = cardano_tx_table(header.hash.clone().into(), &body.tx);
let table =
cardano_tx_table(Some(header.hash.clone().into()), &body.tx);
println!("{table}");
}
}
Expand All @@ -153,35 +161,30 @@ impl OutputFormatter for Vec<query::AnyChainBlock> {
}
}

impl OutputFormatter for query::AnyChainTx {
impl OutputFormatter for utxorpc::ChainTx<utxorpc::spec::cardano::Tx> {
fn to_table(&self) {
if let Some(chain) = &self.chain {
match chain {
query::any_chain_tx::Chain::Cardano(tx) => {
let block_hash = self.block_ref.as_ref().unwrap().hash.clone();
let table = cardano_tx_table(block_hash.into(), std::slice::from_ref(tx));
println!("{table}");
}
}
if let Some(parsed) = &self.parsed {
let table = cardano_tx_table(
self.block_ref.as_ref().map(|b| b.hash.clone().into()),
std::slice::from_ref(parsed),
);
println!("{table}");
}
}

fn to_json(&self) {
if let Some(chain) = &self.chain {
match chain {
query::any_chain_tx::Chain::Cardano(tx) => {
let result = serde_json::to_value(tx);
if let Err(err) = result {
eprintln!("{err}");
return;
}
if let Some(tx) = &self.parsed {
let result = serde_json::to_value(tx);

println!(
"{}",
serde_json::to_string_pretty(&result.unwrap()).unwrap()
);
}
if let Err(err) = result {
eprintln!("{err}");
return;
}

println!(
"{}",
serde_json::to_string_pretty(&result.unwrap()).unwrap()
);
}
}
}
8 changes: 6 additions & 2 deletions src/tx/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ pub fn inquire_args(
"tx3 arg {key} is a custom type {x}, not supported yet"
));
}
tx3_lang::ir::Type::Map => {
return Err(anyhow::anyhow!(
"tx3 arg {key} is of type Map, not supported yet",
));
}
};
}

Expand All @@ -190,8 +195,7 @@ pub fn define_args(
) -> Result<HashMap<String, ArgValue>> {
let mut remaining_params = params.clone();

let mut loaded_args =
super::common::load_args(inline_args, file_args, &remaining_params)?;
let mut loaded_args = super::common::load_args(inline_args, file_args, &remaining_params)?;

// remove from the remaining params the args we already managed to load from the
// file or json
Expand Down
Loading
Loading