Skip to content

Commit

Permalink
Use internal function for encoding accounts (solana-labs#22822)
Browse files Browse the repository at this point in the history
* Use internal function for encoding accounts

* fix tests
  • Loading branch information
fanatid authored Feb 1, 2022
1 parent 65f8f43 commit 4bc3a11
Showing 1 changed file with 32 additions and 43 deletions.
75 changes: 32 additions & 43 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,17 +1800,13 @@ impl JsonRpcRequestProcessor {
} else {
keyed_accounts
.into_iter()
.map(|(pubkey, account)| RpcKeyedAccount {
pubkey: pubkey.to_string(),
account: UiAccount::encode(
&pubkey,
&account,
encoding,
None,
data_slice_config,
),
.map(|(pubkey, account)| {
Ok(RpcKeyedAccount {
pubkey: pubkey.to_string(),
account: encode_account(&account, &pubkey, encoding, data_slice_config)?,
})
})
.collect()
.collect::<Result<Vec<_>>>()?
};
Ok(new_response(&bank, accounts))
}
Expand Down Expand Up @@ -1857,17 +1853,13 @@ impl JsonRpcRequestProcessor {
} else {
keyed_accounts
.into_iter()
.map(|(pubkey, account)| RpcKeyedAccount {
pubkey: pubkey.to_string(),
account: UiAccount::encode(
&pubkey,
&account,
encoding,
None,
data_slice_config,
),
.map(|(pubkey, account)| {
Ok(RpcKeyedAccount {
pubkey: pubkey.to_string(),
account: encode_account(&account, &pubkey, encoding, data_slice_config)?,
})
})
.collect()
.collect::<Result<Vec<_>>>()?
};
Ok(new_response(&bank, accounts))
}
Expand Down Expand Up @@ -3617,25 +3609,22 @@ pub mod rpc_full {
if result.is_err() {
Some(vec![None; config_accounts.addresses.len()])
} else {
let mut accounts = vec![];
for address_str in config_accounts.addresses {
let address = verify_pubkey(&address_str)?;
accounts.push(
post_simulation_accounts
.iter()
.find(|(key, _account)| key == &address)
.map(|(pubkey, account)| {
UiAccount::encode(
pubkey,
account,
accounts_encoding,
None,
None,
)
}),
);
}
Some(accounts)
Some(
config_accounts
.addresses
.iter()
.map(|address_str| {
let address = verify_pubkey(address_str)?;
post_simulation_accounts
.iter()
.find(|(key, _account)| key == &address)
.map(|(pubkey, account)| {
encode_account(account, pubkey, accounts_encoding, None)
})
.transpose()
})
.collect::<Result<Vec<_>>>()?,
)
}
} else {
None
Expand Down Expand Up @@ -7441,7 +7430,7 @@ pub mod tests {
"jsonrpc":"2.0",
"id":1,
"method":"getTokenAccountsByOwner",
"params":["{}", {{"programId": "{}"}}]
"params":["{}", {{"programId": "{}"}}, {{"encoding":"base64"}}]
}}"#,
owner,
spl_token_id(),
Expand Down Expand Up @@ -7493,7 +7482,7 @@ pub mod tests {
r#"{{
"jsonrpc":"2.0",
"id":1,"method":"getTokenAccountsByOwner",
"params":["{}", {{"mint": "{}"}}]
"params":["{}", {{"mint": "{}"}}, {{"encoding":"base64"}}]
}}"#,
owner, mint,
);
Expand Down Expand Up @@ -7558,7 +7547,7 @@ pub mod tests {
"jsonrpc":"2.0",
"id":1,
"method":"getTokenAccountsByDelegate",
"params":["{}", {{"programId": "{}"}}]
"params":["{}", {{"programId": "{}"}}, {{"encoding":"base64"}}]
}}"#,
delegate,
spl_token_id(),
Expand All @@ -7576,7 +7565,7 @@ pub mod tests {
"jsonrpc":"2.0",
"id":1,"method":
"getTokenAccountsByDelegate",
"params":["{}", {{"mint": "{}"}}]
"params":["{}", {{"mint": "{}"}}, {{"encoding":"base64"}}]
}}"#,
delegate, mint,
);
Expand Down

0 comments on commit 4bc3a11

Please sign in to comment.