Document more RpcClient methods (#19236)
* Document more RpcClient methods * Update client/src/rpc_client.rs Co-authored-by: Tyera Eulberg <teulberg@gmail.com> * Update RpcClient docs per feedback * Address review feedback Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
This commit is contained in:
parent
82ea4891fd
commit
628ad58912
|
@ -7,22 +7,31 @@ use {
|
||||||
rpc_request::RpcRequest,
|
rpc_request::RpcRequest,
|
||||||
rpc_response::{
|
rpc_response::{
|
||||||
Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcBlockhash,
|
Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcBlockhash,
|
||||||
RpcFees, RpcResponseContext, RpcSimulateTransactionResult, RpcStakeActivation,
|
RpcConfirmedTransactionStatusWithSignature, RpcContactInfo, RpcFees, RpcPerfSample,
|
||||||
RpcSupply, RpcVersionInfo, RpcVoteAccountStatus, StakeActivationState,
|
RpcResponseContext, RpcSimulateTransactionResult, RpcStakeActivation, RpcSupply,
|
||||||
|
RpcVersionInfo, RpcVoteAccountInfo, RpcVoteAccountStatus, StakeActivationState,
|
||||||
},
|
},
|
||||||
rpc_sender::RpcSender,
|
rpc_sender::RpcSender,
|
||||||
},
|
},
|
||||||
serde_json::{json, Number, Value},
|
serde_json::{json, Number, Value},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
|
clock::{Slot, UnixTimestamp},
|
||||||
epoch_info::EpochInfo,
|
epoch_info::EpochInfo,
|
||||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
|
message::MessageHeader,
|
||||||
signature::Signature,
|
signature::Signature,
|
||||||
|
sysvar::epoch_schedule::EpochSchedule,
|
||||||
transaction::{self, Transaction, TransactionError},
|
transaction::{self, Transaction, TransactionError},
|
||||||
},
|
},
|
||||||
solana_transaction_status::{TransactionConfirmationStatus, TransactionStatus},
|
solana_transaction_status::{
|
||||||
|
EncodedConfirmedBlock, EncodedConfirmedTransaction, EncodedTransaction,
|
||||||
|
EncodedTransactionWithStatusMeta, Rewards, TransactionConfirmationStatus,
|
||||||
|
TransactionStatus, UiCompiledInstruction, UiMessage, UiRawMessage, UiTransaction,
|
||||||
|
UiTransactionEncoding, UiTransactionStatusMeta,
|
||||||
|
},
|
||||||
solana_version::Version,
|
solana_version::Version,
|
||||||
std::{collections::HashMap, sync::RwLock},
|
std::{collections::HashMap, net::SocketAddr, sync::RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const PUBKEY: &str = "7RoSF9fUmdphVCpabEoefH81WwrW7orsWonXWqTXkKV8";
|
pub const PUBKEY: &str = "7RoSF9fUmdphVCpabEoefH81WwrW7orsWonXWqTXkKV8";
|
||||||
|
@ -167,6 +176,47 @@ impl RpcSender for MockSender {
|
||||||
value: statuses,
|
value: statuses,
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
|
"getTransaction" => serde_json::to_value(EncodedConfirmedTransaction {
|
||||||
|
slot: 2,
|
||||||
|
transaction: EncodedTransactionWithStatusMeta {
|
||||||
|
transaction: EncodedTransaction::Json(
|
||||||
|
UiTransaction {
|
||||||
|
signatures: vec!["3AsdoALgZFuq2oUVWrDYhg2pNeaLJKPLf8hU2mQ6U8qJxeJ6hsrPVpMn9ma39DtfYCrDQSvngWRP8NnTpEhezJpE".to_string()],
|
||||||
|
message: UiMessage::Raw(
|
||||||
|
UiRawMessage {
|
||||||
|
header: MessageHeader {
|
||||||
|
num_required_signatures: 1,
|
||||||
|
num_readonly_signed_accounts: 0,
|
||||||
|
num_readonly_unsigned_accounts: 1,
|
||||||
|
},
|
||||||
|
account_keys: vec![
|
||||||
|
"C6eBmAXKg6JhJWkajGa5YRGUfG4YKXwbxF5Ufv7PtExZ".to_string(),
|
||||||
|
"2Gd5eoR5J4BV89uXbtunpbNhjmw3wa1NbRHxTHzDzZLX".to_string(),
|
||||||
|
"11111111111111111111111111111111".to_string(),
|
||||||
|
],
|
||||||
|
recent_blockhash: "D37n3BSG71oUWcWjbZ37jZP7UfsxG2QMKeuALJ1PYvM6".to_string(),
|
||||||
|
instructions: vec![UiCompiledInstruction {
|
||||||
|
program_id_index: 2,
|
||||||
|
accounts: vec![0, 1],
|
||||||
|
data: "3Bxs49DitAvXtoDR".to_string(),
|
||||||
|
}],
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
meta: Some(UiTransactionStatusMeta {
|
||||||
|
err: None,
|
||||||
|
status: Ok(()),
|
||||||
|
fee: 0,
|
||||||
|
pre_balances: vec![499999999999999950, 50, 1],
|
||||||
|
post_balances: vec![499999999999999950, 50, 1],
|
||||||
|
inner_instructions: None,
|
||||||
|
log_messages: None,
|
||||||
|
pre_token_balances: None,
|
||||||
|
post_token_balances: None,
|
||||||
|
rewards: None,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
block_time: Some(1628633791),
|
||||||
|
})?,
|
||||||
"getTransactionCount" => json![1234],
|
"getTransactionCount" => json![1234],
|
||||||
"getSlot" => json![0],
|
"getSlot" => json![0],
|
||||||
"getMaxShredInsertSlot" => json![0],
|
"getMaxShredInsertSlot" => json![0],
|
||||||
|
@ -213,7 +263,7 @@ impl RpcSender for MockSender {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"getStakeActivation" => json!(RpcStakeActivation {
|
"getStakeActivation" => json!(RpcStakeActivation {
|
||||||
state: StakeActivationState::Active,
|
state: StakeActivationState::Activating,
|
||||||
active: 123,
|
active: 123,
|
||||||
inactive: 12,
|
inactive: 12,
|
||||||
}),
|
}),
|
||||||
|
@ -240,7 +290,16 @@ impl RpcSender for MockSender {
|
||||||
"getVoteAccounts" => {
|
"getVoteAccounts" => {
|
||||||
json!(RpcVoteAccountStatus {
|
json!(RpcVoteAccountStatus {
|
||||||
current: vec![],
|
current: vec![],
|
||||||
delinquent: vec![],
|
delinquent: vec![RpcVoteAccountInfo {
|
||||||
|
vote_pubkey: PUBKEY.to_string(),
|
||||||
|
node_pubkey: PUBKEY.to_string(),
|
||||||
|
activated_stake: 0,
|
||||||
|
commission: 0,
|
||||||
|
epoch_vote_account: false,
|
||||||
|
epoch_credits: vec![],
|
||||||
|
last_vote: 0,
|
||||||
|
root_slot: Slot::default(),
|
||||||
|
}],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
"sendTransaction" => {
|
"sendTransaction" => {
|
||||||
|
@ -282,6 +341,54 @@ impl RpcSender for MockSender {
|
||||||
context: RpcResponseContext { slot: 1 },
|
context: RpcResponseContext { slot: 1 },
|
||||||
value: json!(Some(0)),
|
value: json!(Some(0)),
|
||||||
})?,
|
})?,
|
||||||
|
"getClusterNodes" => serde_json::to_value(vec![RpcContactInfo {
|
||||||
|
pubkey: PUBKEY.to_string(),
|
||||||
|
gossip: Some(SocketAddr::from(([10, 239, 6, 48], 8899))),
|
||||||
|
tpu: Some(SocketAddr::from(([10, 239, 6, 48], 8856))),
|
||||||
|
rpc: Some(SocketAddr::from(([10, 239, 6, 48], 8899))),
|
||||||
|
version: Some("1.0.0 c375ce1f".to_string()),
|
||||||
|
feature_set: None,
|
||||||
|
shred_version: None,
|
||||||
|
}])?,
|
||||||
|
"getBlock" => serde_json::to_value(EncodedConfirmedBlock {
|
||||||
|
previous_blockhash: "mfcyqEXB3DnHXki6KjjmZck6YjmZLvpAByy2fj4nh6B".to_string(),
|
||||||
|
blockhash: "3Eq21vXNB5s86c62bVuUfTeaMif1N2kUqRPBmGRJhyTA".to_string(),
|
||||||
|
parent_slot: 429,
|
||||||
|
transactions: vec![EncodedTransactionWithStatusMeta {
|
||||||
|
transaction: EncodedTransaction::Binary(
|
||||||
|
"ju9xZWuDBX4pRxX2oZkTjxU5jB4SSTgEGhX8bQ8PURNzyzqKMPPpNvWihx8zUe\
|
||||||
|
FfrbVNoAaEsNKZvGzAnTDy5bhNT9kt6KFCTBixpvrLCzg4M5UdFUQYrn1gdgjX\
|
||||||
|
pLHxcaShD81xBNaFDgnA2nkkdHnKtZt4hVSfKAmw3VRZbjrZ7L2fKZBx21CwsG\
|
||||||
|
hD6onjM2M3qZW5C8J6d1pj41MxKmZgPBSha3MyKkNLkAGFASK"
|
||||||
|
.to_string(),
|
||||||
|
UiTransactionEncoding::Base58,
|
||||||
|
),
|
||||||
|
meta: None,
|
||||||
|
}],
|
||||||
|
rewards: Rewards::new(),
|
||||||
|
block_time: None,
|
||||||
|
block_height: Some(428),
|
||||||
|
})?,
|
||||||
|
"getBlocks" => serde_json::to_value(vec![1, 2, 3])?,
|
||||||
|
"getBlocksWithLimit" => serde_json::to_value(vec![1, 2, 3])?,
|
||||||
|
"getSignaturesForAddress" => {
|
||||||
|
serde_json::to_value(vec![RpcConfirmedTransactionStatusWithSignature {
|
||||||
|
signature: SIGNATURE.to_string(),
|
||||||
|
slot: 123,
|
||||||
|
err: None,
|
||||||
|
memo: None,
|
||||||
|
block_time: None,
|
||||||
|
confirmation_status: Some(TransactionConfirmationStatus::Finalized),
|
||||||
|
}])?
|
||||||
|
}
|
||||||
|
"getBlockTime" => serde_json::to_value(UnixTimestamp::default())?,
|
||||||
|
"getEpochSchedule" => serde_json::to_value(EpochSchedule::default())?,
|
||||||
|
"getRecentPerformanceSamples" => serde_json::to_value(vec![RpcPerfSample {
|
||||||
|
slot: 347873,
|
||||||
|
num_transactions: 125,
|
||||||
|
num_slots: 123,
|
||||||
|
sample_period_secs: 60,
|
||||||
|
}])?,
|
||||||
_ => Value::Null,
|
_ => Value::Null,
|
||||||
};
|
};
|
||||||
Ok(val)
|
Ok(val)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue