-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add posible to set custom path to certificate
- Loading branch information
Showing
2 changed files
with
104 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/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/master/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) | ||
cert = "-----BEGIN CERTIFICATE-----" \ | ||
"MIIDiDCCAnACCQDp6UiqpNfRazANBgkqhkiG9w0BAQsFADCBhTELMAkGA1UEBhMC" \ | ||
"cnUxDjAMBgNVBAgMBWlyb2hhMRIwEAYDVQQHDAlpbm5vcG9saXMxEjAQBgNVBAoM" \ | ||
"CXNvcmFtaXRzdTENMAsGA1UECwwEc29yYTESMBAGA1UEAwwJbG9jYWxob3N0MRsw" \ | ||
"GQYJKoZIhvcNAQkBFgxtYWlsQ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etfGEIo+DlniGbXyeFXFrWRJotITjG7UVc6U/SB6Pg=" \ | ||
"-----END CERTIFICATE-----" | ||
byte_cert = bytes(cert, 'utf-8') | ||
net = IrohaGrpc('{}:{}'.format(IROHA_HOST_ADDR, IROHA_TLS_PORT), secure=None, root_certificates=byte_cert) | ||
|
||
|
||
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() |
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