Skip to content

Commit c0a53ef

Browse files
authored
added comments for iroha docs (#68)
Signed-off-by: Sara <[email protected]>
1 parent 3968c39 commit c0a53ef

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

examples/tx-example.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,33 @@
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:
711
import os
812
import binascii
913
from iroha import IrohaCrypto
1014
from 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
1120
from iroha.primitive_pb2 import can_set_my_account_detail
1221
import sys
1322

1423
if 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:
1827
IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', '127.0.0.1')
1928
IROHA_PORT = os.getenv('IROHA_PORT', '50051')
2029
ADMIN_ACCOUNT_ID = os.getenv('ADMIN_ACCOUNT_ID', 'admin@test')
2130
ADMIN_PRIVATE_KEY = os.getenv(
2231
'ADMIN_PRIVATE_KEY', 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70')
2332

33+
# Here we will create user keys
2434
user_private_key = IrohaCrypto.private_key()
2535
user_public_key = IrohaCrypto.derive_public_key(user_private_key)
2636
iroha = 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
4656
def 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
5670
def 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
7188
def 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:
177194
create_domain_and_asset()
178195
add_coin_to_admin()
179196
create_account_userone()

0 commit comments

Comments
 (0)