Rename RpcAccount struct
This commit is contained in:
@ -15,9 +15,9 @@ use std::str::FromStr;
|
||||
/// A duplicate representation of a Message for pretty JSON serialization
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RpcAccount {
|
||||
pub struct EncodedAccount {
|
||||
pub lamports: u64,
|
||||
pub data: EncodedAccount,
|
||||
pub data: EncodedAccountData,
|
||||
pub owner: String,
|
||||
pub executable: bool,
|
||||
pub rent_epoch: Epoch,
|
||||
@ -25,12 +25,12 @@ pub struct RpcAccount {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase", untagged)]
|
||||
pub enum EncodedAccount {
|
||||
pub enum EncodedAccountData {
|
||||
Binary(String),
|
||||
Json(Value),
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for EncodedAccount {
|
||||
impl From<Vec<u8>> for EncodedAccountData {
|
||||
fn from(data: Vec<u8>) -> Self {
|
||||
Self::Binary(bs58::encode(data).into_string())
|
||||
}
|
||||
@ -43,19 +43,19 @@ pub enum AccountEncoding {
|
||||
Json,
|
||||
}
|
||||
|
||||
impl RpcAccount {
|
||||
impl EncodedAccount {
|
||||
pub fn encode(account: Account, encoding: AccountEncoding) -> Self {
|
||||
let data = match encoding {
|
||||
AccountEncoding::Binary => account.data.into(),
|
||||
AccountEncoding::Json => {
|
||||
if let Ok(parsed_data) = parse_account_data(&account.owner, &account.data) {
|
||||
EncodedAccount::Json(parsed_data)
|
||||
EncodedAccountData::Json(parsed_data)
|
||||
} else {
|
||||
account.data.into()
|
||||
}
|
||||
}
|
||||
};
|
||||
RpcAccount {
|
||||
EncodedAccount {
|
||||
lamports: account.lamports,
|
||||
data,
|
||||
owner: account.owner.to_string(),
|
||||
@ -66,8 +66,8 @@ impl RpcAccount {
|
||||
|
||||
pub fn decode(&self) -> Option<Account> {
|
||||
let data = match &self.data {
|
||||
EncodedAccount::Json(_) => None,
|
||||
EncodedAccount::Binary(blob) => bs58::decode(blob).into_vec().ok(),
|
||||
EncodedAccountData::Json(_) => None,
|
||||
EncodedAccountData::Binary(blob) => bs58::decode(blob).into_vec().ok(),
|
||||
}?;
|
||||
Some(Account {
|
||||
lamports: self.lamports,
|
||||
|
@ -15,7 +15,7 @@ use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
|
||||
use log::*;
|
||||
use num_traits::FromPrimitive;
|
||||
use serde_json::{self, json, Value};
|
||||
use solana_account_decoder::{AccountEncoding, RpcAccount};
|
||||
use solana_account_decoder::{AccountEncoding, EncodedAccount};
|
||||
use solana_budget_program::budget_instruction::{self, BudgetError};
|
||||
use solana_clap_utils::{
|
||||
commitment::commitment_arg_with_default, input_parsers::*, input_validators::*,
|
||||
@ -1226,7 +1226,7 @@ fn process_show_account(
|
||||
let cli_account = CliAccount {
|
||||
keyed_account: RpcKeyedAccount {
|
||||
pubkey: account_pubkey.to_string(),
|
||||
account: RpcAccount::encode(account, AccountEncoding::Binary),
|
||||
account: EncodedAccount::encode(account, AccountEncoding::Binary),
|
||||
},
|
||||
use_lamports_unit,
|
||||
};
|
||||
|
@ -111,7 +111,7 @@ mod tests {
|
||||
use crate::{nonce::nonce_arg, offline::blockhash_query::BlockhashQuery};
|
||||
use clap::App;
|
||||
use serde_json::{self, json, Value};
|
||||
use solana_account_decoder::{AccountEncoding, RpcAccount};
|
||||
use solana_account_decoder::{AccountEncoding, EncodedAccount};
|
||||
use solana_client::{
|
||||
rpc_request::RpcRequest,
|
||||
rpc_response::{Response, RpcFeeCalculator, RpcResponseContext},
|
||||
@ -350,7 +350,7 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
let nonce_pubkey = Pubkey::new(&[4u8; 32]);
|
||||
let rpc_nonce_account = RpcAccount::encode(nonce_account, AccountEncoding::Binary);
|
||||
let rpc_nonce_account = EncodedAccount::encode(nonce_account, AccountEncoding::Binary);
|
||||
let get_account_response = json!(Response {
|
||||
context: RpcResponseContext { slot: 1 },
|
||||
value: json!(Some(rpc_nonce_account)),
|
||||
|
@ -11,7 +11,7 @@ use bincode::serialize;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use log::*;
|
||||
use serde_json::{json, Value};
|
||||
use solana_account_decoder::RpcAccount;
|
||||
use solana_account_decoder::EncodedAccount;
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
clock::{
|
||||
@ -441,7 +441,7 @@ impl RpcClient {
|
||||
let Response {
|
||||
context,
|
||||
value: rpc_account,
|
||||
} = serde_json::from_value::<Response<Option<RpcAccount>>>(result_json)?;
|
||||
} = serde_json::from_value::<Response<Option<EncodedAccount>>>(result_json)?;
|
||||
trace!("Response account {:?} {:?}", pubkey, rpc_account);
|
||||
let account = rpc_account.and_then(|rpc_account| rpc_account.decode());
|
||||
Ok(Response {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::client_error;
|
||||
use solana_account_decoder::RpcAccount;
|
||||
use solana_account_decoder::EncodedAccount;
|
||||
use solana_sdk::{
|
||||
clock::{Epoch, Slot},
|
||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||
@ -90,7 +90,7 @@ pub struct RpcInflationRate {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RpcKeyedAccount {
|
||||
pub pubkey: String,
|
||||
pub account: RpcAccount,
|
||||
pub account: EncodedAccount,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||
use bincode::serialize;
|
||||
use jsonrpc_core::{Error, Metadata, Result};
|
||||
use jsonrpc_derive::rpc;
|
||||
use solana_account_decoder::{AccountEncoding, RpcAccount};
|
||||
use solana_account_decoder::{AccountEncoding, EncodedAccount};
|
||||
use solana_client::{
|
||||
rpc_config::*,
|
||||
rpc_request::{
|
||||
@ -207,14 +207,14 @@ impl JsonRpcRequestProcessor {
|
||||
&self,
|
||||
pubkey: &Pubkey,
|
||||
config: Option<RpcAccountInfoConfig>,
|
||||
) -> Result<RpcResponse<Option<RpcAccount>>> {
|
||||
) -> Result<RpcResponse<Option<EncodedAccount>>> {
|
||||
let config = config.unwrap_or_default();
|
||||
let bank = self.bank(config.commitment)?;
|
||||
let encoding = config.encoding.unwrap_or(AccountEncoding::Binary);
|
||||
new_response(
|
||||
&bank,
|
||||
bank.get_account(pubkey)
|
||||
.map(|account| RpcAccount::encode(account, encoding)),
|
||||
.map(|account| EncodedAccount::encode(account, encoding)),
|
||||
)
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ impl JsonRpcRequestProcessor {
|
||||
.into_iter()
|
||||
.map(|(pubkey, account)| RpcKeyedAccount {
|
||||
pubkey: pubkey.to_string(),
|
||||
account: RpcAccount::encode(account, encoding.clone()),
|
||||
account: EncodedAccount::encode(account, encoding.clone()),
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
@ -833,7 +833,7 @@ pub trait RpcSol {
|
||||
meta: Self::Metadata,
|
||||
pubkey_str: String,
|
||||
config: Option<RpcAccountInfoConfig>,
|
||||
) -> Result<RpcResponse<Option<RpcAccount>>>;
|
||||
) -> Result<RpcResponse<Option<EncodedAccount>>>;
|
||||
|
||||
#[rpc(meta, name = "getProgramAccounts")]
|
||||
fn get_program_accounts(
|
||||
@ -1086,7 +1086,7 @@ impl RpcSol for RpcSolImpl {
|
||||
meta: Self::Metadata,
|
||||
pubkey_str: String,
|
||||
config: Option<RpcAccountInfoConfig>,
|
||||
) -> Result<RpcResponse<Option<RpcAccount>>> {
|
||||
) -> Result<RpcResponse<Option<EncodedAccount>>> {
|
||||
debug!("get_account_info rpc request received: {:?}", pubkey_str);
|
||||
let pubkey = verify_pubkey(pubkey_str)?;
|
||||
meta.get_account_info(&pubkey, config)
|
||||
|
@ -4,7 +4,7 @@ use crate::rpc_subscriptions::{RpcSubscriptions, RpcVote, SlotInfo};
|
||||
use jsonrpc_core::{Error, ErrorCode, Result};
|
||||
use jsonrpc_derive::rpc;
|
||||
use jsonrpc_pubsub::{typed::Subscriber, Session, SubscriptionId};
|
||||
use solana_account_decoder::RpcAccount;
|
||||
use solana_account_decoder::EncodedAccount;
|
||||
use solana_client::rpc_response::{Response as RpcResponse, RpcKeyedAccount, RpcSignatureResult};
|
||||
#[cfg(test)]
|
||||
use solana_runtime::bank_forks::BankForks;
|
||||
@ -36,7 +36,7 @@ pub trait RpcSolPubSub {
|
||||
fn account_subscribe(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
subscriber: Subscriber<RpcResponse<RpcAccount>>,
|
||||
subscriber: Subscriber<RpcResponse<EncodedAccount>>,
|
||||
pubkey_str: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
);
|
||||
@ -171,7 +171,7 @@ impl RpcSolPubSub for RpcSolPubSubImpl {
|
||||
fn account_subscribe(
|
||||
&self,
|
||||
_meta: Self::Metadata,
|
||||
subscriber: Subscriber<RpcResponse<RpcAccount>>,
|
||||
subscriber: Subscriber<RpcResponse<EncodedAccount>>,
|
||||
pubkey_str: String,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
) {
|
||||
|
@ -7,7 +7,7 @@ use jsonrpc_pubsub::{
|
||||
SubscriptionId,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use solana_account_decoder::{AccountEncoding, RpcAccount};
|
||||
use solana_account_decoder::{AccountEncoding, EncodedAccount};
|
||||
use solana_client::rpc_response::{
|
||||
Response, RpcKeyedAccount, RpcResponseContext, RpcSignatureResult,
|
||||
};
|
||||
@ -91,7 +91,7 @@ struct SubscriptionData<S> {
|
||||
last_notified_slot: RwLock<Slot>,
|
||||
}
|
||||
type RpcAccountSubscriptions =
|
||||
RwLock<HashMap<Pubkey, HashMap<SubscriptionId, SubscriptionData<Response<RpcAccount>>>>>;
|
||||
RwLock<HashMap<Pubkey, HashMap<SubscriptionId, SubscriptionData<Response<EncodedAccount>>>>>;
|
||||
type RpcProgramSubscriptions =
|
||||
RwLock<HashMap<Pubkey, HashMap<SubscriptionId, SubscriptionData<Response<RpcKeyedAccount>>>>>;
|
||||
type RpcSignatureSubscriptions = RwLock<
|
||||
@ -226,13 +226,13 @@ impl RpcNotifier {
|
||||
fn filter_account_result(
|
||||
result: Option<(Account, Slot)>,
|
||||
last_notified_slot: Slot,
|
||||
) -> (Box<dyn Iterator<Item = RpcAccount>>, Slot) {
|
||||
) -> (Box<dyn Iterator<Item = EncodedAccount>>, Slot) {
|
||||
if let Some((account, fork)) = result {
|
||||
// If fork < last_notified_slot this means that we last notified for a fork
|
||||
// and should notify that the account state has been reverted.
|
||||
if fork != last_notified_slot {
|
||||
return (
|
||||
Box::new(iter::once(RpcAccount::encode(
|
||||
Box::new(iter::once(EncodedAccount::encode(
|
||||
account,
|
||||
AccountEncoding::Binary,
|
||||
))),
|
||||
@ -267,7 +267,7 @@ fn filter_program_results(
|
||||
.into_iter()
|
||||
.map(|(pubkey, account)| RpcKeyedAccount {
|
||||
pubkey: pubkey.to_string(),
|
||||
account: RpcAccount::encode(account, AccountEncoding::Binary),
|
||||
account: EncodedAccount::encode(account, AccountEncoding::Binary),
|
||||
}),
|
||||
),
|
||||
last_notified_slot,
|
||||
@ -456,7 +456,7 @@ impl RpcSubscriptions {
|
||||
pubkey: Pubkey,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
sub_id: SubscriptionId,
|
||||
subscriber: Subscriber<Response<RpcAccount>>,
|
||||
subscriber: Subscriber<Response<EncodedAccount>>,
|
||||
) {
|
||||
let commitment_level = commitment
|
||||
.unwrap_or_else(CommitmentConfig::single)
|
||||
|
@ -7,7 +7,7 @@ use jsonrpc_core_client::transports::ws;
|
||||
use log::*;
|
||||
use reqwest::{self, header::CONTENT_TYPE};
|
||||
use serde_json::{json, Value};
|
||||
use solana_account_decoder::RpcAccount;
|
||||
use solana_account_decoder::EncodedAccount;
|
||||
use solana_client::{
|
||||
rpc_client::{get_rpc_request_str, RpcClient},
|
||||
rpc_response::{Response, RpcSignatureResult},
|
||||
@ -173,7 +173,7 @@ fn test_rpc_subscriptions() {
|
||||
// Track when subscriptions are ready
|
||||
let (ready_sender, ready_receiver) = channel::<()>();
|
||||
// Track account notifications are received
|
||||
let (account_sender, account_receiver) = channel::<Response<RpcAccount>>();
|
||||
let (account_sender, account_receiver) = channel::<Response<EncodedAccount>>();
|
||||
// Track when status notifications are received
|
||||
let (status_sender, status_receiver) = channel::<(String, Response<RpcSignatureResult>)>();
|
||||
|
||||
|
Reference in New Issue
Block a user