@@ -27,7 +27,7 @@ use crate::{
27
27
stake_info:: { FullStakeInfo , StakeInfo , StakedNativeTokenInfo } ,
28
28
} ,
29
29
responses:: WithErrorResponses ,
30
- types:: cardano:: cip19_stake_address:: Cip19StakeAddress ,
30
+ types:: cardano:: { asset_name :: AssetName , cip19_stake_address:: Cip19StakeAddress } ,
31
31
} ,
32
32
} ;
33
33
@@ -79,8 +79,7 @@ struct TxoAssetInfo {
79
79
/// Asset hash.
80
80
id : Vec < u8 > ,
81
81
/// Asset name.
82
- // TODO: https://github.com/input-output-hk/catalyst-voices/issues/1121
83
- name : String ,
82
+ name : AssetName ,
84
83
/// Asset amount.
85
84
amount : num_bigint:: BigInt ,
86
85
}
@@ -100,8 +99,7 @@ struct TxoInfo {
100
99
/// Whether the TXO was spent.
101
100
spent_slot_no : Option < num_bigint:: BigInt > ,
102
101
/// TXO assets.
103
- // TODO: https://github.com/input-output-hk/catalyst-voices/issues/1121
104
- assets : HashMap < Vec < u8 > , TxoAssetInfo > ,
102
+ assets : HashMap < Vec < u8 > , Vec < TxoAssetInfo > > ,
105
103
}
106
104
107
105
/// Calculate the stake info for a given stake address.
@@ -186,12 +184,18 @@ async fn get_txo_by_txn(
186
184
let entry = txo_info
187
185
. assets
188
186
. entry ( row. policy_id . clone ( ) )
189
- . or_insert ( TxoAssetInfo {
190
- id : row. policy_id ,
191
- name : row. policy_name ,
192
- amount : num_bigint:: BigInt :: ZERO ,
193
- } ) ;
194
- entry. amount += row. value ;
187
+ . or_insert_with ( Vec :: new) ;
188
+
189
+ match entry. iter_mut ( ) . find ( |item| item. id == row. policy_id ) {
190
+ Some ( item) => item. amount += row. value ,
191
+ None => {
192
+ entry. push ( TxoAssetInfo {
193
+ id : row. policy_id ,
194
+ name : row. asset_name . into ( ) ,
195
+ amount : row. value ,
196
+ } ) ;
197
+ } ,
198
+ }
195
199
}
196
200
197
201
let mut txos_by_txn = HashMap :: new ( ) ;
@@ -274,10 +278,10 @@ fn build_stake_info(
274
278
stake_info. ada_amount +=
275
279
i64:: try_from ( txo_info. value ) . map_err ( |err| anyhow ! ( err) ) ?;
276
280
277
- for asset in txo_info. assets . into_values ( ) {
281
+ for asset in txo_info. assets . into_values ( ) . flatten ( ) {
278
282
stake_info. native_tokens . push ( StakedNativeTokenInfo {
279
283
policy_hash : asset. id . try_into ( ) ?,
280
- asset_name : asset. name . into ( ) ,
284
+ asset_name : asset. name ,
281
285
amount : asset. amount . try_into ( ) ?,
282
286
} ) ;
283
287
}
0 commit comments