Skip to content

Commit

Permalink
[feature] hyperledger-iroha#3184: Add Token derive macro
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <arjentix@gmail.com>
  • Loading branch information
Arjentix committed Feb 21, 2023
1 parent ec4740b commit 2afac2b
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 224 deletions.
6 changes: 4 additions & 2 deletions wasm/derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iroha_wasm_derive"
version = "0.1.0"
version = "2.0.0-pre-rc.13"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,5 +9,7 @@ edition = "2021"
proc-macro = true

[dependencies]
syn = {version = "1", default-features = false, features = ["full", "extra-traits"] }
syn = {version = "1", default-features = false, features = ["full", "extra-traits", "derive"] }
quote = "1.0"
proc-macro2 = "1.0.50"
convert_case = "0.6.0"
27 changes: 25 additions & 2 deletions wasm/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub fn entrypoint(attr: TokenStream, item: TokenStream) -> TokenStream {
/// ```ignore
/// use iroha_wasm::validator::prelude::*;
///
/// #[entrypoint(params = "[authoriy, instruction]")]
/// #[entrypoint(params = "[authority, instruction]")]
/// pub fn validate(authority: AccountId, _: Instruction) -> Verdict {
/// let admin_domain = "admin_domain".parse()
/// .dbg_expect("Failed to parse `admin_domain` as a domain id");
Expand All @@ -166,7 +166,30 @@ pub fn entrypoint(attr: TokenStream, item: TokenStream) -> TokenStream {
///
#[proc_macro_attribute]
pub fn validator_entrypoint(attr: TokenStream, item: TokenStream) -> TokenStream {
validator::impl_entrypoint(attr, item)
validator::entrypoint::impl_entrypoint(attr, item)
}

/// Derive macro for `Token` trait.
///
/// # Example
///
/// ```ignore
/// use iroha_wasm::{validator::prelude::*, parse, Token};
///
/// #[derive(Token)]
/// struct CanDoSomething {
/// some_data: String,
/// some_asset_id: <Asset as Identifiable>::Id,
/// }
///
/// CanDoSomething {
/// some_data: "some data".to_owned(),
/// some_asset_id: parse!("rose#wonderland" as <Asset as Identifiable>::Id),
/// }.is_owned_by(&authority)
/// ```
#[proc_macro_derive(Token)]
pub fn derive_token(input: TokenStream) -> TokenStream {
validator::token::impl_derive_token(input)
}

macro_rules! parse_keywords {
Expand Down
Loading

0 comments on commit 2afac2b

Please sign in to comment.