diff --git a/account-decoder/src/lib.rs b/account-decoder/src/lib.rs index 8f247979d3..c996b7beb1 100644 --- a/account-decoder/src/lib.rs +++ b/account-decoder/src/lib.rs @@ -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> for EncodedAccount { +impl From> for EncodedAccountData { fn from(data: Vec) -> 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 { 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, diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 8bc8f64bcf..17e8814641 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -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, }; diff --git a/cli/src/offline/blockhash_query.rs b/cli/src/offline/blockhash_query.rs index ab40a5266f..3b7bf672ce 100644 --- a/cli/src/offline/blockhash_query.rs +++ b/cli/src/offline/blockhash_query.rs @@ -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)), diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 3117573ce0..c2f32e1e58 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -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::>>(result_json)?; + } = serde_json::from_value::>>(result_json)?; trace!("Response account {:?} {:?}", pubkey, rpc_account); let account = rpc_account.and_then(|rpc_account| rpc_account.decode()); Ok(Response { diff --git a/client/src/rpc_response.rs b/client/src/rpc_response.rs index b93fe357a9..5234443c9b 100644 --- a/client/src/rpc_response.rs +++ b/client/src/rpc_response.rs @@ -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)] diff --git a/core/src/rpc.rs b/core/src/rpc.rs index e42f822834..c7aeae15ed 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -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, - ) -> Result>> { + ) -> Result>> { 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, - ) -> Result>>; + ) -> Result>>; #[rpc(meta, name = "getProgramAccounts")] fn get_program_accounts( @@ -1086,7 +1086,7 @@ impl RpcSol for RpcSolImpl { meta: Self::Metadata, pubkey_str: String, config: Option, - ) -> Result>> { + ) -> Result>> { debug!("get_account_info rpc request received: {:?}", pubkey_str); let pubkey = verify_pubkey(pubkey_str)?; meta.get_account_info(&pubkey, config) diff --git a/core/src/rpc_pubsub.rs b/core/src/rpc_pubsub.rs index 08be0a08f0..dc414ca6c7 100644 --- a/core/src/rpc_pubsub.rs +++ b/core/src/rpc_pubsub.rs @@ -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>, + subscriber: Subscriber>, pubkey_str: String, commitment: Option, ); @@ -171,7 +171,7 @@ impl RpcSolPubSub for RpcSolPubSubImpl { fn account_subscribe( &self, _meta: Self::Metadata, - subscriber: Subscriber>, + subscriber: Subscriber>, pubkey_str: String, commitment: Option, ) { diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index a160436492..56521e2237 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -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 { last_notified_slot: RwLock, } type RpcAccountSubscriptions = - RwLock>>>>; + RwLock>>>>; type RpcProgramSubscriptions = RwLock>>>>; type RpcSignatureSubscriptions = RwLock< @@ -226,13 +226,13 @@ impl RpcNotifier { fn filter_account_result( result: Option<(Account, Slot)>, last_notified_slot: Slot, -) -> (Box>, Slot) { +) -> (Box>, 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, sub_id: SubscriptionId, - subscriber: Subscriber>, + subscriber: Subscriber>, ) { let commitment_level = commitment .unwrap_or_else(CommitmentConfig::single) diff --git a/core/tests/rpc.rs b/core/tests/rpc.rs index adae7e7143..c32c8d6cc0 100644 --- a/core/tests/rpc.rs +++ b/core/tests/rpc.rs @@ -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::>(); + let (account_sender, account_receiver) = channel::>(); // Track when status notifications are received let (status_sender, status_receiver) = channel::<(String, Response)>();