Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit

Permalink
enable doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Sep 22, 2023
1 parent 5c20159 commit 6c56437
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions libraries/tlv-account-resolution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ spl-type-length-value = { version = "0.2", path = "../type-length-value" }
spl-pod = { version = "0.1.0", path = "../pod" }

[dev-dependencies]
futures = "0.3.28"
futures-util = "0.3"
solana-client = "1.16.3"
solana-program-test = "1.16.3"
solana-sdk = "1.16.3"
spl-discriminator = { version = "0.1", path = "../discriminator" }
Expand Down
44 changes: 30 additions & 14 deletions libraries/tlv-account-resolution/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ fn de_escalate_account_meta(account_meta: &mut AccountMeta, account_metas: &[Acc
///
/// Sample usage:
///
/// ```rust,ignore
/// ```rust
/// use {
/// futures_util::TryFutureExt,
/// solana_client::nonblocking::rpc_client::RpcClient,
/// solana_program::{
/// account_info::AccountInfo, instruction::{AccountMeta, Instruction},
Expand All @@ -76,7 +77,7 @@ fn de_escalate_account_meta(account_meta: &mut AccountMeta, account_metas: &[Acc
/// spl_tlv_account_resolution::{
/// account::ExtraAccountMeta,
/// seeds::Seed,
/// state::ExtraAccountMetaList
/// state::{AccountDataResult, AccountFetchError, ExtraAccountMetaList}
/// },
/// };
///
Expand Down Expand Up @@ -121,20 +122,35 @@ fn de_escalate_account_meta(account_meta: &mut AccountMeta, account_metas: &[Acc
///
/// // Off-chain, you can add the additional accounts directly from the account data
/// // You need to provide the resolver a way to fetch account data off-chain
/// let client = RpcClient::new_mock("succeeds".to_string());
/// struct MyClient {
/// client: RpcClient,
/// }
/// impl MyClient {
/// pub fn new() -> Self {
/// Self {
/// client: RpcClient::new_mock("succeeds".to_string()),
/// }
/// }
/// pub async fn get_account_data(&self, address: Pubkey) -> AccountDataResult {
/// self.client.get_account(&address)
/// .await
/// .map(|acct| Some(acct.data))
/// .map_err(|e| Box::new(e) as AccountFetchError)
/// }
/// }
///
/// let client = MyClient::new();
/// let program_id = Pubkey::new_unique();
/// let mut instruction = Instruction::new_with_bytes(program_id, &[0, 1, 2], vec![]);
/// ExtraAccountMetaList::add_to_instruction::<MyInstruction, _, _>(
/// &mut instruction,
/// |address: &Pubkey| {
/// client
/// .get_account(address)
/// .map_ok(|acct| Some(acct.data))
/// },
/// &buffer,
/// )
/// .await
/// .unwrap();
/// futures::executor::block_on(async {
/// // Now use the resolver to add the additional accounts off-chain
/// ExtraAccountMetaList::add_to_instruction::<MyInstruction, _, _>(
/// &mut instruction,
/// |address: Pubkey| client.get_account_data(address),
/// &buffer,
/// )
/// .await;
/// });
///
/// // On-chain, you can add the additional accounts *and* account infos
/// let mut cpi_instruction = Instruction::new_with_bytes(program_id, &[0, 1, 2], vec![]);
Expand Down

0 comments on commit 6c56437

Please sign in to comment.