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:
parent
611af87fdb
commit
3eecb6f4ae
|
@ -384,19 +384,14 @@ impl JsonRpcRequestProcessor {
|
|||
if program_id == &spl_token_id_v2_0() && encoding == UiAccountEncoding::JsonParsed {
|
||||
get_parsed_token_accounts(bank.clone(), keyed_accounts.into_iter()).collect()
|
||||
} else {
|
||||
keyed_accounts
|
||||
.into_iter()
|
||||
.map(|(pubkey, account)| RpcKeyedAccount {
|
||||
let mut encoded_accounts = vec![];
|
||||
for (pubkey, account) in keyed_accounts {
|
||||
encoded_accounts.push(RpcKeyedAccount {
|
||||
pubkey: pubkey.to_string(),
|
||||
account: UiAccount::encode(
|
||||
&pubkey,
|
||||
&account,
|
||||
encoding,
|
||||
None,
|
||||
data_slice_config,
|
||||
),
|
||||
})
|
||||
.collect()
|
||||
account: encode_account(&account, &pubkey, encoding, data_slice_config)?,
|
||||
});
|
||||
}
|
||||
encoded_accounts
|
||||
};
|
||||
Ok(result).map(|result| match with_context {
|
||||
true => OptionalContext::Context(new_response(&bank, result)),
|
||||
|
@ -1995,26 +1990,41 @@ fn get_encoded_account(
|
|||
encoding: UiAccountEncoding,
|
||||
data_slice: Option<UiDataSliceConfig>,
|
||||
) -> Result<Option<UiAccount>> {
|
||||
let mut response = None;
|
||||
if let Some(account) = bank.get_account(pubkey) {
|
||||
if account.owner() == &spl_token_id_v2_0() && encoding == UiAccountEncoding::JsonParsed {
|
||||
response = Some(get_parsed_token_account(bank.clone(), pubkey, account));
|
||||
} else if (encoding == UiAccountEncoding::Binary || encoding == UiAccountEncoding::Base58)
|
||||
match bank.get_account(pubkey) {
|
||||
Some(account) => {
|
||||
let response = if account.owner() == &spl_token_id_v2_0()
|
||||
&& encoding == UiAccountEncoding::JsonParsed
|
||||
{
|
||||
get_parsed_token_account(bank.clone(), pubkey, account)
|
||||
} else {
|
||||
encode_account(&account, pubkey, encoding, data_slice)?
|
||||
};
|
||||
Ok(Some(response))
|
||||
}
|
||||
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();
|
||||
return Err(error::Error {
|
||||
Err(error::Error {
|
||||
code: error::ErrorCode::InvalidRequest,
|
||||
message,
|
||||
data: None,
|
||||
});
|
||||
})
|
||||
} else {
|
||||
response = Some(UiAccount::encode(
|
||||
pubkey, &account, encoding, None, data_slice,
|
||||
));
|
||||
Ok(UiAccount::encode(
|
||||
pubkey, account, encoding, None, data_slice,
|
||||
))
|
||||
}
|
||||
}
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn get_spl_token_owner_filter(program_id: &Pubkey, filters: &[RpcFilterType]) -> Option<Pubkey> {
|
||||
|
|
Loading…
Reference in New Issue