44# SPDX-License-Identifier: Apache-2.0
55#
66
7+
8+ # Here are Iroha dependencies.
9+ # Python library generally consists of 3 parts:
10+ # Iroha, IrohaCrypto and IrohaGrpc which we need to import:
711import os
812import binascii
913from iroha import IrohaCrypto
1014from iroha import Iroha , IrohaGrpc
15+
16+ # The following line is actually about the permissions
17+ # you might be using for the transaction.
18+ # You can find all the permissions here:
19+ # https://iroha.readthedocs.io/en/main/develop/api/permissions.html
1120from iroha .primitive_pb2 import can_set_my_account_detail
1221import sys
1322
1423if sys .version_info [0 ] < 3 :
1524 raise Exception ('Python 3 or a more recent version is required.' )
1625
17-
26+ # Here is the information about the environment and admin account information:
1827IROHA_HOST_ADDR = os .getenv ('IROHA_HOST_ADDR' , '127.0.0.1' )
1928IROHA_PORT = os .getenv ('IROHA_PORT' , '50051' )
2029ADMIN_ACCOUNT_ID = os .getenv ('ADMIN_ACCOUNT_ID' , 'admin@test' )
2130ADMIN_PRIVATE_KEY = os .getenv (
2231 'ADMIN_PRIVATE_KEY' , 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70' )
2332
33+ # Here we will create user keys
2434user_private_key = IrohaCrypto .private_key ()
2535user_public_key = IrohaCrypto .derive_public_key (user_private_key )
2636iroha = Iroha (ADMIN_ACCOUNT_ID )
@@ -41,7 +51,7 @@ def tracer(*args, **kwargs):
4151
4252 return tracer
4353
44-
54+ # Let's start defining the commands:
4555@trace
4656def send_transaction_and_print_status (transaction ):
4757 hex_hash = binascii .hexlify (IrohaCrypto .hash (transaction ))
@@ -51,21 +61,28 @@ def send_transaction_and_print_status(transaction):
5161 for status in net .tx_status_stream (transaction ):
5262 print (status )
5363
54-
64+ # For example, below we define a transaction made of 2 commands:
65+ # CreateDomain and CreateAsset.
66+ # Each of Iroha commands has its own set of parameters and there are many commands.
67+ # You can check out all of them here:
68+ # https://iroha.readthedocs.io/en/main/develop/api/commands.html
5569@trace
5670def create_domain_and_asset ():
5771 """
58- Creates domain 'domain' and asset 'coin#domain' with precision 2
72+ Create domain 'domain' and asset 'coin#domain' with precision 2
5973 """
6074 commands = [
6175 iroha .command ('CreateDomain' , domain_id = 'domain' , default_role = 'user' ),
6276 iroha .command ('CreateAsset' , asset_name = 'coin' ,
6377 domain_id = 'domain' , precision = 2 )
6478 ]
79+ # And sign the transaction using the keys from earlier:
6580 tx = IrohaCrypto .sign_transaction (
6681 iroha .transaction (commands ), ADMIN_PRIVATE_KEY )
6782 send_transaction_and_print_status (tx )
68-
83+ # You can define queries
84+ # (https://iroha.readthedocs.io/en/main/develop/api/queries.html)
85+ # the same way.
6986
7087@trace
7188def add_coin_to_admin ():
@@ -173,7 +190,7 @@ def get_userone_details():
173190 data = response .account_detail_response
174191 print ('Account id = {}, details = {}' .format ('userone@domain' , data .detail ))
175192
176-
193+ # Let's run the commands defined previously:
177194create_domain_and_asset ()
178195add_coin_to_admin ()
179196create_account_userone ()
0 commit comments