Skip to content

Commit 33c10d5

Browse files
committed
chore: update utxorpc to v0.13
1 parent 7277b04 commit 33c10d5

7 files changed

Lines changed: 159 additions & 65 deletions

File tree

Cargo.lock

Lines changed: 20 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tx3-sdk = "0.9.2"
1919
# tx3-sdk = { path = "../../tx3-lang/rust-sdk/sdk" }
2020

2121
# utxorpc = { git = "https://github.com/utxorpc/rust-sdk" }
22-
utxorpc = "0.12.0"
22+
utxorpc = "0.13.0"
2323
# utxorpc = { path = "../../utxorpc/rust-sdk" }
2424

2525
bech32 = "0.11.1"

src/explorer/widgets/tabs/transactions.rs

Lines changed: 74 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ use ratatui::{
1414
};
1515
use regex::Regex;
1616
use tui_tree_widget::{Tree, TreeItem, TreeState};
17-
use utxorpc::spec::{
18-
cardano::{
19-
self, big_int,
20-
certificate::Certificate,
21-
d_rep, metadatum, native_script, plutus_data,
22-
script::{self},
23-
stake_credential, AuxData, Datum, Metadatum, NativeScript, PlutusData, Redeemer,
24-
RedeemerPurpose, Script, Tx, TxInput, TxOutput, TxValidity, VKeyWitness, Withdrawal,
25-
WitnessSet,
26-
},
27-
query,
17+
use utxorpc::spec::cardano::{
18+
self, big_int,
19+
certificate::Certificate,
20+
d_rep, metadatum, native_script, plutus_data,
21+
script::{self},
22+
stake_credential, AuxData, Datum, Metadatum, NativeScript, PlutusData, Redeemer,
23+
RedeemerPurpose, Script, Tx, TxInput, TxOutput, TxValidity, VKeyWitness, Withdrawal,
24+
WitnessSet,
2825
};
2926

3027
use crate::{
@@ -371,7 +368,10 @@ impl TransactionsDetail {
371368

372369
let mut root = vec![
373370
TreeItem::new_leaf("tx_hash_info".to_string(), format!("Hash: {tx_hash}")),
374-
TreeItem::new_leaf("tx_fee_info".to_string(), format!("Fee: {}", tx.fee)),
371+
TreeItem::new_leaf(
372+
"tx_fee_info".to_string(),
373+
format!("Fee: {:?}", crate::utils::format_bigint_opt(&tx.fee)),
374+
),
375375
];
376376

377377
// Block Info
@@ -454,16 +454,13 @@ impl TransactionsDetail {
454454
TreeItem::new(
455455
format!("mint_asset_{policy_id}_{i}_{j}"),
456456
format!("Asset: {name}"),
457-
vec![
458-
TreeItem::new_leaf(
459-
format!("mint_asset_mintcoin_{policy_id}_{i}_{j}"),
460-
format!("Mint Coin: {}", asset.mint_coin),
457+
vec![TreeItem::new_leaf(
458+
format!("mint_asset_quantity_{policy_id}_{i}_{j}"),
459+
format!(
460+
"Quantity: {:?}",
461+
crate::utils::format_asset_quantity(&asset.quantity)
461462
),
462-
TreeItem::new_leaf(
463-
format!("mint_asset_outputcoin_{policy_id}_{i}_{j}"),
464-
format!("Output Coin: {}", asset.output_coin),
465-
),
466-
],
463+
)],
467464
)
468465
.expect("Failed to create mint asset node")
469466
})
@@ -504,7 +501,10 @@ impl TransactionsDetail {
504501
}
505502
children.push(TreeItem::new_leaf(
506503
"total_collateral".to_string(),
507-
format!("Total Collateral: {}", collateral.total_collateral),
504+
format!(
505+
"Total Collateral: {:?}",
506+
crate::utils::format_bigint_opt(&collateral.total_collateral)
507+
),
508508
));
509509
let collateral_node =
510510
TreeItem::new("collateral".to_string(), "Collateral".to_string(), children)
@@ -603,7 +603,17 @@ impl TxView {
603603
let hash = hex::encode(&tx.hash);
604604
let certs = tx.certificates.len();
605605
let assets = tx.outputs.iter().map(|o| o.assets.len()).sum();
606-
let amount_ada = tx.outputs.iter().map(|o| o.coin).sum();
606+
let amount_ada: u64 = tx
607+
.outputs
608+
.iter()
609+
.filter_map(|o| o.coin.as_ref())
610+
.filter_map(|c| {
611+
c.big_int.as_ref().map(|bi| match bi {
612+
big_int::BigInt::Int(i) => *i as u64,
613+
_ => 0,
614+
})
615+
})
616+
.sum();
607617
let datum = tx
608618
.outputs
609619
.iter()
@@ -632,7 +642,17 @@ impl TxView {
632642
let hash = hex::encode(&tx.hash);
633643
let certs = tx.certificates.len();
634644
let assets = tx.outputs.iter().map(|o| o.assets.len()).sum();
635-
let amount_ada = tx.outputs.iter().map(|o| o.coin).sum();
645+
let amount_ada: u64 = tx
646+
.outputs
647+
.iter()
648+
.filter_map(|o| o.coin.as_ref())
649+
.filter_map(|c| {
650+
c.big_int.as_ref().map(|bi| match bi {
651+
big_int::BigInt::Int(i) => *i as u64,
652+
_ => 0,
653+
})
654+
})
655+
.sum();
636656
let datum = tx
637657
.outputs
638658
.iter()
@@ -751,8 +771,14 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
751771
format!("vrf_keyhash_{i}"),
752772
format!("VRF Key Hash: {}", hex::encode(&v.vrf_keyhash)),
753773
),
754-
TreeItem::new_leaf(format!("pledge_{i}"), format!("Pledge: {}", v.pledge)),
755-
TreeItem::new_leaf(format!("cost_{i}"), format!("Cost: {}", v.cost)),
774+
TreeItem::new_leaf(
775+
format!("pledge_{i}"),
776+
format!("Pledge: {:?}", crate::utils::format_bigint_opt(&v.pledge)),
777+
),
778+
TreeItem::new_leaf(
779+
format!("cost_{i}"),
780+
format!("Cost: {:?}", crate::utils::format_bigint_opt(&v.cost)),
781+
),
756782
TreeItem::new_leaf(
757783
format!("reward_account_{i}"),
758784
format!("Reward Account: {}", hex::encode(&v.reward_account)),
@@ -875,7 +901,10 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
875901
.unwrap_or_default();
876902
target_children.push(TreeItem::new_leaf(
877903
format!("delta_coin_{i}_{j}"),
878-
format!("Delta Coin: {}", target.delta_coin),
904+
format!(
905+
"Delta Coin: {:?}",
906+
crate::utils::format_bigint_opt(&target.delta_coin)
907+
),
879908
));
880909
TreeItem::new(
881910
format!("mir_target_{i}_{j}"),
@@ -908,7 +937,7 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
908937
.unwrap_or_default();
909938
reg_children.push(TreeItem::new_leaf(
910939
format!("coin_{i}"),
911-
format!("Coin: {}", v.coin),
940+
format!("Coin: {:?}", crate::utils::format_bigint_opt(&v.coin)),
912941
));
913942
TreeItem::new(format!("reg_cert_{i}"), "Registration", reg_children)
914943
.expect("Failed to create registration certificate node")
@@ -921,7 +950,7 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
921950
.unwrap_or_default();
922951
unreg_children.push(TreeItem::new_leaf(
923952
format!("coin_{i}"),
924-
format!("Coin: {}", v.coin),
953+
format!("Coin: {:?}", crate::utils::format_bigint_opt(&v.coin)),
925954
));
926955
TreeItem::new(format!("unreg_cert_{i}"), "Unregistration", unreg_children)
927956
.expect("Failed to create unregistration certificate node")
@@ -956,7 +985,7 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
956985
));
957986
stake_reg_children.push(TreeItem::new_leaf(
958987
format!("coin_{i}"),
959-
format!("Coin: {}", v.coin),
988+
format!("Coin: {:?}", crate::utils::format_bigint_opt(&v.coin)),
960989
));
961990
TreeItem::new(
962991
format!("stake_reg_deleg_cert_{i}"),
@@ -974,7 +1003,7 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
9741003
vote_reg_children.extend(map_drep(&v.drep, i));
9751004
vote_reg_children.push(TreeItem::new_leaf(
9761005
format!("coin_{i}"),
977-
format!("Coin: {}", v.coin),
1006+
format!("Coin: {:?}", crate::utils::format_bigint_opt(&v.coin)),
9781007
));
9791008
TreeItem::new(
9801009
format!("vote_reg_deleg_cert_{i}"),
@@ -996,7 +1025,7 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
9961025
stake_vote_reg_children.extend(map_drep(&v.drep, i));
9971026
stake_vote_reg_children.push(TreeItem::new_leaf(
9981027
format!("coin_{i}"),
999-
format!("Coin: {}", v.coin),
1028+
format!("Coin: {:?}", crate::utils::format_bigint_opt(&v.coin)),
10001029
));
10011030
TreeItem::new(
10021031
format!("stake_vote_reg_deleg_cert_{i}"),
@@ -1054,7 +1083,7 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
10541083
.unwrap_or_default();
10551084
reg_drep_children.push(TreeItem::new_leaf(
10561085
format!("coin_{i}"),
1057-
format!("Coin: {}", v.coin),
1086+
format!("Coin: {:?}", crate::utils::format_bigint_opt(&v.coin)),
10581087
));
10591088
if let Some(anchor) = &v.anchor {
10601089
reg_drep_children.push(TreeItem::new_leaf(
@@ -1081,7 +1110,7 @@ fn map_cert<'a>(tx: &Tx) -> TreeItem<'a, String> {
10811110
.unwrap_or_default();
10821111
unreg_drep_children.push(TreeItem::new_leaf(
10831112
format!("coin_{i}"),
1084-
format!("Coin: {}", v.coin),
1113+
format!("Coin: {:?}", crate::utils::format_bigint_opt(&v.coin)),
10851114
));
10861115
TreeItem::new(
10871116
format!("unreg_drep_cert_{i}"),
@@ -1544,7 +1573,10 @@ fn map_withdrawal<'a>(withdrawal: &Withdrawal, index: &str) -> Vec<TreeItem<'a,
15441573
),
15451574
TreeItem::new_leaf(
15461575
format!("withdrawal_coin_{index}"),
1547-
format!("Coin: {}", withdrawal.coin),
1576+
format!(
1577+
"Coin: {:?}",
1578+
crate::utils::format_bigint_opt(&withdrawal.coin)
1579+
),
15481580
),
15491581
];
15501582
children.extend(map_redeemer(&withdrawal.redeemer, index));
@@ -1753,7 +1785,7 @@ fn map_tx_output<'a>(output: &TxOutput, index: usize, tx_hash: &str) -> TreeItem
17531785
),
17541786
TreeItem::new_leaf(
17551787
format!("output_{tx_hash}_{index}_coin"),
1756-
format!("Coin: {}", output.coin),
1788+
format!("Coin: {:?}", crate::utils::format_bigint_opt(&output.coin)),
17571789
),
17581790
];
17591791
if !output.assets.is_empty() {
@@ -1777,16 +1809,13 @@ fn map_tx_output<'a>(output: &TxOutput, index: usize, tx_hash: &str) -> TreeItem
17771809
TreeItem::new(
17781810
format!("output_asset_{policy_id}_{i}_{j}"),
17791811
format!("Asset: {name}"),
1780-
vec![
1781-
TreeItem::new_leaf(
1782-
format!("output_asset_mintcoin_{policy_id}_{i}_{j}"),
1783-
format!("Mint Coin: {}", asset.mint_coin),
1784-
),
1785-
TreeItem::new_leaf(
1786-
format!("output_asset_outputcoin_{policy_id}_{i}_{j}"),
1787-
format!("Output Coin: {}", asset.output_coin),
1812+
vec![TreeItem::new_leaf(
1813+
format!("output_asset_quantity_{policy_id}_{i}_{j}"),
1814+
format!(
1815+
"Quantity: {:?}",
1816+
crate::utils::format_asset_quantity(&asset.quantity)
17881817
),
1789-
],
1818+
)],
17901819
)
17911820
.expect("Failed to create asset node")
17921821
})

src/provider/types.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ impl Provider {
107107
.items
108108
.clone()
109109
.into_iter()
110-
.map(|x| x.parsed.unwrap().coin)
110+
.filter_map(|x| x.parsed.and_then(|p| p.coin))
111+
.filter_map(|c| {
112+
c.big_int.as_ref().and_then(|bi| match bi {
113+
utxorpc::spec::cardano::big_int::BigInt::Int(i) => Some(*i as u64),
114+
_ => None,
115+
})
116+
})
111117
.sum();
112118

113119
let assets = utxos
@@ -126,7 +132,7 @@ impl Provider {
126132
.iter()
127133
.map(|inner| Asset {
128134
name: inner.name.to_vec(),
129-
output_coin: inner.output_coin.to_string(),
135+
quantity: crate::utils::format_asset_quantity(&inner.quantity),
130136
})
131137
.collect::<Vec<Asset>>(),
132138
})
@@ -195,6 +201,7 @@ impl Provider {
195201
parsed_state: utxo
196202
.parsed
197203
.map(utxorpc::spec::query::any_utxo_data::ParsedState::Cardano),
204+
block_ref: None,
198205
})
199206
.collect();
200207

@@ -233,7 +240,7 @@ impl Provider {
233240
tx: txoref.hash.to_vec(),
234241
tx_index: txoref.index as u64,
235242
address: address.to_string(),
236-
coin: utxo.coin.to_string(),
243+
coin: crate::utils::format_bigint_opt(&utxo.coin),
237244
assets: utxo
238245
.assets
239246
.iter()
@@ -244,7 +251,7 @@ impl Provider {
244251
.iter()
245252
.map(|inner| Asset {
246253
name: inner.name.to_vec(),
247-
output_coin: inner.output_coin.to_string(),
254+
quantity: crate::utils::format_asset_quantity(&inner.quantity),
248255
})
249256
.collect::<Vec<Asset>>(),
250257
})
@@ -273,11 +280,8 @@ impl Provider {
273280
pub async fn submit(&self, tx: &[u8]) -> Result<Vec<u8>> {
274281
let mut client: CardanoSubmitClient = self.client().await?;
275282

276-
match client.submit_tx(vec![tx.to_vec()]).await {
277-
Ok(response) => response
278-
.first()
279-
.map(|r| r.to_vec())
280-
.ok_or_else(|| anyhow!("No response received from submit")),
283+
match client.submit_tx(tx.to_vec()).await {
284+
Ok(response) => Ok(response.to_vec()),
281285
Err(err) => {
282286
match err {
283287
utxorpc::Error::TransportError(e) => {

0 commit comments

Comments
 (0)