@@ -50,7 +50,6 @@ use crate::error::{EncodingError, Error, TxSubmitError};
50
50
use crate :: eth_bridge_pool:: PendingTransfer ;
51
51
use crate :: governance:: storage:: proposal:: { AddRemove , PGFAction , PGFTarget } ;
52
52
use crate :: rpc:: validate_amount;
53
- use crate :: token:: Account ;
54
53
use crate :: tx:: {
55
54
Commitment , TX_BECOME_VALIDATOR_WASM , TX_BOND_WASM , TX_BRIDGE_POOL_WASM ,
56
55
TX_CHANGE_COMMISSION_WASM , TX_CHANGE_CONSENSUS_KEY_WASM ,
@@ -707,7 +706,7 @@ pub struct LedgerVector {
707
706
708
707
/// Adds a Ledger output line describing a given transaction amount and address
709
708
fn make_ledger_amount_addr (
710
- tokens : & HashMap < Address , String > ,
709
+ tokens : & HashMap < Address , & str > ,
711
710
output : & mut Vec < String > ,
712
711
amount : DenominatedAmount ,
713
712
token : & Address ,
@@ -717,7 +716,7 @@ fn make_ledger_amount_addr(
717
716
output. push ( format ! (
718
717
"{}Amount : {} {}" ,
719
718
prefix,
720
- token. to_uppercase ( ) ,
719
+ token,
721
720
to_ledger_decimal_variable_token( amount) ,
722
721
) ) ;
723
722
} else {
@@ -735,7 +734,7 @@ fn make_ledger_amount_addr(
735
734
/// Adds a Ledger output line describing a given transaction amount and asset
736
735
/// type
737
736
async fn make_ledger_amount_asset (
738
- tokens : & HashMap < Address , String > ,
737
+ tokens : & HashMap < Address , & str > ,
739
738
output : & mut Vec < String > ,
740
739
amount : u64 ,
741
740
token : & AssetType ,
@@ -752,7 +751,7 @@ async fn make_ledger_amount_asset(
752
751
output. push ( format ! (
753
752
"{}Amount : {} {}" ,
754
753
prefix,
755
- token. to_uppercase ( ) ,
754
+ token,
756
755
to_ledger_decimal_variable_token( amount) ,
757
756
) ) ;
758
757
} else {
@@ -822,37 +821,26 @@ fn format_outputs(output: &mut Vec<String>) {
822
821
}
823
822
}
824
823
825
- /// Convert a map with key pairs into a nested structure
826
- fn nest_map < V > (
827
- map : BTreeMap < Account , V > ,
828
- ) -> BTreeMap < Address , BTreeMap < Address , V > > {
829
- let mut nested = BTreeMap :: new ( ) ;
830
- for ( account, v) in map {
831
- let inner: & mut BTreeMap < _ , _ > =
832
- nested. entry ( account. owner ) . or_default ( ) ;
833
- inner. insert ( account. token , v) ;
834
- }
835
- nested
836
- }
837
-
838
824
/// Adds a Ledger output for the senders and destinations for transparent and
839
825
/// MASP transactions
840
826
async fn make_ledger_token_transfer_endpoints (
841
- tokens : & HashMap < Address , String > ,
827
+ tokens : & HashMap < Address , & str > ,
842
828
output : & mut Vec < String > ,
843
829
transfer : & token:: Transfer ,
844
830
builder : Option < & MaspBuilder > ,
845
831
assets : & HashMap < AssetType , AssetData > ,
846
832
) -> Result < ( ) , Error > {
847
- for ( owner, changes ) in nest_map ( transfer. sources . clone ( ) ) {
833
+ for ( owner, amount ) in transfer. sources . clone ( ) {
848
834
// MASP inputs will be printed below
849
- if owner != MASP {
850
- output. push ( format ! ( "Sender : {}" , owner) ) ;
851
- for ( token, amount) in changes {
852
- make_ledger_amount_addr (
853
- tokens, output, amount, & token, "Sending " ,
854
- ) ;
855
- }
835
+ if owner. owner != MASP {
836
+ output. push ( format ! ( "Sender : {}" , owner. owner) ) ;
837
+ make_ledger_amount_addr (
838
+ tokens,
839
+ output,
840
+ amount,
841
+ & owner. token ,
842
+ "Sending " ,
843
+ ) ;
856
844
}
857
845
}
858
846
if let Some ( builder) = builder {
@@ -870,19 +858,17 @@ async fn make_ledger_token_transfer_endpoints(
870
858
. await ;
871
859
}
872
860
}
873
- for ( owner, changes ) in nest_map ( transfer. targets . clone ( ) ) {
861
+ for ( owner, amount ) in transfer. targets . clone ( ) {
874
862
// MASP outputs will be printed below
875
- if owner != MASP {
876
- output. push ( format ! ( "Destination : {}" , owner) ) ;
877
- for ( token, amount) in changes {
878
- make_ledger_amount_addr (
879
- tokens,
880
- output,
881
- amount,
882
- & token,
883
- "Receiving " ,
884
- ) ;
885
- }
863
+ if owner. owner != MASP {
864
+ output. push ( format ! ( "Destination : {}" , owner. owner) ) ;
865
+ make_ledger_amount_addr (
866
+ tokens,
867
+ output,
868
+ amount,
869
+ & owner. token ,
870
+ "Receiving " ,
871
+ ) ;
886
872
}
887
873
}
888
874
if let Some ( builder) = builder {
@@ -1156,16 +1142,9 @@ fn format_timeout_height(height: &TimeoutHeight) -> String {
1156
1142
/// Converts the given transaction to the form that is displayed on the Ledger
1157
1143
/// device
1158
1144
pub async fn to_ledger_vector (
1159
- wallet : & Wallet < impl WalletIo > ,
1145
+ tokens : & HashMap < Address , & str > ,
1160
1146
tx : & Tx ,
1161
1147
) -> Result < LedgerVector , Error > {
1162
- // To facilitate lookups of human-readable token names
1163
- let tokens: HashMap < Address , String > = wallet
1164
- . get_addresses ( )
1165
- . into_iter ( )
1166
- . map ( |( alias, addr) | ( addr, alias) )
1167
- . collect ( ) ;
1168
-
1169
1148
let mut tv = LedgerVector {
1170
1149
blob : HEXLOWER . encode ( & tx. serialize_to_vec ( ) ) ,
1171
1150
index : 0 ,
@@ -1498,15 +1477,15 @@ pub async fn to_ledger_vector(
1498
1477
)
1499
1478
. map_err ( |_| Error :: Other ( "Invalid Data" . to_string ( ) ) ) ?;
1500
1479
make_ledger_token_transfer_endpoints (
1501
- & tokens,
1480
+ tokens,
1502
1481
& mut tv. output ,
1503
1482
& transfer,
1504
1483
builder,
1505
1484
& asset_types,
1506
1485
)
1507
1486
. await ?;
1508
1487
make_ledger_token_transfer_endpoints (
1509
- & tokens,
1488
+ tokens,
1510
1489
& mut tv. output_expert ,
1511
1490
& transfer,
1512
1491
builder,
@@ -1596,15 +1575,15 @@ pub async fn to_ledger_vector(
1596
1575
)
1597
1576
. map_err ( |_| Error :: Other ( "Invalid Data" . to_string ( ) ) ) ?;
1598
1577
make_ledger_token_transfer_endpoints (
1599
- & tokens,
1578
+ tokens,
1600
1579
& mut tv. output ,
1601
1580
& transfer,
1602
1581
builder,
1603
1582
& asset_types,
1604
1583
)
1605
1584
. await ?;
1606
1585
make_ledger_token_transfer_endpoints (
1607
- & tokens,
1586
+ tokens,
1608
1587
& mut tv. output_expert ,
1609
1588
& transfer,
1610
1589
builder,
@@ -1765,15 +1744,15 @@ pub async fn to_ledger_vector(
1765
1744
)
1766
1745
. map_err ( |_| Error :: Other ( "Invalid Data" . to_string ( ) ) ) ?;
1767
1746
make_ledger_token_transfer_endpoints (
1768
- & tokens,
1747
+ tokens,
1769
1748
& mut tv. output ,
1770
1749
& transfer,
1771
1750
builder,
1772
1751
& asset_types,
1773
1752
)
1774
1753
. await ?;
1775
1754
make_ledger_token_transfer_endpoints (
1776
- & tokens,
1755
+ tokens,
1777
1756
& mut tv. output_expert ,
1778
1757
& transfer,
1779
1758
builder,
@@ -2218,15 +2197,10 @@ pub async fn to_ledger_vector(
2218
2197
format!( "Gas limit : {}" , u64 :: from( wrapper. gas_limit) ) ,
2219
2198
] ) ;
2220
2199
if let Some ( token) = tokens. get ( & wrapper. fee . token ) {
2221
- tv. output . push ( format ! (
2222
- "Fee : {} {}" ,
2223
- token. to_uppercase( ) ,
2224
- fee_limit
2225
- ) ) ;
2200
+ tv. output . push ( format ! ( "Fee : {} {}" , token, fee_limit) ) ;
2226
2201
tv. output_expert . push ( format ! (
2227
2202
"Fees/gas unit : {} {}" ,
2228
- token. to_uppercase( ) ,
2229
- fee_amount_per_gas_unit,
2203
+ token, fee_amount_per_gas_unit,
2230
2204
) ) ;
2231
2205
} else {
2232
2206
tv. output . extend ( vec ! [
@@ -2274,6 +2248,7 @@ mod test_signing {
2274
2248
use crate :: args:: InputAmount ;
2275
2249
use crate :: masp:: fs:: FsShieldedUtils ;
2276
2250
use crate :: masp:: { ShieldedContext , WalletMap } ;
2251
+ use crate :: token:: Account ;
2277
2252
2278
2253
fn arbitrary_args ( ) -> args:: Tx {
2279
2254
args:: Tx {
@@ -2688,14 +2663,8 @@ mod test_signing {
2688
2663
shielded_section_hash : None ,
2689
2664
} ;
2690
2665
let tokens = HashMap :: from ( [
2691
- (
2692
- Address :: Internal ( InternalAddress :: Governance ) ,
2693
- "SuperMoney" . to_string ( ) ,
2694
- ) ,
2695
- (
2696
- Address :: Internal ( InternalAddress :: Pgf ) ,
2697
- "BloodMoney" . to_string ( ) ,
2698
- ) ,
2666
+ ( Address :: Internal ( InternalAddress :: Governance ) , "SuperMoney" ) ,
2667
+ ( Address :: Internal ( InternalAddress :: Pgf ) , "BloodMoney" ) ,
2699
2668
] ) ;
2700
2669
2701
2670
let mut output = vec ! [ ] ;
@@ -2714,12 +2683,12 @@ mod test_signing {
2714
2683
"Sender : {}" ,
2715
2684
Address :: Internal ( InternalAddress :: Governance )
2716
2685
) ,
2717
- "Sending Amount : SUPERMONEY 1" . to_string( ) ,
2686
+ "Sending Amount : SuperMoney 1" . to_string( ) ,
2718
2687
format!(
2719
2688
"Destination : {}" ,
2720
2689
Address :: Internal ( InternalAddress :: Pgf )
2721
2690
) ,
2722
- "Receiving Amount : BLOODMONEY 2" . to_string( ) ,
2691
+ "Receiving Amount : BloodMoney 2" . to_string( ) ,
2723
2692
] ;
2724
2693
assert_eq ! ( output, expected) ;
2725
2694
output. clear ( ) ;
@@ -2761,8 +2730,7 @@ mod test_signing {
2761
2730
/// extracts and validates the presence of a code section
2762
2731
#[ tokio:: test]
2763
2732
async fn test_to_ledger_vector_code_sections ( ) {
2764
- let wallet =
2765
- Wallet :: < TestWalletUtils > :: new ( TestWalletUtils , Default :: default ( ) ) ;
2733
+ let wallet = HashMap :: new ( ) ;
2766
2734
let mut tx = Tx :: new ( ChainId :: default ( ) , None ) ;
2767
2735
// an empty tx should work correctly
2768
2736
to_ledger_vector ( & wallet, & tx) . await . expect ( "Test failed" ) ;
0 commit comments