@@ -287,7 +287,11 @@ pub fn utxo_outpoint_to_json(utxo: &UtxoOutPoint) -> serde_json::Value {
287
287
}
288
288
}
289
289
290
- pub fn tx_input_to_json ( inp : & TxInput , chain_config : & ChainConfig ) -> serde_json:: Value {
290
+ pub fn tx_input_to_json (
291
+ inp : & TxInput ,
292
+ token_decimals : & TokenDecimals ,
293
+ chain_config : & ChainConfig ,
294
+ ) -> serde_json:: Value {
291
295
match inp {
292
296
TxInput :: Utxo ( utxo) => match utxo. source_id ( ) {
293
297
OutPointSourceId :: Transaction ( tx_id) => {
@@ -349,7 +353,7 @@ pub fn tx_input_to_json(inp: &TxInput, chain_config: &ChainConfig) -> serde_json
349
353
"input_type" : "AccountCommand" ,
350
354
"command" : "MintTokens" ,
351
355
"token_id" : Address :: new( chain_config, * token_id) . expect( "addressable" ) . to_string( ) ,
352
- "amount" : amount_to_json( * amount, chain_config . coin_decimals ( ) ) ,
356
+ "amount" : amount_to_json( * amount, token_decimals . get ( token_id ) ) ,
353
357
"nonce" : nonce,
354
358
} )
355
359
}
@@ -432,19 +436,20 @@ pub fn tx_to_json(
432
436
additional_info : & TxAdditionalInfo ,
433
437
chain_config : & ChainConfig ,
434
438
) -> serde_json:: Value {
439
+ let token_decimals = & ( & additional_info. token_decimals ) . into ( ) ;
435
440
json ! ( {
436
441
"id" : tx. get_id( ) . to_hash( ) . encode_hex:: <String >( ) ,
437
442
"version_byte" : tx. version_byte( ) ,
438
443
"is_replaceable" : tx. is_replaceable( ) ,
439
444
"flags" : tx. flags( ) ,
440
445
"fee" : amount_to_json( additional_info. fee, chain_config. coin_decimals( ) ) ,
441
446
"inputs" : tx. inputs( ) . iter( ) . zip( additional_info. input_utxos. iter( ) ) . map( |( inp, utxo) | json!( {
442
- "input" : tx_input_to_json( inp, chain_config) ,
443
- "utxo" : utxo. as_ref( ) . map( |txo| txoutput_to_json( txo, chain_config, & ( & additional_info . token_decimals) . into ( ) ) ) ,
447
+ "input" : tx_input_to_json( inp, token_decimals , chain_config) ,
448
+ "utxo" : utxo. as_ref( ) . map( |txo| txoutput_to_json( txo, chain_config, token_decimals) ) ,
444
449
} ) ) . collect:: <Vec <_>>( ) ,
445
450
"outputs" : tx. outputs( )
446
451
. iter( )
447
- . map( |out| txoutput_to_json( out, chain_config, & ( & additional_info . token_decimals) . into ( ) ) )
452
+ . map( |out| txoutput_to_json( out, chain_config, token_decimals) )
448
453
. collect:: <Vec <_>>( )
449
454
} )
450
455
}
0 commit comments