Skip to content

Commit d0bec79

Browse files
user.emailuser.email
authored andcommitted
refactor(pinocchio): migrate account_view naming and ToAccountView APIs across lang/client/cli/spl
1 parent a0f2daa commit d0bec79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+678
-658
lines changed

client/src/lib.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@
6464
//!
6565
//! [`RpcClient::new_mock`]: https://docs.rs/solana-rpc-client/3.0.0/solana_rpc_client/rpc_client/struct.RpcClient.html#method.new_mock
6666
67-
use anchor_lang::pinocchio_runtime::instruction::{AccountMeta, InstructionView};
6867
use anchor_lang::pinocchio_runtime::program_error::ProgramError;
6968
use anchor_lang::pinocchio_runtime::pubkey::Pubkey;
70-
use anchor_lang::prelude::instruction::InstructionView;
7169
use anchor_lang::{AccountDeserialize, Discriminator, InstructionData, ToAccountMetas};
7270
use futures::{Future, StreamExt};
7371
use regex::Regex;
7472
use solana_account_decoder::{UiAccount, UiAccountEncoding};
7573
use solana_commitment_config::CommitmentConfig;
74+
use solana_instruction::{AccountMeta as SolanaAccountMeta, Instruction};
7675
use solana_program::hash::Hash;
7776
use solana_pubsub_client::nonblocking::pubsub_client::{PubsubClient, PubsubClientError};
7877
use solana_rpc_client::nonblocking::rpc_client::RpcClient as AsyncRpcClient;
@@ -499,12 +498,12 @@ impl AsSigner for Box<dyn Signer + '_> {
499498

500499
/// `RequestBuilder` provides a builder interface to create and send
501500
/// transactions to a cluster.
502-
pub struct RequestBuilder<'a, 'b, 'c, 'd, C, S: 'a> {
501+
pub struct RequestBuilder<'a, C, S: 'a> {
503502
cluster: String,
504503
program_id: Pubkey,
505-
accounts: Vec<AccountMeta<'a>>,
504+
accounts: Vec<SolanaAccountMeta>,
506505
options: CommitmentConfig,
507-
instructions: Vec<InstructionView<'a, 'b, 'c, 'd>>,
506+
instructions: Vec<Instruction>,
508507
payer: C,
509508
instruction_data: Option<Vec<u8>>,
510509
signers: Vec<S>,
@@ -515,7 +514,7 @@ pub struct RequestBuilder<'a, 'b, 'c, 'd, C, S: 'a> {
515514
}
516515

