This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 296
Update tx-example.py and blocks-query.py #1844
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e76b20
Refactored tx-example.py (uses new python irohalib)
e067504
Add blocks query support to new python irohalib
bf18497
Update blocks-query.py to use new python irohalib
01b909d
Improve query signer in python irohalib
6dcda0c
Move python version guards to the top of files
5edef9e
Fix a typo
65f0ba9
Format py files with autopep8
a0826df
Put python version guards to the top of files after autopep8
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,46 @@ | ||
import sys | ||
sys.path.insert(0, 'build/shared_model/bindings') | ||
import iroha | ||
# | ||
# Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
import endpoint_pb2_grpc | ||
import queries_pb2 | ||
import grpc | ||
import time | ||
import sys | ||
|
||
if sys.version_info[0] < 3: | ||
raise Exception('Python 3 or a more recent version is required.') | ||
|
||
blocks_query_builder = iroha.ModelBlocksQueryBuilder() | ||
crypto = iroha.ModelCrypto() | ||
|
||
admin_priv = open("../[email protected]", "r").read() | ||
admin_pub = open("../[email protected]", "r").read() | ||
key_pair = crypto.convertFromExisting(admin_pub, admin_priv) | ||
from irohalib import IrohaCrypto | ||
from irohalib import Iroha, IrohaGrpc | ||
|
||
creator = "admin@test" | ||
current_time = int(round(time.time() * 1000)) - 10**5 | ||
|
||
def get_blocks(): | ||
query = blocks_query_builder.creatorAccountId(creator)\ | ||
.createdTime(current_time)\ | ||
.queryCounter(1) \ | ||
.build() | ||
admin_private_key = open('../[email protected]').read() | ||
iroha = Iroha('admin@test') | ||
net = IrohaGrpc() | ||
|
||
query_blob = iroha.ModelProtoBlocksQuery(query).signAndAddSignature(key_pair).finish().blob() | ||
proto_query = queries_pb2.BlocksQuery() | ||
|
||
if sys.version_info[0] == 2: | ||
tmp = ''.join(map(chr, query_blob)) | ||
else: | ||
tmp = bytes(query_blob) | ||
def trace(func): | ||
""" | ||
A decorator for tracing methods' begin/end execution points | ||
""" | ||
def tracer(*args, **kwargs): | ||
name = func.__name__ | ||
print('\tEntering "{}"'.format(name)) | ||
result = func(*args, **kwargs) | ||
print('\tLeaving "{}"'.format(name)) | ||
return result | ||
return tracer | ||
|
||
proto_query.ParseFromString(tmp) | ||
|
||
channel = grpc.insecure_channel('127.0.0.1:50051') | ||
query_stub = endpoint_pb2_grpc.QueryServiceStub(channel) | ||
query_response = query_stub.FetchCommits(proto_query) | ||
@trace | ||
def get_blocks(): | ||
""" | ||
Subscribe to blocks stream from the network | ||
:return: | ||
""" | ||
query = iroha.blocks_query() | ||
IrohaCrypto.sign_query(query, admin_private_key) | ||
for block in net.send_blocks_stream_query(query): | ||
print('The next block arrived:', block) | ||
|
||
for block in query_response: | ||
print("block:") | ||
print(block) | ||
|
||
get_blocks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
May be just
creator_account=self.creator_account, created_time=self.now()
? Lines 228-231 could be removed after that.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.
Unfortunately, that won't work, since self is not defined at the moment of evaluation.
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.
Python was definitely overrated by me.