Skip to content

Commit 2889ebe

Browse files
authored
Merge pull request #73 from staratlasmeta/stegaBOB/chore/remove-unneccesary-set-method
Chore: removed account set methods
2 parents 8d88c9f + e5f244c commit 2889ebe

File tree

10 files changed

+9
-202
lines changed

10 files changed

+9
-202
lines changed

framework/star_frame/src/account_set/impls/account_info.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,8 @@ use solana_program::pubkey::Pubkey;
88
use star_frame::account_set::{AccountSet, AccountSetCleanup, AccountSetValidate};
99
use std::cell::{Ref, RefMut};
1010

11-
impl<'info> AccountSet<'info> for AccountInfo<'info> {
12-
fn try_to_accounts<'a, E>(
13-
&'a self,
14-
mut add_account: impl FnMut(&'a AccountInfo<'info>) -> Result<(), E>,
15-
) -> Result<(), E>
16-
where
17-
'info: 'a,
18-
{
19-
add_account(self)
20-
}
21-
22-
fn to_account_metas(&self, mut add_account_meta: impl FnMut(AccountMeta)) {
23-
add_account_meta(self.account_meta());
24-
}
25-
}
26-
impl<'__a, 'info> AccountSet<'info> for &'__a AccountInfo<'info> {
27-
fn try_to_accounts<'a, E>(
28-
&'a self,
29-
mut add_account: impl FnMut(&'a AccountInfo<'info>) -> Result<(), E>,
30-
) -> Result<(), E>
31-
where
32-
'info: 'a,
33-
{
34-
add_account(self)
35-
}
36-
37-
fn to_account_metas(&self, mut add_account_meta: impl FnMut(AccountMeta)) {
38-
add_account_meta(self.account_meta());
39-
}
40-
}
11+
impl<'info> AccountSet<'info> for AccountInfo<'info> {}
12+
impl<'__a, 'info> AccountSet<'info> for &'__a AccountInfo<'info> {}
4113
impl<'info> SingleAccountSet<'info> for AccountInfo<'info> {
4214
fn account_info(&self) -> &AccountInfo<'info> {
4315
self

framework/star_frame/src/account_set/impls/array.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,8 @@ use crate::syscalls::SyscallInvoke;
33
use crate::Result;
44
use array_init::try_array_init;
55
use solana_program::account_info::AccountInfo;
6-
use solana_program::instruction::AccountMeta;
76

8-
impl<'info, A, const N: usize> AccountSet<'info> for [A; N]
9-
where
10-
A: AccountSet<'info>,
11-
{
12-
fn try_to_accounts<'a, E>(
13-
&'a self,
14-
mut add_account: impl FnMut(&'a AccountInfo<'info>) -> Result<(), E>,
15-
) -> Result<(), E>
16-
where
17-
'info: 'a,
18-
{
19-
for a in self {
20-
a.try_to_accounts(&mut add_account)?;
21-
}
22-
Ok(())
23-
}
24-
25-
fn to_account_metas(&self, mut add_account_meta: impl FnMut(AccountMeta)) {
26-
for a in self {
27-
a.to_account_metas(&mut add_account_meta);
28-
}
29-
}
30-
}
7+
impl<'info, A, const N: usize> AccountSet<'info> for [A; N] where A: AccountSet<'info> {}
318

329
impl<'a, 'info, A, const N: usize, DArg> AccountSetDecode<'a, 'info, [DArg; N]> for [A; N]
3310
where

framework/star_frame/src/account_set/impls/option.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,10 @@ use crate::syscalls::SyscallInvoke;
33
use crate::Result;
44
use anyhow::bail;
55
use solana_program::account_info::AccountInfo;
6-
use solana_program::instruction::AccountMeta;
76
use solana_program::msg;
87
use solana_program::program_error::ProgramError;
98

10-
impl<'info, A> AccountSet<'info> for Option<A>
11-
where
12-
A: AccountSet<'info>,
13-
{
14-
fn try_to_accounts<'a, E>(
15-
&'a self,
16-
add_account: impl FnMut(&'a AccountInfo<'info>) -> crate::Result<(), E>,
17-
) -> crate::Result<(), E>
18-
where
19-
'info: 'a,
20-
{
21-
if let Some(s) = self {
22-
s.try_to_accounts(add_account)
23-
} else {
24-
Ok(())
25-
}
26-
}
27-
28-
fn to_account_metas(&self, add_account_meta: impl FnMut(AccountMeta)) {
29-
if let Some(s) = self {
30-
s.to_account_metas(add_account_meta);
31-
}
32-
}
33-
}
9+
impl<'info, A> AccountSet<'info> for Option<A> where A: AccountSet<'info> {}
3410

3511
impl<'a, 'info, A, DArg> AccountSetDecode<'a, 'info, Option<DArg>> for Option<A>
3612
where

framework/star_frame/src/account_set/impls/phantom_data.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,9 @@ use crate::account_set::{AccountSet, AccountSetCleanup, AccountSetDecode, Accoun
22
use crate::syscalls::SyscallInvoke;
33
use crate::Result;
44
use solana_program::account_info::AccountInfo;
5-
use solana_program::instruction::AccountMeta;
65
use std::marker::PhantomData;
76

8-
impl<'info, T> AccountSet<'info> for PhantomData<T>
9-
where
10-
T: ?Sized,
11-
{
12-
fn try_to_accounts<'a, E>(
13-
&'a self,
14-
_add_account: impl FnMut(&'a AccountInfo<'info>) -> crate::Result<(), E>,
15-
) -> Result<(), E>
16-
where
17-
'info: 'a,
18-
{
19-
Ok(())
20-
}
21-
22-
fn to_account_metas(&self, _add_account_meta: impl FnMut(AccountMeta)) {}
23-
}
7+
impl<'info, T> AccountSet<'info> for PhantomData<T> where T: ?Sized {}
248
impl<'a, 'info, T> AccountSetDecode<'a, 'info, ()> for PhantomData<T>
259
where
2610
T: ?Sized,

framework/star_frame/src/account_set/impls/unit.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,8 @@ use crate::account_set::{AccountSet, AccountSetCleanup, AccountSetDecode, Accoun
22
use crate::syscalls::SyscallInvoke;
33
use crate::Result;
44
use solana_program::account_info::AccountInfo;
5-
use solana_program::instruction::AccountMeta;
65

7-
impl<'info> AccountSet<'info> for () {
8-
fn try_to_accounts<'a, E>(
9-
&'a self,
10-
_add_account: impl FnMut(&'a AccountInfo<'info>) -> Result<(), E>,
11-
) -> Result<(), E>
12-
where
13-
'info: 'a,
14-
{
15-
Ok(())
16-
}
17-
18-
fn to_account_metas(&self, _add_account_meta: impl FnMut(AccountMeta)) {}
19-
}
6+
impl<'info> AccountSet<'info> for () {}
207
impl<'a, 'info> AccountSetDecode<'a, 'info, ()> for () {
218
fn decode_accounts(
229
_accounts: &mut &'a [AccountInfo],

framework/star_frame/src/account_set/impls/vec.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,9 @@ use crate::syscalls::SyscallInvoke;
33
use crate::Result;
44
use anyhow::bail;
55
use solana_program::account_info::AccountInfo;
6-
use solana_program::instruction::AccountMeta;
76
use solana_program::program_error::ProgramError;
87

9-
impl<'info, T> AccountSet<'info> for Vec<T>
10-
where
11-
T: AccountSet<'info>,
12-
{
13-
fn try_to_accounts<'a, E>(
14-
&'a self,
15-
mut add_account: impl FnMut(&'a AccountInfo<'info>) -> crate::Result<(), E>,
16-
) -> crate::Result<(), E>
17-
where
18-
'info: 'a,
19-
{
20-
for acc in self {
21-
acc.try_to_accounts(&mut add_account)?;
22-
}
23-
Ok(())
24-
}
25-
26-
fn to_account_metas(&self, mut add_account_meta: impl FnMut(AccountMeta)) {
27-
for acc in self {
28-
acc.to_account_metas(&mut add_account_meta);
29-
}
30-
}
31-
}
8+
impl<'info, T> AccountSet<'info> for Vec<T> where T: AccountSet<'info> {}
329
impl<'a, 'info, T> AccountSetDecode<'a, 'info, usize> for Vec<T>
3310
where
3411
T: AccountSetDecode<'a, 'info, ()>,

framework/star_frame/src/account_set/mod.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,12 @@ use solana_program::instruction::AccountMeta;
2222
use solana_program::program_error::ProgramError;
2323
use solana_program::pubkey::Pubkey;
2424
use std::cell::{Ref, RefMut};
25-
use std::convert::Infallible;
2625
use std::slice;
2726

2827
/// A set of accounts that can be used as input to an instruction.
2928
pub trait AccountSet<'info> {
3029
/// Sets account cache
3130
fn set_account_cache(&mut self, _syscalls: &mut impl SyscallAccountCache<'info>) {}
32-
33-
fn try_to_accounts<'a, E>(
34-
&'a self,
35-
add_account: impl FnMut(&'a AccountInfo<'info>) -> Result<(), E>,
36-
) -> Result<(), E>
37-
where
38-
'info: 'a;
39-
40-
/// Add all the accounts in this set using `add_account`.
41-
fn to_accounts<'a>(&'a self, mut add_account: impl FnMut(&'a AccountInfo<'info>))
42-
where
43-
'info: 'a,
44-
{
45-
self.try_to_accounts::<Infallible>(|a| {
46-
add_account(a);
47-
Ok(())
48-
})
49-
.unwrap();
50-
}
51-
52-
/// Gets a vector of all the accounts in this set.
53-
fn to_accounts_vec<'a>(&'a self) -> Vec<&'a AccountInfo<'info>> {
54-
let mut out = Vec::new();
55-
self.to_accounts(|acc| out.push(acc));
56-
out
57-
}
58-
59-
/// Add all accounts in this set using `add_account_meta`.
60-
fn to_account_metas(&self, add_account_meta: impl FnMut(AccountMeta));
61-
62-
/// Gets a vector of all the account metas in this set.
63-
fn to_account_metas_vec(&self) -> Vec<AccountMeta> {
64-
let mut out = Vec::new();
65-
self.to_account_metas(|acc| out.push(acc));
66-
out
67-
}
6831
}
6932

7033
/// Convenience methods for decoding and validating a list of [`AccountInfo`]s to an [`AccountSet`]. Performs

framework/star_frame_proc/src/account_set/generics.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::util::{new_generic, new_lifetime};
1+
use crate::util::new_generic;
22
use proc_macro2::{Ident, Span};
33
use std::collections::HashMap;
44
use syn::{GenericParam, Generics, Lifetime, LifetimeParam};
@@ -10,7 +10,6 @@ pub struct AccountSetGenerics {
1010
pub decode_generics: Generics,
1111
pub info_lifetime: Lifetime,
1212
pub decode_lifetime: Lifetime,
13-
pub function_lifetime: Lifetime,
1413
pub function_generic_type: Ident,
1514
}
1615

@@ -27,7 +26,6 @@ pub fn account_set_generics(generics: Generics) -> AccountSetGenerics {
2726
LifetimeParam::new(Lifetime::new("'info", Span::call_site()))
2827
})
2928
.clone();
30-
let function_lifetime = new_lifetime(&generics);
3129
let function_generic_type = new_generic(&generics);
3230
let mut decode_lifetimes = lifetimes.clone();
3331
let mut add_decode = false;
@@ -61,7 +59,6 @@ pub fn account_set_generics(generics: Generics) -> AccountSetGenerics {
6159
decode_generics,
6260
info_lifetime: info_lifetime.lifetime,
6361
decode_lifetime: decode_lifetime.lifetime,
64-
function_lifetime,
6562
function_generic_type,
6663
}
6764
}

framework/star_frame_proc/src/account_set/struct_impl/mod.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,13 @@ pub(super) fn derive_account_set_impl_struct(
6767
main_generics,
6868
other_generics,
6969
info_lifetime,
70-
function_lifetime,
7170
function_generic_type,
7271
..
7372
} = &account_set_generics;
7473

7574
let Paths {
7675
account_info,
7776
account_set,
78-
crate_name,
7977
macro_prelude,
8078
result,
8179
..
@@ -450,31 +448,6 @@ pub(super) fn derive_account_set_impl_struct(
450448
#set_account_caches
451449
#(<#field_type as #account_set<#info_lifetime>>::set_account_cache(&mut self.#field_name, syscalls);)*
452450
}
453-
454-
fn try_to_accounts<#function_lifetime, #function_generic_type>(
455-
&#function_lifetime self,
456-
mut add_account: impl FnMut(&#function_lifetime #account_info<#info_lifetime>) -> #result<(), #function_generic_type>,
457-
) -> #result<(), #function_generic_type>
458-
where
459-
#info_lifetime: #function_lifetime,
460-
{
461-
#(<#field_type as #account_set<#info_lifetime>>::try_to_accounts(&self.#field_name, &mut add_account)?;)*
462-
Ok(())
463-
}
464-
465-
fn to_accounts<#function_lifetime>(
466-
&#function_lifetime self,
467-
mut add_account: impl FnMut(&#function_lifetime #account_info<#info_lifetime>),
468-
)
469-
where
470-
#info_lifetime: #function_lifetime,
471-
{
472-
#(<#field_type as #account_set<#info_lifetime>>::to_accounts(&self.#field_name, &mut add_account);)*
473-
}
474-
475-
fn to_account_metas(&self, mut add_account_meta: impl FnMut(#crate_name::solana_program::instruction::AccountMeta)) {
476-
#(<#field_type as #account_set<#info_lifetime>>::to_account_metas(&self.#field_name, &mut add_account_meta);)*
477-
}
478451
}
479452

480453
#(#decodes)*

framework/star_frame_proc/src/util/generics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl CombineGenerics for Generics {
137137
}
138138
}
139139

140+
#[allow(dead_code)]
140141
pub fn new_lifetime<G: GetGenerics>(generics: &G) -> Lifetime {
141142
let mut lifetime = "l".to_string();
142143
while generics

0 commit comments

Comments
 (0)