diff --git a/transaction-status/src/parse_token.rs b/transaction-status/src/parse_token.rs index bd4b69d346..fff20abc92 100644 --- a/transaction-status/src/parse_token.rs +++ b/transaction-status/src/parse_token.rs @@ -1,5 +1,6 @@ use crate::parse_instruction::{ParsableProgram, ParseInstructionError, ParsedInstructionEnum}; use serde_json::{json, Map, Value}; +use solana_account_decoder::parse_token::token_amount_to_ui_amount; use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey}; use spl_token_v2_0::{ instruction::{AuthorityType, TokenInstruction}, @@ -92,7 +93,7 @@ pub fn parse_token( let mut value = json!({ "source": account_keys[instruction.accounts[0] as usize].to_string(), "destination": account_keys[instruction.accounts[1] as usize].to_string(), - "amount": amount, + "amount": amount.to_string(), }); let mut map = value.as_object_mut().unwrap(); parse_signers( @@ -117,7 +118,7 @@ pub fn parse_token( let mut value = json!({ "source": account_keys[instruction.accounts[0] as usize].to_string(), "delegate": account_keys[instruction.accounts[1] as usize].to_string(), - "amount": amount, + "amount": amount.to_string(), }); let mut map = value.as_object_mut().unwrap(); parse_signers( @@ -200,7 +201,7 @@ pub fn parse_token( let mut value = json!({ "mint": account_keys[instruction.accounts[0] as usize].to_string(), "account": account_keys[instruction.accounts[1] as usize].to_string(), - "amount": amount, + "amount": amount.to_string(), }); let mut map = value.as_object_mut().unwrap(); parse_signers( @@ -225,7 +226,7 @@ pub fn parse_token( let mut value = json!({ "account": account_keys[instruction.accounts[0] as usize].to_string(), "mint": account_keys[instruction.accounts[1] as usize].to_string(), - "amount": amount, + "amount": amount.to_string(), }); let mut map = value.as_object_mut().unwrap(); parse_signers( @@ -323,8 +324,7 @@ pub fn parse_token( "source": account_keys[instruction.accounts[0] as usize].to_string(), "mint": account_keys[instruction.accounts[1] as usize].to_string(), "destination": account_keys[instruction.accounts[2] as usize].to_string(), - "amount": amount, - "decimals": decimals, + "tokenAmount": token_amount_to_ui_amount(amount, decimals), }); let mut map = value.as_object_mut().unwrap(); parse_signers( @@ -350,8 +350,7 @@ pub fn parse_token( "source": account_keys[instruction.accounts[0] as usize].to_string(), "mint": account_keys[instruction.accounts[1] as usize].to_string(), "delegate": account_keys[instruction.accounts[2] as usize].to_string(), - "amount": amount, - "decimals": decimals, + "tokenAmount": token_amount_to_ui_amount(amount, decimals), }); let mut map = value.as_object_mut().unwrap(); parse_signers( @@ -376,8 +375,7 @@ pub fn parse_token( let mut value = json!({ "mint": account_keys[instruction.accounts[0] as usize].to_string(), "account": account_keys[instruction.accounts[1] as usize].to_string(), - "amount": amount, - "decimals": decimals, + "tokenAmount": token_amount_to_ui_amount(amount, decimals), }); let mut map = value.as_object_mut().unwrap(); parse_signers( @@ -402,8 +400,7 @@ pub fn parse_token( let mut value = json!({ "account": account_keys[instruction.accounts[0] as usize].to_string(), "mint": account_keys[instruction.accounts[1] as usize].to_string(), - "amount": amount, - "decimals": decimals, + "tokenAmount": token_amount_to_ui_amount(amount, decimals), }); let mut map = value.as_object_mut().unwrap(); parse_signers( @@ -620,7 +617,7 @@ mod test { "source": keys[1].to_string(), "destination": keys[2].to_string(), "authority": keys[0].to_string(), - "amount": 42, + "amount": "42", }) } ); @@ -645,7 +642,7 @@ mod test { "destination": keys[3].to_string(), "multisigAuthority": keys[4].to_string(), "signers": keys[0..2].iter().map(|key| key.to_string()).collect::>(), - "amount": 42, + "amount": "42", }) } ); @@ -670,7 +667,7 @@ mod test { "source": keys[1].to_string(), "delegate": keys[2].to_string(), "owner": keys[0].to_string(), - "amount": 42, + "amount": "42", }) } ); @@ -695,7 +692,7 @@ mod test { "delegate": keys[3].to_string(), "multisigOwner": keys[4].to_string(), "signers": keys[0..2].iter().map(|key| key.to_string()).collect::>(), - "amount": 42, + "amount": "42", }) } ); @@ -791,7 +788,7 @@ mod test { "mint": keys[1].to_string(), "account": keys[2].to_string(), "mintAuthority": keys[0].to_string(), - "amount": 42, + "amount": "42", }) } ); @@ -816,7 +813,7 @@ mod test { "account": keys[1].to_string(), "mint": keys[2].to_string(), "authority": keys[0].to_string(), - "amount": 42, + "amount": "42", }) } ); @@ -913,8 +910,11 @@ mod test { "destination": keys[2].to_string(), "mint": keys[3].to_string(), "authority": keys[0].to_string(), - "amount": 42, - "decimals": 2, + "tokenAmount": { + "uiAmount": 0.42, + "decimals": 2, + "amount": "42" + } }) } ); @@ -942,8 +942,11 @@ mod test { "mint": keys[4].to_string(), "multisigAuthority": keys[5].to_string(), "signers": keys[0..2].iter().map(|key| key.to_string()).collect::>(), - "amount": 42, - "decimals": 2, + "tokenAmount": { + "uiAmount": 0.42, + "decimals": 2, + "amount": "42" + } }) } ); @@ -971,8 +974,11 @@ mod test { "mint": keys[2].to_string(), "delegate": keys[3].to_string(), "owner": keys[0].to_string(), - "amount": 42, - "decimals": 2, + "tokenAmount": { + "uiAmount": 0.42, + "decimals": 2, + "amount": "42" + } }) } ); @@ -995,13 +1001,16 @@ mod test { ParsedInstructionEnum { instruction_type: "approve2".to_string(), info: json!({ - "source": keys[2].to_string(), - "mint": keys[3].to_string(), - "delegate": keys[4].to_string(), - "multisigOwner": keys[5].to_string(), - "signers": keys[0..2].iter().map(|key| key.to_string()).collect::>(), - "amount": 42, - "decimals": 2, + "source": keys[2].to_string(), + "mint": keys[3].to_string(), + "delegate": keys[4].to_string(), + "multisigOwner": keys[5].to_string(), + "signers": keys[0..2].iter().map(|key| key.to_string()).collect::>(), + "tokenAmount": { + "uiAmount": 0.42, + "decimals": 2, + "amount": "42" + } }) } ); @@ -1027,8 +1036,11 @@ mod test { "mint": keys[1].to_string(), "account": keys[2].to_string(), "mintAuthority": keys[0].to_string(), - "amount": 42, - "decimals": 2, + "tokenAmount": { + "uiAmount": 0.42, + "decimals": 2, + "amount": "42" + } }) } ); @@ -1054,8 +1066,11 @@ mod test { "account": keys[1].to_string(), "mint": keys[2].to_string(), "authority": keys[0].to_string(), - "amount": 42, - "decimals": 2, + "tokenAmount": { + "uiAmount": 0.42, + "decimals": 2, + "amount": "42" + } }) } );