diff --git a/src/cookbook/register-roles.md b/src/cookbook/register-roles.md index 6d9e9a100..b473bf292 100644 --- a/src/cookbook/register-roles.md +++ b/src/cookbook/register-roles.md @@ -11,4 +11,40 @@ head: # How to Register a Role -TODO \ No newline at end of file +The minimal case is an empty role (without any permission tokens): + +```rust +fn register_new_role( + role_name: &str, + iroha_client: &Client +) { + let role_id = RoleId::from_str(role_name).unwrap(); + let role = iroha_data_model::role::Role::new(role_id); + let register_role = Register::role(role); + iroha_client.submit(register_role).unwrap(); +} +``` + +Permission tokens may be added to a role. In the following example, +a predefined `CanUnregisterDomain` permission token is used. + +You can also define your own permission tokens, +see [Define Custom Permission Tokens](define-custom-permission-tokens.md). + +```rust +fn register_new_role_with_permission( + role_name: &str, + domain_id: DomainId, + iroha_client: &Client +) { + let role_id = RoleId::from_str(role_name).unwrap(); + let can_unregister_domain = PermissionToken::new( + "CanUnregisterDomain".parse().unwrap(), + &json!({ "domain_id": domain_id }), + ); + let role = iroha_data_model::role::Role::new(role_id) + .add_permission(can_unregister_domain); + let register_role = Register::role(role); + iroha_client.submit(register_role).unwrap(); +} +``` diff --git a/src/cookbook/use-instructions.md b/src/cookbook/use-instructions.md index 46afe65dd..ed0832ffd 100644 --- a/src/cookbook/use-instructions.md +++ b/src/cookbook/use-instructions.md @@ -11,4 +11,20 @@ head: # How to Use Iroha Special Instructions -TODO \ No newline at end of file +Building and submitting an instruction: + +```rust +fn use_instruction( + client: &Client, + roses: AssetDefinitionId, + alice: AccountId, +) { + // build an instruction + let mint_roses_for_alice = Mint::asset_numeric( + 42_u32, + AssetId::new(roses, alice) + ); + // submit the instruction + client.submit(mint_roses_for_alice).unwrap(); +} +``` \ No newline at end of file diff --git a/src/cookbook/work-with-numeric-assets.md b/src/cookbook/work-with-numeric-assets.md index e1edf6bfa..37a264aae 100644 --- a/src/cookbook/work-with-numeric-assets.md +++ b/src/cookbook/work-with-numeric-assets.md @@ -11,4 +11,52 @@ head: # How to Work with Numeric Assets -TODO \ No newline at end of file +Minting roses for Alice: + +```rust +fn mint_numeric_asset( + client: &Client, + roses: AssetDefinitionId, + alice: AccountId, +) { + let mint_roses_for_alice = Mint::asset_numeric( + 42_u32, + AssetId::new(roses, alice) + ); + client.submit(mint_roses_for_alice).unwrap(); +} +``` + +Burning Alice's roses: + +```rust +fn burn_numeric_asset( + client: &Client, + roses: AssetDefinitionId, + alice: AccountId, +) { + let burn_roses_of_alice = Burn::asset_numeric( + 8_u32, + AssetId::new(roses, alice) + ); + client.submit(burn_roses_of_alice).unwrap(); +} +``` + +Transferring Alice's roses to Mouse: + +```rust +fn transfer_numeric_asset( + client: &Client, + roses: AssetDefinitionId, + alice: AccountId, + mouse: AccountId, +) { + let transfer_roses_from_alice_to_mouse = Transfer::asset_numeric( + AssetId::new(roses, alice), + 13_u32, + mouse + ); + client.submit(transfer_roses_from_alice_to_mouse).unwrap(); +} +``` \ No newline at end of file