Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lang: use phantomdata in account type instead of '_account: T' #1155

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions lang/src/accounts/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,32 @@ use solana_program::instruction::AccountMeta;
use solana_program::program_error::ProgramError;
use solana_program::pubkey::Pubkey;
use std::fmt;
use std::marker::PhantomData;
use std::ops::Deref;

/// Account container that checks ownership on deserialization.
#[derive(Clone)]
pub struct Program<'info, T: Id + AccountDeserialize + Clone> {
_account: T,
info: AccountInfo<'info>,
programdata_address: Option<Pubkey>,
_phantom: PhantomData<T>,
}

impl<'info, T: Id + AccountDeserialize + Clone + fmt::Debug> fmt::Debug for Program<'info, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Program")
.field("account", &self._account)
.field("info", &self.info)
.field("programdata_address", &self.programdata_address)
.finish()
}
}

impl<'a, T: Id + AccountDeserialize + Clone> Program<'a, T> {
fn new(
info: AccountInfo<'a>,
_account: T,
programdata_address: Option<Pubkey>,
) -> Program<'a, T> {
fn new(info: AccountInfo<'a>, programdata_address: Option<Pubkey>) -> Program<'a, T> {
Self {
info,
_account,
programdata_address,
_phantom: PhantomData,
}
}

Expand Down Expand Up @@ -75,13 +71,7 @@ impl<'a, T: Id + AccountDeserialize + Clone> Program<'a, T> {
None
};

// Programs have no data so use an empty slice.
let mut empty = &[][..];
Ok(Program::new(
info.clone(),
T::try_deserialize(&mut empty)?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this trait bound and the associated implementations as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Deserialize trait bound for T?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dex struct also implements AccountSerialize. Was that intentional?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a mistake. Can remove that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

programdata_address,
))
Ok(Program::new(info.clone(), programdata_address))
}

pub fn programdata_address(&self) -> Option<Pubkey> {
Expand Down