Skip to content

Commit

Permalink
[add]: revoke-permissions, revoke-roles, transfer-assets, work-with-s…
Browse files Browse the repository at this point in the history
…tore-assets

Signed-off-by: Nurzhan Sakén <[email protected]>
  • Loading branch information
nxsaken committed Apr 16, 2024
1 parent e7f8ab7 commit 1763b34
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 4 deletions.
30 changes: 29 additions & 1 deletion src/cookbook/revoke-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,32 @@ head:

# How to Revoke Permissions

TODO
```rust
fn revoke_permission_from_account(
iroha: &Client,
) {
let revoke_permission_to_unregister_kingdom = Revoke::permission(
PermissionToken::new(
"CanUnregisterDomain".parse().unwrap(),
&json!({ "domain_id": "kingdom" }),
),
AccountId::from_str("alice@wonderland").unwrap()
);
iroha.submit(revoke_permission_to_unregister_kingdom).unwrap();
}
```

```rust
fn revoke_permission_from_role(
iroha: &Client,
) {
let revoke_permission_to_unregister_kingdom = Revoke::role_permission(
PermissionToken::new(
"CanUnregisterDomain".parse().unwrap(),
&json!({ "domain_id": "kingdom" }),
),
RoleId::from_str("DOMAIN_DESTROYER").unwrap(),
);
iroha.submit(revoke_permission_to_unregister_kingdom).unwrap();
}
```
13 changes: 12 additions & 1 deletion src/cookbook/revoke-roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ head:

# How to Revoke Roles

TODO
```rust
fn revoke_role(
iroha: &Client,
) {
// given that Alice has the role, revoke it
let revoke_role = Revoke::role(
RoleId::from_str("DOMAIN_DESTROYER"),
AccountId::from_str("alice@wonderland").unwrap()
);
iroha.submit(revoke_role).unwrap();
}
```
31 changes: 30 additions & 1 deletion src/cookbook/transfer-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,33 @@ head:

# How to Transfer Assets Between Accounts

TODO
```rust
fn transfer_numeric_asset(
iroha: &Client,
) {
let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap();
let alice = AccountId::from_str("alice@wonderland").unwrap();
let mouse = AccountId::from_str("mouse@wonderland").unwrap();
let transfer_roses_from_alice_to_mouse = Transfer::asset_numeric(
AssetId::new(roses, alice),
13_u32,
mouse,
);
iroha.submit(transfer_roses_from_alice_to_mouse).unwrap();
}
```

```rust
fn transfer_store_asset(
iroha: &Client,
) {
let hats = AssetDefinitionId::from_str("hat#outfit").unwrap();
let alice = AccountId::from_str("alice@outfit").unwrap();
let mouse = AccountId::from_str("mouse@outfit").unwrap();
let transfer_hat_from_alice_to_mouse = Transfer::asset_store(
AssetId::new(hats, alice),
mouse,
);
iroha.submit(transfer_hat_from_alice_to_mouse).unwrap();
}
```
37 changes: 36 additions & 1 deletion src/cookbook/work-with-store-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,39 @@ head:

# How to Work with Store Assets

TODO
While numeric assets represent quantities, store assets represent
arbitrary key-value tables.

```rust
fn define_store_asset(
iroha: &Client,
) {
let hats = AssetDefinitionId::from_str("hat#outfit").unwrap();
let hats_as_a_concept = AssetDefinition::store(hats);
iroha.submit(Register::asset_definition(hats_as_a_concept)).unwrap();
}
```

```rust
fn set_key_value_pair(
iroha: &Client,
) {
let hat_of_alice = AssetId::from_str("hat##alice@outfit").unwrap();
let color = Name::from_str("color").unwrap();
iroha.submit(SetKeyValue::asset(
hat_of_alice,
color,
"red".to_owned()
)).unwrap();
}
```

```rust
fn unset_key_value_pair(
iroha: &Client,
) {
let hat_of_alice = AssetId::from_str("hat##alice@outfit").unwrap();
let color = Name::from_str("color").unwrap();
iroha.submit(RemoveKeyValue::asset(hats, color)).unwrap();
}
```

0 comments on commit 1763b34

Please sign in to comment.