From e422bd3d8c85161599a56dc6959dc4defe587287 Mon Sep 17 00:00:00 2001 From: Stan Drozd Date: Mon, 31 May 2021 16:55:35 +0200 Subject: [PATCH] clean up solitaire! macro Change-Id: I208d7b71c870b5f22c802fe25b0d003fc1047c54 --- solana/anchor-bridge/Cargo.lock | 60 ------------------- .../programs/bridge/src/api/initialize.rs | 1 - .../anchor-bridge/programs/bridge/src/lib.rs | 2 +- .../programs/solitaire/src/lib.rs | 21 +++---- 4 files changed, 12 insertions(+), 72 deletions(-) diff --git a/solana/anchor-bridge/Cargo.lock b/solana/anchor-bridge/Cargo.lock index fe17918fc..3fc99aaa2 100644 --- a/solana/anchor-bridge/Cargo.lock +++ b/solana/anchor-bridge/Cargo.lock @@ -206,17 +206,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "digest" version = "0.8.1" @@ -403,28 +392,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_enum" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b45a5c2ac4dd696ed30fa6b94b057ad909c7b7fc2e0d0808192bced894066" -dependencies = [ - "derivative", - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c0fd9eba1d5db0994a239e09c1be402d35622277e35468ba891aa5e3188ce7e" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "opaque-debug" version = "0.3.0" @@ -720,20 +687,6 @@ dependencies = [ "solana-program", ] -[[package]] -name = "spl-token" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbfa8fd791aeb4d7ad5fedb7872478de9f4e8b4fcb02dfd9e7f2f9ae3f3ddd73" -dependencies = [ - "arrayref", - "num-derive", - "num-traits", - "num_enum", - "solana-program", - "thiserror", -] - [[package]] name = "subtle" version = "2.4.0" @@ -780,19 +733,6 @@ dependencies = [ "syn", ] -[[package]] -name = "token-bridge" -version = "0.1.0" -dependencies = [ - "borsh", - "byteorder", - "rocksalt", - "sha3", - "solana-program", - "solitaire", - "spl-token", -] - [[package]] name = "toml" version = "0.5.8" diff --git a/solana/anchor-bridge/programs/bridge/src/api/initialize.rs b/solana/anchor-bridge/programs/bridge/src/api/initialize.rs index 71f1203d3..f725d9b66 100644 --- a/solana/anchor-bridge/programs/bridge/src/api/initialize.rs +++ b/solana/anchor-bridge/programs/bridge/src/api/initialize.rs @@ -1,5 +1,4 @@ use crate::types::*; -use solana_program::program_error::ProgramError; use solitaire::*; type Payer<'a> = Signer>; diff --git a/solana/anchor-bridge/programs/bridge/src/lib.rs b/solana/anchor-bridge/programs/bridge/src/lib.rs index 5a6cc94b7..7d42ccdaa 100644 --- a/solana/anchor-bridge/programs/bridge/src/lib.rs +++ b/solana/anchor-bridge/programs/bridge/src/lib.rs @@ -11,5 +11,5 @@ use types::BridgeConfig; use solitaire::*; solitaire! { - Initialize(config: BridgeConfig) => initialize, + Initialize(BridgeConfig) => initialize, } diff --git a/solana/anchor-bridge/programs/solitaire/src/lib.rs b/solana/anchor-bridge/programs/solitaire/src/lib.rs index e6826b13e..af222e94c 100644 --- a/solana/anchor-bridge/programs/solitaire/src/lib.rs +++ b/solana/anchor-bridge/programs/solitaire/src/lib.rs @@ -63,6 +63,7 @@ impl Into for SolitaireError { /// Quality of life Result type for the Solitaire stack. pub type Result = std::result::Result; +pub type ErrBox = Box; pub trait Persist { fn persist(self); @@ -153,13 +154,13 @@ impl<'a, 'b: 'a, 'c, T> Context<'a, 'b, 'c, T> { program: &'a Pubkey, iter: &'c mut Iter<'a, AccountInfo<'b>>, data: &'a T, - deps: &'c mut Vec, + deps: &'c mut Vec, ) -> Self { Context { this: program, iter, data, - deps, + deps , info: None, } } @@ -393,7 +394,7 @@ pub trait FromAccounts<'a, 'b: 'a, 'c> { /// - A set of client calls scoped to the module `api` that can generate instructions. #[macro_export] macro_rules! solitaire { - { $($row:ident($($name:ident: $kind:ty),* $(,)*) => $fn:ident),+ $(,)* } => { + { $($row:ident($kind:ty) => $fn:ident),+ $(,)* } => { mod instruction { use super::*; use borsh::{BorshDeserialize, BorshSerialize}; @@ -405,7 +406,7 @@ macro_rules! solitaire { #[derive(BorshSerialize, BorshDeserialize)] enum Instruction { - $($row($($kind,)*),)* + $($row($kind),)* } /// This entrypoint is generated from the enum above, it deserializes incoming bytes @@ -413,9 +414,9 @@ macro_rules! solitaire { pub fn dispatch<'a, 'b: 'a, 'c>(p: &Pubkey, a: &'c [AccountInfo<'b>], d: &[u8]) -> ProgramResult { match Instruction::try_from_slice(d)? { $( - Instruction::$row($($name,)*) => { + Instruction::$row(ix_data) => { let (mut accounts, _deps): ($row, _) = FromAccounts::from(p, &mut a.iter(), &()).unwrap(); - $fn(&ExecutionContext{program_id: p, accounts: a}, &mut accounts, $($name,)*); + $fn(&ExecutionContext{program_id: p, accounts: a}, &mut accounts, ix_data)?; accounts.persist(); Ok(()) } @@ -441,12 +442,12 @@ macro_rules! solitaire { use solana_program::instruction::Instruction; /// Generated from Instruction Field - $(pub(crate) fn $fn(pid: &Pubkey, $($name: $kind,)*) -> Instruction { - Instruction { + $(pub(crate) fn $fn(pid: &Pubkey, accounts: $row, ix_data: $kind) -> std::result::Result { + Ok(Instruction { program_id: *pid, accounts: vec![], - data: vec![], - } + data: ix_data.try_to_vec()?, + }) })* }