@@ -5,7 +5,8 @@ use gloo_utils::format::JsValueSerdeExt;
55use namada_sdk:: borsh:: { self , BorshDeserialize , BorshSerialize } ;
66use namada_sdk:: collections:: HashSet ;
77use namada_sdk:: masp_primitives:: transaction:: components:: sapling:: builder:: StoredBuildParams ;
8- use namada_sdk:: masp_primitives:: transaction:: components:: sapling:: fees:: { InputView , OutputView } ;
8+ use namada_sdk:: masp_primitives:: transaction:: components:: sapling:: fees:: { ConvertView , InputView , OutputView } ;
9+ use namada_sdk:: masp_primitives:: transaction:: components:: I128Sum ;
910use namada_sdk:: masp_primitives:: zip32:: ExtendedFullViewingKey ;
1011use namada_sdk:: signing:: SigningTxData ;
1112use namada_sdk:: token:: { Amount , DenominatedAmount , Transfer } ;
@@ -264,15 +265,22 @@ pub fn deserialize_tx(tx_bytes: Vec<u8>, wasm_hashes: JsValue) -> Result<Vec<u8>
264265 Ok ( borsh:: to_vec ( & tx) ?)
265266}
266267
267- #[ derive( BorshSerialize , BorshDeserialize ) ]
268+ #[ derive( Debug , BorshSerialize , BorshDeserialize ) ]
268269#[ borsh( crate = "namada_sdk::borsh" ) ]
269270pub struct TxIn {
270271 pub token : String ,
271272 pub value : String ,
272273 pub owner : String ,
273274}
274275
275- #[ derive( BorshSerialize , BorshDeserialize ) ]
276+ #[ derive( Debug , BorshSerialize , BorshDeserialize ) ]
277+ #[ borsh( crate = "namada_sdk::borsh" ) ]
278+ pub struct TxConv {
279+ pub token : String ,
280+ pub value : String ,
281+ }
282+
283+ #[ derive( Debug , BorshSerialize , BorshDeserialize ) ]
276284#[ borsh( crate = "namada_sdk::borsh" ) ]
277285pub struct TxOut {
278286 pub token : String ,
@@ -290,6 +298,7 @@ pub struct Commitment {
290298 memo : Option < String > ,
291299 masp_tx_in : Option < Vec < TxIn > > ,
292300 masp_tx_out : Option < Vec < TxOut > > ,
301+ masp_tx_conv : Option < Vec < TxConv > > ,
293302}
294303
295304#[ derive( BorshSerialize , BorshDeserialize ) ]
@@ -352,7 +361,12 @@ impl TxDetails {
352361 let tx_kind = transaction:: TransactionKind :: from ( tx_type, & tx_data) ;
353362 let data = tx_kind. to_bytes ( ) ?;
354363
355- let ( inputs, outputs) = get_masp_details ( & tx, & tx_kind) ;
364+ let ( inputs, outputs, conversions) = get_masp_details ( & tx, & tx_kind) ;
365+
366+ web_sys:: console:: log_1 ( & format ! (
367+ "Conversions: {:?}" ,
368+ conversions
369+ ) . into ( ) ) ;
356370
357371 commitments. push ( Commitment {
358372 tx_type,
@@ -362,6 +376,7 @@ impl TxDetails {
362376 memo,
363377 masp_tx_out : outputs,
364378 masp_tx_in : inputs,
379+ masp_tx_conv : conversions,
365380 } ) ;
366381 }
367382 }
@@ -380,7 +395,7 @@ impl TxDetails {
380395fn get_masp_details (
381396 tx : & tx:: Tx ,
382397 tx_kind : & transaction:: TransactionKind ,
383- ) -> ( Option < Vec < TxIn > > , Option < Vec < TxOut > > ) {
398+ ) -> ( Option < Vec < TxIn > > , Option < Vec < TxOut > > , Option < Vec < TxConv > > ) {
384399 let parse = |transfer : & Transfer | {
385400 if let Some ( shielded_hash) = transfer. shielded_section_hash {
386401 let masp_builder = tx
@@ -410,6 +425,29 @@ fn get_masp_details(
410425 } )
411426 . collect :: < Vec < _ > > ( ) ;
412427
428+ let conversions = masp_builder. builder . sapling_converts ( ) .
429+ iter ( )
430+ . map ( |convert| {
431+ let asset_data = asset_types
432+ . iter ( )
433+ . find ( |ad| {
434+ let conv_asset_types = I128Sum :: from ( convert. conversion ( ) . clone ( ) ) . asset_types ( )
435+ . cloned ( ) . collect :: < Vec < _ > > ( ) ;
436+ let ad = ad. encode ( ) . unwrap ( ) ;
437+
438+ conv_asset_types. into_iter ( ) . any ( |w| w == ad)
439+ } )
440+ . expect ( "Asset data to exist" ) ;
441+
442+ let amount = Amount :: from_u64 ( convert. value ( ) ) ;
443+ let denominated_amount = DenominatedAmount :: new ( amount, asset_data. denom ) ;
444+
445+ TxConv {
446+ token : asset_data. token . to_string ( ) ,
447+ value : denominated_amount. to_string ( ) ,
448+ }
449+ } ) . collect :: < Vec < _ > > ( ) ;
450+
413451 let outputs = masp_builder
414452 . builder
415453 . sapling_outputs ( )
@@ -431,19 +469,19 @@ fn get_masp_details(
431469 } )
432470 . collect :: < Vec < _ > > ( ) ;
433471
434- ( Some ( inputs) , Some ( outputs) )
472+ ( Some ( inputs) , Some ( outputs) , Some ( conversions ) )
435473 } else {
436- ( None , None )
474+ ( None , None , None )
437475 }
438476 } ;
439477
440478 match tx_kind {
441479 transaction:: TransactionKind :: IbcTransfer ( ibc_transfer) => match & ibc_transfer. transfer {
442480 Some ( transfer) => parse ( transfer) ,
443- None => ( None , None ) ,
481+ None => ( None , None , None ) ,
444482 } ,
445483 transaction:: TransactionKind :: Transfer ( transfer) => parse ( transfer) ,
446- _ => ( None , None ) ,
484+ _ => ( None , None , None ) ,
447485 }
448486}
449487
0 commit comments