Implement Wrap for solitaire::Sysvar<...>
Change-Id: I066e425d1e1549ea296a4b54ef019872064a8acd
This commit is contained in:
parent
834b26b773
commit
e1c2f73e29
|
@ -5,6 +5,7 @@
|
||||||
//! Client-specific code
|
//! Client-specific code
|
||||||
|
|
||||||
pub use solana_program::pubkey::Pubkey;
|
pub use solana_program::pubkey::Pubkey;
|
||||||
|
use solana_program::sysvar::Sysvar as SolSysvar;
|
||||||
pub use solana_sdk;
|
pub use solana_sdk;
|
||||||
|
|
||||||
pub use solana_sdk::{
|
pub use solana_sdk::{
|
||||||
|
@ -20,7 +21,10 @@ pub use solana_sdk::{
|
||||||
|
|
||||||
use borsh::BorshSerialize;
|
use borsh::BorshSerialize;
|
||||||
|
|
||||||
use solitaire::AccountState;
|
use solitaire::{
|
||||||
|
AccountState,
|
||||||
|
Sysvar,
|
||||||
|
};
|
||||||
pub use solitaire::{
|
pub use solitaire::{
|
||||||
Data,
|
Data,
|
||||||
Derive,
|
Derive,
|
||||||
|
@ -52,7 +56,7 @@ pub enum AccEntry {
|
||||||
CPIProgramSigner(Keypair),
|
CPIProgramSigner(Keypair),
|
||||||
|
|
||||||
/// Key decided from SPL constants
|
/// Key decided from SPL constants
|
||||||
Sysvar,
|
Sysvar(Pubkey),
|
||||||
|
|
||||||
/// Key derived from constants and/or program address
|
/// Key derived from constants and/or program address
|
||||||
Derived(Pubkey),
|
Derived(Pubkey),
|
||||||
|
@ -146,6 +150,26 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'b, Var> Wrap for Sysvar<'b, Var>
|
||||||
|
where
|
||||||
|
Var: SolSysvar,
|
||||||
|
{
|
||||||
|
fn wrap(a: &AccEntry) -> StdResult<Vec<AccountMeta>, ErrBox> {
|
||||||
|
if let AccEntry::Sysvar(k) = a {
|
||||||
|
if Var::check_id(k) {
|
||||||
|
Ok(vec![AccountMeta::new_readonly(k.clone(), false)])
|
||||||
|
} else {
|
||||||
|
Err(format!("{} does not point at sysvar {}", k, std::any::type_name::<Var>()).into())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(format!(
|
||||||
|
"{} must be passed as Sysvar",
|
||||||
|
std::any::type_name::<Self>()
|
||||||
|
).into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Trait used on client side to easily validate a program accounts + ix_data for a bare Solana call
|
/// Trait used on client side to easily validate a program accounts + ix_data for a bare Solana call
|
||||||
pub trait ToInstruction {
|
pub trait ToInstruction {
|
||||||
fn to_ix(
|
fn to_ix(
|
||||||
|
|
Loading…
Reference in New Issue