Skip to content

Commit

Permalink
Fixup docs in sdk to use new clients (solana-labs#27362)
Browse files Browse the repository at this point in the history
Fixup client docs in sdk
  • Loading branch information
Tyera Eulberg authored Aug 25, 2022
1 parent ad6c2d8 commit 1095cdf
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 128 deletions.
68 changes: 34 additions & 34 deletions sdk/program/src/example_mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,15 @@
#![doc(hidden)]
#![allow(clippy::new_without_default)]

pub mod solana_client {
pub mod client_error {
#[derive(thiserror::Error, Debug)]
#[error("mock-error")]
pub struct ClientError;
pub type Result<T> = std::result::Result<T, ClientError>;
}

pub mod nonce_utils {
use {
super::super::solana_sdk::{
account::ReadableAccount, account_utils::StateMut, pubkey::Pubkey,
},
crate::nonce::state::{Data, DurableNonce, Versions},
};

#[derive(thiserror::Error, Debug)]
#[error("mock-error")]
pub struct Error;

pub fn data_from_account<T: ReadableAccount + StateMut<Versions>>(
_account: &T,
) -> Result<Data, Error> {
Ok(Data::new(
Pubkey::new_unique(),
DurableNonce::default(),
5000,
))
}
}

pub mod solana_rpc_client {
pub mod rpc_client {
use {
super::{
super::solana_sdk::{
super::super::{
solana_rpc_client_api::client_error::Result as ClientResult,
solana_sdk::{
account::Account, hash::Hash, pubkey::Pubkey, signature::Signature,
transaction::Transaction,
},
client_error::Result as ClientResult,
},
std::{cell::RefCell, collections::HashMap, rc::Rc},
};
Expand Down Expand Up @@ -106,6 +76,36 @@ pub mod solana_client {
}
}

pub mod solana_rpc_client_api {
pub mod client_error {
#[derive(thiserror::Error, Debug)]
#[error("mock-error")]
pub struct ClientError;
pub type Result<T> = std::result::Result<T, ClientError>;
}
}

pub mod solana_rpc_client_nonce_utils {
use {
super::solana_sdk::{account::ReadableAccount, account_utils::StateMut, pubkey::Pubkey},
crate::nonce::state::{Data, DurableNonce, Versions},
};

#[derive(thiserror::Error, Debug)]
#[error("mock-error")]
pub struct Error;

pub fn data_from_account<T: ReadableAccount + StateMut<Versions>>(
_account: &T,
) -> Result<Data, Error> {
Ok(Data::new(
Pubkey::new_unique(),
DurableNonce::default(),
5000,
))
}
}

/// Re-exports and mocks of solana-program modules that mirror those from
/// solana-program.
///
Expand Down
8 changes: 4 additions & 4 deletions sdk/program/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
//! network. Note though that transactions that fail during pre-flight
//! simulation are not displayed here.
//! - When submitting transactions via [`RpcClient`], if Rust's own logging is
//! active then the `solana_client` crate logs at the "debug" level any logs
//! active then the `solana_rpc_client` crate logs at the "debug" level any logs
//! for transactions that failed during simulation. If using [`env_logger`]
//! these logs can be activated by setting `RUST_LOG=solana_client=debug`.
//! these logs can be activated by setting `RUST_LOG=solana_rpc_client=debug`.
//! - Logs can be retrieved from a finalized transaction by calling
//! [`RpcClient::get_transaction`].
//! - Block explorers may display logs.
//!
//! [`RpcClient`]: https://docs.rs/solana-client/latest/solana_client/rpc_client/struct.RpcClient.html
//! [`RpcClient`]: https://docs.rs/solana-rpc-client/latest/solana_rpc_client/rpc_client/struct.RpcClient.html
//! [`env_logger`]: https://docs.rs/env_logger
//! [`RpcClient::get_transaction`]: https://docs.rs/solana-client/latest/solana_client/rpc_client/struct.RpcClient.html#method.get_transaction
//! [`RpcClient::get_transaction`]: https://docs.rs/solana-rpc-client/latest/solana_rpc_client/rpc_client/struct.RpcClient.html#method.get_transaction
//!
//! While most logging functions are defined in this module, [`Pubkey`]s can
//! also be efficiently logged with the [`Pubkey::log`] function.
Expand Down
24 changes: 12 additions & 12 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,18 @@ impl Message {
///
/// # Examples
///
/// This example uses the [`solana_sdk`], [`solana_client`] and [`anyhow`] crates.
/// This example uses the [`solana_sdk`], [`solana_rpc_client`] and [`anyhow`] crates.
///
/// [`solana_sdk`]: https://docs.rs/solana-sdk
/// [`solana_client`]: https://docs.rs/solana-client
/// [`solana_rpc_client`]: https://docs.rs/solana-rpc-client
/// [`anyhow`]: https://docs.rs/anyhow
///
/// ```
/// # use solana_program::example_mocks::solana_sdk;
/// # use solana_program::example_mocks::solana_client;
/// # use solana_program::example_mocks::solana_rpc_client;
/// use anyhow::Result;
/// use borsh::{BorshSerialize, BorshDeserialize};
/// use solana_client::rpc_client::RpcClient;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// instruction::Instruction,
/// message::Message,
Expand Down Expand Up @@ -240,18 +240,18 @@ impl Message {
///
/// # Examples
///
/// This example uses the [`solana_sdk`], [`solana_client`] and [`anyhow`] crates.
/// This example uses the [`solana_sdk`], [`solana_rpc_client`] and [`anyhow`] crates.
///
/// [`solana_sdk`]: https://docs.rs/solana-sdk
/// [`solana_client`]: https://docs.rs/solana-client
/// [`solana_rpc_client`]: https://docs.rs/solana-rpc-client
/// [`anyhow`]: https://docs.rs/anyhow
///
/// ```
/// # use solana_program::example_mocks::solana_sdk;
/// # use solana_program::example_mocks::solana_client;
/// # use solana_program::example_mocks::solana_rpc_client;
/// use anyhow::Result;
/// use borsh::{BorshSerialize, BorshDeserialize};
/// use solana_client::rpc_client::RpcClient;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// instruction::Instruction,
/// message::Message,
Expand Down Expand Up @@ -336,18 +336,18 @@ impl Message {
///
/// # Examples
///
/// This example uses the [`solana_sdk`], [`solana_client`] and [`anyhow`] crates.
/// This example uses the [`solana_sdk`], [`solana_rpc_client`] and [`anyhow`] crates.
///
/// [`solana_sdk`]: https://docs.rs/solana-sdk
/// [`solana_client`]: https://docs.rs/solana-client
/// [`solana_rpc_client`]: https://docs.rs/solana-client
/// [`anyhow`]: https://docs.rs/anyhow
///
/// ```
/// # use solana_program::example_mocks::solana_sdk;
/// # use solana_program::example_mocks::solana_client;
/// # use solana_program::example_mocks::solana_rpc_client;
/// use anyhow::Result;
/// use borsh::{BorshSerialize, BorshDeserialize};
/// use solana_client::rpc_client::RpcClient;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// hash::Hash,
/// instruction::Instruction,
Expand Down
8 changes: 4 additions & 4 deletions sdk/program/src/message/versions/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,24 @@ impl Message {
///
/// # Examples
///
/// This example uses the [`solana_address_lookup_table_program`], [`solana_client`], [`solana_sdk`], and [`anyhow`] crates.
/// This example uses the [`solana_address_lookup_table_program`], [`solana_rpc_client`], [`solana_sdk`], and [`anyhow`] crates.
///
/// [`solana_address_lookup_table_program`]: https://docs.rs/solana-address-lookup-table-program
/// [`solana_client`]: https://docs.rs/solana-client
/// [`solana_rpc_client`]: https://docs.rs/solana-rpc-client
/// [`solana_sdk`]: https://docs.rs/solana-sdk
/// [`anyhow`]: https://docs.rs/anyhow
///
/// ```
/// # use solana_program::example_mocks::{
/// # solana_address_lookup_table_program,
/// # solana_client,
/// # solana_rpc_client,
/// # solana_sdk,
/// # };
/// # use std::borrow::Cow;
/// # use solana_sdk::account::Account;
/// use anyhow::Result;
/// use solana_address_lookup_table_program::state::AddressLookupTable;
/// use solana_client::rpc_client::RpcClient;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// address_lookup_table_account::AddressLookupTableAccount,
/// instruction::{AccountMeta, Instruction},
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl Pubkey {
///
/// ```
/// # use borsh::{BorshSerialize, BorshDeserialize};
/// # use solana_program::example_mocks::{solana_sdk, solana_client};
/// # use solana_program::example_mocks::{solana_sdk, solana_rpc_client};
/// # use solana_program::{
/// # pubkey::Pubkey,
/// # instruction::Instruction,
Expand All @@ -385,7 +385,7 @@ impl Pubkey {
/// # signature::{Signer, Signature},
/// # transaction::Transaction,
/// # };
/// # use solana_client::rpc_client::RpcClient;
/// # use solana_rpc_client::rpc_client::RpcClient;
/// # use std::convert::TryFrom;
/// # use anyhow::Result;
/// #
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/secp256k1_recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ impl Secp256k1Pubkey {
/// The RPC client program:
///
/// ```no_run
/// # use solana_program::example_mocks::solana_client;
/// # use solana_program::example_mocks::solana_rpc_client;
/// # use solana_program::example_mocks::solana_sdk;
/// use anyhow::Result;
/// use solana_client::rpc_client::RpcClient;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// instruction::Instruction,
/// keccak,
Expand Down
26 changes: 12 additions & 14 deletions sdk/program/src/system_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,8 @@ pub fn create_nonce_account_with_seed(
///
/// ```
/// # use solana_program::example_mocks::solana_sdk;
/// # use solana_program::example_mocks::solana_client;
/// use solana_client::rpc_client::RpcClient;
/// # use solana_program::example_mocks::solana_rpc_client;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// # pubkey::Pubkey,
/// signature::{Keypair, Signer},
Expand Down Expand Up @@ -671,15 +671,15 @@ pub fn create_nonce_account(
/// setting it to a recent blockhash, the value of the nonce must be retreived
/// and deserialized from the nonce account, and that value specified as the
/// "recent blockhash". A nonce account can be deserialized with the
/// [`solana_client::nonce_utils::data_from_account`][dfa] function.
/// [`solana_rpc_client_nonce_utils::data_from_account`][dfa] function.
///
/// For further description of durable transaction nonces see
/// [`create_nonce_account`].
///
/// [`Message`]: crate::message::Message
/// [`Message::new_with_nonce`]: crate::message::Message::new_with_nonce
/// [`recent_blockhash`]: crate::message::Message::recent_blockhash
/// [dfa]: https://docs.rs/solana-client/latest/solana_client/nonce_utils/fn.data_from_account.html
/// [dfa]: https://docs.rs/solana-rpc-client-nonce-utils/latest/solana_rpc_client_nonce_utils/fn.data_from_account.html
///
/// # Required signers
///
Expand All @@ -691,11 +691,9 @@ pub fn create_nonce_account(
///
/// ```
/// # use solana_program::example_mocks::solana_sdk;
/// # use solana_program::example_mocks::solana_client;
/// use solana_client::{
/// rpc_client::RpcClient,
/// nonce_utils,
/// };
/// # use solana_program::example_mocks::solana_rpc_client;
/// # use solana_program::example_mocks::solana_rpc_client_nonce_utils;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// message::Message,
/// pubkey::Pubkey,
Expand Down Expand Up @@ -751,7 +749,7 @@ pub fn create_nonce_account(
/// # rent_epoch: 1,
/// # });
/// let nonce_account = client.get_account(nonce_account_pubkey)?;
/// let nonce_data = nonce_utils::data_from_account(&nonce_account)?;
/// let nonce_data = solana_rpc_client_nonce_utils::data_from_account(&nonce_account)?;
/// let blockhash = nonce_data.blockhash();
///
/// tx.try_sign(&[payer], blockhash)?;
Expand Down Expand Up @@ -817,8 +815,8 @@ pub fn advance_nonce_account(nonce_pubkey: &Pubkey, authorized_pubkey: &Pubkey)
///
/// ```
/// # use solana_program::example_mocks::solana_sdk;
/// # use solana_program::example_mocks::solana_client;
/// use solana_client::rpc_client::RpcClient;
/// # use solana_program::example_mocks::solana_rpc_client;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// pubkey::Pubkey,
/// signature::{Keypair, Signer},
Expand Down Expand Up @@ -899,8 +897,8 @@ pub fn withdraw_nonce_account(
///
/// ```
/// # use solana_program::example_mocks::solana_sdk;
/// # use solana_program::example_mocks::solana_client;
/// use solana_client::rpc_client::RpcClient;
/// # use solana_program::example_mocks::solana_rpc_client;
/// use solana_rpc_client::rpc_client::RpcClient;
/// use solana_sdk::{
/// pubkey::Pubkey,
/// signature::{Keypair, Signer},
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/sysvar/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@
//!
//! ```
//! # use solana_program::example_mocks::solana_sdk;
//! # use solana_program::example_mocks::solana_client;
//! # use solana_program::example_mocks::solana_rpc_client;
//! # use solana_sdk::account::Account;
//! # use solana_client::rpc_client::RpcClient;
//! # use solana_rpc_client::rpc_client::RpcClient;
//! # use solana_sdk::sysvar::clock::{self, Clock};
//! # use anyhow::Result;
//! #
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/sysvar/epoch_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@
//!
//! ```
//! # use solana_program::example_mocks::solana_sdk;
//! # use solana_program::example_mocks::solana_client;
//! # use solana_program::example_mocks::solana_rpc_client;
//! # use solana_sdk::account::Account;
//! # use solana_client::rpc_client::RpcClient;
//! # use solana_rpc_client::rpc_client::RpcClient;
//! # use solana_sdk::sysvar::epoch_schedule::{self, EpochSchedule};
//! # use anyhow::Result;
//! #
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/sysvar/rent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@
//!
//! ```
//! # use solana_program::example_mocks::solana_sdk;
//! # use solana_program::example_mocks::solana_client;
//! # use solana_program::example_mocks::solana_rpc_client;
//! # use solana_sdk::account::Account;
//! # use solana_client::rpc_client::RpcClient;
//! # use solana_rpc_client::rpc_client::RpcClient;
//! # use solana_sdk::sysvar::rent::{self, Rent};
//! # use anyhow::Result;
//! #
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/sysvar/slot_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//!
//! ```
//! # use solana_program::example_mocks::solana_sdk;
//! # use solana_program::example_mocks::solana_client;
//! # use solana_program::example_mocks::solana_rpc_client;
//! # use solana_sdk::account::Account;
//! # use solana_client::rpc_client::RpcClient;
//! # use solana_rpc_client::rpc_client::RpcClient;
//! # use solana_sdk::sysvar::slot_hashes::{self, SlotHashes};
//! # use anyhow::Result;
//! #
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/sysvar/slot_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//!
//! ```
//! # use solana_program::example_mocks::solana_sdk;
//! # use solana_program::example_mocks::solana_client;
//! # use solana_program::example_mocks::solana_rpc_client;
//! # use solana_sdk::account::Account;
//! # use solana_client::rpc_client::RpcClient;
//! # use solana_rpc_client::rpc_client::RpcClient;
//! # use solana_sdk::sysvar::slot_history::{self, SlotHistory};
//! # use anyhow::Result;
//! #
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/sysvar/stake_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//!
//! ```
//! # use solana_program::example_mocks::solana_sdk;
//! # use solana_program::example_mocks::solana_client;
//! # use solana_program::example_mocks::solana_rpc_client;
//! # use solana_sdk::account::Account;
//! # use solana_client::rpc_client::RpcClient;
//! # use solana_rpc_client::rpc_client::RpcClient;
//! # use solana_sdk::sysvar::stake_history::{self, StakeHistory};
//! # use anyhow::Result;
//! #
Expand Down
Loading

0 comments on commit 1095cdf

Please sign in to comment.