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