Rpc: getProgramAccounts, restruct base58 account data size (#18852)
* Refactor account encoding to povide helper w/out querying Bank * Use new method in get_program_accounts to properly return length err
This commit is contained in:
@ -384,19 +384,14 @@ impl JsonRpcRequestProcessor {
|
|||||||
if program_id == &spl_token_id_v2_0() && encoding == UiAccountEncoding::JsonParsed {
|
if program_id == &spl_token_id_v2_0() && encoding == UiAccountEncoding::JsonParsed {
|
||||||
get_parsed_token_accounts(bank.clone(), keyed_accounts.into_iter()).collect()
|
get_parsed_token_accounts(bank.clone(), keyed_accounts.into_iter()).collect()
|
||||||
} else {
|
} else {
|
||||||
keyed_accounts
|
let mut encoded_accounts = vec![];
|
||||||
.into_iter()
|
for (pubkey, account) in keyed_accounts {
|
||||||
.map(|(pubkey, account)| RpcKeyedAccount {
|
encoded_accounts.push(RpcKeyedAccount {
|
||||||
pubkey: pubkey.to_string(),
|
pubkey: pubkey.to_string(),
|
||||||
account: UiAccount::encode(
|
account: encode_account(&account, &pubkey, encoding, data_slice_config)?,
|
||||||
&pubkey,
|
});
|
||||||
&account,
|
}
|
||||||
encoding,
|
encoded_accounts
|
||||||
None,
|
|
||||||
data_slice_config,
|
|
||||||
),
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
};
|
};
|
||||||
Ok(result).map(|result| match with_context {
|
Ok(result).map(|result| match with_context {
|
||||||
true => OptionalContext::Context(new_response(&bank, result)),
|
true => OptionalContext::Context(new_response(&bank, result)),
|
||||||
@ -1995,26 +1990,41 @@ fn get_encoded_account(
|
|||||||
encoding: UiAccountEncoding,
|
encoding: UiAccountEncoding,
|
||||||
data_slice: Option<UiDataSliceConfig>,
|
data_slice: Option<UiDataSliceConfig>,
|
||||||
) -> Result<Option<UiAccount>> {
|
) -> Result<Option<UiAccount>> {
|
||||||
let mut response = None;
|
match bank.get_account(pubkey) {
|
||||||
if let Some(account) = bank.get_account(pubkey) {
|
Some(account) => {
|
||||||
if account.owner() == &spl_token_id_v2_0() && encoding == UiAccountEncoding::JsonParsed {
|
let response = if account.owner() == &spl_token_id_v2_0()
|
||||||
response = Some(get_parsed_token_account(bank.clone(), pubkey, account));
|
&& encoding == UiAccountEncoding::JsonParsed
|
||||||
} else if (encoding == UiAccountEncoding::Binary || encoding == UiAccountEncoding::Base58)
|
{
|
||||||
&& account.data().len() > 128
|
get_parsed_token_account(bank.clone(), pubkey, account)
|
||||||
{
|
} else {
|
||||||
let message = "Encoded binary (base 58) data should be less than 128 bytes, please use Base64 encoding.".to_string();
|
encode_account(&account, pubkey, encoding, data_slice)?
|
||||||
return Err(error::Error {
|
};
|
||||||
code: error::ErrorCode::InvalidRequest,
|
Ok(Some(response))
|
||||||
message,
|
|
||||||
data: None,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
response = Some(UiAccount::encode(
|
|
||||||
pubkey, &account, encoding, None, data_slice,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
None => Ok(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode_account<T: ReadableAccount>(
|
||||||
|
account: &T,
|
||||||
|
pubkey: &Pubkey,
|
||||||
|
encoding: UiAccountEncoding,
|
||||||
|
data_slice: Option<UiDataSliceConfig>,
|
||||||
|
) -> Result<UiAccount> {
|
||||||
|
if (encoding == UiAccountEncoding::Binary || encoding == UiAccountEncoding::Base58)
|
||||||
|
&& account.data().len() > 128
|
||||||
|
{
|
||||||
|
let message = "Encoded binary (base 58) data should be less than 128 bytes, please use Base64 encoding.".to_string();
|
||||||
|
Err(error::Error {
|
||||||
|
code: error::ErrorCode::InvalidRequest,
|
||||||
|
message,
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Ok(UiAccount::encode(
|
||||||
|
pubkey, account, encoding, None, data_slice,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
Ok(response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_spl_token_owner_filter(program_id: &Pubkey, filters: &[RpcFilterType]) -> Option<Pubkey> {
|
fn get_spl_token_owner_filter(program_id: &Pubkey, filters: &[RpcFilterType]) -> Option<Pubkey> {
|
||||||
|
Reference in New Issue
Block a user