diff --git a/solana/anchor-bridge/solitaire-client/src/lib.rs b/solana/anchor-bridge/solitaire-client/src/lib.rs index 0d405d050..a44b3fbe2 100644 --- a/solana/anchor-bridge/solitaire-client/src/lib.rs +++ b/solana/anchor-bridge/solitaire-client/src/lib.rs @@ -5,6 +5,7 @@ //! Client-specific code pub use solana_program::pubkey::Pubkey; +use solana_program::sysvar::Sysvar as SolSysvar; pub use solana_sdk; pub use solana_sdk::{ @@ -20,7 +21,10 @@ pub use solana_sdk::{ use borsh::BorshSerialize; -use solitaire::AccountState; +use solitaire::{ + AccountState, + Sysvar, +}; pub use solitaire::{ Data, Derive, @@ -52,7 +56,7 @@ pub enum AccEntry { CPIProgramSigner(Keypair), /// Key decided from SPL constants - Sysvar, + Sysvar(Pubkey), /// Key derived from constants and/or program address Derived(Pubkey), @@ -146,6 +150,26 @@ where } } +impl<'b, Var> Wrap for Sysvar<'b, Var> +where + Var: SolSysvar, +{ + fn wrap(a: &AccEntry) -> StdResult, 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::()).into()) + } + } else { + Err(format!( + "{} must be passed as Sysvar", + std::any::type_name::() + ).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(