Skip to content

Commit f9dbc8a

Browse files
committed
fix mint token decimals in Api Server
1 parent 6b4aa39 commit f9dbc8a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

api-server/stack-test-suite/tests/v2/transaction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ async fn multiple_tx_in_same_block(#[case] seed: Seed) {
196196
"is_replaceable": transaction.is_replaceable(),
197197
"flags": transaction.flags(),
198198
"inputs": transaction.inputs().iter().zip(utxos).map(|(inp, utxo)| json!({
199-
"input": tx_input_to_json(inp, &chain_config),
199+
"input": tx_input_to_json(inp, &TokenDecimals::Single(None), &chain_config),
200200
"utxo": utxo.as_ref().map(|txo| txoutput_to_json(txo, &chain_config, &TokenDecimals::Single(None))),
201201
})).collect::<Vec<_>>(),
202202
"outputs": transaction.outputs()
@@ -342,7 +342,7 @@ async fn ok(#[case] seed: Seed) {
342342
"is_replaceable": transaction.is_replaceable(),
343343
"flags": transaction.flags(),
344344
"inputs": transaction.inputs().iter().zip(utxos).map(|(inp, utxo)| json!({
345-
"input": tx_input_to_json(inp, &chain_config),
345+
"input": tx_input_to_json(inp, &TokenDecimals::Single(None), &chain_config),
346346
"utxo": utxo.as_ref().map(|txo| txoutput_to_json(txo, &chain_config, &TokenDecimals::Single(None))),
347347
})).collect::<Vec<_>>(),
348348
"outputs": transaction.outputs()

api-server/web-server/src/api/json_helpers.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ pub fn utxo_outpoint_to_json(utxo: &UtxoOutPoint) -> serde_json::Value {
287287
}
288288
}
289289

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 {
291295
match inp {
292296
TxInput::Utxo(utxo) => match utxo.source_id() {
293297
OutPointSourceId::Transaction(tx_id) => {
@@ -349,7 +353,7 @@ pub fn tx_input_to_json(inp: &TxInput, chain_config: &ChainConfig) -> serde_json
349353
"input_type": "AccountCommand",
350354
"command": "MintTokens",
351355
"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)),
353357
"nonce": nonce,
354358
})
355359
}
@@ -432,19 +436,20 @@ pub fn tx_to_json(
432436
additional_info: &TxAdditionalInfo,
433437
chain_config: &ChainConfig,
434438
) -> serde_json::Value {
439+
let token_decimals = &(&additional_info.token_decimals).into();
435440
json!({
436441
"id": tx.get_id().to_hash().encode_hex::<String>(),
437442
"version_byte": tx.version_byte(),
438443
"is_replaceable": tx.is_replaceable(),
439444
"flags": tx.flags(),
440445
"fee": amount_to_json(additional_info.fee, chain_config.coin_decimals()),
441446
"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)),
444449
})).collect::<Vec<_>>(),
445450
"outputs": tx.outputs()
446451
.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))
448453
.collect::<Vec<_>>()
449454
})
450455
}

0 commit comments

Comments
 (0)