-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactoring & Improve SDK (#4)
- Loading branch information
1 parent
07a2f4a
commit 48ccd73
Showing
9 changed files
with
336 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ members = [ | |
resolver = "2" | ||
|
||
[workspace.package] | ||
version = "0.0.5" | ||
version = "0.0.6" | ||
authors = ["Magicblock Labs <[email protected]>"] | ||
edition = "2021" | ||
license = "MIT" | ||
|
@@ -17,9 +17,11 @@ readme = "./README.md" | |
keywords = ["solana", "crypto", "delegation", "ephemeral-rollups", "magicblock"] | ||
|
||
[workspace.dependencies] | ||
ephemeral-rollups-sdk-attribute-delegate = { path = "sdk/delegate", version = "=0.0.5" } | ||
ephemeral-rollups-sdk-attribute-delegate = { path = "sdk/delegate", version = "=0.0.6" } | ||
ephemeral-rollups-sdk-attribute-commit = { path = "sdk/commit_attribute", version = "=0.0.6" } | ||
|
||
## External crates | ||
anchor-lang = "0.30.1" | ||
borsh = "0.10.3" | ||
paste = "^1.0" | ||
solana-program = "^1.16" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "ephemeral-rollups-sdk-attribute-commit" | ||
description = "ephemeral-rollups-sdk-attribute-commit" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
repository = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
proc-macro2 = { workspace = true } | ||
syn = { workspace = true, features = ["full"] } | ||
quote = { workspace = true } | ||
|
||
[lib] | ||
proc-macro = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
extern crate proc_macro; | ||
use syn::parse::Parser; | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::{parse_macro_input, Fields, Field, ItemStruct}; | ||
|
||
#[proc_macro_attribute] | ||
pub fn commit(_attr: TokenStream, item: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(item as ItemStruct); | ||
|
||
let name = &input.ident; | ||
let expanded = if let Fields::Named(fields_named) = &input.fields { | ||
let mut has_magic_program = false; | ||
let mut has_magic_context = false; | ||
|
||
for field in &fields_named.named { | ||
if let Some(ident) = &field.ident { | ||
if ident == "magic_program" { | ||
has_magic_program = true; | ||
} else if ident == "magic_context" { | ||
has_magic_context = true; | ||
} | ||
} | ||
} | ||
|
||
let mut new_fields = fields_named.named.clone(); | ||
|
||
if !has_magic_program { | ||
new_fields.push(Field::parse_named.parse2(quote! { | ||
pub magic_program: Program<'info, MagicProgram> | ||
}).unwrap()); | ||
} | ||
|
||
if !has_magic_context { | ||
new_fields.push(Field::parse_named.parse2(quote! { | ||
#[account(mut, address = ephemeral_rollups_sdk::consts::MAGIC_CONTEXT_ID)] | ||
/// CHECK:` | ||
pub magic_context: AccountInfo<'info> | ||
}).unwrap()); | ||
} | ||
|
||
quote! { | ||
#[derive(Accounts)] | ||
pub struct #name<'info> { | ||
#new_fields | ||
} | ||
} | ||
} else { | ||
quote! { | ||
compile_error!("Commit attribute can only be used with structs with named fields"); | ||
} | ||
}; | ||
|
||
TokenStream::from(expanded) | ||
} |
Oops, something went wrong.