@@ -14,17 +14,14 @@ use ratatui::{
1414} ;
1515use regex:: Regex ;
1616use 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
3027use 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 } )
0 commit comments