Skip to content

Commit

Permalink
Develop rebase with main branch (#83)
Browse files Browse the repository at this point in the history
* Add ordering sequence to params in query (#73)

* Add ordering sequence to params

Makes possible to add ordering sequence to Query. Fixes #72

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* Add :param ordering_sequence:

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* Fix wrong example for :param ordering_sequence:

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* fix wrong ordering message construction in query

After more documentation I got to the way to construct to ordering object

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* remove redundant OR clause to manage ordering_sequence

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* Correction after review

Signed-off-by: Grzegorz Bazior <bazior@agh.edu.pl>

* Migrated from main branch also protobuf files

Signed-off-by: G.Bazior <bazior@agh.edu.pl>

* Updated proto files with script download-schema.py

Signed-off-by: G.Bazior <bazior@agh.edu.pl>

* Updated generated from protobuf python files (script compile-proto.py)

Signed-off-by: G.Bazior <bazior@agh.edu.pl>

Co-authored-by: Rafik NACCACHE <rafik@fekr.tech>
  • Loading branch information
baziorek and turbopape committed Feb 17, 2022
1 parent 68f4255 commit d5e8cf4
Show file tree
Hide file tree
Showing 23 changed files with 2,914 additions and 946 deletions.
23 changes: 23 additions & 0 deletions SECURITY.md
@@ -0,0 +1,23 @@
# Hyperledger Security Policy

## Reporting a Security Bug

If you think you have discovered a security issue in any of the Hyperledger
projects, we'd love to hear from you. We will take all security bugs
seriously and if confirmed upon investigation we will patch it within a
reasonable amount of time and release a public security bulletin discussing
the impact and credit the discoverer.

There are two ways to report a security bug. The easiest is to email a
description of the flaw and any related information (e.g. reproduction
steps, version) to
[security at hyperledger dot org](mailto:security@hyperledger.org).

The other way is to file a confidential security bug in our
[JIRA bug tracking system](https://jira.hyperledger.org).
Be sure to set the “Security Level” to “Security issue”.

The process by which the Hyperledger Security Team handles security bugs
is documented further in our
[Defect Response](https://wiki.hyperledger.org/display/HYP/Defect+Response)
page on our [wiki](https://wiki.hyperledger.org).
7 changes: 4 additions & 3 deletions dev-requirements.txt
@@ -1,3 +1,4 @@
protobuf==3.5.1
grpcio_tools==1.11.0
six==1.12.0
PyNaCl==1.4.0
protobuf==3.12.2
grpcio_tools==1.21.1
six==1.12.0
90 changes: 90 additions & 0 deletions examples/tls-example.py
@@ -0,0 +1,90 @@
#!/usr/bin/env python3
#
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

import os
import binascii
from iroha import IrohaCrypto
from iroha import Iroha, IrohaGrpc
import sys

if sys.version_info[0] < 3:
raise Exception('Python 3 or a more recent version is required.')

print("""
This example works only through a TLS connection, you must first configure torii_tls_params
https://iroha.readthedocs.io/en/main/configure/torii-tls.html
""")

IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', 'localhost')
IROHA_TLS_PORT = os.getenv('IROHA_PORT', '55552')
ADMIN_ACCOUNT_ID = os.getenv('ADMIN_ACCOUNT_ID', 'admin@test')
ADMIN_PRIVATE_KEY = os.getenv(
'ADMIN_PRIVATE_KEY', 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70')
iroha = Iroha(ADMIN_ACCOUNT_ID)
certificate = """-----BEGIN CERTIFICATE-----
MIIDUDCCAjgCCQCsHEs/sUtihTANBgkqhkiG9w0BAQsFADBqMQswCQYDVQQGEwJy
dTELMAkGA1UECAwCZGYxCzAJBgNVBAcMAmRmMQswCQYDVQQKDAJkZjELMAkGA1UE
CwwCZGYxEjAQBgNVBAMMCWxvY2FsaG9zdDETMBEGCSqGSIb3DQEJARYEbWFpbDAe
Fw0yMDExMTkxOTM1MzVaFw0yMDEyMTkxOTM1MzVaMGoxCzAJBgNVBAYTAnJ1MQsw
CQYDVQQIDAJkZjELMAkGA1UEBwwCZGYxCzAJBgNVBAoMAmRmMQswCQYDVQQLDAJk
ZjESMBAGA1UEAwwJbG9jYWxob3N0MRMwEQYJKoZIhvcNAQkBFgRtYWlsMIIBIjAN
BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu/vS/zgCIJOfpP58OFX+4EDByDnQ
42MSQtgw1+nDQjc2thasHrNI5pFrWIRtVYUIIPhhPUEJJFW034awLWiggiZHWO9a
gocO95AxjaborxRVavOLUIX17HnEiU6lb3lyfwq9t2bpluT+ooRM2ymDCl/NCsdS
nvRomFvCcfpbVu0rc0hBVsLGrg+Hr/+mS88MIL6sU95Suawj8f8A0QoMN0zxQjto
EyXVWN46vurxXMYFDbdRejwg1ba+DFajm6Dcl1nIq/u7dpG6mmDMzFVrwmYh6wYf
XpT4eW9KNe9EEIh+loF7ohg+GE2YGXW/9f8UuQfsgyTHHj+uS0jdiD3PDwIDAQAB
MA0GCSqGSIb3DQEBCwUAA4IBAQBQxyCYOA47Uzxc3qdYwnmqQ6oug73heh5qMbjC
dJ9eY+BKZgd97kI+msX1ha9PKQaITONeZxE2907m2RQckCFXYFPxumQ/O8YiN3Vb
UXy3otCPKlF+RoPEFH2UJiiIakbgE796FB/TskO1pEvdrE9i1GiCV2503VUzP9IC
QRFMvWvZ4lk5Jw7rthL3xsdz3BDESULfN4mXQthZ98H+v7z7WaARzdOauFLwJ4rV
XNlyBGw14951Xm/MoKQZdZlsG80xDucBf/VJrKLkQW60CWmXhit0GiZu79LzYMuN
QAGWtoyyaJ7TmCOUR9MpH/2bna429WOhg9/hgMDGdJ9bG1Bm
-----END CERTIFICATE-----
"""
byte_certificate = bytes(certificate, 'utf-8')
net = IrohaGrpc('{}:{}'.format(IROHA_HOST_ADDR, IROHA_TLS_PORT), secure=True, root_certificates=byte_certificate)


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


@trace
def send_transaction_and_print_status(transaction):
hex_hash = binascii.hexlify(IrohaCrypto.hash(transaction))
print('Transaction hash = {}, creator = {}'.format(
hex_hash, transaction.payload.reduced_payload.creator_account_id))
net.send_tx(transaction)
for status in net.tx_status_stream(transaction):
print(status)


@trace
def add_coin_to_admin():
"""
Add 1000.00 units of 'coin#domain' to 'admin@test'
"""
tx = iroha.transaction([
iroha.command('AddAssetQuantity',
asset_id='coin#domain', amount='1000.00')
])
IrohaCrypto.sign_transaction(tx, ADMIN_PRIVATE_KEY)
send_transaction_and_print_status(tx)


add_coin_to_admin()
27 changes: 22 additions & 5 deletions examples/tx-example.py
Expand Up @@ -4,23 +4,33 @@
# SPDX-License-Identifier: Apache-2.0
#


# Here are Iroha dependencies.
# Python library generally consists of 3 parts:
# Iroha, IrohaCrypto and IrohaGrpc which we need to import:
import os
import binascii
from iroha import IrohaCrypto
from iroha import Iroha, IrohaGrpc

# The following line is actually about the permissions
# you might be using for the transaction.
# You can find all the permissions here:
# https://iroha.readthedocs.io/en/main/develop/api/permissions.html
from iroha.primitive_pb2 import can_set_my_account_detail
import sys

if sys.version_info[0] < 3:
raise Exception('Python 3 or a more recent version is required.')


# Here is the information about the environment and admin account information:
IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', '127.0.0.1')
IROHA_PORT = os.getenv('IROHA_PORT', '50051')
ADMIN_ACCOUNT_ID = os.getenv('ADMIN_ACCOUNT_ID', 'admin@test')
ADMIN_PRIVATE_KEY = os.getenv(
'ADMIN_PRIVATE_KEY', 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70')

# Here we will create user keys
user_private_key = IrohaCrypto.private_key()
user_public_key = IrohaCrypto.derive_public_key(user_private_key)
iroha = Iroha(ADMIN_ACCOUNT_ID)
Expand All @@ -41,7 +51,7 @@ def tracer(*args, **kwargs):

return tracer


# Let's start defining the commands:
@trace
def send_transaction_and_print_status(transaction):
hex_hash = binascii.hexlify(IrohaCrypto.hash(transaction))
Expand All @@ -51,7 +61,11 @@ def send_transaction_and_print_status(transaction):
for status in net.tx_status_stream(transaction):
print(status)


# For example, below we define a transaction made of 2 commands:
# CreateDomain and CreateAsset.
# Each of Iroha commands has its own set of parameters and there are many commands.
# You can check out all of them here:
# https://iroha.readthedocs.io/en/main/develop/api/commands.html
@trace
def create_domain_and_asset():
"""
Expand All @@ -62,10 +76,13 @@ def create_domain_and_asset():
iroha.command('CreateAsset', asset_name='coin',
domain_id='domain', precision=2)
]
# And sign the transaction using the keys from earlier:
tx = IrohaCrypto.sign_transaction(
iroha.transaction(commands), ADMIN_PRIVATE_KEY)
send_transaction_and_print_status(tx)

# You can define queries
# (https://iroha.readthedocs.io/en/main/develop/api/queries.html)
# the same way.

@trace
def add_coin_to_admin():
Expand Down Expand Up @@ -173,7 +190,7 @@ def get_userone_details():
data = response.account_detail_response
print('Account id = {}, details = {}'.format('userone@domain', data.detail))


# Let's run the commands defined previously:
create_domain_and_asset()
add_coin_to_admin()
create_account_userone()
Expand Down
62 changes: 34 additions & 28 deletions iroha/block_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d5e8cf4

Please sign in to comment.