Skip to content

Commit

Permalink
[feature] hyperledger-iroha#3271: Add asset_definition/transfer val…
Browse files Browse the repository at this point in the history
…idator

Signed-off-by: Daniil Polyakov <arjentix@gmail.com>
  • Loading branch information
Arjentix committed Mar 1, 2023
1 parent eb51e1d commit 26c0247
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions permission_validators/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"asset_definition/set_key_value",
"asset_definition/remove_key_value",
"asset_definition/unregister",
"asset_definition/transfer",
"account/set_key_value",
"account/remove_key_value",
]
Expand Down
13 changes: 13 additions & 0 deletions permission_validators/runtime/asset_definition/transfer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "iroha_asset_definition_transfer_validator"
version.workspace = true
authors.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ['rlib']

[dependencies]
iroha_wasm.workspace = true
39 changes: 39 additions & 0 deletions permission_validators/runtime/asset_definition/transfer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! Validator that checks [`Transfer`] instruction related to asset definitions

#![no_std]
#![no_main]

extern crate alloc;

use iroha_wasm::validator::{prelude::*, utils};

/// Validate [`Transfer`] instruction
///
/// # [`Transfer`]
///
/// ## Pass
///
/// - [`Transfer`] `source_id` is not an [`AssetDefinitionId`];
/// - `authority` is an asset definition owner;
///
/// ## Deny
///
/// If none of the `Pass` conditions are met.
pub fn validate(authority: <Account as Identifiable>::Id, instruction: Instruction) -> Verdict {
let Instruction::Transfer(transfer) = instruction else {
pass!();
};

let IdBox::AssetDefinitionId(asset_definition_id) = transfer.source_id
.evaluate_on_host()
.dbg_expect("Failed to evaluate `Transfer` source id") else {
pass!();
};

pass_if!(utils::is_asset_definition_owner(
&asset_definition_id,
&authority
));

deny!("Can't transfer asset definition of another account")
}

0 comments on commit 26c0247

Please sign in to comment.