Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Update main branch from develop branch #120

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions .jenkinsci/linux-build-wheels.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
def doPythonWheels() {
version = sh(script: 'git describe --tags \$(git rev-list --tags --max-count=1) || true', returnStdout: true).trim()
checkTag = sh(script: 'git describe --tags --exact-match ${GIT_COMMIT}', returnStatus: true)
repo = "master"
if (!checkTag) {
if (checkTag != 0) {
version += ".dev" + env.BUILD_NUMBER
repo = "develop"
}

sh(script: "sed -i.bak 's/{{ PYPI_VERSION }}/${version}/g' setup.py;")
Expand All @@ -18,17 +16,25 @@ def doPythonWheels() {
}

def publishWheels() {
checkTag = sh(script: 'git describe --tags --exact-match ${GIT_COMMIT}', returnStatus: true)
withCredentials([usernamePassword(credentialsId: 'ci_nexus', passwordVariable: 'CI_NEXUS_PASSWORD', usernameVariable: 'CI_NEXUS_USERNAME')]) {
sh(script: "cd wheelhouse && find . -type f -name \"iroha*.whl\" -exec curl -u ${CI_NEXUS_USERNAME}:${CI_NEXUS_PASSWORD} --upload-file {} https://nexus.iroha.tech/repository/artifacts/iroha-python/${repo}/{} \\;")
sh(script: "cd wheelhouse && find . -type f -name \"iroha*.whl\" -exec echo 'https://nexus.iroha.tech/service/rest/repository/browse/artifacts/iroha-python/${repo}/{} \\;")
repo = "release"
checkTag = sh(script: 'git describe --tags --exact-match ${GIT_COMMIT}', returnStatus: true)
version = sh(script: 'git describe --tags \$(git rev-list --tags --max-count=1) || true', returnStdout: true).trim()
if (checkTag != 0) {
version += ".dev" + env.BUILD_NUMBER
repo = "develop"
}
if (checkTag) {
iC = docker.image('quay.io/pypa/manylinux1_x86_64')
iC.inside("") {
sh(script: '/opt/python/cp35-cp35m/bin/pip install twine', returnStdout: true)
sh(script: "cd wheelhouse && find . -type f -name \"iroha*.whl\" -exec echo 'https://nexus.iroha.tech/service/rest/repository/browse/artifacts/iroha-python/latest.whl \\;")
sh "/opt/python/cp35-cp35m/bin/twine upload --skip-existing -u ${ci_pypi_username} -p ${ci_pypi_password} --repository-url https://test.pypi.org/legacy/ wheelhouse/iroha*.whl"
withCredentials([usernamePassword(credentialsId: 'ci_nexus', passwordVariable: 'CI_NEXUS_PASSWORD', usernameVariable: 'CI_NEXUS_USERNAME'), usernamePassword(credentialsId: 'ci_iroha_pypi', passwordVariable: 'CI_PYPI_PASSWORD', usernameVariable: 'CI_PYPI_USERNAME')]) {
sh(script: "cd wheelhouse && find . -type f -name \"iroha*.whl\" -exec curl -u ${CI_NEXUS_USERNAME}:${CI_NEXUS_PASSWORD} --upload-file {} https://nexus.iroha.tech/repository/artifacts/iroha-python/${repo}/{} \\;")
sh(script: "cd wheelhouse && find . -type f -name \"iroha*.whl\" -exec echo 'Wheel available at https://nexus.iroha.tech/service/rest/repository/browse/artifacts/iroha-python/${repo}/{}' \\;")

if (checkTag == 0) {
iC = docker.image('quay.io/pypa/manylinux1_x86_64')
iC.inside("") {
sh(script: '/opt/python/cp35-cp35m/bin/pip install twine', returnStdout: true)
sh(script: "cd wheelhouse && find . -type f -name \"iroha*.whl\" -exec curl -u ${CI_NEXUS_USERNAME}:${CI_NEXUS_PASSWORD} --upload-file {} https://nexus.iroha.tech/repository/artifacts/iroha-python/latest.whl \\;")
sh(script: "cd wheelhouse && find . -type f -name \"iroha*.whl\" -exec echo 'Latest release available at https://nexus.iroha.tech/service/rest/repository/browse/artifacts/iroha-python/latest.whl' \\;")
sh "/opt/python/cp35-cp35m/bin/twine upload --skip-existing -u ${CI_PYPI_USERNAME} -p ${CI_PYPI_PASSWORD} wheelhouse/iroha*.whl"
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ pipeline {
}
}
}
post {
cleanup {
cleanWs()
}
}
}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

This is a source repository for HL Iroha Python library.

Currently, latest HL Iroha rc5 release (`hyperledger/iroha:latest` Docker image) is supported.
Currently, latest [HL Iroha release 1.5](https://github.com/hyperledger/iroha/releases) is supported. It can be ussed with one of official docker images:
- `hyperledger/iroha:latest`
- `hyperledger/iroha-burrow:latest` with Hyperledger-Burrow support (smart contracts).

The library works in Python 3 environment (Python 2 is not supported now).
The library works in Python 3 environment (Python 2 is not supported).

### Installation

Expand Down Expand Up @@ -45,3 +47,5 @@ Please explore [examples](examples) directory for more usage examples.
All the library methods have docstrings in its source [iroha.py](iroha/iroha.py).

*The links above are broken outside the [hyperledger/iroha-python](https://github.com/hyperledger/iroha-python) GitHub repository.*

If you are interested in different HL Iroha client libraries you can check our [Wiki](https://wiki.hyperledger.org/display/iroha/Hyperledger+Iroha).
23 changes: 23 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
container_name: iroha-${SUBNET}
depends_on:
- some-postgres
restart: always
tty: true
environment:
- KEY=keys/node0
Expand Down
121 changes: 121 additions & 0 deletions examples/add-syncing-peer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""
This example demonstrates how to add new peer, when new peer is syncing node.
Details about how to add new peer to the network are here:
https://iroha.readthedocs.io/en/develop/maintenance/add_peer.html
"""

import os
import sys
from functools import wraps
from iroha import primitive_pb2, IrohaCrypto, binascii, IrohaGrpc, Iroha
import grpc # grpc.RpcError
import inspect # inspect.stack(0)
from utilities.errorCodes2Hr import get_proper_functions_for_commands


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


ADMIN_ACCOUNT_ID = os.getenv('ADMIN_ACCOUNT_ID', 'admin@test')
ADMIN_PRIVATE_KEY = os.getenv(
'ADMIN_PRIVATE_KEY', 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70')

iroha_admin = Iroha(ADMIN_ACCOUNT_ID)


IROHA_HOST_ADDR = os.getenv('IROHA_HOST_ADDR', 'localhost')
IROHA_PORT = os.getenv('IROHA_PORT', '50051')

NEW_PEER_PUBLIC_KEY = os.getenv(
'NEW_PEER_PUBLIC_KEY', 'edfa0f05d019c0a0dd6ca491e0c2e78d1ef4148ffa10ffc72f48a0fd6af08e5b')
NEW_PEER_ADDRESS = os.getenv('NEW_PEER_ADDRESS', 'localhost')
NEW_PEER_IROHA_PORT = os.getenv('NEW_PEER_IROHA_PORT', '50050')
NEW_PEER_FULL_ADDRESS = f'{NEW_PEER_ADDRESS}:{NEW_PEER_IROHA_PORT}'

net = IrohaGrpc(f'{IROHA_HOST_ADDR}:{IROHA_PORT}')
net_new_peer = IrohaGrpc(NEW_PEER_FULL_ADDRESS)


def trace(func):
"""
A decorator for tracing methods' begin/end execution points
"""
@wraps(func)
def tracer(*args, **kwargs):
name = func.__name__
stack_size = int(len(inspect.stack(0)) / 2) # @wraps(func) is also increasing the size
indent = stack_size*'\t'
print(f'{indent}> Entering "{name}": args: {args}')
result = func(*args, **kwargs)
print(f'{indent}< Leaving "{name}"')
return result

return tracer


@trace
def add_peers(iroha_connection, peer_address: str, peer_public_key: str):
peer = primitive_pb2.Peer(address=peer_address, peer_key=peer_public_key, syncing_peer=True)
tx = iroha_connection.transaction([
iroha_connection.command('AddPeer', peer=peer)
])
IrohaCrypto.sign_transaction(tx, ADMIN_PRIVATE_KEY)
send_transaction_and_print_status(tx)


@trace
def send_transaction_and_print_status(transaction):
hex_hash = binascii.hexlify(IrohaCrypto.hash(transaction))
creator_id = transaction.payload.reduced_payload.creator_account_id
commands = get_commands_from_tx(transaction)
print(f'Transaction "{commands}",'
f' hash = {hex_hash}, creator = {creator_id}')
net.send_tx(transaction)
for i, status in enumerate(net.tx_status_stream(transaction)):
status_name, status_code, error_code = status
print(f"{i}: status_name={status_name}, status_code={status_code}, "
f"error_code={error_code}")
if status_name in ('STATEFUL_VALIDATION_FAILED', 'STATELESS_VALIDATION_FAILED', 'REJECTED'):
error_code_hr = get_proper_functions_for_commands(commands)(error_code)
raise RuntimeError(f"{status_name} failed on tx: "
f"{transaction} due to reason {error_code}: "
f"{error_code_hr}")


def get_commands_from_tx(transaction):
commands_from_tx = []
for command in transaction.payload.reduced_payload.__getattribute__("commands"):
listed_fields = command.ListFields()
commands_from_tx.append(listed_fields[0][0].name)
return commands_from_tx


@trace
def print_peers(text: str, net_to_query: IrohaGrpc):
print('-------', text, '-------')
query = iroha_admin.query('GetPeers')
IrohaCrypto.sign_query(query, ADMIN_PRIVATE_KEY)
response = net_to_query.send_query(query)
peers_response = response.peers_response.peers
for i, p in enumerate(peers_response):
print(i, p)


if __name__ == '__main__':
try:
print(f'!!!New peer in address {NEW_PEER_FULL_ADDRESS} should work now! '
f'It not the script {sys.argv[0]} would fail!!!')
print_peers('Peers before adding new one', net)
add_peers(iroha_connection=iroha_admin, peer_address=NEW_PEER_FULL_ADDRESS,
peer_public_key=NEW_PEER_PUBLIC_KEY)
print_peers('Peers after adding the new one - query to old peer', net)
print_peers('Peers after adding the new one - query to new peer', net_new_peer)
except grpc.RpcError as rpc_error:
if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
print(f'[E] Iroha is not running in address: '
f'{IROHA_HOST_ADDR}:{IROHA_PORT}!')
else:
print(e)
except RuntimeError as e:
print(e)
Loading