Add account-decoder utilities (#10846)
* Fix comment and make less pub
* Add account-decoder crate and use to decode vote and system (nonce) accounts
* Update docs
* Rename RpcAccount struct
* s/Rpc/Display
* Call it jsonParsed and update docs
* Revert "s/Rpc/Display"
This reverts commit 6e7149f503
.
* s/Rpc/Ui
* Add tests
* Ui more things
* Comments
This commit is contained in:
@@ -7,8 +7,9 @@ use jsonrpc_pubsub::{
|
||||
SubscriptionId,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use solana_account_decoder::{UiAccount, UiAccountEncoding};
|
||||
use solana_client::rpc_response::{
|
||||
Response, RpcAccount, RpcKeyedAccount, RpcResponseContext, RpcSignatureResult,
|
||||
Response, RpcKeyedAccount, RpcResponseContext, RpcSignatureResult,
|
||||
};
|
||||
use solana_runtime::{bank::Bank, bank_forks::BankForks, commitment::BlockCommitmentCache};
|
||||
use solana_sdk::{
|
||||
@@ -90,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<UiAccount>>>>>;
|
||||
type RpcProgramSubscriptions =
|
||||
RwLock<HashMap<Pubkey, HashMap<SubscriptionId, SubscriptionData<Response<RpcKeyedAccount>>>>>;
|
||||
type RpcSignatureSubscriptions = RwLock<
|
||||
@@ -225,12 +226,18 @@ impl RpcNotifier {
|
||||
fn filter_account_result(
|
||||
result: Option<(Account, Slot)>,
|
||||
last_notified_slot: Slot,
|
||||
) -> (Box<dyn Iterator<Item = RpcAccount>>, Slot) {
|
||||
) -> (Box<dyn Iterator<Item = UiAccount>>, 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(account))), fork);
|
||||
return (
|
||||
Box::new(iter::once(UiAccount::encode(
|
||||
account,
|
||||
UiAccountEncoding::Binary,
|
||||
))),
|
||||
fork,
|
||||
);
|
||||
}
|
||||
}
|
||||
(Box::new(iter::empty()), last_notified_slot)
|
||||
@@ -260,7 +267,7 @@ fn filter_program_results(
|
||||
.into_iter()
|
||||
.map(|(pubkey, account)| RpcKeyedAccount {
|
||||
pubkey: pubkey.to_string(),
|
||||
account: RpcAccount::encode(account),
|
||||
account: UiAccount::encode(account, UiAccountEncoding::Binary),
|
||||
}),
|
||||
),
|
||||
last_notified_slot,
|
||||
@@ -449,7 +456,7 @@ impl RpcSubscriptions {
|
||||
pubkey: Pubkey,
|
||||
commitment: Option<CommitmentConfig>,
|
||||
sub_id: SubscriptionId,
|
||||
subscriber: Subscriber<Response<RpcAccount>>,
|
||||
subscriber: Subscriber<Response<UiAccount>>,
|
||||
) {
|
||||
let commitment_level = commitment
|
||||
.unwrap_or_else(CommitmentConfig::single)
|
||||
|
Reference in New Issue
Block a user