forked from hyperledger-iroha/iroha
-
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.
[feature] hyperledger-iroha#3271: Add
asset_definition/transfer
val…
…idator Signed-off-by: Daniil Polyakov <arjentix@gmail.com>
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
permission_validators/runtime/asset_definition/transfer/Cargo.toml
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,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
39
permission_validators/runtime/asset_definition/transfer/src/lib.rs
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,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") | ||
} |