-
Notifications
You must be signed in to change notification settings - Fork 296
Add platform independent Python lib and Batch example #1761
Conversation
Signed-off-by: Igor Egorov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall! Consider python 2 support and block query in next pull requests.
example/python/irohalib.py
Outdated
|
||
class Iroha(object): | ||
""" | ||
Collection of fabric methods for transactions and queries creation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fabric -> factory
example/python/irohalib.py
Outdated
def transaction(self, commands, quorum=1, creator_account=None, created_time=None): | ||
""" | ||
Creates a protobuf transaction with specified set of entities | ||
:param commands: list of commands generated via command fabric method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fabric -> factory
example/python/irohalib.py
Outdated
""" | ||
Creates a protobuf transaction with specified set of entities | ||
:param commands: list of commands generated via command fabric method | ||
:param quorum: required amount of signatures, 1 is default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amount -> number, because signature is a countable noun
def command(name, **kwargs): | ||
""" | ||
Creates a protobuf command to be inserted into a transaction | ||
:param name: CamelCased name of command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these consistent in command and query please, CamelCased or CamelCase
""" | ||
Send a transaction to Iroha | ||
:param transaction: protobuf Transaction | ||
:return: None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to return gRPC status to check whether the transaction was successfully sent. Same for other methods
example/python/irohalib.py
Outdated
:param transaction: protobuf Transaction | ||
:return: None | ||
""" | ||
channel = grpc.insecure_channel(self.address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like channel and stub can be made class fields
'TransferAsset', src_account_id='bob@test', dest_account_id='alice@test', asset_id='dogecoin#test', | ||
amount='2' | ||
)], | ||
creator_account='bob@test' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe leave a comment to clarify that alice does not know about bob's quorum.
Signed-off-by: Igor Egorov <[email protected]>
example/python/batch-example.py
Outdated
creator_account='bob@test' | ||
# we intentionally omit here bob's quorum, since alice is the originator of the exchange and in general case | ||
# alice does not know bob's quorum. | ||
# bob knowing onw quorum in case of accept should sign the tx using all the number of missing keys at once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onw
- looks like a typo
example/python/irohalib.md
Outdated
@@ -0,0 +1,30 @@ | |||
# Python Iroha Lib Description | |||
|
|||
irohalib.py is a possible implemetation of a platform-independent way of interaction with Iroha network via Python 3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possible -> example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible is ok here and perfectly reflects the initial intention.
Thanks for commenting anyway - I have found a type in "implementation" word!
:return: a proto command | ||
|
||
Usage example: | ||
cmd = Iroha.command('CreateDomain', domain_id='test', default_role='user') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Igor Egorov <[email protected]>
…amples Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Kitsu <[email protected]>
CI fail was caused by a separate bug that is fixed in hyperledger-iroha/iroha#1793 |
* Add platform independent Python Iroha Lib and batch example Signed-off-by: Igor Egorov <[email protected]> Signed-off-by: Kitsu <[email protected]>
Signed-off-by: Igor Egorov [email protected]
Description of the Change
Introduced SWIG-free Iroha lib for Python.
Batches usage example included.
Benefits
A little step towards user-friendly Iroha.
Possible Drawbacks
None ?
Usage Examples or Tests
Read irohalib.md and do the preparation steps
Run
python3 batch-example.py