def create_account(): account_name = request.args.get("account_name") if is_string_nil_or_empty(account_name): return json_response(False, "Please send your account name", {}, 404) else: response = MessageToDict(IrohaHelper.get_account(account_name)) # in case we don't have account_name on network if "errorResponse" in response and response["errorResponse"][ "reason"] == "NO_ACCOUNT": user_kp = iroha.ModelCrypto().generateKeypair() is_success = IrohaHelper.create_account_with_100_coin( account_name, user_kp) if is_success: account_id = account_name + "@moneyforward" IrohaHelper.grant_can_transfer_my_assets_permission_to_admin( account_id, user_kp) return json_response(is_success, "Created Account Successfully", \ {"public_key": user_kp.publicKey().hex(), "balance": 100}, 200) else: return json_response(is_success, "Can't create account", {}, 501) else: response = IrohaHelper.get_account_asset(account_name) assets_response = MessageToDict(response)["accountAssetsResponse"] balance = assets_response["accountAssets"][-1]["balance"] return json_response(True, "", {"balance": balance}, 200)
def add_peer_tx(): peer_key = iroha.ModelCrypto().generateKeypair() tx = iroha.ModelTransactionBuilder() \ .createdTime(commons.now()) \ .creatorAccountId(alice['id']) \ .addPeer('192.168.10.10:50541', peer_key.publicKey()) \ .build() return iroha.ModelProtoTransaction(tx) \ .signAndAddSignature(alice['key']).finish()
def add_signatory_tx(): extra_key = iroha.ModelCrypto().generateKeypair() tx = iroha.ModelTransactionBuilder() \ .createdTime(commons.now()) \ .creatorAccountId(alice['id']) \ .addSignatory(alice['id'], extra_key.publicKey()) \ .build() return iroha.ModelProtoTransaction(tx) \ .signAndAddSignature(alice['key']).finish()
def grant_can_remove_my_signatory_tx(): extra_key = iroha.ModelCrypto().generateKeypair() tx = iroha.ModelTransactionBuilder() \ .createdTime(commons.now()) \ .creatorAccountId(alice['id']) \ .grantPermission(bob['id'], iroha.Grantable_kRemoveMySignatory) \ .addSignatory(alice['id'], extra_key.publicKey()) \ .build() return iroha.ModelProtoTransaction(tx) \ .signAndAddSignature(alice['key']).finish()
def genesis_tx(): test_permissions = iroha.RolePermissionSet([iroha.Role_kSetQuorum]) extra_key = iroha.ModelCrypto().generateKeypair() tx = iroha.ModelTransactionBuilder() \ .createdTime(commons.now()) \ .creatorAccountId(admin['id']) \ .addPeer('0.0.0.0:50541', admin['key'].publicKey()) \ .createRole('admin_role', commons.all_permissions()) \ .createRole('test_role', test_permissions) \ .createDomain('test', 'test_role') \ .createAccount('admin', 'test', admin['key'].publicKey()) \ .createAccount('alice', 'test', alice['key'].publicKey()) \ .appendRole(admin['id'], 'admin_role') \ .addSignatory(alice['id'], extra_key.publicKey()) \ .build() return iroha.ModelProtoTransaction(tx) \ .signAndAddSignature(admin['key']).finish()
def setUp(self): self.keys = iroha.ModelCrypto().generateKeypair() self.builder = self.base()
import sys sys.path.insert(0, 'build/shared_model/bindings') import iroha import transaction_pb2 import endpoint_pb2 import endpoint_pb2_grpc import queries_pb2 import grpc import time tx_builder = iroha.ModelTransactionBuilder() query_builder = iroha.ModelQueryBuilder() 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) user1_kp = crypto.generateKeypair() def current_time(): return int(round(time.time() * 1000)) creator = "admin@test" query_counter = 1
def setUp(self): self.keys = iroha.ModelCrypto().generateKeypair()
def new_user(user_id): key = iroha.ModelCrypto().generateKeypair() if user_id.lower().startswith('admin'): print('K{}'.format(key.privateKey().hex())) return {'id': user_id, 'key': key}