Update to token pack/unpack changes (#11900)

This commit is contained in:
Tyera Eulberg
2020-08-28 22:06:30 -06:00
committed by GitHub
parent c4253dc0f9
commit 2eff9a19c3
6 changed files with 26 additions and 27 deletions

View File

@ -65,7 +65,6 @@ use spl_token_v2_0::{
use std::{
cmp::{max, min},
collections::{HashMap, HashSet},
mem::size_of,
net::SocketAddr,
str::FromStr,
sync::{
@ -1080,7 +1079,7 @@ impl JsonRpcRequestProcessor {
encoding: None,
}),
// Filter on Token Account state
RpcFilterType::DataSize(size_of::<TokenAccount>() as u64),
RpcFilterType::DataSize(TokenAccount::get_packed_len() as u64),
];
let mut token_balances: Vec<RpcTokenAccountBalance> =
get_filtered_program_accounts(&bank, &mint_owner, filters)
@ -1128,7 +1127,7 @@ impl JsonRpcRequestProcessor {
encoding: None,
}),
// Filter on Token Account state
RpcFilterType::DataSize(size_of::<TokenAccount>() as u64),
RpcFilterType::DataSize(TokenAccount::get_packed_len() as u64),
];
if let Some(mint) = mint {
// Optional filter on Mint address
@ -1187,7 +1186,7 @@ impl JsonRpcRequestProcessor {
encoding: None,
}),
// Filter on Token Account state
RpcFilterType::DataSize(size_of::<TokenAccount>() as u64),
RpcFilterType::DataSize(TokenAccount::get_packed_len() as u64),
];
if let Some(mint) = mint {
// Optional filter on Mint address
@ -4727,7 +4726,7 @@ pub mod tests {
fn test_token_rpcs() {
let RpcHandler { io, meta, bank, .. } = start_rpc_handler_with_tx(&Pubkey::new_rand());
let mut account_data = [0; size_of::<TokenAccount>()];
let mut account_data = vec![0; TokenAccount::get_packed_len()];
let mint = SplTokenPubkey::new(&[2; 32]);
let owner = SplTokenPubkey::new(&[3; 32]);
let delegate = SplTokenPubkey::new(&[4; 32]);
@ -4755,7 +4754,7 @@ pub mod tests {
bank.store_account(&token_account_pubkey, &token_account);
// Add the mint
let mut mint_data = [0; size_of::<Mint>()];
let mut mint_data = vec![0; Mint::get_packed_len()];
Mint::unpack_unchecked_mut(&mut mint_data, &mut |mint: &mut Mint| {
*mint = Mint {
mint_authority: COption::Some(owner),
@ -4829,7 +4828,7 @@ pub mod tests {
bank.store_account(&other_token_account_pubkey, &token_account);
// Add another token account with the same owner and delegate but different mint
let mut account_data = [0; size_of::<TokenAccount>()];
let mut account_data = vec![0; TokenAccount::get_packed_len()];
let new_mint = SplTokenPubkey::new(&[5; 32]);
TokenAccount::unpack_unchecked_mut(&mut account_data, &mut |account: &mut TokenAccount| {
*account = TokenAccount {
@ -5038,7 +5037,7 @@ pub mod tests {
assert!(accounts.is_empty());
// Add new_mint, and another token account on new_mint with different balance
let mut mint_data = [0; size_of::<Mint>()];
let mut mint_data = vec![0; Mint::get_packed_len()];
Mint::unpack_unchecked_mut(&mut mint_data, &mut |mint: &mut Mint| {
*mint = Mint {
mint_authority: COption::Some(owner),
@ -5060,7 +5059,7 @@ pub mod tests {
&Pubkey::from_str(&new_mint.to_string()).unwrap(),
&mint_account,
);
let mut account_data = [0; size_of::<TokenAccount>()];
let mut account_data = vec![0; TokenAccount::get_packed_len()];
TokenAccount::unpack_unchecked_mut(&mut account_data, &mut |account: &mut TokenAccount| {
*account = TokenAccount {
mint: new_mint,
@ -5121,7 +5120,7 @@ pub mod tests {
fn test_token_parsing() {
let RpcHandler { io, meta, bank, .. } = start_rpc_handler_with_tx(&Pubkey::new_rand());
let mut account_data = [0; size_of::<TokenAccount>()];
let mut account_data = vec![0; TokenAccount::get_packed_len()];
let mint = SplTokenPubkey::new(&[2; 32]);
let owner = SplTokenPubkey::new(&[3; 32]);
let delegate = SplTokenPubkey::new(&[4; 32]);
@ -5149,7 +5148,7 @@ pub mod tests {
bank.store_account(&token_account_pubkey, &token_account);
// Add the mint
let mut mint_data = [0; size_of::<Mint>()];
let mut mint_data = vec![0; Mint::get_packed_len()];
Mint::unpack_unchecked_mut(&mut mint_data, &mut |mint: &mut Mint| {
*mint = Mint {
mint_authority: COption::Some(owner),
@ -5180,7 +5179,7 @@ pub mod tests {
result["result"]["value"]["data"],
json!({
"program": "spl-token",
"space": 176,
"space": TokenAccount::get_packed_len(),
"parsed": {
"type": "account",
"info": {
@ -5222,7 +5221,7 @@ pub mod tests {
result["result"]["value"]["data"],
json!({
"program": "spl-token",
"space": 88,
"space": Mint::get_packed_len(),
"parsed": {
"type": "mint",
"info": {