clean up solitaire! macro

Change-Id: I208d7b71c870b5f22c802fe25b0d003fc1047c54
This commit is contained in:
Stan Drozd 2021-05-31 16:55:35 +02:00
parent 652f4ea3b1
commit e422bd3d8c
4 changed files with 12 additions and 72 deletions

View File

@ -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"

View File

@ -1,5 +1,4 @@
use crate::types::*;
use solana_program::program_error::ProgramError;
use solitaire::*;
type Payer<'a> = Signer<Info<'a>>;

View File

@ -11,5 +11,5 @@ use types::BridgeConfig;
use solitaire::*;
solitaire! {
Initialize(config: BridgeConfig) => initialize,
Initialize(BridgeConfig) => initialize,
}

View File

@ -63,6 +63,7 @@ impl Into<ProgramError> for SolitaireError {
/// Quality of life Result type for the Solitaire stack.
pub type Result<T> = std::result::Result<T, ProgramError>;
pub type ErrBox = Box<dyn std::error::Error>;
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<Pubkey>,
deps: &'c mut Vec<Pubkey>,
) -> 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<Instruction, ErrBox> {
Ok(Instruction {
program_id: *pid,
accounts: vec![],
data: vec![],
}
data: ix_data.try_to_vec()?,
})
})*
}