517516
// Shared implementation for all RequestBuilders
518-
impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, '_, '_, '_, C, S> {
517+
impl<'a, C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'a, C, S> {
519518
#[must_use]
520519
pub fn payer(mut self, payer: C) -> Self {
521520
self.payer = payer;
@@ -529,7 +528,7 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, '_,
529528
}
530529

531530
#[must_use]
532-
pub fn instruction(mut self, ix: InstructionView<'_, '_, '_, '_>) -> Self {
531+
pub fn instruction(mut self, ix: Instruction) -> Self {
533532
self.instructions.push(ix);
534533
self
535534
}
@@ -571,9 +570,18 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, '_,
571570
/// .send()?;
572571
/// ```
573572
#[must_use]
574-
pub fn accounts(mut self, accounts: impl ToAccountMetas) -> Self {
575-
let mut metas = accounts.to_account_metas(None);
576-
self.accounts.append(&mut metas);
573+
pub fn accounts(mut self, accounts: impl ToAccountMetas + 'a) -> Self {
574+
self.accounts
575+
.extend(
576+
accounts
577+
.to_account_metas(None)
578+
.into_iter()
579+
.map(|meta| SolanaAccountMeta {
580+
pubkey: *meta.address,
581+
is_signer: meta.is_signer,
582+
is_writable: meta.is_writable,
583+
}),
584+
);
577585
self
578586
}
579587

@@ -589,10 +597,10 @@ impl<C: Deref<Target = impl Signer> + Clone, S: AsSigner> RequestBuilder<'_, '_,
589597
self
590598
}
591599

592-
pub fn instructions(&self) -> Vec<InstructionView> {
600+
pub fn instructions(&self) -> Vec<Instruction> {
593601
let mut instructions = self.instructions.clone();
594602
if let Some(ix_data) = &self.instruction_data {
595-
instructions.push(InstructionView {
603+
instructions.push(Instruction {
596604
program_id: self.program_id,
597605
data: ix_data.clone(),
598606
accounts: self.accounts.clone(),

lang/attribute/access-control/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syn::parse_macro_input;
3131
///
3232
/// impl Create {
3333
/// pub fn accounts(ctx: &Context<Create>, bump_seed: u8) -> Result<()> {
34-
/// let seeds = &[ctx.accounts.my_account.to_account_info().key.as_ref(), &[bump_seed]];
34+
/// let seeds = &[ctx.accounts.my_account.to_account_view().key.as_ref(), &[bump_seed]];
3535
/// Pubkey::create_program_address(seeds, ctx.program_id)
3636
/// .map_err(|_| ErrorCode::InvalidNonce)?;
3737
/// Ok(())

lang/attribute/event/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn emit_cpi(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
163163

164164
proc_macro::TokenStream::from(quote! {
165165
{
166-
let authority_info = ctx.accounts.#authority_name.to_account_info();
166+
let authority_info = ctx.accounts.#authority_name.to_account_view();
167167

168168
let disc = anchor_lang::event::EVENT_IX_TAG_LE;
169169
let inner_data = anchor_lang::Event::data(&#event_struct);

lang/attribute/program/src/declare_program/mods/cpi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn gen_cpi_instructions(idl: &Idl) -> proc_macro2::TokenStream {
8383
}
8484
};
8585

86-
let mut acc_infos = ctx.to_account_infos();
86+
let mut acc_infos = ctx.to_account_views();
8787
anchor_lang::pinocchio_runtime::program::invoke_signed(
8888
&ix,
8989
&acc_infos,

lang/src/accounts/account.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
33
use crate::bpf_writer::BpfWriter;
44
use crate::error::{Error, ErrorCode};
5-
use crate::pinocchio_runtime::account_info::AccountView;
5+
use crate::pinocchio_runtime::account_view::AccountView;
66
use crate::pinocchio_runtime::bpf_loader_upgradeable::{self, UpgradeableLoaderState};
77
use crate::pinocchio_runtime::instruction::AccountMeta;
88
use crate::pinocchio_runtime::pubkey::Pubkey;
99
use crate::pinocchio_runtime::system_program;
1010
use crate::{
1111
AccountDeserialize, AccountSerialize, Accounts, AccountsClose, AccountsExit, Id, Key, Owner,
12-
Result, ToAccountInfo, ToAccountInfos, ToAccountMetas,
12+
Result, ToAccountMetas, ToAccountView, ToAccountViews,
1313
};
1414
use std::collections::BTreeSet;
1515
use std::fmt;
1616
use std::marker::PhantomData;
1717
use std::ops::{Deref, DerefMut};
1818

19-
/// Wrapper around [`AccountView`](crate::pinocchio_runtime::account_info::AccountView)
19+
/// Wrapper around [`AccountView`](crate::pinocchio_runtime::account_view::AccountView)
2020
/// that verifies program ownership and deserializes underlying data into a Rust type.
2121
///
2222
/// # Table of Contents
@@ -374,7 +374,7 @@ impl<'info, T: AccountChecks> AccountsExit<'info> for Account<'info, T> {
374374

375375
impl<'info, T: AccountChecks> AccountsClose<'info> for Account<'info, T> {
376376
fn close(&self, sol_destination: AccountView) -> Result<()> {
377-
crate::common::close(self.to_account_info(), sol_destination)
377+
crate::common::close(self.to_account_view(), sol_destination)
378378
}
379379
}
380380

@@ -391,8 +391,8 @@ impl<T: AccountChecks> ToAccountMetas for Account<'_, T> {
391391
}
392392
}
393393

394-
impl<'info, T: AccountChecks> ToAccountInfos for Account<'info, T> {
395-
fn to_account_infos(&self) -> Vec<AccountView> {
394+
impl<'info, T: AccountChecks> ToAccountViews for Account<'info, T> {
395+
fn to_account_views(&self) -> Vec<AccountView> {
396396
vec![self.info]
397397
}
398398
}

lang/src/accounts/account_info.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
//! should be used instead.
44
55
use crate::error::ErrorCode;
6-
use crate::pinocchio_runtime::account_info::AccountView;
6+
use crate::pinocchio_runtime::account_view::AccountView;
77
use crate::pinocchio_runtime::instruction::AccountMeta;
88
use crate::pinocchio_runtime::pubkey::Pubkey;
9-
use crate::{Accounts, AccountsExit, Key, Result, ToAccountInfos, ToAccountMetas};
9+
use crate::{Accounts, AccountsExit, Key, Result, ToAccountMetas, ToAccountViews};
1010
use std::collections::BTreeSet;
1111

1212
impl<'info, B> Accounts<'info, B> for AccountView {
@@ -39,8 +39,8 @@ impl ToAccountMetas for AccountView {
3939
}
4040
}
4141

42-
impl ToAccountInfos for AccountView {
43-
fn to_account_infos(&self) -> Vec<AccountView> {
42+
impl ToAccountViews for AccountView {
43+
fn to_account_views(&self) -> Vec<AccountView> {
4444
vec![*self]
4545
}
4646
}

lang/src/accounts/account_loader.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! Type facilitating on demand zero copy deserialization.
22
3-
use crate::pinocchio_runtime::account_info::{AccountView, Ref, RefMut};
3+
use crate::pinocchio_runtime::account_view::{AccountView, Ref, RefMut};
44

55
use crate::bpf_writer::BpfWriter;
66
use crate::error::{Error, ErrorCode};
77
use crate::pinocchio_runtime::instruction::AccountMeta;
88
use crate::pinocchio_runtime::pubkey::Pubkey;
99
use crate::{
10-
Accounts, AccountsClose, AccountsExit, Key, Owner, Result, ToAccountInfo, ToAccountInfos,
11-
ToAccountMetas, ZeroCopy,
10+
Accounts, AccountsClose, AccountsExit, Key, Owner, Result, ToAccountMetas, ToAccountView,
11+
ToAccountViews, ZeroCopy,
1212
};
1313

1414
use std::collections::BTreeSet;
@@ -252,7 +252,7 @@ impl<'info, T: ZeroCopy + Owner> AccountsExit<'info> for AccountLoader<'info, T>
252252

253253
impl<'info, T: ZeroCopy + Owner> AccountsClose<'info> for AccountLoader<'info, T> {
254254
fn close(&self, sol_destination: AccountView) -> Result<()> {
255-
crate::common::close(self.to_account_info(), sol_destination)
255+
crate::common::close(self.to_account_view(), sol_destination)
256256
}
257257
}
258258

@@ -275,8 +275,8 @@ impl<'info, T: ZeroCopy + Owner> AsRef<AccountView> for AccountLoader<'info, T>
275275
}
276276
}
277277

278-
impl<'info, T: ZeroCopy + Owner> ToAccountInfos for AccountLoader<'info, T> {
279-
fn to_account_infos(&self) -> Vec<AccountView> {
278+
impl<'info, T: ZeroCopy + Owner> ToAccountViews for AccountLoader<'info, T> {
279+
fn to_account_views(&self) -> Vec<AccountView> {
280280
vec![self.acc_info]
281281
}
282282
}

lang/src/accounts/boxed.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
//! }
1414
//! ```
1515
16-
use crate::pinocchio_runtime::account_info::AccountView;
16+
use crate::pinocchio_runtime::account_view::AccountView;
1717
use crate::pinocchio_runtime::instruction::AccountMeta;
1818
use crate::pinocchio_runtime::pubkey::Pubkey;
19-
use crate::{Accounts, AccountsClose, AccountsExit, Result, ToAccountInfos, ToAccountMetas};
19+
use crate::{Accounts, AccountsClose, AccountsExit, Result, ToAccountMetas, ToAccountViews};
2020
use std::collections::BTreeSet;
2121
use std::ops::Deref;
2222

@@ -38,9 +38,9 @@ impl<'info, T: AccountsExit<'info>> AccountsExit<'info> for Box<T> {
3838
}
3939
}
4040

41-
impl<T: ToAccountInfos> ToAccountInfos for Box<T> {
42-
fn to_account_infos(&self) -> Vec<AccountView> {
43-
T::to_account_infos(self)
41+
impl<T: ToAccountViews> ToAccountViews for Box<T> {
42+
fn to_account_views(&self) -> Vec<AccountView> {
43+
T::to_account_views(self)
4444
}
4545
}
4646

lang/src/accounts/interface.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
use crate::accounts::account::AnyProgram;
44
use crate::accounts::program::Program;
55
use crate::error::{Error, ErrorCode};
6-
use crate::pinocchio_runtime::account_info::AccountView;
6+
use crate::pinocchio_runtime::account_view::AccountView;
77
use crate::pinocchio_runtime::instruction::AccountMeta;
88
use crate::pinocchio_runtime::pubkey::Pubkey;
99
use crate::{
10-
AccountDeserialize, Accounts, AccountsExit, CheckId, Key, Result, ToAccountInfos,
10+
AccountDeserialize, Accounts, AccountsExit, CheckId, Key, Result, ToAccountViews,
1111
ToAccountMetas,
1212
};
1313
use std::collections::BTreeSet;
@@ -134,9 +134,9 @@ impl<T> ToAccountMetas for Interface<'_, T> {
134134
}
135135
}
136136

137-
impl<'info, T> ToAccountInfos for Interface<'info, T> {
138-
fn to_account_infos(&self) -> Vec<AccountView> {
139-
self.program.to_account_infos()
137+
impl<'info, T> ToAccountViews for Interface<'info, T> {
138+
fn to_account_views(&self) -> Vec<AccountView> {
139+
self.program.to_account_views()
140140
}
141141
}
142142

lang/src/accounts/interface_account.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
33
use crate::accounts::account::Account;
44
use crate::error::{Error, ErrorCode};
5-
use crate::pinocchio_runtime::account_info::AccountView;
5+
use crate::pinocchio_runtime::account_view::AccountView;
66
use crate::pinocchio_runtime::instruction::AccountMeta;
77
use crate::pinocchio_runtime::pubkey::Pubkey;
88
use crate::pinocchio_runtime::system_program;
99
use crate::{
1010
AccountDeserialize, AccountSerialize, Accounts, AccountsClose, AccountsExit, CheckOwner, Key,
11-
Owner, Owners, Result, ToAccountInfo, ToAccountInfos, ToAccountMetas,
11+
Owner, Owners, Result, ToAccountMetas, ToAccountView, ToAccountViews,
1212
};
1313
use std::collections::BTreeSet;
1414
use std::convert::AsRef;
1515
use std::fmt;
1616
use std::ops::{Deref, DerefMut};
1717

18-
/// Wrapper around [`AccountView`](crate::pinocchio_runtime::account_info::AccountView)
18+
/// Wrapper around [`AccountView`](crate::pinocchio_runtime::account_view::AccountView)
1919
/// that verifies program ownership and deserializes underlying data into a Rust type.
2020
///
2121
/// # Table of Contents
@@ -194,7 +194,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Owner + Clone> InterfaceAcco
194194
/// If you need discriminator validation on reload, use `Account<T>` with an Anchor
195195
/// #[account] type.
196196
pub fn reload(&mut self) -> Result<()> {
197-
let info = self.account.to_account_info();
197+
let info = self.account.to_account_view();
198198

199199
// Enforce owner stability: must match the one validated at construction.
200200
if !info.owned_by(&self.owner) {
@@ -308,11 +308,11 @@ impl<T: AccountSerialize + AccountDeserialize + Owner + Clone> ToAccountMetas
308308
}
309309
}
310310

311-
impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> ToAccountInfos
311+
impl<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone> ToAccountViews
312312
for InterfaceAccount<'info, T>
313313
{
314-
fn to_account_infos(&self) -> Vec<AccountView> {
315-
self.account.to_account_infos()
314+
fn to_account_views(&self) -> Vec<AccountView> {
315+
self.account.to_account_views()
316316
}
317317
}
318318

0 commit comments

Comments
 (0)