From 60a1acf3511403bb27018e522a8c87223f0dc893 Mon Sep 17 00:00:00 2001 From: Stan Drozd Date: Fri, 25 Jun 2021 16:05:03 +0200 Subject: [PATCH] solitaire: Wrap for Info, auto Wrap for data_wrapper() Change-Id: I5cc0ba7870e140a2acf77b8fc8814ee953f56b51 --- solana/solitaire/client/src/lib.rs | 15 +++++++++++++++ solana/solitaire/program/src/macros.rs | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/solana/solitaire/client/src/lib.rs b/solana/solitaire/client/src/lib.rs index d4eddfcb6..140e1c304 100644 --- a/solana/solitaire/client/src/lib.rs +++ b/solana/solitaire/client/src/lib.rs @@ -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, 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::() + ) + .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( diff --git a/solana/solitaire/program/src/macros.rs b/solana/solitaire/program/src/macros.rs index 5e44c7586..9a987a9d5 100644 --- a/solana/solitaire/program/src/macros.rs +++ b/solana/solitaire/program/src/macros.rs @@ -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, solitaire_client::ErrBox> + { + solitaire::Data::<'b, $embed, { $state }>::wrap(a) + } + } }; }