Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Add platform independent Python lib and Batch example #1761

Merged
merged 6 commits into from
Oct 18, 2018

Conversation

igor-egorov
Copy link
Contributor

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

@igor-egorov igor-egorov added needs-review pr awaits review from maintainers SDK Anything related to the client bindings labels Oct 4, 2018
Copy link
Contributor

@lebdron lebdron left a 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.


class Iroha(object):
"""
Collection of fabric methods for transactions and queries creation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fabric -> factory

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fabric -> factory

"""
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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

:param transaction: protobuf Transaction
:return: None
"""
channel = grpc.insecure_channel(self.address)
Copy link
Contributor

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'
Copy link
Contributor

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]>
l4l
l4l previously requested changes Oct 8, 2018
example/python/batch-example.py Outdated Show resolved Hide resolved
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
Copy link
Contributor

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/batch-example.py Show resolved Hide resolved
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible -> example?

Copy link
Contributor Author

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!

example/python/batch-example.py Show resolved Hide resolved
example/python/irohalib.py Show resolved Hide resolved
:return: a proto command

Usage example:
cmd = Iroha.command('CreateDomain', domain_id='test', default_role='user')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

example/python/irohalib.py Show resolved Hide resolved
Signed-off-by: Igor Egorov <[email protected]>
@igor-egorov igor-egorov dismissed l4l’s stale review October 15, 2018 08:26

requested changes were applied

@igor-egorov igor-egorov requested a review from l4l October 15, 2018 08:26
Igor Egorov added 2 commits October 15, 2018 12:31
@l4l l4l removed the needs-review pr awaits review from maintainers label Oct 15, 2018
Signed-off-by: Kitsu <[email protected]>
@igor-egorov
Copy link
Contributor Author

CI fail was caused by a separate bug that is fixed in hyperledger-iroha/iroha#1793

@igor-egorov igor-egorov merged commit 1cfac65 into dev Oct 18, 2018
@l4l l4l deleted the feature/more-python-examples branch October 18, 2018 16:05
bakhtin pushed a commit that referenced this pull request Nov 2, 2018
* Add platform independent Python Iroha Lib and batch example

Signed-off-by: Igor Egorov <[email protected]>
Signed-off-by: Kitsu <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
SDK Anything related to the client bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants