Skip to content

Commit

Permalink
[add]: work-with-non-mintable-assets
Browse files Browse the repository at this point in the history
[edit]: work-with-numeric-assets

Signed-off-by: Nurzhan Sakén <[email protected]>
  • Loading branch information
nxsaken committed Apr 16, 2024
1 parent 9ebde90 commit e7f8ab7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/cookbook/work-with-non-mintable-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,48 @@ head:

# How to Work with Non-Mintable Assets

TODO
```rust
fn register_non_mintable_asset(
iroha: &Client,
) {
let magical_keys = AssetDefinitionId::from_str("magical_key#wonderland").unwrap();
// register keys as an asset definition
let register_keys_as_a_concept = Register::asset_definition(
AssetDefinition::new(
magical_keys.clone(),
AssetValueType::Numeric(NumericSpec::integer()),
).mintable_once()
);
let alice = "alice@wonderland".parse().unwrap();
// Alice owns ten keys and cannot mint more
let initial_keys_of_alice = Asset::new(
AssetId::new(roses, alice),
10_u32
);
let register_keys_of_alice = Register::asset(initial_keys_of_alice);
iroha.submit_all([
InstructionBox::from(register_keys_as_a_concept),
InstructionBox::from(register_keys_of_alice)
]).unwrap();
}
```

```rust
fn mint_non_mintable_asset(
iroha: &Client,
) {
// Alice owns zero keys and can mint once
let keys_of_alice = "magical_key##alice@wonderland".parse().unwrap();
let zero_keys_of_alice = Asset::new(
keys_of_alice.clone(),
0_u32
);
let register_keys_of_alice = Register::asset(zero_keys_of_alice);
let mint_keys_for_alice = Mint::asset_numeric(10_u32, keys_of_alice);
iroha.submit_all([
InstructionBox::from(register_keys_as_a_concept),
InstructionBox::from(register_keys_of_alice),
InstructionBox::from(mint_keys_for_alice),
]).unwrap();
}
```
27 changes: 27 additions & 0 deletions src/cookbook/work-with-numeric-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ head:

# How to Work with Numeric Assets

Registering Alice's roses:

```rust
fn register_numeric_asset(
iroha: &Client,
) {
let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap();
// register roses as an asset definition
let register_roses_as_a_concept = Register::asset_definition(
AssetDefinition::new(
roses.clone(),
// for the sake of the example, allow whole roses only
AssetValueType::Numeric(NumericSpec::integer()),
)
);
let alice = "alice@wonderland".parse().unwrap();
let roses_of_alice = AssetId::new(roses, alice);
let initial_roses_of_alice = Asset::new(roses_of_alice, 0_u32);
// register zero roses as Alice's asset
let register_roses_of_alice = Register::asset(initial_roses_of_alice);
iroha.submit_all([
InstructionBox::from(register_roses_as_a_concept),
InstructionBox::from(register_roses_of_alice)
]).unwrap();
}
```

Minting roses for Alice:

```rust
Expand Down

0 comments on commit e7f8ab7

Please sign in to comment.