From b5c440bd6907608e8541c56763049dc5b24b6c6b Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 2 Nov 2023 16:21:08 +0300 Subject: [PATCH 01/31] Introduce cookbook (updated init version) Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 334 ++++++++++++++++++++++++++++++++++++++++++ src/cookbook/index.md | 3 + src/index.md | 5 +- 3 files changed, 341 insertions(+), 1 deletion(-) create mode 100644 src/cookbook/index.md diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 3f0c7964a..389f92637 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -35,6 +35,339 @@ function nav(): DefaultTheme.NavItem[] { link: '/reference/torii-endpoints', activeMatch: '/reference/', }, + { + text: 'Cookbook', + link: '/cookbook/', + activeMatch: '/cookbook/', + }, + ] +} + +function sidebarCookbook(): DefaultTheme.SidebarItem[] { + return [ + { + text: 'Access Control', + collapsed: true, + items: [ + { + text: 'Permission Tokens', + collapsed: true, + items: [ + { + text: 'Grant Permissions' + }, + { + text: 'Revoke Permissions' + }, + { + text: 'Mint Permission Tokens' + }, + { + text: 'Burn Permission Tokens' + }, + ], + }, + { + text: 'Roles', + collapsed: true, + items: [ + { + text: 'Register a Role', + }, + { + text: 'Grant a Role', + }, + { + text: 'Revoke a Role', + }, + ], + }, + { + text: 'Executors (Permission Validators)', + collapsed: true, + items: [ + { + text: 'Write Executor', + }, + { + text: 'Update Executor', + } + ], + } + ], + }, + { + text: 'Accounts', + collapsed: true, + items: [ + { + text: 'Register Accounts', + }, + { + text: 'Unregister Accounts', + }, + { + text: 'Update Account Metadata' + }, + // ...? + ], + }, + { + text: 'Assets', + collapsed: true, + items: [ + { + text: 'Assets', // All Assets? + collapsed: true, + items: [ + { + text: 'Register Assets', + }, + { + text: 'Unregister Assets', + }, + { + text: 'Transfer Assets Between Accounts', + }, + // ...? + ], + }, + { + text: 'Numeric Assets', + collapsed: true, + items: [ + { + text: 'Work with Numeric Assets', + } + ], + }, + { + text: 'Store Assets', + collapsed: true, + items: [ + { + text: 'Work with Store Assets', + } + ], + }, + { + text: 'Mintable Assets', + collapsed: true, + items: [ + { + text: 'Mint Assets', + }, + { + text: 'Mint More of a Mintable Asset', + }, + { + text: 'Burn Assets', + }, + ], + }, + { + text: 'Non-Mintable Assets', + collapsed: true, + items: [ + { + text: 'Work with Non-Mintable Assets', + }, + ], + }, + { + text: 'Tokens', + collapsed: true, + items: [ + { + text: 'Create Asset-backed Tokens', + }, + { + text: 'Create Non-Fungible Tokens (NFTs)', + }, + ], + }, + ], + }, + { + text: 'Domains', + collapsed: true, + items: [ + { + text: 'Register Domains', + }, + { + text: 'Unregister Domains' + }, + { + text: 'Update Domain Metadata', + }, + // ... + // access management for domains? + ], + }, + { + text: 'Events and Filters', + collapsed: true, + items: [ + { + text: 'Pipeline Events', + collapsed: true, + items: [], + }, + { + text: 'Data Events', + collapsed: true, + items: [], + }, + { + text: 'Trigger Events', + collapsed: true, + items: [], + }, + { + text: 'Advanced Filtering', + collapsed: true, + items: [], + }, + { + text: 'Block Stream', + collapsed: true, + items: [ + { + text: 'Subscribe to Block Stream', + }, + { + text: 'View output', + }, + ], + }, + ], + }, + { + text: 'Instructions', + collapsed: true, + items: [ + { + text: 'Use Instructions', + }, + { + text: 'Combine Instructions via Expressions', + }, + ], + }, + { + text: 'Metadata', + collapsed: true, + items: [ + { + text: 'Set Key Value', + }, + { + text: 'Remove Key Value', + }, + { + text: 'Access Metadata', + }, + ], + }, + { + text: 'Peers', + collapsed: true, + items: [ + { + text: 'Register Peers', + }, + { + text: "Check Current Peer's Load", + }, + { + text: 'Find the Leader Among Running Peers', + }, + ], + }, + { + text: 'Queries', + collapsed: true, + items: [ + {text: 'Use queries'}, + {text: 'Filter query results'}, + {text: 'Use Lazy Pagination'}, + {text: 'Query Connected Peers'}, + ], + }, + { + text: 'Telemetry', + collapsed: true, + items: [ + { + text: 'Check Status', + }, + { + text: 'Get Metrics', + }, + { + text: 'Monitor Iroha Performance', + }, + { + text: 'Check Health', + }, + ], + }, + { + text: 'Transactions', + collapsed: true, + items: [ + { + text: 'Create Transactions', + }, + { + text: 'Submit Transactions', + }, + { + text: 'Compile Transactions', + }, + { + text: 'Use Multi-Signature Transactions', + }, + ], + }, + { + text: 'Triggers', + collapsed: true, + items: [ + { + text: 'Data Triggers', + collapsed: true, + items: [ + { + text: 'Register a Data Trigger', + }, + ], + }, + { + text: 'Time Triggers', + collapsed: true, + items: [ + { + text: 'Register a Scheduled Trigger', + }, + { + text: 'Register a Pre-commit Trigger', + }, + ], + }, + { + text: 'By-call Triggers', + collapsed: true, + items: [ + { + text: 'Register a By-call Trigger', + }, + ], + }, + ], + }, + ] } @@ -481,6 +814,7 @@ export default defineConfig({ sidebar: { '/guide/': sidebarGuide(), '/reference/': sidebarAPI(), + '/cookbook/': sidebarCookbook(), }, search: { diff --git a/src/cookbook/index.md b/src/cookbook/index.md new file mode 100644 index 000000000..6cb8213d5 --- /dev/null +++ b/src/cookbook/index.md @@ -0,0 +1,3 @@ +# Cookbook + +TODO \ No newline at end of file diff --git a/src/index.md b/src/index.md index c3b667e86..0ffd1f8a3 100644 --- a/src/index.md +++ b/src/index.md @@ -23,4 +23,7 @@ features: title: Reference details: Consult reference documentation for extensive information about available functionality link: /reference/torii-endpoints - # - title: Cookbook # (TBA) + - icon: 📓 + title: Cookbook + details: Find code samples and example showcasing Iroha functionality + link: /cookbook/ From ea2c326bb67859b463859990a4b6498672aeeaf7 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 16 Nov 2023 17:06:32 +0300 Subject: [PATCH 02/31] Update .vitepress/config.mts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marin Veršić Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 389f92637..a2be1e22e 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -291,7 +291,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ {text: 'Use queries'}, {text: 'Filter query results'}, - {text: 'Use Lazy Pagination'}, + {text: 'Use Sorting and Pagination'}, {text: 'Query Connected Peers'}, ], }, From ffd86e1398d3099a39de11c7ebdc9592e39e1c15 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 16 Nov 2023 17:06:42 +0300 Subject: [PATCH 03/31] Update .vitepress/config.mts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marin Veršić Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index a2be1e22e..727a00f9b 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -275,7 +275,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { collapsed: true, items: [ { - text: 'Register Peers', + text: 'Register and Unregister Peers', }, { text: "Check Current Peer's Load", From a4c58a7937a8b9c5e03df3e353c5fed610ce7801 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 16 Nov 2023 17:06:49 +0300 Subject: [PATCH 04/31] Update .vitepress/config.mts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marin Veršić Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 727a00f9b..c64a50dba 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -278,7 +278,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { text: 'Register and Unregister Peers', }, { - text: "Check Current Peer's Load", + text: "Check Peer's Load", }, { text: 'Find the Leader Among Running Peers', From 9f5abbc2904456f8837b38dfa10a1d5e16dbec0b Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 16 Nov 2023 17:07:01 +0300 Subject: [PATCH 05/31] Update .vitepress/config.mts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marin Veršić Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index c64a50dba..4685ae1f6 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -59,12 +59,6 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Revoke Permissions' }, - { - text: 'Mint Permission Tokens' - }, - { - text: 'Burn Permission Tokens' - }, ], }, { From 64b80f73b01125c4ca240436ce3cd8020f223045 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 16 Nov 2023 17:07:17 +0300 Subject: [PATCH 06/31] Update .vitepress/config.mts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marin Veršić Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 4685ae1f6..1145cf4ca 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -195,6 +195,9 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Update Domain Metadata', }, + { + text: 'Transfer Domain Owner' + }, // ... // access management for domains? ], From 955593623ea667313add090fff0617cca7660cf7 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 16 Nov 2023 17:09:45 +0300 Subject: [PATCH 07/31] Update .vitepress/config.mts Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 3 --- 1 file changed, 3 deletions(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 1145cf4ca..ad9d68d3e 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -192,9 +192,6 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Unregister Domains' }, - { - text: 'Update Domain Metadata', - }, { text: 'Transfer Domain Owner' }, From a6e80fb424c324792bc1e80aba3e6285774374fb Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Tue, 21 Nov 2023 13:50:37 +0300 Subject: [PATCH 08/31] Update .vitepress/config.mts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marin Veršić Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index ad9d68d3e..4a832779c 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -330,34 +330,19 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { collapsed: true, items: [ { - text: 'Data Triggers', - collapsed: true, - items: [ - { - text: 'Register a Data Trigger', - }, - ], + text: 'Register a Data Trigger', }, { - text: 'Time Triggers', - collapsed: true, - items: [ - { - text: 'Register a Scheduled Trigger', - }, - { - text: 'Register a Pre-commit Trigger', - }, - ], + text: 'Register a Scheduled Trigger', }, { - text: 'By-call Triggers', - collapsed: true, - items: [ - { - text: 'Register a By-call Trigger', - }, - ], + text: 'Register a Pre-commit Trigger', + }, + { + text: 'Register a By-call Trigger', + }, + { + text: 'Unregister a Trigger', }, ], }, From 772e30f05a8b21b0f6daa7cc0fb7e2794f078426 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Tue, 21 Nov 2023 13:57:26 +0300 Subject: [PATCH 09/31] Address comments Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 50 +++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 4a832779c..a3619bbf5 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -76,18 +76,6 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { }, ], }, - { - text: 'Executors (Permission Validators)', - collapsed: true, - items: [ - { - text: 'Write Executor', - }, - { - text: 'Update Executor', - } - ], - } ], }, { @@ -100,10 +88,22 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Unregister Accounts', }, + // ...? + ], + }, + { + text: 'Asset Definitions', + collapsed: true, + items: [ { - text: 'Update Account Metadata' + text: 'Register Asset Definitions', + }, + { + text: 'Unregister Asset Definitions', + }, + { + text: 'Transfer Asset Definitions', }, - // ...? ], }, { @@ -237,6 +237,21 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { }, ], }, + { + text: 'Executors', + collapsed: true, + items: [ + { + text: 'Write Executor', + }, + { + text: 'Update Executor', + }, + { + text: 'Define Custom Permission Tokens', + }, + ], + }, { text: 'Instructions', collapsed: true, @@ -277,6 +292,9 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Find the Leader Among Running Peers', }, + { + text: 'Query Connected Peers', + }, ], }, { @@ -286,7 +304,6 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { {text: 'Use queries'}, {text: 'Filter query results'}, {text: 'Use Sorting and Pagination'}, - {text: 'Query Connected Peers'}, ], }, { @@ -317,9 +334,6 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Submit Transactions', }, - { - text: 'Compile Transactions', - }, { text: 'Use Multi-Signature Transactions', }, From d227ba1bf59b9a5a96cc62bbf0a64ebf56cfa633 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Tue, 21 Nov 2023 14:26:38 +0300 Subject: [PATCH 10/31] Remove comments Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index a3619bbf5..2705ca522 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -88,7 +88,6 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Unregister Accounts', }, - // ...? ], }, { @@ -111,7 +110,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { collapsed: true, items: [ { - text: 'Assets', // All Assets? + text: 'Assets', collapsed: true, items: [ { @@ -123,7 +122,6 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Transfer Assets Between Accounts', }, - // ...? ], }, { @@ -195,8 +193,6 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Transfer Domain Owner' }, - // ... - // access management for domains? ], }, { From 5dd9d2196fe0d9f3c9c4da6de3cde4236bc5a90f Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Tue, 21 Nov 2023 14:42:49 +0300 Subject: [PATCH 11/31] Fix formatting Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 2705ca522..2ba057f2b 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -54,10 +54,10 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { collapsed: true, items: [ { - text: 'Grant Permissions' + text: 'Grant Permissions', }, { - text: 'Revoke Permissions' + text: 'Revoke Permissions', }, ], }, @@ -130,7 +130,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Work with Numeric Assets', - } + }, ], }, { @@ -139,7 +139,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Work with Store Assets', - } + }, ], }, { @@ -188,10 +188,10 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { text: 'Register Domains', }, { - text: 'Unregister Domains' + text: 'Unregister Domains', }, { - text: 'Transfer Domain Owner' + text: 'Transfer Domain Owner', }, ], }, @@ -296,11 +296,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { { text: 'Queries', collapsed: true, - items: [ - {text: 'Use queries'}, - {text: 'Filter query results'}, - {text: 'Use Sorting and Pagination'}, - ], + items: [{ text: 'Use queries' }, { text: 'Filter query results' }, { text: 'Use Sorting and Pagination' }], }, { text: 'Telemetry', @@ -340,23 +336,22 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { collapsed: true, items: [ { - text: 'Register a Data Trigger', + text: 'Register a Data Trigger', }, { - text: 'Register a Scheduled Trigger', + text: 'Register a Scheduled Trigger', }, { - text: 'Register a Pre-commit Trigger', + text: 'Register a Pre-commit Trigger', }, { - text: 'Register a By-call Trigger', + text: 'Register a By-call Trigger', }, { - text: 'Unregister a Trigger', + text: 'Unregister a Trigger', }, ], }, - ] } From c1738e2649acc9b7aca3f07c1ed604ba57075061 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 23 Nov 2023 14:39:10 +0300 Subject: [PATCH 12/31] Add files with metadata Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 58 ++++++++++++++++++- .vscode/settings.json | 8 ++- src/cookbook/access-metadata.md | 14 +++++ src/cookbook/burn-assets.md | 14 +++++ src/cookbook/check-health.md | 14 +++++ src/cookbook/check-peer-load.md | 14 +++++ src/cookbook/check-status.md | 14 +++++ src/cookbook/combine-instructions.md | 14 +++++ src/cookbook/create-asset-backed-tokens.md | 14 +++++ src/cookbook/create-nfts.md | 14 +++++ src/cookbook/create-transactions.md | 14 +++++ .../define-custom-permission-tokens.md | 14 +++++ .../find-leader-among-running-peers.md | 14 +++++ src/cookbook/get-metrics.md | 14 +++++ src/cookbook/grant-permissions.md | 14 +++++ src/cookbook/grant-roles.md | 14 +++++ src/cookbook/mint-assets.md | 14 +++++ src/cookbook/mint-more-assets.md | 14 +++++ src/cookbook/monitor-iroha-performance.md | 14 +++++ src/cookbook/query-connected-peers.md | 14 +++++ src/cookbook/register-accounts.md | 14 +++++ src/cookbook/register-asset-definitions.md | 12 ++++ src/cookbook/register-assets.md | 14 +++++ src/cookbook/register-by-call-triggers.md | 14 +++++ src/cookbook/register-data-triggers.md | 14 +++++ src/cookbook/register-domains.md | 14 +++++ src/cookbook/register-peers.md | 14 +++++ src/cookbook/register-pre-commit-triggers.md | 14 +++++ src/cookbook/register-roles.md | 14 +++++ src/cookbook/register-scheduled-triggers.md | 14 +++++ src/cookbook/remove-key-value.md | 14 +++++ src/cookbook/revoke-permissions.md | 14 +++++ src/cookbook/revoke-roles.md | 14 +++++ src/cookbook/set-key-value.md | 14 +++++ src/cookbook/submit-transactions.md | 14 +++++ src/cookbook/transfer-asset-definitions.md | 14 +++++ src/cookbook/transfer-assets.md | 14 +++++ src/cookbook/transfer-domain-owner.md | 14 +++++ src/cookbook/unregister-accounts.md | 14 +++++ src/cookbook/unregister-asset-definitions.md | 15 +++++ src/cookbook/unregister-assets.md | 14 +++++ src/cookbook/unregister-domains.md | 14 +++++ src/cookbook/unregister-peers.md | 14 +++++ src/cookbook/unregister-triggers.md | 14 +++++ src/cookbook/update-executor.md | 14 +++++ src/cookbook/use-instructions.md | 14 +++++ .../use-multi-signature-transactions.md | 14 +++++ src/cookbook/work-with-non-mintable-assets.md | 14 +++++ src/cookbook/work-with-numeric-assets.md | 14 +++++ src/cookbook/work-with-store-assets.md | 14 +++++ src/cookbook/write-executor.md | 14 +++++ 51 files changed, 747 insertions(+), 4 deletions(-) create mode 100644 src/cookbook/access-metadata.md create mode 100644 src/cookbook/burn-assets.md create mode 100644 src/cookbook/check-health.md create mode 100644 src/cookbook/check-peer-load.md create mode 100644 src/cookbook/check-status.md create mode 100644 src/cookbook/combine-instructions.md create mode 100644 src/cookbook/create-asset-backed-tokens.md create mode 100644 src/cookbook/create-nfts.md create mode 100644 src/cookbook/create-transactions.md create mode 100644 src/cookbook/define-custom-permission-tokens.md create mode 100644 src/cookbook/find-leader-among-running-peers.md create mode 100644 src/cookbook/get-metrics.md create mode 100644 src/cookbook/grant-permissions.md create mode 100644 src/cookbook/grant-roles.md create mode 100644 src/cookbook/mint-assets.md create mode 100644 src/cookbook/mint-more-assets.md create mode 100644 src/cookbook/monitor-iroha-performance.md create mode 100644 src/cookbook/query-connected-peers.md create mode 100644 src/cookbook/register-accounts.md create mode 100644 src/cookbook/register-asset-definitions.md create mode 100644 src/cookbook/register-assets.md create mode 100644 src/cookbook/register-by-call-triggers.md create mode 100644 src/cookbook/register-data-triggers.md create mode 100644 src/cookbook/register-domains.md create mode 100644 src/cookbook/register-peers.md create mode 100644 src/cookbook/register-pre-commit-triggers.md create mode 100644 src/cookbook/register-roles.md create mode 100644 src/cookbook/register-scheduled-triggers.md create mode 100644 src/cookbook/remove-key-value.md create mode 100644 src/cookbook/revoke-permissions.md create mode 100644 src/cookbook/revoke-roles.md create mode 100644 src/cookbook/set-key-value.md create mode 100644 src/cookbook/submit-transactions.md create mode 100644 src/cookbook/transfer-asset-definitions.md create mode 100644 src/cookbook/transfer-assets.md create mode 100644 src/cookbook/transfer-domain-owner.md create mode 100644 src/cookbook/unregister-accounts.md create mode 100644 src/cookbook/unregister-asset-definitions.md create mode 100644 src/cookbook/unregister-assets.md create mode 100644 src/cookbook/unregister-domains.md create mode 100644 src/cookbook/unregister-peers.md create mode 100644 src/cookbook/unregister-triggers.md create mode 100644 src/cookbook/update-executor.md create mode 100644 src/cookbook/use-instructions.md create mode 100644 src/cookbook/use-multi-signature-transactions.md create mode 100644 src/cookbook/work-with-non-mintable-assets.md create mode 100644 src/cookbook/work-with-numeric-assets.md create mode 100644 src/cookbook/work-with-store-assets.md create mode 100644 src/cookbook/write-executor.md diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 2ba057f2b..fdf82c9ae 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -55,9 +55,11 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Grant Permissions', + link: '/cookbook/grant-permissions', }, { text: 'Revoke Permissions', + link: '/cookbook/revoke-permissions', }, ], }, @@ -67,12 +69,15 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Register a Role', + link: '/cookbook/register-roles', }, { text: 'Grant a Role', + link: '/cookbook/grant-roles', }, { text: 'Revoke a Role', + link: '/cookbook/revoke-roles', }, ], }, @@ -84,9 +89,11 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Register Accounts', + link: '/cookbook/register-accounts', }, { text: 'Unregister Accounts', + link: '/cookbook/unregister-accounts', }, ], }, @@ -96,12 +103,15 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Register Asset Definitions', + link: '/cookbook/register-asset-definitions', }, { text: 'Unregister Asset Definitions', + link: '/cookbook/unregister-asset-definitions', }, { text: 'Transfer Asset Definitions', + link: '/cookbook/transfer-asset-definitions', }, ], }, @@ -115,12 +125,15 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Register Assets', + link: '/cookbook/register-assets', }, { text: 'Unregister Assets', + link: '/cookbook/unregister-assets', }, { text: 'Transfer Assets Between Accounts', + link: '/cookbook/transfer-assets', }, ], }, @@ -130,6 +143,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Work with Numeric Assets', + link: '/cookbook/work-with-numeric-assets', }, ], }, @@ -139,6 +153,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Work with Store Assets', + link: '/cookbook/work-with-store-assets', }, ], }, @@ -148,12 +163,15 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Mint Assets', + link: '/cookbook/mint-assets', }, { text: 'Mint More of a Mintable Asset', + link: '/cookbook/mint-more-assets', }, { text: 'Burn Assets', + link: '/cookbook/burn-assets', }, ], }, @@ -163,6 +181,7 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Work with Non-Mintable Assets', + link: '/cookbook/work-with-non-mintable-assets', }, ], }, @@ -172,9 +191,11 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Create Asset-backed Tokens', + link: '/cookbook/create-asset-backed-tokens', }, { text: 'Create Non-Fungible Tokens (NFTs)', + link: '/cookbook/create-nfts', }, ], }, @@ -186,17 +207,20 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Register Domains', + link: '/cookbook/register-domains', }, { text: 'Unregister Domains', + link: '/cookbook/unregister-domains', }, { text: 'Transfer Domain Owner', + link: '/cookbook/transfer-domain-owner', }, ], }, { - text: 'Events and Filters', + text: 'Events and Filters', // for this sections no files were created collapsed: true, items: [ { @@ -239,12 +263,15 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Write Executor', + link: '/cookbook/write-executor', }, { text: 'Update Executor', + link: '/cookbook/update-executor', }, { text: 'Define Custom Permission Tokens', + link: '/cookbook/define-custom-permission-tokens', }, ], }, @@ -254,9 +281,11 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Use Instructions', + link: '/cookbook/use-instructions', }, { text: 'Combine Instructions via Expressions', + link: '/cookbook/combine-instructions', }, ], }, @@ -266,12 +295,15 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Set Key Value', + link: '/cookbook/set-key-value', }, { text: 'Remove Key Value', + link: '/cookbook/remove-key-value', }, { text: 'Access Metadata', + link: '/cookbook/access-metadata', }, ], }, @@ -280,16 +312,24 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { collapsed: true, items: [ { - text: 'Register and Unregister Peers', + text: 'Register Peers', + link: '/cookbook/register-peers', + }, + { + text: 'Unregister Peers', + link: '/cookbook/unregister-peers', }, { text: "Check Peer's Load", + link: '/cookbook/check-peer-load', }, { text: 'Find the Leader Among Running Peers', + link: '/cookbook/find-leader-among-running-peers', }, { text: 'Query Connected Peers', + link: '/cookbook/query-connected-peers', }, ], }, @@ -304,15 +344,19 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Check Status', + link: '/cookbook/check-status', }, { text: 'Get Metrics', + link: '/cookbook/get-metrics', }, { text: 'Monitor Iroha Performance', + link: '/cookbook/monitor-iroha-performance', }, { text: 'Check Health', + link: '/cookbook/check-health', }, ], }, @@ -322,12 +366,15 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Create Transactions', + link: '/cookbook/create-transactions', }, { text: 'Submit Transactions', + link: '/cookbook/submit-transactions', }, { text: 'Use Multi-Signature Transactions', + link: '/cookbook/use-multi-signature-transactions', }, ], }, @@ -337,18 +384,23 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { items: [ { text: 'Register a Data Trigger', + link: '/cookbook/register-data-triggers', }, { text: 'Register a Scheduled Trigger', + link: '/cookbook/register-scheduled-triggers', }, { text: 'Register a Pre-commit Trigger', + link: '/cookbook/register-pre-commit-triggers', }, { text: 'Register a By-call Trigger', + link: '/cookbook/register-by-call-triggers', }, { text: 'Unregister a Trigger', + link: '/cookbook/unregister-triggers', }, ], }, @@ -722,7 +774,7 @@ export default defineConfig({ base: BASE, srcDir: 'src', srcExclude: ['snippets/*.md'], - title: 'Hyperledger Iroha 2 Tutorial', + title: 'Hyperledger Iroha 2 Documentation', description: 'Documentation for Hyperledger Iroha 2 offering step-by-step guides for SDKs and outlining the main differences between Iroha versions.', lang: 'en-US', diff --git a/.vscode/settings.json b/.vscode/settings.json index d4a90eccc..f8dd72800 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,9 @@ { - "eslint.workingDirectories": [".vitepress", "."] + "eslint.workingDirectories": [ + ".vitepress", + "." + ], + "cSpell.words": [ + "Iroha" + ] } diff --git a/src/cookbook/access-metadata.md b/src/cookbook/access-metadata.md new file mode 100644 index 000000000..cd20f3d5a --- /dev/null +++ b/src/cookbook/access-metadata.md @@ -0,0 +1,14 @@ +--- +title: "Access Metadata | Cookbook" +head: + - - meta + - name: description + content: "Learn how to access metadata of Iroha objects such as domains, accounts, assets, and so on." + - - meta + - name: keywords + content: "Iroha metadata" +--- + +# How to Access an Object's Metadata + +TODO \ No newline at end of file diff --git a/src/cookbook/burn-assets.md b/src/cookbook/burn-assets.md new file mode 100644 index 000000000..3776f63c7 --- /dev/null +++ b/src/cookbook/burn-assets.md @@ -0,0 +1,14 @@ +--- +title: "Burn Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to burn assets." + - - meta + - name: keywords + content: "mintable assets, burning assets" +--- + +# How to Burn an Asset + +TODO \ No newline at end of file diff --git a/src/cookbook/check-health.md b/src/cookbook/check-health.md new file mode 100644 index 000000000..931aee845 --- /dev/null +++ b/src/cookbook/check-health.md @@ -0,0 +1,14 @@ +--- +title: "Check Health | Cookbook" +head: + - - meta + - name: description + content: "Learn how to check health to monitor Iroha performance." + - - meta + - name: keywords + content: "telemetry, health, Iroha performance" +--- + +# How to Check Health + +TODO \ No newline at end of file diff --git a/src/cookbook/check-peer-load.md b/src/cookbook/check-peer-load.md new file mode 100644 index 000000000..ecdfd4a05 --- /dev/null +++ b/src/cookbook/check-peer-load.md @@ -0,0 +1,14 @@ +--- +title: "Check Peer's Load | Cookbook" +head: + - - meta + - name: description + content: "Learn how to check an Iroha peer's load." + - - meta + - name: keywords + content: "peer load" +--- + +# How to Check a Peer's Load + +TODO \ No newline at end of file diff --git a/src/cookbook/check-status.md b/src/cookbook/check-status.md new file mode 100644 index 000000000..44314f253 --- /dev/null +++ b/src/cookbook/check-status.md @@ -0,0 +1,14 @@ +--- +title: "Check Status | Cookbook" +head: + - - meta + - name: description + content: "Learn how to check Iroha status." + - - meta + - name: keywords + content: "telemetry, Iroha status" +--- + +# How to Check Iroha Status + +TODO \ No newline at end of file diff --git a/src/cookbook/combine-instructions.md b/src/cookbook/combine-instructions.md new file mode 100644 index 000000000..2b299d495 --- /dev/null +++ b/src/cookbook/combine-instructions.md @@ -0,0 +1,14 @@ +--- +title: "Combine Instructions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to combine different Iroha Special Instructions (ISI) via expressions." + - - meta + - name: keywords + content: "Iroha Special Instructions, expressions" +--- + +# How to Combine Iroha Special Instructions + +TODO \ No newline at end of file diff --git a/src/cookbook/create-asset-backed-tokens.md b/src/cookbook/create-asset-backed-tokens.md new file mode 100644 index 000000000..0d5e4af75 --- /dev/null +++ b/src/cookbook/create-asset-backed-tokens.md @@ -0,0 +1,14 @@ +--- +title: "Create Asset-backed Tokens | Cookbook" +head: + - - meta + - name: description + content: "Learn how to create asset-backed tokens in Iroha." + - - meta + - name: keywords + content: "asset-backed tokens" +--- + +# How to Create an Asset-backed Token + +TODO \ No newline at end of file diff --git a/src/cookbook/create-nfts.md b/src/cookbook/create-nfts.md new file mode 100644 index 000000000..7a5f1d52e --- /dev/null +++ b/src/cookbook/create-nfts.md @@ -0,0 +1,14 @@ +--- +title: "Create NFTs | Cookbook" +head: + - - meta + - name: description + content: "Learn how to create non-fungible tokens in Iroha." + - - meta + - name: keywords + content: "non-fungible tokens, NFT" +--- + +# How to Create a Non-Fungible Token (NFT) + +TODO \ No newline at end of file diff --git a/src/cookbook/create-transactions.md b/src/cookbook/create-transactions.md new file mode 100644 index 000000000..149d46a1d --- /dev/null +++ b/src/cookbook/create-transactions.md @@ -0,0 +1,14 @@ +--- +title: "Create transactions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to create transactions in Iroha." + - - meta + - name: keywords + content: "transactions" +--- + +# How to Create a Transaction + +TODO \ No newline at end of file diff --git a/src/cookbook/define-custom-permission-tokens.md b/src/cookbook/define-custom-permission-tokens.md new file mode 100644 index 000000000..ffb3ef80a --- /dev/null +++ b/src/cookbook/define-custom-permission-tokens.md @@ -0,0 +1,14 @@ +--- +title: "Define Custom Permission Tokens | Cookbook" +head: + - - meta + - name: description + content: "Learn how to define custom permission tokens in Iroha." + - - meta + - name: keywords + content: "permission tokens, executors" +--- + +# How to Define a Custom Permission Token + +TODO \ No newline at end of file diff --git a/src/cookbook/find-leader-among-running-peers.md b/src/cookbook/find-leader-among-running-peers.md new file mode 100644 index 000000000..60a4b16b8 --- /dev/null +++ b/src/cookbook/find-leader-among-running-peers.md @@ -0,0 +1,14 @@ +--- +title: "Find Leader Among Running Peers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to find the leader among running Iroha peers." + - - meta + - name: keywords + content: "peers, leader" +--- + +# How to Find the Leader Among Running Peers + +TODO \ No newline at end of file diff --git a/src/cookbook/get-metrics.md b/src/cookbook/get-metrics.md new file mode 100644 index 000000000..93dfd4154 --- /dev/null +++ b/src/cookbook/get-metrics.md @@ -0,0 +1,14 @@ +--- +title: "Get Metrics | Cookbook" +head: + - - meta + - name: description + content: "Learn how to get metrics to monitor Iroha performance." + - - meta + - name: keywords + content: "telemetry, metrics, Iroha performance" +--- + +# Get Metrics + +TODO \ No newline at end of file diff --git a/src/cookbook/grant-permissions.md b/src/cookbook/grant-permissions.md new file mode 100644 index 000000000..7876a68f0 --- /dev/null +++ b/src/cookbook/grant-permissions.md @@ -0,0 +1,14 @@ +--- +title: "Grant Permissions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to grant permissions in Iroha." + - - meta + - name: keywords + content: "granting permissions, permission tokens" +--- + +# How to Grant Permissions + +TODO \ No newline at end of file diff --git a/src/cookbook/grant-roles.md b/src/cookbook/grant-roles.md new file mode 100644 index 000000000..4c32c1201 --- /dev/null +++ b/src/cookbook/grant-roles.md @@ -0,0 +1,14 @@ +--- +title: "Grant Roles | Cookbook" +head: + - - meta + - name: description + content: "Learn how to grant roles to accounts in Iroha." + - - meta + - name: keywords + content: "granting roles, roles, permission groups" +--- + +# How to Grant a Role + +TODO \ No newline at end of file diff --git a/src/cookbook/mint-assets.md b/src/cookbook/mint-assets.md new file mode 100644 index 000000000..27495e6bd --- /dev/null +++ b/src/cookbook/mint-assets.md @@ -0,0 +1,14 @@ +--- +title: "Mint Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to mint assets in Iroha." + - - meta + - name: keywords + content: "minting assets, mintable assets" +--- + +# How to Mint an Asset + +TODO \ No newline at end of file diff --git a/src/cookbook/mint-more-assets.md b/src/cookbook/mint-more-assets.md new file mode 100644 index 000000000..6155171a5 --- /dev/null +++ b/src/cookbook/mint-more-assets.md @@ -0,0 +1,14 @@ +--- +title: "Mint More of a Mintable Asset | Cookbook" +head: + - - meta + - name: description + content: "Learn how to mint more of a mintable asset." + - - meta + - name: keywords + content: "minting assets, mintable assets" +--- + +# How to Mint More of a Mintable Asset + +TODO \ No newline at end of file diff --git a/src/cookbook/monitor-iroha-performance.md b/src/cookbook/monitor-iroha-performance.md new file mode 100644 index 000000000..3432e3a76 --- /dev/null +++ b/src/cookbook/monitor-iroha-performance.md @@ -0,0 +1,14 @@ +--- +title: "Monitor Iroha Performance | Cookbook" +head: + - - meta + - name: description + content: "Learn how to monitor Iroha performance." + - - meta + - name: keywords + content: "telemetry, Iroha performance, monitoring performance" +--- + +# How to Monitor Iroha Performance + +TODO \ No newline at end of file diff --git a/src/cookbook/query-connected-peers.md b/src/cookbook/query-connected-peers.md new file mode 100644 index 000000000..c4859bc98 --- /dev/null +++ b/src/cookbook/query-connected-peers.md @@ -0,0 +1,14 @@ +--- +title: "Query Connected Peers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to query connected peers." + - - meta + - name: keywords + content: "connected peers, Iroha queries" +--- + +# How to Query Connected Peers + +TODO \ No newline at end of file diff --git a/src/cookbook/register-accounts.md b/src/cookbook/register-accounts.md new file mode 100644 index 000000000..d7e143015 --- /dev/null +++ b/src/cookbook/register-accounts.md @@ -0,0 +1,14 @@ +--- +title: "Register Accounts | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register accounts in Iroha." + - - meta + - name: keywords + content: "registering accounts" +--- + +# How to Register an Account + +TODO \ No newline at end of file diff --git a/src/cookbook/register-asset-definitions.md b/src/cookbook/register-asset-definitions.md new file mode 100644 index 000000000..c4bc04af6 --- /dev/null +++ b/src/cookbook/register-asset-definitions.md @@ -0,0 +1,12 @@ +--- +title: "Register Asset Definitions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register asset definitions in Iroha." + - - meta + - name: keywords + content: "asset definitions, registering asset definitions" +--- + +# How to Register an Asset Definition \ No newline at end of file diff --git a/src/cookbook/register-assets.md b/src/cookbook/register-assets.md new file mode 100644 index 000000000..3cef14c15 --- /dev/null +++ b/src/cookbook/register-assets.md @@ -0,0 +1,14 @@ +--- +title: "Register Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register assets in Iroha." + - - meta + - name: keywords + content: "registering assets" +--- + +# How to Register an Asset + +TODO \ No newline at end of file diff --git a/src/cookbook/register-by-call-triggers.md b/src/cookbook/register-by-call-triggers.md new file mode 100644 index 000000000..ee3d032c2 --- /dev/null +++ b/src/cookbook/register-by-call-triggers.md @@ -0,0 +1,14 @@ +--- +title: "Register By-call Triggers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register a by-call trigger in Iroha." + - - meta + - name: keywords + content: "Iroha triggers, by-call triggers" +--- + +# How to Register a By-call Trigger + +TODO \ No newline at end of file diff --git a/src/cookbook/register-data-triggers.md b/src/cookbook/register-data-triggers.md new file mode 100644 index 000000000..a39cd27ed --- /dev/null +++ b/src/cookbook/register-data-triggers.md @@ -0,0 +1,14 @@ +--- +title: "Register Data Triggers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register a data trigger in Iroha." + - - meta + - name: keywords + content: "Iroha triggers, data triggers" +--- + +# How to Register a Data Trigger + +TODO \ No newline at end of file diff --git a/src/cookbook/register-domains.md b/src/cookbook/register-domains.md new file mode 100644 index 000000000..c73a5fc96 --- /dev/null +++ b/src/cookbook/register-domains.md @@ -0,0 +1,14 @@ +--- +title: "Register Domains | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register a domain in Iroha." + - - meta + - name: keywords + content: "Iroha domains, registering domains" +--- + +# How to Register a Domain + +TODO \ No newline at end of file diff --git a/src/cookbook/register-peers.md b/src/cookbook/register-peers.md new file mode 100644 index 000000000..04da2a5a2 --- /dev/null +++ b/src/cookbook/register-peers.md @@ -0,0 +1,14 @@ +--- +title: "Register Peers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register an Iroha peer." + - - meta + - name: keywords + content: "registering peers, Iroha peers" +--- + +# How to Register a Peer + +TODO \ No newline at end of file diff --git a/src/cookbook/register-pre-commit-triggers.md b/src/cookbook/register-pre-commit-triggers.md new file mode 100644 index 000000000..484de8b5c --- /dev/null +++ b/src/cookbook/register-pre-commit-triggers.md @@ -0,0 +1,14 @@ +--- +title: "Register Pre-commit Triggers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to ." + - - meta + - name: keywords + content: "Iroha triggers, pre-commit triggers" +--- + +# How to Register a Pre-commit Trigger + +TODO \ No newline at end of file diff --git a/src/cookbook/register-roles.md b/src/cookbook/register-roles.md new file mode 100644 index 000000000..c15f9f369 --- /dev/null +++ b/src/cookbook/register-roles.md @@ -0,0 +1,14 @@ +--- +title: "Register Roles | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register a role in Iroha." + - - meta + - name: keywords + content: "registering roles, permissions" +--- + +# How to Register a Role + +TODO \ No newline at end of file diff --git a/src/cookbook/register-scheduled-triggers.md b/src/cookbook/register-scheduled-triggers.md new file mode 100644 index 000000000..d443f6897 --- /dev/null +++ b/src/cookbook/register-scheduled-triggers.md @@ -0,0 +1,14 @@ +--- +title: "Register Scheduled Triggers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to register a scheduled trigger in Iroha." + - - meta + - name: keywords + content: "Iroha triggers, scheduled triggers" +--- + +# How to Register a Scheduled Trigger + +TODO \ No newline at end of file diff --git a/src/cookbook/remove-key-value.md b/src/cookbook/remove-key-value.md new file mode 100644 index 000000000..ddffe4703 --- /dev/null +++ b/src/cookbook/remove-key-value.md @@ -0,0 +1,14 @@ +--- +title: "Remove Key Value | Cookbook" +head: + - - meta + - name: description + content: "Learn how to use the RemoveKeyValue instruction in Iroha." + - - meta + - name: keywords + content: "Iroha metadata, Iroha Special Instructions" +--- + +# How to Remove Key Value + +TODO \ No newline at end of file diff --git a/src/cookbook/revoke-permissions.md b/src/cookbook/revoke-permissions.md new file mode 100644 index 000000000..d4e37a80d --- /dev/null +++ b/src/cookbook/revoke-permissions.md @@ -0,0 +1,14 @@ +--- +title: "Revoke Permissions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to revoke permissions in Iroha." + - - meta + - name: keywords + content: "revoking permissions, permission tokens" +--- + +# How to Revoke Permissions + +TODO \ No newline at end of file diff --git a/src/cookbook/revoke-roles.md b/src/cookbook/revoke-roles.md new file mode 100644 index 000000000..f5025ffbe --- /dev/null +++ b/src/cookbook/revoke-roles.md @@ -0,0 +1,14 @@ +--- +title: "Revoke Roles | Cookbook" +head: + - - meta + - name: description + content: "Learn how to revoke roles from accounts in Iroha." + - - meta + - name: keywords + content: "revoking roles, roles, permission groups" +--- + +# How to Revoke Roles + +TODO \ No newline at end of file diff --git a/src/cookbook/set-key-value.md b/src/cookbook/set-key-value.md new file mode 100644 index 000000000..624e70919 --- /dev/null +++ b/src/cookbook/set-key-value.md @@ -0,0 +1,14 @@ +--- +title: "Set Key Value | Cookbook" +head: + - - meta + - name: description + content: "Learn how to use the SetKeyValue instruction in Iroha." + - - meta + - name: keywords + content: "Iroha metadata, Iroha Special Instructions" +--- + +# How to Set Key Value + +TODO \ No newline at end of file diff --git a/src/cookbook/submit-transactions.md b/src/cookbook/submit-transactions.md new file mode 100644 index 000000000..6194682e7 --- /dev/null +++ b/src/cookbook/submit-transactions.md @@ -0,0 +1,14 @@ +--- +title: "Submit Transactions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to submit a transaction in Iroha." + - - meta + - name: keywords + content: "submitting transactions, Iroha transactions" +--- + +# How to Submit a Transaction + +TODO \ No newline at end of file diff --git a/src/cookbook/transfer-asset-definitions.md b/src/cookbook/transfer-asset-definitions.md new file mode 100644 index 000000000..b7bb6ef4b --- /dev/null +++ b/src/cookbook/transfer-asset-definitions.md @@ -0,0 +1,14 @@ +--- +title: "Transfer Asset Definitions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to transfer asset definitions." + - - meta + - name: keywords + content: "asset definitions, transferring asset definitions" +--- + +# How to Transfer Asset Definitions + +TODO \ No newline at end of file diff --git a/src/cookbook/transfer-assets.md b/src/cookbook/transfer-assets.md new file mode 100644 index 000000000..f0b74ada5 --- /dev/null +++ b/src/cookbook/transfer-assets.md @@ -0,0 +1,14 @@ +--- +title: "Transfer Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to transfer assets between accounts in Iroha." + - - meta + - name: keywords + content: "transferring assets" +--- + +# How to Transfer Assets Between Accounts + +TODO \ No newline at end of file diff --git a/src/cookbook/transfer-domain-owner.md b/src/cookbook/transfer-domain-owner.md new file mode 100644 index 000000000..555821611 --- /dev/null +++ b/src/cookbook/transfer-domain-owner.md @@ -0,0 +1,14 @@ +--- +title: "Transfer Domain Owner | Cookbook" +head: + - - meta + - name: description + content: "Learn how to transfer a domain owner." + - - meta + - name: keywords + content: "Iroha domains, domain owners" +--- + +# How to Transfer a Domain Owner + +TODO \ No newline at end of file diff --git a/src/cookbook/unregister-accounts.md b/src/cookbook/unregister-accounts.md new file mode 100644 index 000000000..23d050954 --- /dev/null +++ b/src/cookbook/unregister-accounts.md @@ -0,0 +1,14 @@ +--- +title: "Unregister Accounts | Cookbook" +head: + - - meta + - name: description + content: "Learn how to unregister an account in Iroha." + - - meta + - name: keywords + content: "Iroha accounts, unregister instruction" +--- + +# How to Unregister Accounts + +TODO \ No newline at end of file diff --git a/src/cookbook/unregister-asset-definitions.md b/src/cookbook/unregister-asset-definitions.md new file mode 100644 index 000000000..ae1b97d6c --- /dev/null +++ b/src/cookbook/unregister-asset-definitions.md @@ -0,0 +1,15 @@ +--- +title: "Unregister Asset Definitions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to unregister an asset definition." + - - meta + - name: keywords + content: "Iroha asset definition, unregister instruction" +--- + +# How to Unregister an Asset Definition + +TODO + diff --git a/src/cookbook/unregister-assets.md b/src/cookbook/unregister-assets.md new file mode 100644 index 000000000..b4cb2d788 --- /dev/null +++ b/src/cookbook/unregister-assets.md @@ -0,0 +1,14 @@ +--- +title: "Unregister Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to unregister an asset in Iroha." + - - meta + - name: keywords + content: "Iroha assets, unregister instruction" +--- + +# How to Unregister an Asset + +TODO \ No newline at end of file diff --git a/src/cookbook/unregister-domains.md b/src/cookbook/unregister-domains.md new file mode 100644 index 000000000..24df8e72a --- /dev/null +++ b/src/cookbook/unregister-domains.md @@ -0,0 +1,14 @@ +--- +title: "Unregister Domains | Cookbook" +head: + - - meta + - name: description + content: "Learn how to unregister a domain in Iroha." + - - meta + - name: keywords + content: "Iroha domains, unregister instruction" +--- + +# How to Unregister a Domain + +TODO \ No newline at end of file diff --git a/src/cookbook/unregister-peers.md b/src/cookbook/unregister-peers.md new file mode 100644 index 000000000..e36285eab --- /dev/null +++ b/src/cookbook/unregister-peers.md @@ -0,0 +1,14 @@ +--- +title: "Unregister Peers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to unregister a peer in Iroha." + - - meta + - name: keywords + content: "Iroha peers, unregister instruction" +--- + +# How to Unregister a Peer + +TODO \ No newline at end of file diff --git a/src/cookbook/unregister-triggers.md b/src/cookbook/unregister-triggers.md new file mode 100644 index 000000000..fcb4b71b8 --- /dev/null +++ b/src/cookbook/unregister-triggers.md @@ -0,0 +1,14 @@ +--- +title: "Unregister Triggers | Cookbook" +head: + - - meta + - name: description + content: "Learn how to unregister a trigger in Iroha." + - - meta + - name: keywords + content: "Iroha triggers, unregister instruction" +--- + +# How to Unregister a Trigger + +TODO \ No newline at end of file diff --git a/src/cookbook/update-executor.md b/src/cookbook/update-executor.md new file mode 100644 index 000000000..ff0ac8062 --- /dev/null +++ b/src/cookbook/update-executor.md @@ -0,0 +1,14 @@ +--- +title: "Update Executor | Cookbook" +head: + - - meta + - name: description + content: "Learn how to update an executor in Iroha." + - - meta + - name: keywords + content: "Iroha executor" +--- + +# How to Update an Executor + +TODO \ No newline at end of file diff --git a/src/cookbook/use-instructions.md b/src/cookbook/use-instructions.md new file mode 100644 index 000000000..46afe65dd --- /dev/null +++ b/src/cookbook/use-instructions.md @@ -0,0 +1,14 @@ +--- +title: "Use Instructions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to use Iroha Special Instructions (ISI)." + - - meta + - name: keywords + content: "Iroha Special Instructions" +--- + +# How to Use Iroha Special Instructions + +TODO \ No newline at end of file diff --git a/src/cookbook/use-multi-signature-transactions.md b/src/cookbook/use-multi-signature-transactions.md new file mode 100644 index 000000000..0ca658e6b --- /dev/null +++ b/src/cookbook/use-multi-signature-transactions.md @@ -0,0 +1,14 @@ +--- +title: "Use Multi-Signature Transactions | Cookbook" +head: + - - meta + - name: description + content: "Learn how to use multi-signature transactions in Iroha." + - - meta + - name: keywords + content: "multi-signature transactions" +--- + +# How to Use Multi-Signature Transactions + +TODO \ No newline at end of file diff --git a/src/cookbook/work-with-non-mintable-assets.md b/src/cookbook/work-with-non-mintable-assets.md new file mode 100644 index 000000000..b95f71fe8 --- /dev/null +++ b/src/cookbook/work-with-non-mintable-assets.md @@ -0,0 +1,14 @@ +--- +title: "Work with Non-Mintable Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to work with non-mintable assets in Iroha." + - - meta + - name: keywords + content: "non-mintable assets, Iroha assets" +--- + +# How to Work with Non-Mintable Assets + +TODO \ No newline at end of file diff --git a/src/cookbook/work-with-numeric-assets.md b/src/cookbook/work-with-numeric-assets.md new file mode 100644 index 000000000..e1edf6bfa --- /dev/null +++ b/src/cookbook/work-with-numeric-assets.md @@ -0,0 +1,14 @@ +--- +title: "Work with Numeric Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to work with numeric assets in Iroha." + - - meta + - name: keywords + content: "Iroha assets, numeric assets" +--- + +# How to Work with Numeric Assets + +TODO \ No newline at end of file diff --git a/src/cookbook/work-with-store-assets.md b/src/cookbook/work-with-store-assets.md new file mode 100644 index 000000000..487dfee0b --- /dev/null +++ b/src/cookbook/work-with-store-assets.md @@ -0,0 +1,14 @@ +--- +title: "Work with Store Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to work with Store assets in Iroha." + - - meta + - name: keywords + content: "Iroha assets, Store assets" +--- + +# How to Work with Store Assets + +TODO \ No newline at end of file diff --git a/src/cookbook/write-executor.md b/src/cookbook/write-executor.md new file mode 100644 index 000000000..3d7bbe80b --- /dev/null +++ b/src/cookbook/write-executor.md @@ -0,0 +1,14 @@ +--- +title: "Write Executor | Cookbook" +head: + - - meta + - name: description + content: "Learn how to write an executor in Iroha." + - - meta + - name: keywords + content: "Iroha executor" +--- + +# How to Write an Executor + +TODO \ No newline at end of file From cd28f8f9350b1fb03030341b906cd2e2df11a90b Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 23 Nov 2023 14:45:57 +0300 Subject: [PATCH 13/31] Fix format Signed-off-by: Ekaterina Mekhnetsova --- .vscode/settings.json | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f8dd72800..a352328cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,4 @@ { - "eslint.workingDirectories": [ - ".vitepress", - "." - ], - "cSpell.words": [ - "Iroha" - ] + "eslint.workingDirectories": [".vitepress", "."], + "cSpell.words": ["Iroha"] } From 60f5874f85bab687f8ba8d610cd37f47c3ea59a4 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Fri, 24 Nov 2023 15:57:52 +0300 Subject: [PATCH 14/31] Apply suggestions from code review Co-authored-by: William Richter <88400283+WRRicht3r@users.noreply.github.com> Signed-off-by: Ekaterina Mekhnetsova --- src/cookbook/check-health.md | 2 +- src/cookbook/check-status.md | 2 +- src/cookbook/register-domains.md | 2 +- src/cookbook/register-peers.md | 2 +- src/cookbook/register-pre-commit-triggers.md | 2 +- src/cookbook/register-roles.md | 2 +- src/cookbook/register-scheduled-triggers.md | 2 +- src/cookbook/submit-transactions.md | 2 +- src/cookbook/unregister-accounts.md | 2 +- src/cookbook/unregister-asset-definitions.md | 2 +- src/cookbook/unregister-assets.md | 2 +- src/cookbook/unregister-domains.md | 2 +- src/cookbook/unregister-peers.md | 2 +- src/cookbook/unregister-triggers.md | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cookbook/check-health.md b/src/cookbook/check-health.md index 931aee845..712dc1950 100644 --- a/src/cookbook/check-health.md +++ b/src/cookbook/check-health.md @@ -3,7 +3,7 @@ title: "Check Health | Cookbook" head: - - meta - name: description - content: "Learn how to check health to monitor Iroha performance." + content: "Learn how to monitor Iroha performance by checking health." - - meta - name: keywords content: "telemetry, health, Iroha performance" diff --git a/src/cookbook/check-status.md b/src/cookbook/check-status.md index 44314f253..7596beeae 100644 --- a/src/cookbook/check-status.md +++ b/src/cookbook/check-status.md @@ -3,7 +3,7 @@ title: "Check Status | Cookbook" head: - - meta - name: description - content: "Learn how to check Iroha status." + content: "Learn how to check the Iroha status." - - meta - name: keywords content: "telemetry, Iroha status" diff --git a/src/cookbook/register-domains.md b/src/cookbook/register-domains.md index c73a5fc96..979499ec1 100644 --- a/src/cookbook/register-domains.md +++ b/src/cookbook/register-domains.md @@ -3,7 +3,7 @@ title: "Register Domains | Cookbook" head: - - meta - name: description - content: "Learn how to register a domain in Iroha." + content: "Learn how to register domains in Iroha." - - meta - name: keywords content: "Iroha domains, registering domains" diff --git a/src/cookbook/register-peers.md b/src/cookbook/register-peers.md index 04da2a5a2..eaec5ba58 100644 --- a/src/cookbook/register-peers.md +++ b/src/cookbook/register-peers.md @@ -3,7 +3,7 @@ title: "Register Peers | Cookbook" head: - - meta - name: description - content: "Learn how to register an Iroha peer." + content: "Learn how to register peers in Iroha." - - meta - name: keywords content: "registering peers, Iroha peers" diff --git a/src/cookbook/register-pre-commit-triggers.md b/src/cookbook/register-pre-commit-triggers.md index 484de8b5c..9001c0ef3 100644 --- a/src/cookbook/register-pre-commit-triggers.md +++ b/src/cookbook/register-pre-commit-triggers.md @@ -3,7 +3,7 @@ title: "Register Pre-commit Triggers | Cookbook" head: - - meta - name: description - content: "Learn how to ." + content: "Learn how to register pre-commit triggers in Iroha." - - meta - name: keywords content: "Iroha triggers, pre-commit triggers" diff --git a/src/cookbook/register-roles.md b/src/cookbook/register-roles.md index c15f9f369..6d9e9a100 100644 --- a/src/cookbook/register-roles.md +++ b/src/cookbook/register-roles.md @@ -3,7 +3,7 @@ title: "Register Roles | Cookbook" head: - - meta - name: description - content: "Learn how to register a role in Iroha." + content: "Learn how to register roles in Iroha." - - meta - name: keywords content: "registering roles, permissions" diff --git a/src/cookbook/register-scheduled-triggers.md b/src/cookbook/register-scheduled-triggers.md index d443f6897..abd331270 100644 --- a/src/cookbook/register-scheduled-triggers.md +++ b/src/cookbook/register-scheduled-triggers.md @@ -3,7 +3,7 @@ title: "Register Scheduled Triggers | Cookbook" head: - - meta - name: description - content: "Learn how to register a scheduled trigger in Iroha." + content: "Learn how to register scheduled triggers in Iroha." - - meta - name: keywords content: "Iroha triggers, scheduled triggers" diff --git a/src/cookbook/submit-transactions.md b/src/cookbook/submit-transactions.md index 6194682e7..68073d56b 100644 --- a/src/cookbook/submit-transactions.md +++ b/src/cookbook/submit-transactions.md @@ -3,7 +3,7 @@ title: "Submit Transactions | Cookbook" head: - - meta - name: description - content: "Learn how to submit a transaction in Iroha." + content: "Learn how to submit transactions in Iroha." - - meta - name: keywords content: "submitting transactions, Iroha transactions" diff --git a/src/cookbook/unregister-accounts.md b/src/cookbook/unregister-accounts.md index 23d050954..3411a0796 100644 --- a/src/cookbook/unregister-accounts.md +++ b/src/cookbook/unregister-accounts.md @@ -3,7 +3,7 @@ title: "Unregister Accounts | Cookbook" head: - - meta - name: description - content: "Learn how to unregister an account in Iroha." + content: "Learn how to unregister accounts in Iroha." - - meta - name: keywords content: "Iroha accounts, unregister instruction" diff --git a/src/cookbook/unregister-asset-definitions.md b/src/cookbook/unregister-asset-definitions.md index ae1b97d6c..809441641 100644 --- a/src/cookbook/unregister-asset-definitions.md +++ b/src/cookbook/unregister-asset-definitions.md @@ -3,7 +3,7 @@ title: "Unregister Asset Definitions | Cookbook" head: - - meta - name: description - content: "Learn how to unregister an asset definition." + content: "Learn how to unregister asset definitions in Iroha." - - meta - name: keywords content: "Iroha asset definition, unregister instruction" diff --git a/src/cookbook/unregister-assets.md b/src/cookbook/unregister-assets.md index b4cb2d788..c05c30c97 100644 --- a/src/cookbook/unregister-assets.md +++ b/src/cookbook/unregister-assets.md @@ -3,7 +3,7 @@ title: "Unregister Assets | Cookbook" head: - - meta - name: description - content: "Learn how to unregister an asset in Iroha." + content: "Learn how to unregister assets in Iroha." - - meta - name: keywords content: "Iroha assets, unregister instruction" diff --git a/src/cookbook/unregister-domains.md b/src/cookbook/unregister-domains.md index 24df8e72a..fbe2ec295 100644 --- a/src/cookbook/unregister-domains.md +++ b/src/cookbook/unregister-domains.md @@ -3,7 +3,7 @@ title: "Unregister Domains | Cookbook" head: - - meta - name: description - content: "Learn how to unregister a domain in Iroha." + content: "Learn how to unregister domains in Iroha." - - meta - name: keywords content: "Iroha domains, unregister instruction" diff --git a/src/cookbook/unregister-peers.md b/src/cookbook/unregister-peers.md index e36285eab..1b0635165 100644 --- a/src/cookbook/unregister-peers.md +++ b/src/cookbook/unregister-peers.md @@ -3,7 +3,7 @@ title: "Unregister Peers | Cookbook" head: - - meta - name: description - content: "Learn how to unregister a peer in Iroha." + content: "Learn how to unregister peers in Iroha." - - meta - name: keywords content: "Iroha peers, unregister instruction" diff --git a/src/cookbook/unregister-triggers.md b/src/cookbook/unregister-triggers.md index fcb4b71b8..a9044076f 100644 --- a/src/cookbook/unregister-triggers.md +++ b/src/cookbook/unregister-triggers.md @@ -3,7 +3,7 @@ title: "Unregister Triggers | Cookbook" head: - - meta - name: description - content: "Learn how to unregister a trigger in Iroha." + content: "Learn how to unregister triggers in Iroha." - - meta - name: keywords content: "Iroha triggers, unregister instruction" From 778d8a30a4ae5e1b37917c6e68a3a0b28e04ce89 Mon Sep 17 00:00:00 2001 From: Ekaterina Mekhnetsova Date: Thu, 30 Nov 2023 21:02:41 +0300 Subject: [PATCH 15/31] Add a topic Signed-off-by: Ekaterina Mekhnetsova --- .vitepress/config.mts | 4 ++++ src/cookbook/transfer-group-assets.md | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/cookbook/transfer-group-assets.md diff --git a/.vitepress/config.mts b/.vitepress/config.mts index fdf82c9ae..56948d372 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -135,6 +135,10 @@ function sidebarCookbook(): DefaultTheme.SidebarItem[] { text: 'Transfer Assets Between Accounts', link: '/cookbook/transfer-assets', }, + { + text: 'Transfer Groups of Assets', + link: '/cookbook/transfer-group-assets', + }, ], }, { diff --git a/src/cookbook/transfer-group-assets.md b/src/cookbook/transfer-group-assets.md new file mode 100644 index 000000000..630a0d82a --- /dev/null +++ b/src/cookbook/transfer-group-assets.md @@ -0,0 +1,16 @@ +--- +title: "Transfer Groups of Assets | Cookbook" +head: + - - meta + - name: description + content: "Learn how to transfer a group of assets." + - - meta + - name: keywords + content: "transferring assets" +--- + +# How to Transfer a Group of Assets + +TODO + + \ No newline at end of file From e2df86c8559192e494cf2ce0107a4e48dede9043 Mon Sep 17 00:00:00 2001 From: Dmitry Balashov <43530070+0x009922@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:32:36 +0700 Subject: [PATCH 16/31] [docs]: add MST draft Signed-off-by: Dmitry Balashov <43530070+0x009922@users.noreply.github.com> --- .../use-multi-signature-transactions.md | 191 +++++++++++++++++- 1 file changed, 187 insertions(+), 4 deletions(-) diff --git a/src/cookbook/use-multi-signature-transactions.md b/src/cookbook/use-multi-signature-transactions.md index 0ca658e6b..791ebb37d 100644 --- a/src/cookbook/use-multi-signature-transactions.md +++ b/src/cookbook/use-multi-signature-transactions.md @@ -1,14 +1,197 @@ --- -title: "Use Multi-Signature Transactions | Cookbook" +title: 'Use Multi-Signature Transactions | Cookbook' head: - - meta - name: description - content: "Learn how to use multi-signature transactions in Iroha." + content: 'Learn how to use multi-signature transactions in Iroha.' - - meta - name: keywords - content: "multi-signature transactions" + content: 'multi-signature transactions' --- # How to Use Multi-Signature Transactions -TODO \ No newline at end of file +We will create an account with a key and set a rule that all transactions +made by this account should be also signed by an additional key. Then we +will perform a transaction itself, in two stages: first will be signed and +submitted with the main account key, and then the same transaction will be +submitted with an additional signature by the second key. To check if +everything works, we will also create and asset and the multi-signature +transaction will mint that asset. + +So, our first transaction will: + +- Create account `mad_hatter` in `wonderland` domain with `key1` +- Assign `SignatureCheckCondition` to it, which will enforce transactions + from `mad_hatter@wonderland` to have an additional `key2` +- Register a numeric asset `casomile#wonderland` of type `Quantity` and + infinite mintability. + +::: code-group + +```rust [Rust] +let alice_id = AccountId::from_str("alice@wonderland")?; +let alice_key_pair = get_key_pair(); +let key_pair_2 = KeyPair::generate()?; +let asset_definition_id = AssetDefinitionId::from_str("camomile#wonderland")?; +let create_asset = RegisterExpr::new(AssetDefinition::quantity(asset_definition_id.clone())); +let set_signature_condition = MintExpr::new( + SignatureCheckCondition::AllAccountSignaturesAnd( + vec![key_pair_2.public_key().clone()].into(), + ), + IdBox::AccountId(alice_id.clone()), +); + +let mut client_configuration = ClientConfiguration::test(&network.genesis.api_address); +let client = Client::new(&client_configuration)?; +let instructions: [InstructionExpr; 2] = [create_asset.into(), set_signature_condition.into()]; +client.submit_all_blocking(instructions)?; +``` + +```ts [TypeScript] +const registerAccount = pipe( + sugar.identifiable.newAccount( + MAD_HATTER, + // Using only the first key + [freeScope(() => KEYS[0].publicKey().toDataModel())], + ), + sugar.instruction.register, +) + +const registerAssetDefinition = pipe( + sugar.identifiable.newAssetDefinition( + CASOMILE_DEFINITION_ID, + datamodel.AssetValueType('Quantity'), + { + mintable: datamodel.Mintable('Infinitely'), + }, + ), + sugar.instruction.register, +) + +const setSignatureCondition = sugar.instruction.mint( + datamodel.Value( + 'SignatureCheckCondition', + datamodel.SignatureCheckCondition( + 'AllAccountSignaturesAnd', + datamodel.VecPublicKey( + freeScope(() => + KEYS.map((keypair) => keypair.publicKey().toDataModel()), + ), + ), + ), + ), + datamodel.IdBox('AccountId', MAD_HATTER), +) + +// register Mad Hatter with the admin account + +await blocks.wait(async () => { + await clientAdmin.submitExecutable( + pre, + sugar.executable.instructions(registerAccount), + ) +}) + +// Register the asset definition with the Mad Hatter's account +await blocks.wait(async () => { + await Torii.submit( + pre, + pipe( + sugar.executable.instructions([ + registerAssetDefinition, + setSignatureCondition, + ]), + (executable) => + makeTransactionPayload({ executable, accountId: MAD_HATTER }), + (x) => makeSignedTransaction(x, signer1), + ), + ) +}) +``` + +::: + +Then we build the transaction with the account's primary key: + +::: code-group + +```rust [Rust] +let quantity: u32 = 200; +let asset_id = AssetId::new(asset_definition_id, alice_id.clone()); +let mint_asset = MintExpr::new(quantity.to_value(), IdBox::AssetId(asset_id.clone())); + +let (public_key1, private_key1) = alice_key_pair.into(); +client_configuration.account_id = alice_id.clone(); +client_configuration.public_key = public_key1; +client_configuration.private_key = private_key1; +let client = Client::new(&client_configuration)?; +let instructions = [mint_asset.clone()]; +let transaction = client.build_transaction(instructions, UnlimitedMetadata::new())?; +client.submit_transaction(&client.sign_transaction(transaction)?)?; +``` + +```ts [TypeScript] +const quantity = 100 + +const tx1 = makeSignedTransaction( + makeTransactionPayload({ + executable: pipe( + sugar.instruction.mint( + sugar.value.numericU32(quantity), + datamodel.IdBox( + 'AssetId', + sugar.assetId(MAD_HATTER, CASOMILE_DEFINITION_ID), + ), + ), + sugar.executable.instructions, + ), + accountId: MAD_HATTER, + }), + signer1, +) + +await Torii.submit(pre, tx1) +``` + +::: + +After that, we sign the same transaction with the second key and submit it: + +::: code-group + +```rust [Rust] +let (public_key2, private_key2) = key_pair_2.into(); +client_configuration.public_key = public_key2; +client_configuration.private_key = private_key2; +let client_2 = Client::new(&client_configuration)?; +let instructions = [mint_asset]; +let transaction = client_2.build_transaction(instructions, UnlimitedMetadata::new())?; +let transaction = client_2 + .get_original_transaction(&transaction, 3, Duration::from_millis(100))? + .expect("Found no pending transaction for this account."); +client_2.submit_transaction(&client_2.sign_transaction(transaction)?)?; +``` + +```ts [TypeScript] +const tx2 = + // we use `produce` from `immer` library + // it allows us to produce a new value from `tx1` without touching it in a declarative way + produce(tx1, (draft) => signTransaction(draft, signer2)) + +await Torii.submit(pre, tx2) +``` + +::: + +You could find full code here: [Rust](https://www.example.com/), +[TypeScript](https://www.example.com/). + +--- + +TODO: + +- Add result assertions +- Make JS code complete +- Unify code between Rust and JS +- Make code concise From cbd941be252336bf021978618ba9bedeeb24263d Mon Sep 17 00:00:00 2001 From: 0x009922 <43530070+0x009922@users.noreply.github.com> Date: Thu, 7 Dec 2023 01:18:29 +0000 Subject: [PATCH 17/31] Apply suggestions from code review Co-authored-by: Ekaterina Mekhnetsova Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com> --- .../use-multi-signature-transactions.md | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/cookbook/use-multi-signature-transactions.md b/src/cookbook/use-multi-signature-transactions.md index 791ebb37d..45b1f2936 100644 --- a/src/cookbook/use-multi-signature-transactions.md +++ b/src/cookbook/use-multi-signature-transactions.md @@ -11,21 +11,26 @@ head: # How to Use Multi-Signature Transactions -We will create an account with a key and set a rule that all transactions -made by this account should be also signed by an additional key. Then we -will perform a transaction itself, in two stages: first will be signed and -submitted with the main account key, and then the same transaction will be -submitted with an additional signature by the second key. To check if -everything works, we will also create and asset and the multi-signature -transaction will mint that asset. - -So, our first transaction will: - -- Create account `mad_hatter` in `wonderland` domain with `key1` -- Assign `SignatureCheckCondition` to it, which will enforce transactions - from `mad_hatter@wonderland` to have an additional `key2` -- Register a numeric asset `casomile#wonderland` of type `Quantity` and - infinite mintability. +The following example shows how to set up a rule that all transactions made by a specific account should also be signed by an additional key. + +## Overview + + + +1. Create an account and set up a second signature rule for it. +2. Submit the transaction signed by the main account key. +3. Submit the same transaction signed by the second additional key. +4. Check if everything works correctly. + +## Example + +1. Let's create an account that would need to have an additional signature for its transactions. Let's also create an asset that this account will later mint in order to check that the rule about second signature works as expected. + + The code below covers the following steps: + + - Create account `mad_hatter` in `wonderland` domain with `key1`. + - Assign `SignatureCheckCondition` to the created account. This will enforce transactions from `mad_hatter@wonderland` to have an additional `key2`. + - Register a numeric asset `casomile#wonderland` of type `Quantity` and infinite mintability. ::: code-group @@ -112,7 +117,7 @@ await blocks.wait(async () => { ::: -Then we build the transaction with the account's primary key: +2. Let's build the transaction with the account's primary key: ::: code-group @@ -156,7 +161,7 @@ await Torii.submit(pre, tx1) ::: -After that, we sign the same transaction with the second key and submit it: +3. Let's sign the same transaction with the second key and submit it: ::: code-group @@ -184,6 +189,8 @@ await Torii.submit(pre, tx2) ::: +## Find More + You could find full code here: [Rust](https://www.example.com/), [TypeScript](https://www.example.com/). From 90a4e7e9b2260fd4e832d28d50f20adca6813eaf Mon Sep 17 00:00:00 2001 From: Dmitry Balashov <43530070+0x009922@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:10:11 +0700 Subject: [PATCH 18/31] [docs]: refine MST recipe Signed-off-by: Dmitry Balashov <43530070+0x009922@users.noreply.github.com> --- .../use-multi-signature-transactions.md | 291 +++++++++++------- 1 file changed, 174 insertions(+), 117 deletions(-) diff --git a/src/cookbook/use-multi-signature-transactions.md b/src/cookbook/use-multi-signature-transactions.md index 45b1f2936..8c0d9e3db 100644 --- a/src/cookbook/use-multi-signature-transactions.md +++ b/src/cookbook/use-multi-signature-transactions.md @@ -11,180 +11,246 @@ head: # How to Use Multi-Signature Transactions -The following example shows how to set up a rule that all transactions made by a specific account should also be signed by an additional key. +The following example shows how to set up a rule that all transactions made +by a specific account should also be signed by an additional key. ## Overview -1. Create an account and set up a second signature rule for it. -2. Submit the transaction signed by the main account key. -3. Submit the same transaction signed by the second additional key. -4. Check if everything works correctly. +1. Create an account, set up a second signature rule for it, and register a + new asset. +2. Submit the transaction signed by the main account key, minting the + asset. +3. Check that the transaction is not committed by observing the asset. +4. Submit the same transaction signed by the second additional key. +5. Check that the transaction is committed, and the asset is minted. ## Example -1. Let's create an account that would need to have an additional signature for its transactions. Let's also create an asset that this account will later mint in order to check that the rule about second signature works as expected. +1. Let's create an account that would need to have an additional signature + for its transactions. Let's also create an asset that this account will + later mint in order to check that the rule about second signature works + as expected. The code below covers the following steps: - - Create account `mad_hatter` in `wonderland` domain with `key1`. - - Assign `SignatureCheckCondition` to the created account. This will enforce transactions from `mad_hatter@wonderland` to have an additional `key2`. - - Register a numeric asset `casomile#wonderland` of type `Quantity` and infinite mintability. + - Create account `mad_hatter` in `wonderland` domain with `key_pair_1`. + - Assign `SignatureCheckCondition` to the created account. This will + enforce transactions from `mad_hatter@wonderland` to have an + additional signature by `key_pair_2`. + - Register a numeric asset `casomile#wonderland` of type `Quantity` and + `Infinite` mintability. ::: code-group ```rust [Rust] -let alice_id = AccountId::from_str("alice@wonderland")?; -let alice_key_pair = get_key_pair(); +let key_pair_1 = KeyPair::generate()?; let key_pair_2 = KeyPair::generate()?; + +let account_id = AccountId::from_str("mad_hatter@wonderland")?; let asset_definition_id = AssetDefinitionId::from_str("camomile#wonderland")?; -let create_asset = RegisterExpr::new(AssetDefinition::quantity(asset_definition_id.clone())); + +let register_account = RegisterExpr::new(Account::new( + account_id.clone(), + [key_pair_1.public_key().clone()], +)); let set_signature_condition = MintExpr::new( SignatureCheckCondition::AllAccountSignaturesAnd( vec![key_pair_2.public_key().clone()].into(), ), - IdBox::AccountId(alice_id.clone()), + IdBox::AccountId(account_id.clone()), ); - -let mut client_configuration = ClientConfiguration::test(&network.genesis.api_address); -let client = Client::new(&client_configuration)?; -let instructions: [InstructionExpr; 2] = [create_asset.into(), set_signature_condition.into()]; -client.submit_all_blocking(instructions)?; +let register_asset_definition = + RegisterExpr::new(AssetDefinition::quantity(asset_definition_id.clone())); + +let _hash = admin_client.submit_all_blocking({ + let isi: [InstructionExpr; 3] = [ + register_account.into(), + set_signature_condition.into(), + register_asset_definition.into(), + ]; + isi +})?; ``` ```ts [TypeScript] -const registerAccount = pipe( - sugar.identifiable.newAccount( - MAD_HATTER, - // Using only the first key - [freeScope(() => KEYS[0].publicKey().toDataModel())], - ), - sugar.instruction.register, -) +declare const adminClient: Client +declare const torii: ToriiRequirementsForApiHttp -const registerAssetDefinition = pipe( - sugar.identifiable.newAssetDefinition( - CASOMILE_DEFINITION_ID, - datamodel.AssetValueType('Quantity'), - { - mintable: datamodel.Mintable('Infinitely'), - }, - ), - sugar.instruction.register, -) +const keyPair1 = crypto.KeyPair.generate() +const keyPair2 = crypto.KeyPair.generate() + +const accountId = sugar.accountId('mad_hatter', 'wonderland') +const assetDefinitionId = sugar.assetDefinitionId('camomile', 'wonderland') +const registerAccount = sugar.instruction.register( + sugar.identifiable.newAccount(accountId, [ + freeScope(() => keyPair1.publicKey().toDataModel()), + ]), +) const setSignatureCondition = sugar.instruction.mint( datamodel.Value( 'SignatureCheckCondition', datamodel.SignatureCheckCondition( 'AllAccountSignaturesAnd', - datamodel.VecPublicKey( - freeScope(() => - KEYS.map((keypair) => keypair.publicKey().toDataModel()), - ), - ), + datamodel.VecPublicKey([ + freeScope(() => keyPair2.publicKey().toDataModel()), + ]), ), ), - datamodel.IdBox('AccountId', MAD_HATTER), + datamodel.IdBox('AccountId', accountId), +) +const registerAssetDefinition = sugar.instruction.register( + sugar.identifiable.newAssetDefinition( + assetDefinitionId, + datamodel.AssetValueType('Quantity'), + { mintable: datamodel.Mintable('Infinitely') }, + ), ) -// register Mad Hatter with the admin account - -await blocks.wait(async () => { - await clientAdmin.submitExecutable( - pre, - sugar.executable.instructions(registerAccount), - ) -}) - -// Register the asset definition with the Mad Hatter's account -await blocks.wait(async () => { - await Torii.submit( - pre, - pipe( - sugar.executable.instructions([ - registerAssetDefinition, - setSignatureCondition, - ]), - (executable) => - makeTransactionPayload({ executable, accountId: MAD_HATTER }), - (x) => makeSignedTransaction(x, signer1), - ), - ) -}) +await adminClient.submitExecutable( + torii, + sugar.executable.instructions([ + registerAccount, + setSignatureCondition, + registerAssetDefinition, + ]), +) ``` ::: -2. Let's build the transaction with the account's primary key: +2. Submit the transaction signed by the main account key, minting the + asset: ::: code-group ```rust [Rust] -let quantity: u32 = 200; -let asset_id = AssetId::new(asset_definition_id, alice_id.clone()); +let mut mad_hatter_client = admin_client.clone(); +mad_hatter_client.key_pair = key_pair_1; +mad_hatter_client.account_id = account_id.clone(); + +let quantity: u32 = 42; +let asset_id = AssetId::new(asset_definition_id, account_id.clone()); let mint_asset = MintExpr::new(quantity.to_value(), IdBox::AssetId(asset_id.clone())); -let (public_key1, private_key1) = alice_key_pair.into(); -client_configuration.account_id = alice_id.clone(); -client_configuration.public_key = public_key1; -client_configuration.private_key = private_key1; -let client = Client::new(&client_configuration)?; -let instructions = [mint_asset.clone()]; -let transaction = client.build_transaction(instructions, UnlimitedMetadata::new())?; -client.submit_transaction(&client.sign_transaction(transaction)?)?; +let transaction_1 = { + let tx = + mad_hatter_client.build_transaction([mint_asset.clone()], UnlimitedMetadata::new())?; + mad_hatter_client.sign_transaction(tx)? +}; +mad_hatter_client.submit_transaction(&transaction_1)?; ``` ```ts [TypeScript] -const quantity = 100 +const madHatterClient = new Client({ + signer: new Signer(accountId, keyPair1), +}) -const tx1 = makeSignedTransaction( +const quantity = 42 +const assetId = sugar.assetId(accountId, assetDefinitionId) +const mintAsset = sugar.instruction.mint( + sugar.value.numericU32(quantity), + datamodel.IdBox('AssetId', assetId), +) + +const transaction = makeSignedTransaction( makeTransactionPayload({ - executable: pipe( - sugar.instruction.mint( - sugar.value.numericU32(quantity), - datamodel.IdBox( - 'AssetId', - sugar.assetId(MAD_HATTER, CASOMILE_DEFINITION_ID), - ), - ), - sugar.executable.instructions, - ), - accountId: MAD_HATTER, + executable: sugar.executable.instructions(mintAsset), + accountId, }), - signer1, + madHatterClient.signer, +) + +await Torii.submit(torii, transaction) +``` + +::: + +3. Let's query the asset to ensure that the transaction was not committed + yet, without the second signature: + +::: code-group + +```rust [Rust] +let error = mad_hatter_client + .request(client::asset::by_id(asset_id.clone())) + .expect_err("Asset should not be found"); + +assert!(matches!( + error, + ClientQueryError::Validation(ValidationFail::QueryFailed(QueryExecutionFail::Find( + FindError::Asset(_) + ))) +)); +``` + +```ts [TypeScript] +const asset = await madHatterClient.requestWithQueryBox( + torii, + sugar.find.assetById(assetId), ) -await Torii.submit(pre, tx1) +expect(() => + asset.as('Err').enum.as('QueryFailed').enum.as('Find').enum.as('Asset'), +).not.toThrow() ``` ::: -3. Let's sign the same transaction with the second key and submit it: +4. Now let's submit the same transaction, but signed with the second key + pair: ::: code-group ```rust [Rust] -let (public_key2, private_key2) = key_pair_2.into(); -client_configuration.public_key = public_key2; -client_configuration.private_key = private_key2; -let client_2 = Client::new(&client_configuration)?; -let instructions = [mint_asset]; -let transaction = client_2.build_transaction(instructions, UnlimitedMetadata::new())?; -let transaction = client_2 - .get_original_transaction(&transaction, 3, Duration::from_millis(100))? - .expect("Found no pending transaction for this account."); -client_2.submit_transaction(&client_2.sign_transaction(transaction)?)?; +mad_hatter_client.key_pair = key_pair_2; + +// FIXME: not sign tx1, but get original tx from Iroha and sign it +let transaction_2 = mad_hatter_client.sign_transaction(transaction_1)?; +mad_hatter_client.submit_transaction(&transaction_2)?; ``` ```ts [TypeScript] -const tx2 = - // we use `produce` from `immer` library - // it allows us to produce a new value from `tx1` without touching it in a declarative way - produce(tx1, (draft) => signTransaction(draft, signer2)) +const newSigner = new Signer(accountId, keyPair2) +transaction.enum + .as('V1') + .signatures.push( + signTransaction(transaction.enum.as('V1').payload, newSigner), + ) +await Torii.submit(torii, transaction) +``` -await Torii.submit(pre, tx2) +::: + +5. Let's check the asset to ensure that now the transaction is committed: + +::: code-group + +```rust [Rust] +let asset: Asset = mad_hatter_client + .request(client::asset::by_id(asset_id)) + .expect("Asset should be found") + .try_into() + .expect("Value should be Asset"); + +assert_eq!(asset.value, quantity.into()); +``` + +```ts [TypeScript] +const asset = await madHatterClient.requestWithQueryBox( + torii, + sugar.find.assetById(assetId), +) + +expect( + asset + .as('Ok') + .batch.enum.as('Identifiable') + .enum.as('Asset') + .value.enum.as('Quantity'), +).toEqual(quantity) ``` ::: @@ -193,12 +259,3 @@ await Torii.submit(pre, tx2) You could find full code here: [Rust](https://www.example.com/), [TypeScript](https://www.example.com/). - ---- - -TODO: - -- Add result assertions -- Make JS code complete -- Unify code between Rust and JS -- Make code concise From 951c9dbef9a9882f6030d1d1b504ba55fd7d5254 Mon Sep 17 00:00:00 2001 From: Stukalov-A-M Date: Sat, 20 Jan 2024 18:24:56 +0100 Subject: [PATCH 19/31] ADD: Few examples Signed-off-by: Stukalov-A-M --- src/cookbook/mint-assets.md | 16 +++++++++++++++- src/cookbook/register-accounts.md | 14 +++++++++++++- src/cookbook/register-asset-definitions.md | 17 ++++++++++++++++- src/cookbook/register-assets.md | 15 ++++++++++++++- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/cookbook/mint-assets.md b/src/cookbook/mint-assets.md index 27495e6bd..766090a63 100644 --- a/src/cookbook/mint-assets.md +++ b/src/cookbook/mint-assets.md @@ -11,4 +11,18 @@ head: # How to Mint an Asset -TODO \ No newline at end of file +```rust + //Precondition: The asset definition was registered + // First we need to define the asset definition id + let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); + + //Then we need to create an assetId object + //The AssetId is a complex object which consists of asset definition id and account id + let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); + + //Now we need to define the asset quantity regarding to the asset's value type + let asset_quantity: Fixed = Fixed::from_str("11").unwrap(); + + //And finally we need to send the transaction + iroha_client.submit_blocking(MintExpr::new(asset_quantity, asset_id)).unwrap(); +``` \ No newline at end of file diff --git a/src/cookbook/register-accounts.md b/src/cookbook/register-accounts.md index d7e143015..ec828cd07 100644 --- a/src/cookbook/register-accounts.md +++ b/src/cookbook/register-accounts.md @@ -11,4 +11,16 @@ head: # How to Register an Account -TODO \ No newline at end of file +```rust + //Creating a key pair for a new account + //The key pair must be given to the new account owner + let key_pair = KeyPair::generate().unwrap(); + //Now you can execute public|private keys by using functions of key_pair variable + let public_key = vec![key_pair.public_key().clone()]; + //Creating a NewAccount type + let new_account = Account::new("alex@wonderland".parse()?, public_key); + //And finally submit the transaction + let tx = iroha_client.submit(RegisterExpr::new(new_account))?; + //Optional. To look at the transaction hash + print!("{:?}", tx); +``` \ No newline at end of file diff --git a/src/cookbook/register-asset-definitions.md b/src/cookbook/register-asset-definitions.md index c4bc04af6..20a7e9a4f 100644 --- a/src/cookbook/register-asset-definitions.md +++ b/src/cookbook/register-asset-definitions.md @@ -9,4 +9,19 @@ head: content: "asset definitions, registering asset definitions" --- -# How to Register an Asset Definition \ No newline at end of file +# How to Register an Asset Definition + +```rust + //First we need to create the asset id + let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); + + //Then we need to define the asset value type + //There are only 4 asset value types and they are defined in the AssetValueType struct + let asset_value_type: AssetValueType = AssetValueType::Fixed; + + //Then we need to create an asset definition object + let asset_definition = AssetDefinition::new(asset_definition_id, asset_value_type); + + //And finally we need to send the transaction + iroha_client.submit(RegisterExpr::new(asset_definition)).unwrap(); +``` \ No newline at end of file diff --git a/src/cookbook/register-assets.md b/src/cookbook/register-assets.md index 3cef14c15..f8963cc87 100644 --- a/src/cookbook/register-assets.md +++ b/src/cookbook/register-assets.md @@ -11,4 +11,17 @@ head: # How to Register an Asset -TODO \ No newline at end of file +```rust + //Precondition: The asset definition was registered + // First we need to define the asset definition id + let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); + + //Then we need to create an assetId object + //The AssetId is a complex object which consists of asset definition id and account id + //And the Asset also is a complex object which consists of asset id and its quantity + let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); + let asset: Asset = Asset::new(asset_id, Fixed::from_str("33").unwrap()); + + //And finally we need to send the transaction + iroha_client.submit_blocking(RegisterExpr::new(asset)).unwrap(); +``` \ No newline at end of file From 619c0e8b33d60d83624b2d1bda102d2756729a34 Mon Sep 17 00:00:00 2001 From: Stukalov-A-M Date: Sun, 21 Jan 2024 12:46:09 +0100 Subject: [PATCH 20/31] ADD: burn-assets.md, submit-transactions.md Signed-off-by: Stukalov-A-M --- src/cookbook/burn-assets.md | 17 ++++++++++++++++- src/cookbook/submit-transactions.md | 26 +++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/cookbook/burn-assets.md b/src/cookbook/burn-assets.md index 3776f63c7..852063562 100644 --- a/src/cookbook/burn-assets.md +++ b/src/cookbook/burn-assets.md @@ -11,4 +11,19 @@ head: # How to Burn an Asset -TODO \ No newline at end of file +```rust + //Precondition: The asset definition was registered + // First we need to define the asset definition id + let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); + + //Then we need to create an assetId object + //The AssetId is a complex object which consists of asset definition id and account id + let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); + + //Now we need to define the asset quantity regarding to the asset's value type + let asset_quantity: Fixed = Fixed::from_str("1").unwrap(); + + //And finally we need to send the transaction + //This time we will use the BurnExpr object + iroha_client.submit_blocking(BurnExpr::new(asset_quantity, asset_id)).unwrap(); +``` \ No newline at end of file diff --git a/src/cookbook/submit-transactions.md b/src/cookbook/submit-transactions.md index 68073d56b..1a6b3517c 100644 --- a/src/cookbook/submit-transactions.md +++ b/src/cookbook/submit-transactions.md @@ -11,4 +11,28 @@ head: # How to Submit a Transaction -TODO \ No newline at end of file +```rust + //Precondition: the Client variable must be initialized + + //First we need to build an instruction expression that we want to submit + //The instruction expression structures have a self-explanatory name + //and you can easily understand what each of them does. + //As an example: + //* BurnExp - burns asset quantity + //* MintExpr - mints asset quantity + //* RegisterExpr - registers any Registrable object like + //** Account, Asset, Asset definition, Trigger etc. + //As an example we will take the MintExpr + + let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); + let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); + let asset_quantity: Fixed = Fixed::from_str("7").unwrap(); + + let some_expression = MintExpr::new(asset_quantity, asset_id); + + //The client module in the iroha_client crate has 2 methods for the transaction submission + //* submit() - sends a transaction without waiting for approval + //* submit_blocking() - sends a transaction and waits for approving. + //If the transaction will be rejected, the method will panic + iroha_client.submit_blocking(some_expression).unwrap(); +``` \ No newline at end of file From 9fa9e2e1ea710be1dd60096f5d2aba66b5391678 Mon Sep 17 00:00:00 2001 From: Stukalov-A-M Date: Mon, 22 Jan 2024 10:26:39 +0100 Subject: [PATCH 21/31] EDIT: Indents are removed Signed-off-by: Stukalov-A-M --- src/cookbook/burn-assets.md | 22 ++++++------ src/cookbook/mint-assets.md | 20 +++++------ src/cookbook/register-accounts.md | 20 +++++------ src/cookbook/register-asset-definitions.md | 18 +++++----- src/cookbook/register-assets.md | 20 +++++------ src/cookbook/submit-transactions.md | 40 +++++++++++----------- 6 files changed, 69 insertions(+), 71 deletions(-) diff --git a/src/cookbook/burn-assets.md b/src/cookbook/burn-assets.md index 852063562..218b14c0a 100644 --- a/src/cookbook/burn-assets.md +++ b/src/cookbook/burn-assets.md @@ -12,18 +12,18 @@ head: # How to Burn an Asset ```rust - //Precondition: The asset definition was registered - // First we need to define the asset definition id - let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); +//Precondition: The asset definition was registered +// First we need to define the asset definition id +let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); - //Then we need to create an assetId object - //The AssetId is a complex object which consists of asset definition id and account id - let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); +//Then we need to create an assetId object +//The AssetId is a complex object which consists of asset definition id and account id +let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); - //Now we need to define the asset quantity regarding to the asset's value type - let asset_quantity: Fixed = Fixed::from_str("1").unwrap(); +//Now we need to define the asset quantity regarding to the asset's value type +let asset_quantity: Fixed = Fixed::from_str("1").unwrap(); - //And finally we need to send the transaction - //This time we will use the BurnExpr object - iroha_client.submit_blocking(BurnExpr::new(asset_quantity, asset_id)).unwrap(); +//And finally we need to send the transaction +//This time we will use the BurnExpr object +iroha_client.submit_blocking(BurnExpr::new(asset_quantity, asset_id)).unwrap(); ``` \ No newline at end of file diff --git a/src/cookbook/mint-assets.md b/src/cookbook/mint-assets.md index 766090a63..6c155af8c 100644 --- a/src/cookbook/mint-assets.md +++ b/src/cookbook/mint-assets.md @@ -12,17 +12,17 @@ head: # How to Mint an Asset ```rust - //Precondition: The asset definition was registered - // First we need to define the asset definition id - let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); +//Precondition: The asset definition was registered +// First we need to define the asset definition id +let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); - //Then we need to create an assetId object - //The AssetId is a complex object which consists of asset definition id and account id - let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); +//Then we need to create an assetId object +//The AssetId is a complex object which consists of asset definition id and account id +let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); - //Now we need to define the asset quantity regarding to the asset's value type - let asset_quantity: Fixed = Fixed::from_str("11").unwrap(); +//Now we need to define the asset quantity regarding to the asset's value type +let asset_quantity: Fixed = Fixed::from_str("11").unwrap(); - //And finally we need to send the transaction - iroha_client.submit_blocking(MintExpr::new(asset_quantity, asset_id)).unwrap(); +//And finally we need to send the transaction +iroha_client.submit_blocking(MintExpr::new(asset_quantity, asset_id)).unwrap(); ``` \ No newline at end of file diff --git a/src/cookbook/register-accounts.md b/src/cookbook/register-accounts.md index ec828cd07..aa31fa48a 100644 --- a/src/cookbook/register-accounts.md +++ b/src/cookbook/register-accounts.md @@ -12,15 +12,13 @@ head: # How to Register an Account ```rust - //Creating a key pair for a new account - //The key pair must be given to the new account owner - let key_pair = KeyPair::generate().unwrap(); - //Now you can execute public|private keys by using functions of key_pair variable - let public_key = vec![key_pair.public_key().clone()]; - //Creating a NewAccount type - let new_account = Account::new("alex@wonderland".parse()?, public_key); - //And finally submit the transaction - let tx = iroha_client.submit(RegisterExpr::new(new_account))?; - //Optional. To look at the transaction hash - print!("{:?}", tx); +//Creating a key pair for a new account +//The key pair must be given to the new account owner +let key_pair = KeyPair::generate().unwrap(); +//Now you can execute public|private keys by using functions of key_pair variable +let public_key = vec![key_pair.public_key().clone()]; +//Creating a NewAccount type +let new_account = Account::new("alex@wonderland".parse()?, public_key); +//And finally submit the transaction +let tx = iroha_client.submit(RegisterExpr::new(new_account))?; ``` \ No newline at end of file diff --git a/src/cookbook/register-asset-definitions.md b/src/cookbook/register-asset-definitions.md index 20a7e9a4f..f3ee41050 100644 --- a/src/cookbook/register-asset-definitions.md +++ b/src/cookbook/register-asset-definitions.md @@ -12,16 +12,16 @@ head: # How to Register an Asset Definition ```rust - //First we need to create the asset id - let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); +//First we need to create the asset id +let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); - //Then we need to define the asset value type - //There are only 4 asset value types and they are defined in the AssetValueType struct - let asset_value_type: AssetValueType = AssetValueType::Fixed; +//Then we need to define the asset value type +//There are only 4 asset value types and they are defined in the AssetValueType struct +let asset_value_type: AssetValueType = AssetValueType::Fixed; - //Then we need to create an asset definition object - let asset_definition = AssetDefinition::new(asset_definition_id, asset_value_type); +//Then we need to create an asset definition object +let asset_definition = AssetDefinition::new(asset_definition_id, asset_value_type); - //And finally we need to send the transaction - iroha_client.submit(RegisterExpr::new(asset_definition)).unwrap(); +//And finally we need to send the transaction +iroha_client.submit(RegisterExpr::new(asset_definition)).unwrap(); ``` \ No newline at end of file diff --git a/src/cookbook/register-assets.md b/src/cookbook/register-assets.md index f8963cc87..c80ccdab9 100644 --- a/src/cookbook/register-assets.md +++ b/src/cookbook/register-assets.md @@ -12,16 +12,16 @@ head: # How to Register an Asset ```rust - //Precondition: The asset definition was registered - // First we need to define the asset definition id - let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); +//Precondition: The asset definition was registered +// First we need to define the asset definition id +let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); - //Then we need to create an assetId object - //The AssetId is a complex object which consists of asset definition id and account id - //And the Asset also is a complex object which consists of asset id and its quantity - let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); - let asset: Asset = Asset::new(asset_id, Fixed::from_str("33").unwrap()); +//Then we need to create an assetId object +//The AssetId is a complex object which consists of asset definition id and account id +//And the Asset also is a complex object which consists of asset id and its quantity +let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); +let asset: Asset = Asset::new(asset_id, Fixed::from_str("33").unwrap()); - //And finally we need to send the transaction - iroha_client.submit_blocking(RegisterExpr::new(asset)).unwrap(); +//And finally we need to send the transaction +iroha_client.submit_blocking(RegisterExpr::new(asset)).unwrap(); ``` \ No newline at end of file diff --git a/src/cookbook/submit-transactions.md b/src/cookbook/submit-transactions.md index 1a6b3517c..c4cfb5961 100644 --- a/src/cookbook/submit-transactions.md +++ b/src/cookbook/submit-transactions.md @@ -12,27 +12,27 @@ head: # How to Submit a Transaction ```rust - //Precondition: the Client variable must be initialized +//Precondition: the Client variable must be initialized - //First we need to build an instruction expression that we want to submit - //The instruction expression structures have a self-explanatory name - //and you can easily understand what each of them does. - //As an example: - //* BurnExp - burns asset quantity - //* MintExpr - mints asset quantity - //* RegisterExpr - registers any Registrable object like - //** Account, Asset, Asset definition, Trigger etc. - //As an example we will take the MintExpr +//First we need to build an instruction expression that we want to submit +//The instruction expression structures have a self-explanatory name +//and you can easily understand what each of them does. +//As an example: +//* BurnExp - burns asset quantity +//* MintExpr - mints asset quantity +//* RegisterExpr - registers any Registrable object like +//** Account, Asset, Asset definition, Trigger etc. +//As an example we will take the MintExpr - let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); - let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); - let asset_quantity: Fixed = Fixed::from_str("7").unwrap(); - - let some_expression = MintExpr::new(asset_quantity, asset_id); +let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); +let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); +let asset_quantity: Fixed = Fixed::from_str("7").unwrap(); + +let some_expression = MintExpr::new(asset_quantity, asset_id); - //The client module in the iroha_client crate has 2 methods for the transaction submission - //* submit() - sends a transaction without waiting for approval - //* submit_blocking() - sends a transaction and waits for approving. - //If the transaction will be rejected, the method will panic - iroha_client.submit_blocking(some_expression).unwrap(); +//The client module in the iroha_client crate has 2 methods for the transaction submission +//* submit() - sends a transaction without waiting for approval +//* submit_blocking() - sends a transaction and waits for approving. +//If the transaction will be rejected, the method will panic +iroha_client.submit_blocking(some_expression).unwrap(); ``` \ No newline at end of file From 6d4ff5d6f59ba39794a6900f9aa5e15e160014e3 Mon Sep 17 00:00:00 2001 From: Stukalov-A-M Date: Mon, 29 Jan 2024 14:46:28 +0100 Subject: [PATCH 22/31] [ADD]: access-metadata, check-status, combine-instructions, create-transactions Signed-off-by: Stukalov-A-M --- src/cookbook/access-metadata.md | 29 ++++++++++++++- src/cookbook/check-status.md | 7 +++- src/cookbook/combine-instructions.md | 40 ++++++++++++++++++++- src/cookbook/create-transactions.md | 53 +++++++++++++++++++++++++++- 4 files changed, 125 insertions(+), 4 deletions(-) diff --git a/src/cookbook/access-metadata.md b/src/cookbook/access-metadata.md index cd20f3d5a..0e3eac817 100644 --- a/src/cookbook/access-metadata.md +++ b/src/cookbook/access-metadata.md @@ -11,4 +11,31 @@ head: # How to Access an Object's Metadata -TODO \ No newline at end of file +```rust + /* + + Description: + In the Iroha 2 almost all basic objects like Account, Asset, Domain etc. have a Metadata field, + which is a struct that consists of one field with BTreeMap type. + By default the basic objects are created with 0 metadata capacity so if you get empty result, + be sure that metadata has been added into the object. + + The current example describes how to get metadata from an Account. + + Precondition: The object has been created with a metadata. + + */ + + //Define the target account and make a request to get this account's object + let account_id: AccountId = "artem@wonderland".parse().unwrap(); + let account: Account = iroha_client.request(FindAccountById::new(account_id)).unwrap(); + + //Bind metadata struct to a variable + let account_metadata: &Metadata = account.metadata(); + + //Iterate for the metadata in the account's object + for metadata in account_metadata.iter() { + println!("{:?}", metadata) + } + +``` \ No newline at end of file diff --git a/src/cookbook/check-status.md b/src/cookbook/check-status.md index 7596beeae..fb6ba6b54 100644 --- a/src/cookbook/check-status.md +++ b/src/cookbook/check-status.md @@ -11,4 +11,9 @@ head: # How to Check Iroha Status -TODO \ No newline at end of file +```rust + // To get the status, the Client struct already has a function get_status(), + // so you may just execute it. + let status = iroha_client.get_status().unwrap(); + println!("{:?}", status); +``` \ No newline at end of file diff --git a/src/cookbook/combine-instructions.md b/src/cookbook/combine-instructions.md index 2b299d495..e10f1e20a 100644 --- a/src/cookbook/combine-instructions.md +++ b/src/cookbook/combine-instructions.md @@ -11,4 +11,42 @@ head: # How to Combine Iroha Special Instructions -TODO \ No newline at end of file +```rust +// Instructions should be unified to a single type 'InstructionExpr' + + // Register account + let register_account_instruction: InstructionExpr = { + let key_pair = KeyPair::generate().unwrap(); + RegisterExpr::new(Account::new( + AccountId::from_str("roman@wonderland").unwrap(), + vec![key_pair.public_key().clone()], + )) + .into() + }; + // Register asset definition + let register_asset_definition_instruction: InstructionExpr = RegisterExpr::new( + AssetDefinition::quantity(AssetDefinitionId::from_str("romancoin#wonderland").unwrap()), + ) + .into(); + // Mint asset + let mint_asset_to_roman: InstructionExpr = MintExpr::new( + 51_u32, + AssetId::from_str("romancoin#wonderland#roman@wonderland").unwrap(), + ) + .into(); + // Transfer asset + let transfer_asset_to_alina: InstructionExpr = TransferExpr::new( + AssetId::from_str("romancoin#wonderland#roman@wonderland").unwrap(), + 21_u32, + AccountId::from_str("alina@wonderland").unwrap(), + ) + .into(); + + // Bind instructions into collection + let instructions = vec![ + register_account_instruction, + register_asset_definition_instruction, + mint_asset_to_roman, + transfer_asset_to_alina, + ]; +``` \ No newline at end of file diff --git a/src/cookbook/create-transactions.md b/src/cookbook/create-transactions.md index 149d46a1d..68d08550f 100644 --- a/src/cookbook/create-transactions.md +++ b/src/cookbook/create-transactions.md @@ -11,4 +11,55 @@ head: # How to Create a Transaction -TODO \ No newline at end of file +```rust + /* + Define the Iroha 2 client. + Note: + The author uses his custom get_client() function. + To initialize Client with default methods, please look in the Guide section + */ + let iroha_client: Client = get_client(); + // Define an account on behalf of which a transaction will be build + let account_id: AccountId = "alice@wonderland".parse().unwrap(); + // Define the set of instructions (Can be one or many) + let register_account_instruction = { + let key_pair = KeyPair::generate().unwrap(); + RegisterExpr::new(Account::new( + AccountId::from_str("alina@wonderland").unwrap(), + vec![key_pair.public_key().clone()], + )) + }; + let register_asset_definition_instruction = RegisterExpr::new(AssetDefinition::quantity( + AssetDefinitionId::from_str("wondercoins#wonderland").unwrap(), + )); + let register_asset_id_instruction = RegisterExpr::new(Asset::new( + AssetId::new( + AssetDefinitionId::from_str("wondercoins#wonderland").unwrap(), + AccountId::from_str("alina@wonderland").unwrap(), + ), + 11_u32, + )); + // Bind instruction into collection + let instructions = vec![ + register_account_instruction, + register_asset_definition_instruction, + register_asset_id_instruction, + ]; + /* + Initialize a transaction builder and inserts: + * The transaction owner's account id + * The set of instructions + * The default metadata + */ + let tx_builder = TransactionBuilder::new(account_id.clone()) + .with_instructions(instructions) + .with_metadata(UnlimitedMetadata::default()); + + // Sign the transaction by transaction owner's key pair + let signed_transaction = iroha_client.sign_transaction(tx_builder).unwrap(); + + // Send the transaction to the Iroha 2 + iroha_client + .submit_transaction(&signed_transaction) + .unwrap(); +``` \ No newline at end of file From 1fd5958e213c42f0af9cabb2e72074fe47ef2f6d Mon Sep 17 00:00:00 2001 From: Stukalov-A-M Date: Fri, 9 Feb 2024 19:16:26 +0100 Subject: [PATCH 23/31] [ADD]: register-domains, unregister-asset-def, unregister-assets, unregister-domains Signed-off-by: Stukalov-A-M --- src/cookbook/register-domains.md | 11 ++++++++++- src/cookbook/unregister-asset-definitions.md | 10 ++++++++-- src/cookbook/unregister-assets.md | 13 ++++++++++++- src/cookbook/unregister-domains.md | 9 ++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/cookbook/register-domains.md b/src/cookbook/register-domains.md index 979499ec1..9e8aaa119 100644 --- a/src/cookbook/register-domains.md +++ b/src/cookbook/register-domains.md @@ -11,4 +11,13 @@ head: # How to Register a Domain -TODO \ No newline at end of file +```rust + //First we need to define a domain id (name) + let domain_id = DomainId::new("disneyland".parse().unwrap()); + //Then we need to define a new domain object + let domain: NewDomain = Domain::new(domain_id); + //After, define a Register expression for the new domain + let expression = RegisterExpr::new(domain); + //And finally we need to send the transaction + iroha_client.submit_blocking(expression).unwrap(); +``` \ No newline at end of file diff --git a/src/cookbook/unregister-asset-definitions.md b/src/cookbook/unregister-asset-definitions.md index 809441641..91dbcc60b 100644 --- a/src/cookbook/unregister-asset-definitions.md +++ b/src/cookbook/unregister-asset-definitions.md @@ -11,5 +11,11 @@ head: # How to Unregister an Asset Definition -TODO - +```rust + //First we need to define an asset definition id that we want to unregister + let asset_definition_id: AssetDefinitionId = AssetDefinitionId::from_str("wondercoins#wonderland").unwrap(); + //Then we need to define an Unregister expression with the asset definition id + let expression: UnregisterExpr = UnregisterExpr::new(asset_definition_id); + //And finally we need to send the transaction + iroha_client.submit_blocking(expression).unwrap(); +``` diff --git a/src/cookbook/unregister-assets.md b/src/cookbook/unregister-assets.md index c05c30c97..322cccbd9 100644 --- a/src/cookbook/unregister-assets.md +++ b/src/cookbook/unregister-assets.md @@ -11,4 +11,15 @@ head: # How to Unregister an Asset -TODO \ No newline at end of file +```rust + //First we need to define an account id which has an asset that we want to unregister + let account_id = AccountId::from_str("alina@wonderland").unwrap(); + //Then we need to define an asset definition id that we want to unregister + let asset_definition_id: AssetDefinitionId = AssetDefinitionId::from_str("romancoin#wonderland").unwrap(); + //After, define the asset id as a new object that consists of asset definition id and account id + let asset_id: AssetId = AssetId::new(asset_definition_id, account_id); + // Define an Unregister expression with the asset id + let expression: UnregisterExpr = UnregisterExpr::new(asset_id); + //And finally we need to send the transaction + iroha_client.submit_blocking(expression).unwrap() +``` \ No newline at end of file diff --git a/src/cookbook/unregister-domains.md b/src/cookbook/unregister-domains.md index fbe2ec295..a9d5a4da6 100644 --- a/src/cookbook/unregister-domains.md +++ b/src/cookbook/unregister-domains.md @@ -11,4 +11,11 @@ head: # How to Unregister a Domain -TODO \ No newline at end of file +```rust + //First we need to define a domain id (name) that we want to unregister + let domain_id = DomainId::new("disneyland".parse().unwrap()); + //Then we need to define an Unregister expression for the domain + let expression = UnregisterExpr::new(domain_id); + //And finally we need to send the transaction + iroha_client.submit_blocking(expression).unwrap(); +``` \ No newline at end of file From a4af32b110bf1e77d68439ff4425ef55b509c6ed Mon Sep 17 00:00:00 2001 From: Stukalov-A-M Date: Fri, 9 Feb 2024 19:30:35 +0100 Subject: [PATCH 24/31] [ADD]: unregister-accounts Signed-off-by: Stukalov-A-M --- src/cookbook/access-metadata.md | 2 +- src/cookbook/check-status.md | 4 ++++ src/cookbook/unregister-accounts.md | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cookbook/access-metadata.md b/src/cookbook/access-metadata.md index 0e3eac817..5f2f77b3a 100644 --- a/src/cookbook/access-metadata.md +++ b/src/cookbook/access-metadata.md @@ -27,7 +27,7 @@ head: */ //Define the target account and make a request to get this account's object - let account_id: AccountId = "artem@wonderland".parse().unwrap(); + let account_id: AccountId = "alice@wonderland".parse().unwrap(); let account: Account = iroha_client.request(FindAccountById::new(account_id)).unwrap(); //Bind metadata struct to a variable diff --git a/src/cookbook/check-status.md b/src/cookbook/check-status.md index fb6ba6b54..eed9c4981 100644 --- a/src/cookbook/check-status.md +++ b/src/cookbook/check-status.md @@ -14,6 +14,10 @@ head: ```rust // To get the status, the Client struct already has a function get_status(), // so you may just execute it. + // The result message will include a deserialized json object with parameters like: + // Quantity of peers + // Quantity of blocks + // Quantity of accepted and rejected transactions and some more let status = iroha_client.get_status().unwrap(); println!("{:?}", status); ``` \ No newline at end of file diff --git a/src/cookbook/unregister-accounts.md b/src/cookbook/unregister-accounts.md index 3411a0796..8c6cbadac 100644 --- a/src/cookbook/unregister-accounts.md +++ b/src/cookbook/unregister-accounts.md @@ -11,4 +11,13 @@ head: # How to Unregister Accounts -TODO \ No newline at end of file +```rust + //Note: + // Only domain owner or account with appropriate permission token can unregister another account + //First we need to define an account id that we want to unregister + let account_id = AccountId::from_str("artem@disneyland").unwrap(); + //Then we need to define an Unregister expression + let expression = UnregisterExpr::new(account_id); + //And finally we need to send the transaction + iroha_client.submit_blocking(expression).unwrap(); +``` \ No newline at end of file From 1551872740608145c99d46fd2dfcec972ae176d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nurzhan=20Sak=C3=A9n?= Date: Wed, 10 Apr 2024 17:46:31 +0400 Subject: [PATCH 25/31] [add]: register-roles, use-instructions, work-with-numeric-assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nurzhan Sakén --- src/cookbook/register-roles.md | 38 +++++++++++++++++- src/cookbook/use-instructions.md | 18 ++++++++- src/cookbook/work-with-numeric-assets.md | 50 +++++++++++++++++++++++- 3 files changed, 103 insertions(+), 3 deletions(-) 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 From 9ebde90bebcebbabf0b09a73c0aab849254527e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nurzhan=20Sak=C3=A9n?= Date: Thu, 11 Apr 2024 10:58:19 +0400 Subject: [PATCH 26/31] [add]: grant-permissions, grant-roles [edit]: register-roles, use-instructions, work-with-numeric-assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nurzhan Sakén --- src/cookbook/grant-permissions.md | 37 +++++++++++++++++++++++- src/cookbook/grant-roles.md | 14 ++++++++- src/cookbook/register-roles.md | 33 +++++++++++---------- src/cookbook/use-instructions.md | 8 ++--- src/cookbook/work-with-numeric-assets.md | 30 +++++++++---------- 5 files changed, 84 insertions(+), 38 deletions(-) diff --git a/src/cookbook/grant-permissions.md b/src/cookbook/grant-permissions.md index 7876a68f0..13d9e1a38 100644 --- a/src/cookbook/grant-permissions.md +++ b/src/cookbook/grant-permissions.md @@ -11,4 +11,39 @@ head: # How to Grant Permissions -TODO \ No newline at end of file +Granting a permission to an account: + +```rust +fn grant_permission_to_account( + iroha: &Client, +) { + // Alice will be given permission to unregister the kingdom domain + let grant_permission_to_unregister_kingdom = Grant::permission( + PermissionToken::new( + "CanUnregisterDomain".parse().unwrap(), + &json!({ "domain_id": "kingdom" }), + ), + AccountId::from_str("alice@wonderland").unwrap() + ); + iroha.submit(grant_permission_to_unregister_kingdom).unwrap(); +} +``` + +Granting a permission to a role: + +```rust +fn grant_permission_to_role( + iroha: &Client, +) { + // all accounts with the DOMAIN_DESTROYER role + // will be able to unregister the kingdom domain + let grant_permission_to_unregister_kingdom = Grant::role_permission( + PermissionToken::new( + "CanUnregisterDomain".parse().unwrap(), + &json!({ "domain_id": "kingdom" }), + ), + RoleId::from_str("DOMAIN_DESTROYER").unwrap(), + ); + iroha.submit(grant_permission_to_unregister_kingdom).unwrap(); +} +``` diff --git a/src/cookbook/grant-roles.md b/src/cookbook/grant-roles.md index 4c32c1201..0d1bc4ab1 100644 --- a/src/cookbook/grant-roles.md +++ b/src/cookbook/grant-roles.md @@ -11,4 +11,16 @@ head: # How to Grant a Role -TODO \ No newline at end of file +Roles are granted to accounts: + +```rust +fn grant_role( + iroha: &Client, +) { + let grant_role = Grant::role( + RoleId::from_str("DOMAIN_DESTROYER"), + AccountId::from_str("alice@wonderland").unwrap() + ); + iroha.submit(grant_role).unwrap(); +} +``` diff --git a/src/cookbook/register-roles.md b/src/cookbook/register-roles.md index b473bf292..f25cf627b 100644 --- a/src/cookbook/register-roles.md +++ b/src/cookbook/register-roles.md @@ -15,13 +15,12 @@ The minimal case is an empty role (without any permission tokens): ```rust fn register_new_role( - role_name: &str, - iroha_client: &Client + iroha: &Client ) { - let role_id = RoleId::from_str(role_name).unwrap(); + let role_id = RoleId::from_str("MY_EMPTY_ROLE").unwrap(); let role = iroha_data_model::role::Role::new(role_id); let register_role = Register::role(role); - iroha_client.submit(register_role).unwrap(); + iroha.submit(register_role).unwrap(); } ``` @@ -33,18 +32,22 @@ 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 + iroha: &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 roses_of_alice = AssetId::from_str("rose##alice@wonderland").unwrap(); + let roses_of_mouse = AssetId::from_str("rose##mouse@wonderland").unwrap(); + let can_burn_roses_of_alice = PermissionToken::new( + "CanBurnUserAsset".parse().unwrap(), + &json!({ "asset_id": roses_of_alice }), ); - 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(); + let can_burn_roses_of_mouse = PermissionToken::new( + "CanBurnUserAsset".parse().unwrap(), + &json!({ "asset_id": roses_of_mouse }), + ); + let rose_burner = Role::new("ROSE_BURNER".parse().unwrap()) + .add_permission(can_burn_roses_of_alice) + .add_permission(can_burn_roses_of_mouse); + let register_rose_burner = Register::role(rose_burner); + iroha.submit(register_rose_burner).unwrap(); } ``` diff --git a/src/cookbook/use-instructions.md b/src/cookbook/use-instructions.md index ed0832ffd..1518868fc 100644 --- a/src/cookbook/use-instructions.md +++ b/src/cookbook/use-instructions.md @@ -15,16 +15,16 @@ Building and submitting an instruction: ```rust fn use_instruction( - client: &Client, - roses: AssetDefinitionId, - alice: AccountId, + iroha: &Client, ) { + let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let alice = AccountId::from_str("alice@wonderland").unwrap(); // 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(); + iroha.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 37a264aae..a208f7aa4 100644 --- a/src/cookbook/work-with-numeric-assets.md +++ b/src/cookbook/work-with-numeric-assets.md @@ -15,15 +15,13 @@ Minting roses for Alice: ```rust fn mint_numeric_asset( - client: &Client, - roses: AssetDefinitionId, - alice: AccountId, + iroha: &Client, ) { let mint_roses_for_alice = Mint::asset_numeric( 42_u32, - AssetId::new(roses, alice) + "rose##alice@wonderland".parse().unwrap() ); - client.submit(mint_roses_for_alice).unwrap(); + iroha.submit(mint_roses_for_alice).unwrap(); } ``` @@ -31,15 +29,13 @@ Burning Alice's roses: ```rust fn burn_numeric_asset( - client: &Client, - roses: AssetDefinitionId, - alice: AccountId, + iroha: &Client, ) { let burn_roses_of_alice = Burn::asset_numeric( - 8_u32, - AssetId::new(roses, alice) + 8_u32, + AssetId::from_str("rose##alice@wonderland").unwrap() ); - client.submit(burn_roses_of_alice).unwrap(); + iroha.submit(burn_roses_of_alice).unwrap(); } ``` @@ -47,16 +43,16 @@ Transferring Alice's roses to Mouse: ```rust fn transfer_numeric_asset( - client: &Client, - roses: AssetDefinitionId, - alice: AccountId, - mouse: AccountId, + 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 + mouse, ); - client.submit(transfer_roses_from_alice_to_mouse).unwrap(); + iroha.submit(transfer_roses_from_alice_to_mouse).unwrap(); } ``` \ No newline at end of file From e7f8ab7fec8a12a0092ad790dc60b77a6ad44e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nurzhan=20Sak=C3=A9n?= Date: Tue, 16 Apr 2024 19:10:01 +0400 Subject: [PATCH 27/31] [add]: work-with-non-mintable-assets [edit]: work-with-numeric-assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nurzhan Sakén --- src/cookbook/work-with-non-mintable-assets.md | 46 ++++++++++++++++++- src/cookbook/work-with-numeric-assets.md | 27 +++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/cookbook/work-with-non-mintable-assets.md b/src/cookbook/work-with-non-mintable-assets.md index b95f71fe8..7df0dd79d 100644 --- a/src/cookbook/work-with-non-mintable-assets.md +++ b/src/cookbook/work-with-non-mintable-assets.md @@ -11,4 +11,48 @@ head: # How to Work with Non-Mintable Assets -TODO \ No newline at end of file +```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(); +} +``` \ 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 a208f7aa4..e8341673d 100644 --- a/src/cookbook/work-with-numeric-assets.md +++ b/src/cookbook/work-with-numeric-assets.md @@ -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 From 1763b349cca0ff563dc052fcea4a2b5d167ecde8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nurzhan=20Sak=C3=A9n?= Date: Tue, 16 Apr 2024 22:52:07 +0400 Subject: [PATCH 28/31] [add]: revoke-permissions, revoke-roles, transfer-assets, work-with-store-assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nurzhan Sakén --- src/cookbook/revoke-permissions.md | 30 ++++++++++++++++++++- src/cookbook/revoke-roles.md | 13 ++++++++- src/cookbook/transfer-assets.md | 31 ++++++++++++++++++++- src/cookbook/work-with-store-assets.md | 37 +++++++++++++++++++++++++- 4 files changed, 107 insertions(+), 4 deletions(-) diff --git a/src/cookbook/revoke-permissions.md b/src/cookbook/revoke-permissions.md index d4e37a80d..0d41e2d08 100644 --- a/src/cookbook/revoke-permissions.md +++ b/src/cookbook/revoke-permissions.md @@ -11,4 +11,32 @@ head: # How to Revoke Permissions -TODO \ No newline at end of file +```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(); +} +``` diff --git a/src/cookbook/revoke-roles.md b/src/cookbook/revoke-roles.md index f5025ffbe..56fbcce15 100644 --- a/src/cookbook/revoke-roles.md +++ b/src/cookbook/revoke-roles.md @@ -11,4 +11,15 @@ head: # How to Revoke Roles -TODO \ No newline at end of file +```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(); +} +``` diff --git a/src/cookbook/transfer-assets.md b/src/cookbook/transfer-assets.md index f0b74ada5..e30052edf 100644 --- a/src/cookbook/transfer-assets.md +++ b/src/cookbook/transfer-assets.md @@ -11,4 +11,33 @@ head: # How to Transfer Assets Between Accounts -TODO \ No newline at end of file +```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(); +} +``` diff --git a/src/cookbook/work-with-store-assets.md b/src/cookbook/work-with-store-assets.md index 487dfee0b..c3fc3cd10 100644 --- a/src/cookbook/work-with-store-assets.md +++ b/src/cookbook/work-with-store-assets.md @@ -11,4 +11,39 @@ head: # How to Work with Store Assets -TODO \ No newline at end of file +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(); +} +``` \ No newline at end of file From bc1a100591b20f6f2c7086d83e440b9351836d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nurzhan=20Sak=C3=A9n?= Date: Wed, 17 Apr 2024 18:56:18 +0400 Subject: [PATCH 29/31] [edit]: edit existing entries to match newer examples, replace some obsolete code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nurzhan Sakén --- src/cookbook/access-metadata.md | 26 ++++--- src/cookbook/burn-assets.md | 24 +++---- src/cookbook/check-status.md | 26 ++++--- src/cookbook/combine-instructions.md | 71 ++++++++++--------- src/cookbook/create-transactions.md | 80 +++++++++------------- src/cookbook/mint-assets.md | 32 +++++---- src/cookbook/register-accounts.md | 19 ++--- src/cookbook/register-asset-definitions.md | 49 ++++++++++--- src/cookbook/register-assets.md | 44 +++++++++--- src/cookbook/work-with-numeric-assets.md | 35 ++++++++-- 10 files changed, 239 insertions(+), 167 deletions(-) diff --git a/src/cookbook/access-metadata.md b/src/cookbook/access-metadata.md index 5f2f77b3a..4ab0c9969 100644 --- a/src/cookbook/access-metadata.md +++ b/src/cookbook/access-metadata.md @@ -11,24 +11,22 @@ head: # How to Access an Object's Metadata -```rust - /* - - Description: - In the Iroha 2 almost all basic objects like Account, Asset, Domain etc. have a Metadata field, - which is a struct that consists of one field with BTreeMap type. - By default the basic objects are created with 0 metadata capacity so if you get empty result, - be sure that metadata has been added into the object. - - The current example describes how to get metadata from an Account. +In the Iroha 2 almost all basic objects like Account, Asset, Domain, etc. +have a Metadata field, which is a struct containing a BTreeMap. +By default the basic objects are created with 0 metadata capacity so if you get empty result, +be sure that metadata has been added into the object. - Precondition: The object has been created with a metadata. +The current example describes how to get metadata from an Account. - */ +Precondition: The object has been created with a metadata. +```rust +fn access_metadata( + iroha: &Client, +) { //Define the target account and make a request to get this account's object let account_id: AccountId = "alice@wonderland".parse().unwrap(); - let account: Account = iroha_client.request(FindAccountById::new(account_id)).unwrap(); + let account: Account = iroha.request(FindAccountById::new(account_id)).unwrap(); //Bind metadata struct to a variable let account_metadata: &Metadata = account.metadata(); @@ -37,5 +35,5 @@ head: for metadata in account_metadata.iter() { println!("{:?}", metadata) } - +} ``` \ No newline at end of file diff --git a/src/cookbook/burn-assets.md b/src/cookbook/burn-assets.md index 218b14c0a..903236c6a 100644 --- a/src/cookbook/burn-assets.md +++ b/src/cookbook/burn-assets.md @@ -11,19 +11,15 @@ head: # How to Burn an Asset -```rust -//Precondition: The asset definition was registered -// First we need to define the asset definition id -let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); - -//Then we need to create an assetId object -//The AssetId is a complex object which consists of asset definition id and account id -let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); +Only numeric assets can be burned. -//Now we need to define the asset quantity regarding to the asset's value type -let asset_quantity: Fixed = Fixed::from_str("1").unwrap(); - -//And finally we need to send the transaction -//This time we will use the BurnExpr object -iroha_client.submit_blocking(BurnExpr::new(asset_quantity, asset_id)).unwrap(); +```rust +fn burn_numeric_asset(iroha: &Client) { + let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let alice = AccountId::from_str("alice@wonderland").unwrap(); + let roses_of_alice: AssetId = AssetId::new(roses, alice); + let quantity: Numeric = numeric!(42); + let burn_roses_of_alice = Burn::asset_numeric(quantity, roses_of_alice); + iroha.submit(burn_roses_of_alice).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/check-status.md b/src/cookbook/check-status.md index eed9c4981..3ce8b7b80 100644 --- a/src/cookbook/check-status.md +++ b/src/cookbook/check-status.md @@ -12,12 +12,22 @@ head: # How to Check Iroha Status ```rust - // To get the status, the Client struct already has a function get_status(), - // so you may just execute it. - // The result message will include a deserialized json object with parameters like: - // Quantity of peers - // Quantity of blocks - // Quantity of accepted and rejected transactions and some more - let status = iroha_client.get_status().unwrap(); - println!("{:?}", status); +fn check_status(iroha: &Client) { + let status = iroha.get_status().unwrap(); + println!("{:#?}", status); +} +``` + +Sample output: + +``` +Status { + peers: 4, + blocks: 5, + txs_accepted: 31, + txs_rejected: 3, + uptime: Uptime(5.937s), + view_changes: 2, + queue_size: 18, +} ``` \ No newline at end of file diff --git a/src/cookbook/combine-instructions.md b/src/cookbook/combine-instructions.md index e10f1e20a..a0a004f09 100644 --- a/src/cookbook/combine-instructions.md +++ b/src/cookbook/combine-instructions.md @@ -11,42 +11,45 @@ head: # How to Combine Iroha Special Instructions -```rust -// Instructions should be unified to a single type 'InstructionExpr' +In order to combine instructions of different types in one collection, +you need some sort of polymorphism. We provide this via enum wrappers +for each instruction type (e.g. RegisterBox, MintBox, and others), +as well as the most general `InstructionBox` type. + +Any instruction can be converted to the needed wrapper if compatible, +no allocations involved (despite what the `*Box` suffix might suggest). - // Register account - let register_account_instruction: InstructionExpr = { - let key_pair = KeyPair::generate().unwrap(); - RegisterExpr::new(Account::new( - AccountId::from_str("roman@wonderland").unwrap(), - vec![key_pair.public_key().clone()], +```rust +fn combine_isi(iroha: &Client) { + let alice = AccountId::from_str("alice@wonderland").unwrap(); + let register_alice = { + let (public_key, _) = KeyPair::random().into_parts(); + Register::account(Account::new( + alice.clone(), + public_key, )) - .into() }; - // Register asset definition - let register_asset_definition_instruction: InstructionExpr = RegisterExpr::new( - AssetDefinition::quantity(AssetDefinitionId::from_str("romancoin#wonderland").unwrap()), - ) - .into(); - // Mint asset - let mint_asset_to_roman: InstructionExpr = MintExpr::new( - 51_u32, - AssetId::from_str("romancoin#wonderland#roman@wonderland").unwrap(), - ) - .into(); - // Transfer asset - let transfer_asset_to_alina: InstructionExpr = TransferExpr::new( - AssetId::from_str("romancoin#wonderland#roman@wonderland").unwrap(), - 21_u32, - AccountId::from_str("alina@wonderland").unwrap(), - ) - .into(); - - // Bind instructions into collection - let instructions = vec![ - register_account_instruction, - register_asset_definition_instruction, - mint_asset_to_roman, - transfer_asset_to_alina, + let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let define_roses = Register::asset_definition( + AssetDefinition::numeric(roses.clone()) + ); + let roses_of_alice = AssetId::new(roses.clone(), alice.clone()); + let mint_roses_for_alice = Mint::asset_numeric( + numeric!(20), + roses_of_alice.clone() + ); + let mouse = AccountId::from_str("mouse@wonderland").unwrap(); + let transfer_roses_from_alice_to_mouse = Transfer::asset_numeric( + roses_of_alice, + numeric!(10), + mouse, + ); + let instructions: [InstructionBox; 4] = [ + register_alice.into(), + define_roses.into(), + mint_roses_for_alice.into(), + transfer_roses_from_alice_to_mouse.into(), ]; + iroha.submit_all(instructions).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/create-transactions.md b/src/cookbook/create-transactions.md index 68d08550f..dab9eaabf 100644 --- a/src/cookbook/create-transactions.md +++ b/src/cookbook/create-transactions.md @@ -12,54 +12,40 @@ head: # How to Create a Transaction ```rust - /* - Define the Iroha 2 client. - Note: - The author uses his custom get_client() function. - To initialize Client with default methods, please look in the Guide section - */ - let iroha_client: Client = get_client(); - // Define an account on behalf of which a transaction will be build - let account_id: AccountId = "alice@wonderland".parse().unwrap(); - // Define the set of instructions (Can be one or many) - let register_account_instruction = { - let key_pair = KeyPair::generate().unwrap(); - RegisterExpr::new(Account::new( - AccountId::from_str("alina@wonderland").unwrap(), - vec![key_pair.public_key().clone()], +fn create_transactions(iroha: &Client) { + // Prepare the instructions you want to execute + let alice = AccountId::from_str("alice@wonderland").unwrap(); + let register_alice = { + let (public_key, _) = KeyPair::random().into_parts(); + Register::account(Account::new( + alice.clone(), + public_key, )) }; - let register_asset_definition_instruction = RegisterExpr::new(AssetDefinition::quantity( - AssetDefinitionId::from_str("wondercoins#wonderland").unwrap(), - )); - let register_asset_id_instruction = RegisterExpr::new(Asset::new( - AssetId::new( - AssetDefinitionId::from_str("wondercoins#wonderland").unwrap(), - AccountId::from_str("alina@wonderland").unwrap(), - ), - 11_u32, - )); - // Bind instruction into collection - let instructions = vec![ - register_account_instruction, - register_asset_definition_instruction, - register_asset_id_instruction, - ]; - /* - Initialize a transaction builder and inserts: - * The transaction owner's account id - * The set of instructions - * The default metadata - */ - let tx_builder = TransactionBuilder::new(account_id.clone()) - .with_instructions(instructions) - .with_metadata(UnlimitedMetadata::default()); - - // Sign the transaction by transaction owner's key pair - let signed_transaction = iroha_client.sign_transaction(tx_builder).unwrap(); + let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let define_roses = Register::asset_definition( + AssetDefinition::numeric(roses.clone()) + ); + let roses_of_alice = AssetId::new(roses.clone(), alice.clone()); + let register_roses_of_alice = Register::asset( + Asset::new(roses_of_alice, numeric!(100)) + ); - // Send the transaction to the Iroha 2 - iroha_client - .submit_transaction(&signed_transaction) - .unwrap(); + // Combine the instructions + let instructions: [InstructionBox; 3] = [ + register_alice.into(), + define_roses.into(), + register_roses_of_alice.into(), + ]; + + // Build a transaction with the prepared instructions and empty metadata + // on behalf of the current account configured with the client + let signed_tx = iroha.build_transaction( + instructions, + UnlimitedMetadata::default() + ); + + // Submit the transaction + iroha.submit_transaction(&signed_tx).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/mint-assets.md b/src/cookbook/mint-assets.md index 6c155af8c..b4ad2c6bf 100644 --- a/src/cookbook/mint-assets.md +++ b/src/cookbook/mint-assets.md @@ -11,18 +11,24 @@ head: # How to Mint an Asset -```rust -//Precondition: The asset definition was registered -// First we need to define the asset definition id -let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); - -//Then we need to create an assetId object -//The AssetId is a complex object which consists of asset definition id and account id -let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); +Only numeric assets can be minted – infinitely, or only once. -//Now we need to define the asset quantity regarding to the asset's value type -let asset_quantity: Fixed = Fixed::from_str("11").unwrap(); - -//And finally we need to send the transaction -iroha_client.submit_blocking(MintExpr::new(asset_quantity, asset_id)).unwrap(); +```rust +fn mint_numeric_asset(iroha: &Client) { + let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let roses_definition = iroha + .request(FindAssetDefinitionById::new(roses.clone())) + .unwrap() + .mintable; + match roses_definition.mintable { + Mintable::Infinitely => println!("This code will succeed indefinitely"), + Mintable::Once => println!("This code will succeed only once"), + Mintable::Not => println!("This code will fail"), + } + let alice = AccountId::from_str("alice@wonderland").unwrap(); + let roses_of_alice: AssetId = AssetId::new(roses, alice); + let quantity: Numeric = numeric!(42); + let mint_roses_of_alice = Mint::asset_numeric(quantity, roses_of_alice); + iroha.submit(mint_roses_of_alice).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/register-accounts.md b/src/cookbook/register-accounts.md index aa31fa48a..cdfa8e9bb 100644 --- a/src/cookbook/register-accounts.md +++ b/src/cookbook/register-accounts.md @@ -12,13 +12,14 @@ head: # How to Register an Account ```rust -//Creating a key pair for a new account -//The key pair must be given to the new account owner -let key_pair = KeyPair::generate().unwrap(); -//Now you can execute public|private keys by using functions of key_pair variable -let public_key = vec![key_pair.public_key().clone()]; -//Creating a NewAccount type -let new_account = Account::new("alex@wonderland".parse()?, public_key); -//And finally submit the transaction -let tx = iroha_client.submit(RegisterExpr::new(new_account))?; +fn register_account(iroha: &Client) { + let alice = AccountId::from_str("alice@wonderland").unwrap(); + let (public_key, _private_key) = KeyPair::random().into_parts(); + // Keep your private key secret, + // and use the public key to create an account + let register_alice = Register::account( + Account::new(alice, public_key) + ); + iroha.submit(register_alice).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/register-asset-definitions.md b/src/cookbook/register-asset-definitions.md index f3ee41050..343950a77 100644 --- a/src/cookbook/register-asset-definitions.md +++ b/src/cookbook/register-asset-definitions.md @@ -12,16 +12,43 @@ head: # How to Register an Asset Definition ```rust -//First we need to create the asset id -let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); +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(); +} +``` -//Then we need to define the asset value type -//There are only 4 asset value types and they are defined in the AssetValueType struct -let asset_value_type: AssetValueType = AssetValueType::Fixed; - -//Then we need to create an asset definition object -let asset_definition = AssetDefinition::new(asset_definition_id, asset_value_type); - -//And finally we need to send the transaction -iroha_client.submit(RegisterExpr::new(asset_definition)).unwrap(); +```rust +fn define_numeric_asset(iroha: &Client) { + let define_roses = Register::asset_definition( + AssetDefinition::new( + "rose#wonderland".parse().unwrap(), + // allow only whole values + AssetValueType::Numeric(NumericSpec::integer()), + ) + ); + let define_coins = Register::asset_definition( + AssetDefinition::new( + "coin#wonderland".parse().unwrap(), + // allow fractional values with two decimal places + AssetValueType::Numeric(NumericSpec::fractional(2)), + ) + ); + let define_gold = Register::asset_definition( + // equivalent to `AssetDefinition::numeric(gold)` + AssetDefinition::new( + "gold#wonderland".parse().unwrap(), + // allow arbitrary numeric values + AssetValueType::Numeric(NumericSpec::unconstrained()), + ) + ); + iroha.submit_all([ + define_roses.into(), + define_coins.into(), + define_gold.into(), + ]).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/register-assets.md b/src/cookbook/register-assets.md index c80ccdab9..20fb03035 100644 --- a/src/cookbook/register-assets.md +++ b/src/cookbook/register-assets.md @@ -12,16 +12,38 @@ head: # How to Register an Asset ```rust -//Precondition: The asset definition was registered -// First we need to define the asset definition id -let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); +fn register_store_asset( + iroha: &Client, +) { + let hat_of_alice = AssetId::from_str("hat##alice@wonderland").unwrap(); + let hat_data = { + // hat has at most 3 keys, each value must fit into 100 bytes + let (data, limits) = (Metadata::new(), MetadataLimits::new(3, 100)); + data.insert_with_limits( + Name::from_str("color").unwrap(), + "yellow".to_owned(), + limits, + ) + .unwrap(); + data + }; + // register a hat as Alice's asset + let register_hat_of_alice = Register::asset( + Asset::new(hat_of_alice, AssetValue::Store(hat_data)) + ); + iroha.submit(register_hat_of_alice).unwrap(); +} +``` -//Then we need to create an assetId object -//The AssetId is a complex object which consists of asset definition id and account id -//And the Asset also is a complex object which consists of asset id and its quantity -let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); -let asset: Asset = Asset::new(asset_id, Fixed::from_str("33").unwrap()); - -//And finally we need to send the transaction -iroha_client.submit_blocking(RegisterExpr::new(asset)).unwrap(); +```rust +fn register_numeric_asset( + iroha: &Client, +) { + let roses_of_alice = AssetId::from_str("rose##alice@wonderland").unwrap(); + // register 123 roses as Alice's asset + let register_roses_of_alice = Register::asset( + Asset::new(roses_of_alice, numeric!(123)) + ); + iroha.submit(register_roses_of_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 e8341673d..823e0829c 100644 --- a/src/cookbook/work-with-numeric-assets.md +++ b/src/cookbook/work-with-numeric-assets.md @@ -22,13 +22,14 @@ fn register_numeric_asset( 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()), + // for the sake of the example, + // allow dividing roses into tenths + AssetValueType::Numeric(NumericSpec::fractional(1)), ) ); 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); + let initial_roses_of_alice = Asset::new(roses_of_alice, Numeric::ZERO); // register zero roses as Alice's asset let register_roses_of_alice = Register::asset(initial_roses_of_alice); iroha.submit_all([ @@ -44,8 +45,9 @@ Minting roses for Alice: fn mint_numeric_asset( iroha: &Client, ) { + // mint twelve and a half roses let mint_roses_for_alice = Mint::asset_numeric( - 42_u32, + numeric!(12.5), "rose##alice@wonderland".parse().unwrap() ); iroha.submit(mint_roses_for_alice).unwrap(); @@ -58,8 +60,9 @@ Burning Alice's roses: fn burn_numeric_asset( iroha: &Client, ) { + // burn three roses let burn_roses_of_alice = Burn::asset_numeric( - 8_u32, + numeric!(3), AssetId::from_str("rose##alice@wonderland").unwrap() ); iroha.submit(burn_roses_of_alice).unwrap(); @@ -75,11 +78,31 @@ fn transfer_numeric_asset( let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); let alice = AccountId::from_str("alice@wonderland").unwrap(); let mouse = AccountId::from_str("mouse@wonderland").unwrap(); + // transfer ten roses and a tenth of a rose let transfer_roses_from_alice_to_mouse = Transfer::asset_numeric( AssetId::new(roses, alice), - 13_u32, + numeric!(10.1), mouse, ); iroha.submit(transfer_roses_from_alice_to_mouse).unwrap(); } +``` + +Check that Alice has a whole number of roses: + +```rust +fn query_numeric_asset( + iroha: &Client, +) { + let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let alice = AccountId::from_str("alice@wonderland").unwrap(); + let roses_of_alice = AssetId::new(roses, alice); + let total_roses_of_alice = iroha + .request(FindAssetQuantityById::new(roses_of_alice)) + .unwrap(); + match NumericSpec::integer().check(total_roses_of_alice) { + Ok(_) => println!("Alice has a whole number of roses"), + Err(_) => println!("Alice has a fractional number of roses"), + } +} ``` \ No newline at end of file From 8de8655ea29cecec546d7a70153ea89c6137b6c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nurzhan=20Sak=C3=A9n?= Date: Thu, 18 Apr 2024 13:24:25 +0400 Subject: [PATCH 30/31] [add]: transfer-group-assets [edit]: update obsolete examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nurzhan Sakén --- src/cookbook/create-transactions.md | 16 ++++---- src/cookbook/register-asset-definitions.md | 8 +--- src/cookbook/register-domains.md | 15 ++++---- src/cookbook/submit-transactions.md | 39 +++++++++----------- src/cookbook/transfer-group-assets.md | 29 ++++++++++++++- src/cookbook/unregister-accounts.md | 16 ++++---- src/cookbook/unregister-asset-definitions.md | 14 +++---- src/cookbook/unregister-assets.md | 17 ++++----- src/cookbook/unregister-domains.md | 11 +++--- 9 files changed, 89 insertions(+), 76 deletions(-) diff --git a/src/cookbook/create-transactions.md b/src/cookbook/create-transactions.md index dab9eaabf..3880d87a6 100644 --- a/src/cookbook/create-transactions.md +++ b/src/cookbook/create-transactions.md @@ -1,5 +1,5 @@ --- -title: "Create transactions | Cookbook" +title: "Create Transactions | Cookbook" head: - - meta - name: description @@ -12,7 +12,7 @@ head: # How to Create a Transaction ```rust -fn create_transactions(iroha: &Client) { +fn create_transaction(iroha: &Client) -> SignedTransaction { // Prepare the instructions you want to execute let alice = AccountId::from_str("alice@wonderland").unwrap(); let register_alice = { @@ -40,12 +40,12 @@ fn create_transactions(iroha: &Client) { // Build a transaction with the prepared instructions and empty metadata // on behalf of the current account configured with the client - let signed_tx = iroha.build_transaction( + iroha.build_transaction( instructions, UnlimitedMetadata::default() - ); - - // Submit the transaction - iroha.submit_transaction(&signed_tx).unwrap(); + ) } -``` \ No newline at end of file +``` + +See [Submit Transactions](submit-transactions.md) to learn how to submit +the resulting `SignedTransaction`. \ No newline at end of file diff --git a/src/cookbook/register-asset-definitions.md b/src/cookbook/register-asset-definitions.md index 343950a77..0bf15d18e 100644 --- a/src/cookbook/register-asset-definitions.md +++ b/src/cookbook/register-asset-definitions.md @@ -38,12 +38,8 @@ fn define_numeric_asset(iroha: &Client) { ) ); let define_gold = Register::asset_definition( - // equivalent to `AssetDefinition::numeric(gold)` - AssetDefinition::new( - "gold#wonderland".parse().unwrap(), - // allow arbitrary numeric values - AssetValueType::Numeric(NumericSpec::unconstrained()), - ) + // allow arbitrary numeric values + AssetDefinition::numeric("gold#wonderland".parse().unwrap()) ); iroha.submit_all([ define_roses.into(), diff --git a/src/cookbook/register-domains.md b/src/cookbook/register-domains.md index 9e8aaa119..957723f7b 100644 --- a/src/cookbook/register-domains.md +++ b/src/cookbook/register-domains.md @@ -12,12 +12,11 @@ head: # How to Register a Domain ```rust - //First we need to define a domain id (name) - let domain_id = DomainId::new("disneyland".parse().unwrap()); - //Then we need to define a new domain object - let domain: NewDomain = Domain::new(domain_id); - //After, define a Register expression for the new domain - let expression = RegisterExpr::new(domain); - //And finally we need to send the transaction - iroha_client.submit_blocking(expression).unwrap(); +fn register_domain(iroha: &Client) { + let wonderland = DomainId::from_str("wonderland").unwrap(); + let register_wonderland = Register::domain( + Domain::new(wonderland) + ); + iroha.submit(register_wonderland).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/submit-transactions.md b/src/cookbook/submit-transactions.md index c4cfb5961..ea6865d86 100644 --- a/src/cookbook/submit-transactions.md +++ b/src/cookbook/submit-transactions.md @@ -11,28 +11,23 @@ head: # How to Submit a Transaction -```rust -//Precondition: the Client variable must be initialized - -//First we need to build an instruction expression that we want to submit -//The instruction expression structures have a self-explanatory name -//and you can easily understand what each of them does. -//As an example: -//* BurnExp - burns asset quantity -//* MintExpr - mints asset quantity -//* RegisterExpr - registers any Registrable object like -//** Account, Asset, Asset definition, Trigger etc. -//As an example we will take the MintExpr - -let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap(); -let asset_id: AssetId = AssetId::new(asset_definition_id, AccountId::from_str("alice@wonderland").unwrap()); -let asset_quantity: Fixed = Fixed::from_str("7").unwrap(); +See [Create Transactions](create-transactions.md) to learn how to create +a `SignedTransaction` used in the examples below. -let some_expression = MintExpr::new(asset_quantity, asset_id); +```rust +fn submit_transaction_do_not_wait_for_approval( + iroha: &Client, + transaction: &SignedTransaction +) { + // If the transaction is rejected, the method panics + iroha.submit_transaction(transaction).unwrap() +} -//The client module in the iroha_client crate has 2 methods for the transaction submission -//* submit() - sends a transaction without waiting for approval -//* submit_blocking() - sends a transaction and waits for approving. -//If the transaction will be rejected, the method will panic -iroha_client.submit_blocking(some_expression).unwrap(); +fn submit_transaction_and_wait_for_approval( + iroha: &Client, + transaction: &SignedTransaction +) { + // If the transaction is rejected, the method panics + iroha.submit_transaction_blocking(transaction).unwrap() +} ``` \ No newline at end of file diff --git a/src/cookbook/transfer-group-assets.md b/src/cookbook/transfer-group-assets.md index 630a0d82a..0d6aa5850 100644 --- a/src/cookbook/transfer-group-assets.md +++ b/src/cookbook/transfer-group-assets.md @@ -11,6 +11,33 @@ head: # How to Transfer a Group of Assets -TODO +Transferring multiple assets atomically involves combining multiple +Transfer instructions in a single transaction. +```rust +fn transfer_group_of_assets(iroha: &Client) { + let alice = "alice@wonderland".parse().unwrap(); + let mouse = "mouse@wonderland".parse().unwrap(); + let transfer_roses_from_alice_to_mouse = Transfer::asset_numeric( + AssetId::new("rose#wonderland".parse().unwrap(), alice.clone()), + numeric!(1), + mouse.clone(), + ); + let transfer_coins_from_alice_to_mouse = Transfer::asset_numeric( + AssetId::new("coin#wonderland".parse().unwrap(), alice.clone()), + numeric!(0.99), + mouse.clone(), + ); + let transfer_hat_from_alice_to_mouse = Transfer::asset_store( + AssetId::new("hat#wonderland".parse().unwrap(), alice), + mouse, + ); + let transfers: [TransferBox; 3] = [ + transfer_roses_from_alice_to_mouse, + transfer_coins_from_alice_to_mouse, + transfer_hat_from_alice_to_mouse, + ]; + iroha.submit_all(transfers).unwrap(); +} +``` \ No newline at end of file diff --git a/src/cookbook/unregister-accounts.md b/src/cookbook/unregister-accounts.md index 8c6cbadac..5f376d50e 100644 --- a/src/cookbook/unregister-accounts.md +++ b/src/cookbook/unregister-accounts.md @@ -11,13 +11,13 @@ head: # How to Unregister Accounts +Only domain owners and accounts with an appropriate permission token +can unregister another account. + ```rust - //Note: - // Only domain owner or account with appropriate permission token can unregister another account - //First we need to define an account id that we want to unregister - let account_id = AccountId::from_str("artem@disneyland").unwrap(); - //Then we need to define an Unregister expression - let expression = UnregisterExpr::new(account_id); - //And finally we need to send the transaction - iroha_client.submit_blocking(expression).unwrap(); +fn unregister_account(iroha: &Client) { + let alice = AccountId::from_str("alice@wonderland").unwrap(); + let unregister_alice = Unregister::account(alice); + iroha.submit(unregister_alice).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/unregister-asset-definitions.md b/src/cookbook/unregister-asset-definitions.md index 91dbcc60b..3abb9541c 100644 --- a/src/cookbook/unregister-asset-definitions.md +++ b/src/cookbook/unregister-asset-definitions.md @@ -12,10 +12,10 @@ head: # How to Unregister an Asset Definition ```rust - //First we need to define an asset definition id that we want to unregister - let asset_definition_id: AssetDefinitionId = AssetDefinitionId::from_str("wondercoins#wonderland").unwrap(); - //Then we need to define an Unregister expression with the asset definition id - let expression: UnregisterExpr = UnregisterExpr::new(asset_definition_id); - //And finally we need to send the transaction - iroha_client.submit_blocking(expression).unwrap(); -``` +fn undefine_asset( + iroha: &Client, +) { + let hats = AssetDefinitionId::from_str("hat#outfit").unwrap(); + iroha.submit(Unregister::asset_definition(hats)).unwrap(); +} +``` \ No newline at end of file diff --git a/src/cookbook/unregister-assets.md b/src/cookbook/unregister-assets.md index 322cccbd9..535ba02ae 100644 --- a/src/cookbook/unregister-assets.md +++ b/src/cookbook/unregister-assets.md @@ -12,14 +12,11 @@ head: # How to Unregister an Asset ```rust - //First we need to define an account id which has an asset that we want to unregister - let account_id = AccountId::from_str("alina@wonderland").unwrap(); - //Then we need to define an asset definition id that we want to unregister - let asset_definition_id: AssetDefinitionId = AssetDefinitionId::from_str("romancoin#wonderland").unwrap(); - //After, define the asset id as a new object that consists of asset definition id and account id - let asset_id: AssetId = AssetId::new(asset_definition_id, account_id); - // Define an Unregister expression with the asset id - let expression: UnregisterExpr = UnregisterExpr::new(asset_id); - //And finally we need to send the transaction - iroha_client.submit_blocking(expression).unwrap() +fn unregister_asset( + iroha: &Client, +) { + let roses_of_alice = AssetId::from_str("rose##alice@wonderland").unwrap(); + let unregister_roses_of_alice = Unregister::asset(roses_of_alice); + iroha.submit(unregister_roses_of_alice).unwrap(); +} ``` \ No newline at end of file diff --git a/src/cookbook/unregister-domains.md b/src/cookbook/unregister-domains.md index a9d5a4da6..7e5e147b4 100644 --- a/src/cookbook/unregister-domains.md +++ b/src/cookbook/unregister-domains.md @@ -12,10 +12,9 @@ head: # How to Unregister a Domain ```rust - //First we need to define a domain id (name) that we want to unregister - let domain_id = DomainId::new("disneyland".parse().unwrap()); - //Then we need to define an Unregister expression for the domain - let expression = UnregisterExpr::new(domain_id); - //And finally we need to send the transaction - iroha_client.submit_blocking(expression).unwrap(); +fn unregister_domain(iroha: &Client) { + let wonderland = DomainId::from_str("wonderland").unwrap(); + let unregister_wonderland = Unregister::domain(wonderland); + iroha.submit(unregister_wonderland).unwrap(); +} ``` \ No newline at end of file From 7145cbb06fbb7dc683a103c66cdbedd5d36eb3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nurzhan=20Sak=C3=A9n?= Date: Tue, 21 May 2024 15:09:45 +0400 Subject: [PATCH 31/31] Address feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nurzhan Sakén --- src/cookbook/access-metadata.md | 2 +- src/cookbook/burn-assets.md | 8 +++--- src/cookbook/combine-instructions.md | 17 +++++------- src/cookbook/create-transactions.md | 13 ++++------ src/cookbook/grant-permissions.md | 12 ++++----- src/cookbook/grant-roles.md | 4 +-- src/cookbook/mint-assets.md | 11 ++++---- src/cookbook/register-accounts.md | 2 +- src/cookbook/register-asset-definitions.md | 11 ++++---- src/cookbook/register-assets.md | 6 ++--- src/cookbook/register-domains.md | 2 +- src/cookbook/register-roles.md | 14 +++++----- src/cookbook/revoke-permissions.md | 8 +++--- src/cookbook/revoke-roles.md | 4 +-- src/cookbook/submit-transactions.md | 10 ++++--- src/cookbook/transfer-assets.md | 12 ++++----- src/cookbook/transfer-group-assets.md | 8 +++--- src/cookbook/unregister-accounts.md | 2 +- src/cookbook/unregister-asset-definitions.md | 2 +- src/cookbook/unregister-assets.md | 2 +- src/cookbook/unregister-domains.md | 2 +- src/cookbook/use-instructions.md | 4 +-- src/cookbook/work-with-non-mintable-assets.md | 26 +++++++++++-------- src/cookbook/work-with-numeric-assets.md | 23 ++++++++-------- src/cookbook/work-with-store-assets.md | 25 ++++++++++++++---- 25 files changed, 123 insertions(+), 107 deletions(-) diff --git a/src/cookbook/access-metadata.md b/src/cookbook/access-metadata.md index 4ab0c9969..50fd15f65 100644 --- a/src/cookbook/access-metadata.md +++ b/src/cookbook/access-metadata.md @@ -29,7 +29,7 @@ fn access_metadata( let account: Account = iroha.request(FindAccountById::new(account_id)).unwrap(); //Bind metadata struct to a variable - let account_metadata: &Metadata = account.metadata(); + let account_metadata = account.metadata(); //Iterate for the metadata in the account's object for metadata in account_metadata.iter() { diff --git a/src/cookbook/burn-assets.md b/src/cookbook/burn-assets.md index 903236c6a..3399c2578 100644 --- a/src/cookbook/burn-assets.md +++ b/src/cookbook/burn-assets.md @@ -15,10 +15,10 @@ Only numeric assets can be burned. ```rust fn burn_numeric_asset(iroha: &Client) { - let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); - let alice = AccountId::from_str("alice@wonderland").unwrap(); - let roses_of_alice: AssetId = AssetId::new(roses, alice); - let quantity: Numeric = numeric!(42); + let roses = "rose#wonderland".parse::().unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); + let roses_of_alice = AssetId::new(roses, alice); + let quantity = numeric!(42); let burn_roses_of_alice = Burn::asset_numeric(quantity, roses_of_alice); iroha.submit(burn_roses_of_alice).unwrap(); } diff --git a/src/cookbook/combine-instructions.md b/src/cookbook/combine-instructions.md index a0a004f09..d6de9a186 100644 --- a/src/cookbook/combine-instructions.md +++ b/src/cookbook/combine-instructions.md @@ -13,7 +13,7 @@ head: In order to combine instructions of different types in one collection, you need some sort of polymorphism. We provide this via enum wrappers -for each instruction type (e.g. RegisterBox, MintBox, and others), +for each instruction type (e.g. `RegisterBox`, `MintBox`, and others), as well as the most general `InstructionBox` type. Any instruction can be converted to the needed wrapper if compatible, @@ -21,15 +21,12 @@ no allocations involved (despite what the `*Box` suffix might suggest). ```rust fn combine_isi(iroha: &Client) { - let alice = AccountId::from_str("alice@wonderland").unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); let register_alice = { - let (public_key, _) = KeyPair::random().into_parts(); - Register::account(Account::new( - alice.clone(), - public_key, - )) + let (public_key, _private_key) = KeyPair::random().into_parts(); + Register::account(Account::new(alice.clone(), public_key)) }; - let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let roses = "rose#wonderland".parse::().unwrap(); let define_roses = Register::asset_definition( AssetDefinition::numeric(roses.clone()) ); @@ -38,13 +35,13 @@ fn combine_isi(iroha: &Client) { numeric!(20), roses_of_alice.clone() ); - let mouse = AccountId::from_str("mouse@wonderland").unwrap(); + let mouse = "mouse@wonderland".parse::().unwrap(); let transfer_roses_from_alice_to_mouse = Transfer::asset_numeric( roses_of_alice, numeric!(10), mouse, ); - let instructions: [InstructionBox; 4] = [ + let instructions: [InstructionBox; _] = [ register_alice.into(), define_roses.into(), mint_roses_for_alice.into(), diff --git a/src/cookbook/create-transactions.md b/src/cookbook/create-transactions.md index 3880d87a6..d3bdf6c57 100644 --- a/src/cookbook/create-transactions.md +++ b/src/cookbook/create-transactions.md @@ -14,15 +14,12 @@ head: ```rust fn create_transaction(iroha: &Client) -> SignedTransaction { // Prepare the instructions you want to execute - let alice = AccountId::from_str("alice@wonderland").unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); let register_alice = { - let (public_key, _) = KeyPair::random().into_parts(); - Register::account(Account::new( - alice.clone(), - public_key, - )) + let (public_key, _private_key) = KeyPair::random().into_parts(); + Register::account(Account::new(alice.clone(), public_key)) }; - let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let roses = "rose#wonderland".parse::().unwrap(); let define_roses = Register::asset_definition( AssetDefinition::numeric(roses.clone()) ); @@ -32,7 +29,7 @@ fn create_transaction(iroha: &Client) -> SignedTransaction { ); // Combine the instructions - let instructions: [InstructionBox; 3] = [ + let instructions: [InstructionBox; _] = [ register_alice.into(), define_roses.into(), register_roses_of_alice.into(), diff --git a/src/cookbook/grant-permissions.md b/src/cookbook/grant-permissions.md index 13d9e1a38..11edaa801 100644 --- a/src/cookbook/grant-permissions.md +++ b/src/cookbook/grant-permissions.md @@ -20,10 +20,10 @@ fn grant_permission_to_account( // Alice will be given permission to unregister the kingdom domain let grant_permission_to_unregister_kingdom = Grant::permission( PermissionToken::new( - "CanUnregisterDomain".parse().unwrap(), - &json!({ "domain_id": "kingdom" }), + "CanUnregisterDomain".parse::().unwrap(), + &serde_json::json!({ "domain_id": "kingdom" }), ), - AccountId::from_str("alice@wonderland").unwrap() + "alice@wonderland".parse::().unwrap() ); iroha.submit(grant_permission_to_unregister_kingdom).unwrap(); } @@ -39,10 +39,10 @@ fn grant_permission_to_role( // will be able to unregister the kingdom domain let grant_permission_to_unregister_kingdom = Grant::role_permission( PermissionToken::new( - "CanUnregisterDomain".parse().unwrap(), - &json!({ "domain_id": "kingdom" }), + "CanUnregisterDomain".parse::().unwrap(), + &serde_json::json!({ "domain_id": "kingdom" }), ), - RoleId::from_str("DOMAIN_DESTROYER").unwrap(), + "DOMAIN_DESTROYER".parse::().unwrap(), ); iroha.submit(grant_permission_to_unregister_kingdom).unwrap(); } diff --git a/src/cookbook/grant-roles.md b/src/cookbook/grant-roles.md index 0d1bc4ab1..3a241bd5b 100644 --- a/src/cookbook/grant-roles.md +++ b/src/cookbook/grant-roles.md @@ -18,8 +18,8 @@ fn grant_role( iroha: &Client, ) { let grant_role = Grant::role( - RoleId::from_str("DOMAIN_DESTROYER"), - AccountId::from_str("alice@wonderland").unwrap() + "DOMAIN_DESTROYER".parse::().unwrap(), + "alice@wonderland".parse::().unwrap() ); iroha.submit(grant_role).unwrap(); } diff --git a/src/cookbook/mint-assets.md b/src/cookbook/mint-assets.md index b4ad2c6bf..b6448aaf3 100644 --- a/src/cookbook/mint-assets.md +++ b/src/cookbook/mint-assets.md @@ -15,19 +15,18 @@ Only numeric assets can be minted – infinitely, or only once. ```rust fn mint_numeric_asset(iroha: &Client) { - let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let roses = "rose#wonderland".parse::().unwrap(); let roses_definition = iroha .request(FindAssetDefinitionById::new(roses.clone())) - .unwrap() - .mintable; + .unwrap(); match roses_definition.mintable { Mintable::Infinitely => println!("This code will succeed indefinitely"), Mintable::Once => println!("This code will succeed only once"), Mintable::Not => println!("This code will fail"), } - let alice = AccountId::from_str("alice@wonderland").unwrap(); - let roses_of_alice: AssetId = AssetId::new(roses, alice); - let quantity: Numeric = numeric!(42); + let alice = "alice@wonderland".parse::().unwrap(); + let roses_of_alice = AssetId::new(roses, alice); + let quantity = numeric!(42); let mint_roses_of_alice = Mint::asset_numeric(quantity, roses_of_alice); iroha.submit(mint_roses_of_alice).unwrap(); } diff --git a/src/cookbook/register-accounts.md b/src/cookbook/register-accounts.md index cdfa8e9bb..4d37a89ff 100644 --- a/src/cookbook/register-accounts.md +++ b/src/cookbook/register-accounts.md @@ -13,7 +13,7 @@ head: ```rust fn register_account(iroha: &Client) { - let alice = AccountId::from_str("alice@wonderland").unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); let (public_key, _private_key) = KeyPair::random().into_parts(); // Keep your private key secret, // and use the public key to create an account diff --git a/src/cookbook/register-asset-definitions.md b/src/cookbook/register-asset-definitions.md index 0bf15d18e..e07985f2e 100644 --- a/src/cookbook/register-asset-definitions.md +++ b/src/cookbook/register-asset-definitions.md @@ -15,7 +15,7 @@ head: fn define_store_asset( iroha: &Client, ) { - let hats = AssetDefinitionId::from_str("hat#outfit").unwrap(); + let hats = "hat#outfit".parse::().unwrap(); let hats_as_a_concept = AssetDefinition::store(hats); iroha.submit(Register::asset_definition(hats_as_a_concept)).unwrap(); } @@ -41,10 +41,11 @@ fn define_numeric_asset(iroha: &Client) { // allow arbitrary numeric values AssetDefinition::numeric("gold#wonderland".parse().unwrap()) ); - iroha.submit_all([ - define_roses.into(), - define_coins.into(), + let instructions: [RegisterBox; _] = [ + define_roses.into(), + define_coins.into(), define_gold.into(), - ]).unwrap(); + ]; + iroha.submit_all(instructions).unwrap(); } ``` \ No newline at end of file diff --git a/src/cookbook/register-assets.md b/src/cookbook/register-assets.md index 20fb03035..16f06f915 100644 --- a/src/cookbook/register-assets.md +++ b/src/cookbook/register-assets.md @@ -15,12 +15,12 @@ head: fn register_store_asset( iroha: &Client, ) { - let hat_of_alice = AssetId::from_str("hat##alice@wonderland").unwrap(); + let hat_of_alice = "hat##alice@wonderland".parse::().unwrap(); let hat_data = { // hat has at most 3 keys, each value must fit into 100 bytes let (data, limits) = (Metadata::new(), MetadataLimits::new(3, 100)); data.insert_with_limits( - Name::from_str("color").unwrap(), + "color".parse::().unwrap(), "yellow".to_owned(), limits, ) @@ -39,7 +39,7 @@ fn register_store_asset( fn register_numeric_asset( iroha: &Client, ) { - let roses_of_alice = AssetId::from_str("rose##alice@wonderland").unwrap(); + let roses_of_alice = "rose##alice@wonderland".parse::().unwrap(); // register 123 roses as Alice's asset let register_roses_of_alice = Register::asset( Asset::new(roses_of_alice, numeric!(123)) diff --git a/src/cookbook/register-domains.md b/src/cookbook/register-domains.md index 957723f7b..e3e30a452 100644 --- a/src/cookbook/register-domains.md +++ b/src/cookbook/register-domains.md @@ -13,7 +13,7 @@ head: ```rust fn register_domain(iroha: &Client) { - let wonderland = DomainId::from_str("wonderland").unwrap(); + let wonderland = "wonderland".parse::().unwrap(); let register_wonderland = Register::domain( Domain::new(wonderland) ); diff --git a/src/cookbook/register-roles.md b/src/cookbook/register-roles.md index f25cf627b..239de27af 100644 --- a/src/cookbook/register-roles.md +++ b/src/cookbook/register-roles.md @@ -17,8 +17,8 @@ The minimal case is an empty role (without any permission tokens): fn register_new_role( iroha: &Client ) { - let role_id = RoleId::from_str("MY_EMPTY_ROLE").unwrap(); - let role = iroha_data_model::role::Role::new(role_id); + let role_id = "MY_EMPTY_ROLE".parse::().unwrap(); + let role = Role::new(role_id); let register_role = Register::role(role); iroha.submit(register_role).unwrap(); } @@ -34,15 +34,15 @@ see [Define Custom Permission Tokens](define-custom-permission-tokens.md). fn register_new_role_with_permission( iroha: &Client, ) { - let roses_of_alice = AssetId::from_str("rose##alice@wonderland").unwrap(); - let roses_of_mouse = AssetId::from_str("rose##mouse@wonderland").unwrap(); + let roses_of_alice = "rose##alice@wonderland".parse::().unwrap(); + let roses_of_mouse = "rose##mouse@wonderland".parse::().unwrap(); let can_burn_roses_of_alice = PermissionToken::new( - "CanBurnUserAsset".parse().unwrap(), - &json!({ "asset_id": roses_of_alice }), + "CanBurnUserAsset".parse::().unwrap(), + &serde_json::json!({ "asset_id": roses_of_alice }), ); let can_burn_roses_of_mouse = PermissionToken::new( "CanBurnUserAsset".parse().unwrap(), - &json!({ "asset_id": roses_of_mouse }), + &serde_json::json!({ "asset_id": roses_of_mouse }), ); let rose_burner = Role::new("ROSE_BURNER".parse().unwrap()) .add_permission(can_burn_roses_of_alice) diff --git a/src/cookbook/revoke-permissions.md b/src/cookbook/revoke-permissions.md index 0d41e2d08..e46f70f89 100644 --- a/src/cookbook/revoke-permissions.md +++ b/src/cookbook/revoke-permissions.md @@ -18,9 +18,9 @@ fn revoke_permission_from_account( let revoke_permission_to_unregister_kingdom = Revoke::permission( PermissionToken::new( "CanUnregisterDomain".parse().unwrap(), - &json!({ "domain_id": "kingdom" }), + &serde_json::json!({ "domain_id": "kingdom" }), ), - AccountId::from_str("alice@wonderland").unwrap() + "alice@wonderland".parse::().unwrap() ); iroha.submit(revoke_permission_to_unregister_kingdom).unwrap(); } @@ -33,9 +33,9 @@ fn revoke_permission_from_role( let revoke_permission_to_unregister_kingdom = Revoke::role_permission( PermissionToken::new( "CanUnregisterDomain".parse().unwrap(), - &json!({ "domain_id": "kingdom" }), + &serde_json::json!({ "domain_id": "kingdom" }), ), - RoleId::from_str("DOMAIN_DESTROYER").unwrap(), + "DOMAIN_DESTROYER".parse::().unwrap(), ); iroha.submit(revoke_permission_to_unregister_kingdom).unwrap(); } diff --git a/src/cookbook/revoke-roles.md b/src/cookbook/revoke-roles.md index 56fbcce15..aeece0d7a 100644 --- a/src/cookbook/revoke-roles.md +++ b/src/cookbook/revoke-roles.md @@ -17,8 +17,8 @@ fn revoke_role( ) { // given that Alice has the role, revoke it let revoke_role = Revoke::role( - RoleId::from_str("DOMAIN_DESTROYER"), - AccountId::from_str("alice@wonderland").unwrap() + "DOMAIN_DESTROYER".parse::().unwrap(), + "alice@wonderland".parse::().unwrap() ); iroha.submit(revoke_role).unwrap(); } diff --git a/src/cookbook/submit-transactions.md b/src/cookbook/submit-transactions.md index ea6865d86..6fc0cadae 100644 --- a/src/cookbook/submit-transactions.md +++ b/src/cookbook/submit-transactions.md @@ -19,15 +19,17 @@ fn submit_transaction_do_not_wait_for_approval( iroha: &Client, transaction: &SignedTransaction ) { - // If the transaction is rejected, the method panics - iroha.submit_transaction(transaction).unwrap() + // panics if the transaction is invalid (cannot be submitted) + let _hash = iroha.submit_transaction(transaction).unwrap(); + // transaction may or may not have been committed or rejected } fn submit_transaction_and_wait_for_approval( iroha: &Client, transaction: &SignedTransaction ) { - // If the transaction is rejected, the method panics - iroha.submit_transaction_blocking(transaction).unwrap() + // panics if the transaction is invalid or rejected + let _hash = iroha.submit_transaction_blocking(transaction).unwrap(); + // transaction has been committed } ``` \ No newline at end of file diff --git a/src/cookbook/transfer-assets.md b/src/cookbook/transfer-assets.md index e30052edf..73efcf359 100644 --- a/src/cookbook/transfer-assets.md +++ b/src/cookbook/transfer-assets.md @@ -15,9 +15,9 @@ head: 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 roses = "rose#wonderland".parse::().unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); + let mouse = "mouse@wonderland".parse::().unwrap(); let transfer_roses_from_alice_to_mouse = Transfer::asset_numeric( AssetId::new(roses, alice), 13_u32, @@ -31,9 +31,9 @@ fn transfer_numeric_asset( 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 hats = "hat#outfit".parse::().unwrap(); + let alice = "alice@outfit".parse::().unwrap(); + let mouse = "mouse@outfit".parse::().unwrap(); let transfer_hat_from_alice_to_mouse = Transfer::asset_store( AssetId::new(hats, alice), mouse, diff --git a/src/cookbook/transfer-group-assets.md b/src/cookbook/transfer-group-assets.md index 0d6aa5850..7294b496f 100644 --- a/src/cookbook/transfer-group-assets.md +++ b/src/cookbook/transfer-group-assets.md @@ -32,10 +32,10 @@ fn transfer_group_of_assets(iroha: &Client) { AssetId::new("hat#wonderland".parse().unwrap(), alice), mouse, ); - let transfers: [TransferBox; 3] = [ - transfer_roses_from_alice_to_mouse, - transfer_coins_from_alice_to_mouse, - transfer_hat_from_alice_to_mouse, + let transfers: [TransferBox; _] = [ + transfer_roses_from_alice_to_mouse.into(), + transfer_coins_from_alice_to_mouse.into(), + transfer_hat_from_alice_to_mouse.into(), ]; iroha.submit_all(transfers).unwrap(); } diff --git a/src/cookbook/unregister-accounts.md b/src/cookbook/unregister-accounts.md index 5f376d50e..a98cb8108 100644 --- a/src/cookbook/unregister-accounts.md +++ b/src/cookbook/unregister-accounts.md @@ -16,7 +16,7 @@ can unregister another account. ```rust fn unregister_account(iroha: &Client) { - let alice = AccountId::from_str("alice@wonderland").unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); let unregister_alice = Unregister::account(alice); iroha.submit(unregister_alice).unwrap(); } diff --git a/src/cookbook/unregister-asset-definitions.md b/src/cookbook/unregister-asset-definitions.md index 3abb9541c..9df88f900 100644 --- a/src/cookbook/unregister-asset-definitions.md +++ b/src/cookbook/unregister-asset-definitions.md @@ -15,7 +15,7 @@ head: fn undefine_asset( iroha: &Client, ) { - let hats = AssetDefinitionId::from_str("hat#outfit").unwrap(); + let hats = "hat#outfit".parse::().unwrap(); iroha.submit(Unregister::asset_definition(hats)).unwrap(); } ``` \ No newline at end of file diff --git a/src/cookbook/unregister-assets.md b/src/cookbook/unregister-assets.md index 535ba02ae..df55f963a 100644 --- a/src/cookbook/unregister-assets.md +++ b/src/cookbook/unregister-assets.md @@ -15,7 +15,7 @@ head: fn unregister_asset( iroha: &Client, ) { - let roses_of_alice = AssetId::from_str("rose##alice@wonderland").unwrap(); + let roses_of_alice = "rose##alice@wonderland".parse::().unwrap(); let unregister_roses_of_alice = Unregister::asset(roses_of_alice); iroha.submit(unregister_roses_of_alice).unwrap(); } diff --git a/src/cookbook/unregister-domains.md b/src/cookbook/unregister-domains.md index 7e5e147b4..2d5587beb 100644 --- a/src/cookbook/unregister-domains.md +++ b/src/cookbook/unregister-domains.md @@ -13,7 +13,7 @@ head: ```rust fn unregister_domain(iroha: &Client) { - let wonderland = DomainId::from_str("wonderland").unwrap(); + let wonderland = "wonderland".parse::().unwrap(); let unregister_wonderland = Unregister::domain(wonderland); iroha.submit(unregister_wonderland).unwrap(); } diff --git a/src/cookbook/use-instructions.md b/src/cookbook/use-instructions.md index 1518868fc..dc9b4d5da 100644 --- a/src/cookbook/use-instructions.md +++ b/src/cookbook/use-instructions.md @@ -17,8 +17,8 @@ Building and submitting an instruction: fn use_instruction( iroha: &Client, ) { - let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); - let alice = AccountId::from_str("alice@wonderland").unwrap(); + let roses = "rose#wonderland".parse::().unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); // build an instruction let mint_roses_for_alice = Mint::asset_numeric( 42_u32, diff --git a/src/cookbook/work-with-non-mintable-assets.md b/src/cookbook/work-with-non-mintable-assets.md index 7df0dd79d..d686c6278 100644 --- a/src/cookbook/work-with-non-mintable-assets.md +++ b/src/cookbook/work-with-non-mintable-assets.md @@ -15,7 +15,9 @@ head: fn register_non_mintable_asset( iroha: &Client, ) { - let magical_keys = AssetDefinitionId::from_str("magical_key#wonderland").unwrap(); + let magical_keys = "magical_key#wonderland" + .parse::() + .unwrap(); // register keys as an asset definition let register_keys_as_a_concept = Register::asset_definition( AssetDefinition::new( @@ -26,14 +28,15 @@ fn register_non_mintable_asset( 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), + AssetId::new(magical_keys, 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(); + let instructions: [RegisterBox; _] = [ + register_keys_as_a_concept.into(), + register_keys_of_alice.into(), + ]; + iroha.submit_all(instructions).unwrap(); } ``` @@ -49,10 +52,11 @@ fn mint_non_mintable_asset( ); 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(); + let instructions: [InstructionBox; _] = [ + register_keys_as_a_concept.into(), + register_keys_of_alice.into(), + mint_keys_for_alice.into(), + ]; + iroha.submit_all(instructions).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 823e0829c..a1461bedf 100644 --- a/src/cookbook/work-with-numeric-assets.md +++ b/src/cookbook/work-with-numeric-assets.md @@ -17,7 +17,7 @@ Registering Alice's roses: fn register_numeric_asset( iroha: &Client, ) { - let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); + let roses = "rose#wonderland".parse::().unwrap(); // register roses as an asset definition let register_roses_as_a_concept = Register::asset_definition( AssetDefinition::new( @@ -32,10 +32,11 @@ fn register_numeric_asset( let initial_roses_of_alice = Asset::new(roses_of_alice, Numeric::ZERO); // 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(); + let instructions: [RegisterBox; _] = [ + register_roses_as_a_concept.into(), + register_roses_of_alice.into(), + ]; + iroha.submit_all(instructions).unwrap(); } ``` @@ -63,7 +64,7 @@ fn burn_numeric_asset( // burn three roses let burn_roses_of_alice = Burn::asset_numeric( numeric!(3), - AssetId::from_str("rose##alice@wonderland").unwrap() + "rose##alice@wonderland".parse::().unwrap() ); iroha.submit(burn_roses_of_alice).unwrap(); } @@ -75,9 +76,9 @@ Transferring Alice's roses to Mouse: 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 roses = "rose#wonderland".parse::().unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); + let mouse = "mouse@wonderland".parse::().unwrap(); // transfer ten roses and a tenth of a rose let transfer_roses_from_alice_to_mouse = Transfer::asset_numeric( AssetId::new(roses, alice), @@ -94,8 +95,8 @@ Check that Alice has a whole number of roses: fn query_numeric_asset( iroha: &Client, ) { - let roses = AssetDefinitionId::from_str("rose#wonderland").unwrap(); - let alice = AccountId::from_str("alice@wonderland").unwrap(); + let roses = "rose#wonderland".parse::().unwrap(); + let alice = "alice@wonderland".parse::().unwrap(); let roses_of_alice = AssetId::new(roses, alice); let total_roses_of_alice = iroha .request(FindAssetQuantityById::new(roses_of_alice)) diff --git a/src/cookbook/work-with-store-assets.md b/src/cookbook/work-with-store-assets.md index c3fc3cd10..e26ff6c4a 100644 --- a/src/cookbook/work-with-store-assets.md +++ b/src/cookbook/work-with-store-assets.md @@ -18,7 +18,7 @@ arbitrary key-value tables. fn define_store_asset( iroha: &Client, ) { - let hats = AssetDefinitionId::from_str("hat#outfit").unwrap(); + let hats = "hat#outfit".parse::().unwrap(); let hats_as_a_concept = AssetDefinition::store(hats); iroha.submit(Register::asset_definition(hats_as_a_concept)).unwrap(); } @@ -28,8 +28,8 @@ fn define_store_asset( 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(); + let hat_of_alice = "hat##alice@outfit".parse::().unwrap(); + let color = "color".parse::().unwrap(); iroha.submit(SetKeyValue::asset( hat_of_alice, color, @@ -38,12 +38,27 @@ fn set_key_value_pair( } ``` +```rust +fn read_key_value_pair( + iroha: &Client, +) { + let hat_of_alice = "hat##alice@outfit".parse::().unwrap(); + let color = "color".parse::().unwrap(); + // assume the color has been set to "red" + let red = iroha.request(FindAssetKeyValueByIdAndKey::new( + hat_of_alice, + color + )).unwrap(); + assert_eq!(red, MetadataValueBox::String("red".to_owned())); +} +``` + ```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(); + let hat_of_alice = "hat##alice@outfit".parse::().unwrap(); + let color = "color".parse::().unwrap(); iroha.submit(RemoveKeyValue::asset(hats, color)).unwrap(); } ``` \ No newline at end of file