solitaire: Wrap for Info, auto Wrap for data_wrapper()

Change-Id: I5cc0ba7870e140a2acf77b8fc8814ee953f56b51
This commit is contained in:
Stan Drozd 2021-06-25 16:05:03 +02:00
parent 9d35ec242e
commit 60a1acf351
2 changed files with 25 additions and 0 deletions

View File

@ -23,6 +23,7 @@ use borsh::BorshSerialize;
use solitaire::{
AccountState,
Info,
Sysvar,
};
pub use solitaire::{
@ -172,6 +173,20 @@ where
}
}
impl<'b> Wrap for Info<'b> {
fn wrap(a: &AccEntry) -> StdResult<Vec<AccountMeta>, ErrBox> {
match a {
AccEntry::UnprivilegedRO(k) => Ok(vec![AccountMeta::new_readonly(k.clone(), false)]),
AccEntry::Unprivileged(k) => Ok(vec![AccountMeta::new(k.clone(), false)]),
_other => Err(format!(
"{} must be passed as Unprivileged or UnprivilegedRO",
std::any::type_name::<Self>()
)
.into()),
}
}
}
/// Trait used on client side to easily validate a program accounts + ix_data for a bare Solana call
pub trait ToInstruction {
fn to_ix(

View File

@ -144,6 +144,16 @@ macro_rules! data_wrapper {
return self.1.owner();
}
}
#[cfg(feature = "client")]
impl<'b> solitaire_client::Wrap for $name<'b> {
fn wrap(
a: &solitaire_client::AccEntry,
) -> std::result::Result<Vec<solitaire_client::AccountMeta>, solitaire_client::ErrBox>
{
solitaire::Data::<'b, $embed, { $state }>::wrap(a)
}
}
};
}