(cherry picked from commit b940da4040
)
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
use crate::parse_instruction::{ParsableProgram, ParseInstructionError, ParsedInstructionEnum};
|
use crate::parse_instruction::{ParsableProgram, ParseInstructionError, ParsedInstructionEnum};
|
||||||
use serde_json::{json, Map, Value};
|
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 solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||||
use spl_token_v2_0::{
|
use spl_token_v2_0::{
|
||||||
instruction::{AuthorityType, TokenInstruction},
|
instruction::{AuthorityType, TokenInstruction},
|
||||||
@ -92,7 +93,7 @@ pub fn parse_token(
|
|||||||
let mut value = json!({
|
let mut value = json!({
|
||||||
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||||
"destination": account_keys[instruction.accounts[1] 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();
|
let mut map = value.as_object_mut().unwrap();
|
||||||
parse_signers(
|
parse_signers(
|
||||||
@ -117,7 +118,7 @@ pub fn parse_token(
|
|||||||
let mut value = json!({
|
let mut value = json!({
|
||||||
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||||
"delegate": account_keys[instruction.accounts[1] 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();
|
let mut map = value.as_object_mut().unwrap();
|
||||||
parse_signers(
|
parse_signers(
|
||||||
@ -200,7 +201,7 @@ pub fn parse_token(
|
|||||||
let mut value = json!({
|
let mut value = json!({
|
||||||
"mint": account_keys[instruction.accounts[0] as usize].to_string(),
|
"mint": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||||
"account": account_keys[instruction.accounts[1] 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();
|
let mut map = value.as_object_mut().unwrap();
|
||||||
parse_signers(
|
parse_signers(
|
||||||
@ -225,7 +226,7 @@ pub fn parse_token(
|
|||||||
let mut value = json!({
|
let mut value = json!({
|
||||||
"account": account_keys[instruction.accounts[0] as usize].to_string(),
|
"account": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||||
"mint": account_keys[instruction.accounts[1] 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();
|
let mut map = value.as_object_mut().unwrap();
|
||||||
parse_signers(
|
parse_signers(
|
||||||
@ -323,8 +324,7 @@ pub fn parse_token(
|
|||||||
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||||
"mint": account_keys[instruction.accounts[1] as usize].to_string(),
|
"mint": account_keys[instruction.accounts[1] as usize].to_string(),
|
||||||
"destination": account_keys[instruction.accounts[2] as usize].to_string(),
|
"destination": account_keys[instruction.accounts[2] as usize].to_string(),
|
||||||
"amount": amount,
|
"tokenAmount": token_amount_to_ui_amount(amount, decimals),
|
||||||
"decimals": decimals,
|
|
||||||
});
|
});
|
||||||
let mut map = value.as_object_mut().unwrap();
|
let mut map = value.as_object_mut().unwrap();
|
||||||
parse_signers(
|
parse_signers(
|
||||||
@ -350,8 +350,7 @@ pub fn parse_token(
|
|||||||
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||||
"mint": account_keys[instruction.accounts[1] as usize].to_string(),
|
"mint": account_keys[instruction.accounts[1] as usize].to_string(),
|
||||||
"delegate": account_keys[instruction.accounts[2] as usize].to_string(),
|
"delegate": account_keys[instruction.accounts[2] as usize].to_string(),
|
||||||
"amount": amount,
|
"tokenAmount": token_amount_to_ui_amount(amount, decimals),
|
||||||
"decimals": decimals,
|
|
||||||
});
|
});
|
||||||
let mut map = value.as_object_mut().unwrap();
|
let mut map = value.as_object_mut().unwrap();
|
||||||
parse_signers(
|
parse_signers(
|
||||||
@ -376,8 +375,7 @@ pub fn parse_token(
|
|||||||
let mut value = json!({
|
let mut value = json!({
|
||||||
"mint": account_keys[instruction.accounts[0] as usize].to_string(),
|
"mint": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||||
"account": account_keys[instruction.accounts[1] as usize].to_string(),
|
"account": account_keys[instruction.accounts[1] as usize].to_string(),
|
||||||
"amount": amount,
|
"tokenAmount": token_amount_to_ui_amount(amount, decimals),
|
||||||
"decimals": decimals,
|
|
||||||
});
|
});
|
||||||
let mut map = value.as_object_mut().unwrap();
|
let mut map = value.as_object_mut().unwrap();
|
||||||
parse_signers(
|
parse_signers(
|
||||||
@ -402,8 +400,7 @@ pub fn parse_token(
|
|||||||
let mut value = json!({
|
let mut value = json!({
|
||||||
"account": account_keys[instruction.accounts[0] as usize].to_string(),
|
"account": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||||
"mint": account_keys[instruction.accounts[1] as usize].to_string(),
|
"mint": account_keys[instruction.accounts[1] as usize].to_string(),
|
||||||
"amount": amount,
|
"tokenAmount": token_amount_to_ui_amount(amount, decimals),
|
||||||
"decimals": decimals,
|
|
||||||
});
|
});
|
||||||
let mut map = value.as_object_mut().unwrap();
|
let mut map = value.as_object_mut().unwrap();
|
||||||
parse_signers(
|
parse_signers(
|
||||||
@ -620,7 +617,7 @@ mod test {
|
|||||||
"source": keys[1].to_string(),
|
"source": keys[1].to_string(),
|
||||||
"destination": keys[2].to_string(),
|
"destination": keys[2].to_string(),
|
||||||
"authority": keys[0].to_string(),
|
"authority": keys[0].to_string(),
|
||||||
"amount": 42,
|
"amount": "42",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -645,7 +642,7 @@ mod test {
|
|||||||
"destination": keys[3].to_string(),
|
"destination": keys[3].to_string(),
|
||||||
"multisigAuthority": keys[4].to_string(),
|
"multisigAuthority": keys[4].to_string(),
|
||||||
"signers": keys[0..2].iter().map(|key| key.to_string()).collect::<Vec<String>>(),
|
"signers": keys[0..2].iter().map(|key| key.to_string()).collect::<Vec<String>>(),
|
||||||
"amount": 42,
|
"amount": "42",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -670,7 +667,7 @@ mod test {
|
|||||||
"source": keys[1].to_string(),
|
"source": keys[1].to_string(),
|
||||||
"delegate": keys[2].to_string(),
|
"delegate": keys[2].to_string(),
|
||||||
"owner": keys[0].to_string(),
|
"owner": keys[0].to_string(),
|
||||||
"amount": 42,
|
"amount": "42",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -695,7 +692,7 @@ mod test {
|
|||||||
"delegate": keys[3].to_string(),
|
"delegate": keys[3].to_string(),
|
||||||
"multisigOwner": keys[4].to_string(),
|
"multisigOwner": keys[4].to_string(),
|
||||||
"signers": keys[0..2].iter().map(|key| key.to_string()).collect::<Vec<String>>(),
|
"signers": keys[0..2].iter().map(|key| key.to_string()).collect::<Vec<String>>(),
|
||||||
"amount": 42,
|
"amount": "42",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -791,7 +788,7 @@ mod test {
|
|||||||
"mint": keys[1].to_string(),
|
"mint": keys[1].to_string(),
|
||||||
"account": keys[2].to_string(),
|
"account": keys[2].to_string(),
|
||||||
"mintAuthority": keys[0].to_string(),
|
"mintAuthority": keys[0].to_string(),
|
||||||
"amount": 42,
|
"amount": "42",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -816,7 +813,7 @@ mod test {
|
|||||||
"account": keys[1].to_string(),
|
"account": keys[1].to_string(),
|
||||||
"mint": keys[2].to_string(),
|
"mint": keys[2].to_string(),
|
||||||
"authority": keys[0].to_string(),
|
"authority": keys[0].to_string(),
|
||||||
"amount": 42,
|
"amount": "42",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -913,8 +910,11 @@ mod test {
|
|||||||
"destination": keys[2].to_string(),
|
"destination": keys[2].to_string(),
|
||||||
"mint": keys[3].to_string(),
|
"mint": keys[3].to_string(),
|
||||||
"authority": keys[0].to_string(),
|
"authority": keys[0].to_string(),
|
||||||
"amount": 42,
|
"tokenAmount": {
|
||||||
|
"uiAmount": 0.42,
|
||||||
"decimals": 2,
|
"decimals": 2,
|
||||||
|
"amount": "42"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -942,8 +942,11 @@ mod test {
|
|||||||
"mint": keys[4].to_string(),
|
"mint": keys[4].to_string(),
|
||||||
"multisigAuthority": keys[5].to_string(),
|
"multisigAuthority": keys[5].to_string(),
|
||||||
"signers": keys[0..2].iter().map(|key| key.to_string()).collect::<Vec<String>>(),
|
"signers": keys[0..2].iter().map(|key| key.to_string()).collect::<Vec<String>>(),
|
||||||
"amount": 42,
|
"tokenAmount": {
|
||||||
|
"uiAmount": 0.42,
|
||||||
"decimals": 2,
|
"decimals": 2,
|
||||||
|
"amount": "42"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -971,8 +974,11 @@ mod test {
|
|||||||
"mint": keys[2].to_string(),
|
"mint": keys[2].to_string(),
|
||||||
"delegate": keys[3].to_string(),
|
"delegate": keys[3].to_string(),
|
||||||
"owner": keys[0].to_string(),
|
"owner": keys[0].to_string(),
|
||||||
"amount": 42,
|
"tokenAmount": {
|
||||||
|
"uiAmount": 0.42,
|
||||||
"decimals": 2,
|
"decimals": 2,
|
||||||
|
"amount": "42"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -1000,8 +1006,11 @@ mod test {
|
|||||||
"delegate": keys[4].to_string(),
|
"delegate": keys[4].to_string(),
|
||||||
"multisigOwner": keys[5].to_string(),
|
"multisigOwner": keys[5].to_string(),
|
||||||
"signers": keys[0..2].iter().map(|key| key.to_string()).collect::<Vec<String>>(),
|
"signers": keys[0..2].iter().map(|key| key.to_string()).collect::<Vec<String>>(),
|
||||||
"amount": 42,
|
"tokenAmount": {
|
||||||
|
"uiAmount": 0.42,
|
||||||
"decimals": 2,
|
"decimals": 2,
|
||||||
|
"amount": "42"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -1027,8 +1036,11 @@ mod test {
|
|||||||
"mint": keys[1].to_string(),
|
"mint": keys[1].to_string(),
|
||||||
"account": keys[2].to_string(),
|
"account": keys[2].to_string(),
|
||||||
"mintAuthority": keys[0].to_string(),
|
"mintAuthority": keys[0].to_string(),
|
||||||
"amount": 42,
|
"tokenAmount": {
|
||||||
|
"uiAmount": 0.42,
|
||||||
"decimals": 2,
|
"decimals": 2,
|
||||||
|
"amount": "42"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -1054,8 +1066,11 @@ mod test {
|
|||||||
"account": keys[1].to_string(),
|
"account": keys[1].to_string(),
|
||||||
"mint": keys[2].to_string(),
|
"mint": keys[2].to_string(),
|
||||||
"authority": keys[0].to_string(),
|
"authority": keys[0].to_string(),
|
||||||
"amount": 42,
|
"tokenAmount": {
|
||||||
|
"uiAmount": 0.42,
|
||||||
"decimals": 2,
|
"decimals": 2,
|
||||||
|
"amount": "42"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user