Exemplo n.º 1
0
def get_all_details(iroha, account_id, private_key):
    """
    Consult all details of the node
    :param iroha: (Iroha(name@domain)) Address for connecting to a domain
    :param account_id: (name@domain) Id of the user in the domain
    :param private_key: (str) Private key of the user
    :return: data: (json) solicited details of the user

    Usage example:
    get_detail_from_generator(Iroha('david@federated'),IrohaGrpc('127.0.0.1'), 'david@federated', 'key')

    Return example:
    {
        "nodeA@domain":{
            "Age":"35",
            "Name":"Quetzacoatl"
        },
        "nodeB@domain":{
            "Location":"35.3333535,-45.2141556464",
            "Status":"valid"
        },
        "nodeA@domainB":{
            "FederatingParam":"35.242553",
            "Loop":"3"
        }
    }
    """
    query = iroha.query('GetAccountDetail',
                        account_id=account_id)
    IrohaCrypto.sign_query(query, private_key)

    response = iroha_config.network.send_query(query)
    data = response.account_detail_response
    print('Account id = {}, details = {}'.format(account_id, data.detail))
    return data.detail
Exemplo n.º 2
0
def get_balance(iroha, account_id, private_key):
    """
    Get the balance of the account
    :param iroha: (Iroha('name@domain')) Address for connecting to a domain
    :param account_id: (name@domain) Id of the user in the domain
    :param private_key: (str) Private key of the user
    :return: data: (array) asset id and assets quantity

    Usage example:
    get_balance(Iroha('david@federated'), IrohaGrpc('127.0.0.1'), 'david@federated', 'key')

    Return example:
    [asset_id: "fedcoin#federated"
    account_id: "generator@federated"
    balance: "1000"
    ]
    """
    query = iroha.query('GetAccountAssets',
                        account_id=account_id)
    IrohaCrypto.sign_query(query, private_key)

    response = iroha_config.network.send_query(query)
    data = response.account_assets_response.account_assets
    for asset in data:
        print('Asset id = {}, balance = {}'.format(asset.asset_id, asset.balance))
    return data
Exemplo n.º 3
0
def get_all_details_from_generator(iroha, account_id, private_key, generator_id):
    """
    Consult all the details generated by some node
    :param iroha: (Iroha(name@domain)) Address for connecting to a domain
    :param account_id: (name@domain) Id of the user in the domain
    :param private_key: (str) Private key of the user
    :param generator_id: (name@domain) Id of the user who create de detail
    :return: data: (json) solicited details of the user

    Usage example:
    get_detail_from_generator(Iroha('david@federated'),IrohaGrpc('127.0.0.1'), 'david@federated', 'key',
                              'david@federated')

    Return example:
    {
       "nodeA@domain":{
            "Age":"35",
            "Name":"Quetzacolatl"
        }
    }
    """

    query = iroha.query('GetAccountDetail',
                        account_id=account_id,
                        writer=generator_id)
    IrohaCrypto.sign_query(query, private_key)

    response = iroha_config.network.send_query(query)
    data = response.account_detail_response
    print('Account id = {}, details = {}'.format(account_id, data.detail))
    return data.detail
def account_transactions_query():
    query = iroha.query('GetAccountTransactions',
                        creator_account=alice['id'],
                        account_id=admin['id'],
                        page_size=10)
    IrohaCrypto.sign_query(query, alice['key'])
    return query
Exemplo n.º 5
0
Arquivo: user.py Projeto: LiTrans/BSMD
    def get_balance(self, private_key):
        """
        Get the balance of my account. Use the private key of the user to get his current balance. The function will
        return a dictionary with the id of the asset, the account id  and the balance.

        :Example:
        >>> import json
        >>> x = { "age": 30, "city": "New York" }
        >>> account_information = json.dumps(x)
        >>> user = User('private_key', 'My Name', 'My domain', '123.456.789', account_information)
        >>> balance = user.get_balance('private_key')
        >>> print(balance)
        {asset_id: "fedcoin#federated",
        account_id: "generator@federated",
        balance: "1000"}

        :param str private_key: key to sign the transaction
        :return: A a dictionary with the id of the asset, the account id  and the balance
        :rtype: dict

        """
        account_id = self.name + '@' + self.domain.name
        iroha = Iroha(account_id)
        query = iroha.query('GetAccountAssets',
                            account_id=account_id)
        IrohaCrypto.sign_query(query, private_key)

        response = self.network.send_query(query)
        data = response.account_assets_response.account_assets
        for asset in data:
            print('Asset id = {}, balance = {}'.format(asset.asset_id, asset.balance))
        return data
Exemplo n.º 6
0
def block_listener(host):
    iroha_api = iroha.Iroha("admin@test")
    net = IrohaGrpc(host)
    query = iroha_api.blocks_query()
    ic.sign_query(query, ADMIN_PRIVATE_KEY)
    print("Listeting blocks")
    for block in net.send_blocks_stream_query(query):
        BLOCKS.add(block.block_response.block.block_v1.payload.height)
        hashes = block.block_response.block.block_v1.payload.rejected_transactions_hashes
        txs = block.block_response.block.block_v1.payload.transactions
        for tx in txs:
            hashes.append(ascii_hash(tx))

        for hash in hashes:
            if hash not in TXS.keys():
                continue
            start_time = TXS[hash]
            COMMITTED.add(hash)
            del TXS[hash]
            total_time = int((time.time() - start_time) * 1000)
            try:
                events.request_success.fire(request_type="grpc",
                                            name='send_tx_wait',
                                            response_time=total_time,
                                            response_length=0,
                                            tx_hash=hash,
                                            sent=start_time,
                                            committed=time.time())
            except Exception as e:
                print(e)
Exemplo n.º 7
0
def get_block(height):
    """
    Get the balance of the account
    :param iroha: (Iroha('name@domain')) Address for connecting to a domain
    :param network: (IrohaGrpc('IP address')) Physical address of one node running the BSMD
    :param account_id: (name@domain) Id of the user in the domain
    :param private_key: (str) Private key of the user
    :return: data: (array) asset id and assets quantity

    Usage example:
    get_balance(Iroha('david@federated'), IrohaGrpc('127.0.0.1'), 'david@federated', 'key')

    Return example:
    [asset_id: "fedcoin#federated"
    account_id: "generator@federated"
    balance: "1000"
    ]
    """
    iroha_config.iroha.blocks_query()
    query = iroha_config.iroha.query('GetBlock',
                        height=height)
    IrohaCrypto.sign_query(query, iroha_config.admin_private_key)

    block = iroha_config.network.send_query(query)
    print(block)
    return block
Exemplo n.º 8
0
def get_all_details_from_generator(domain, name, private_key, generator_domain,
                                   generator_name):
    """
    Consult all the details generated by some node
    :param domain: (str) name of the domain
    :param name: (str) name of the node
    :param private_key: (str) Private key of the user
    :param generator_domain: (str) domain of the user who create de detail
    :param generator_name: (str) name of the user who create de detail
    :return: data: (json) solicited details of the user

    Usage example:
    get_detail_from_generator('vehicle', 'Ford Fiesta', key, 'individual', 'david' )

    Return example:
    {
       "nodeA@domain":{
            "Age":"35",
            "Name":"Quetzacolatl"
        }
    }
    """
    account_id = name + '@' + domain
    generator_id = generator_name + '@' + generator_domain
    iroha = Iroha(account_id)
    query = iroha.query('GetAccountDetail',
                        account_id=account_id,
                        writer=generator_id)
    IrohaCrypto.sign_query(query, private_key)

    response = iroha_config.NETWORK.send_query(query)
    data = response.account_detail_response
    print('Account id = {}, details = {}'.format(account_id, data.detail))
    return data.detail
Exemplo n.º 9
0
def create_asset(asset=LEDGER_ASSET, precision=2):
    '''
    Creates a new asset if it does not yet exist.
    '''
    # build the GetAssetInfo query
    qry = iroha.query('GetAssetInfo', asset_id=asset)
    IrohaCrypto.sign_query(qry, admin_private_key)
    status = net.send_query(qry)
    if len(status.error_response.message
           ) != 0:  # probably not the safest check
        # create the asset
        ast = asset.split('#')
        cmd = [
            iroha.command('CreateAsset',
                          asset_name=ast[0],
                          domain_id=ast[1],
                          precision=precision)
        ]
        tx = iroha.transaction(cmd)
        IrohaCrypto.sign_transaction(tx, admin_private_key)
        net.send_tx(tx)
        return [s for s in net.tx_status_stream(tx)]
    else:
        print('Asset {} already exists'.format(asset))
        return [['ASSET_ALREADY_EXISTS']]  # format hack for response parsing
Exemplo n.º 10
0
def get_engine_receipts_address(tx_hash: str):
    query = iroha.query("GetEngineReceipts", tx_hash=tx_hash)
    IrohaCrypto.sign_query(query, ADMIN_PRIVATE_KEY)
    response = net.send_query(query)
    contract_add = response.engine_receipts_response.engine_receipts[
        0].contract_address
    return contract_add
Exemplo n.º 11
0
def get_iroha_user_info(userid):
    '''
    Queries Iroha blockchain for info about userid.
    '''
    qry = iroha.query('GetAccount', account_id=userid)
    IrohaCrypto.sign_query(qry, admin_private_key)
    return net.send_query(qry)
Exemplo n.º 12
0
def put_item():
    item = request.args["address"]
    insured_total = request.args["insured_total"]
    query = iroha.query('GetAccountDetail', account_id=admin_account)
    IrohaCrypto.sign_query(query, admin_private_key)
    response = net.send_query(query)
    data = response.account_detail_response
    all_items = {}
    try:
        all_items = json.loads(str(data)[9:-2].replace("\\",
                                                       ""))[admin_account]
    except:
        pass
    if item in all_items.keys():
        abort(409, 'Item is already insured')
    commands = [
        iroha.command('SetAccountDetail',
                      account_id=admin_account,
                      key=item,
                      value=insured_total),
    ]
    transaction = iroha.transaction(commands)
    IrohaCrypto.sign_transaction(transaction, admin_private_key)
    send_transaction_and_print_status(transaction)
    query = iroha.query('GetAccountDetail', account_id='admin@test')
    IrohaCrypto.sign_query(query, admin_private_key)
    response = net.send_query(query)
    data = response.account_detail_response
    result = item + ":" + str(
        json.loads(str(data)[9:-2].replace("\\", ""))[admin_account][item])
    return result, 201
Exemplo n.º 13
0
def get_asset_info(account_id, asset_id):

    query = iroha.query('GetAssetInfo', asset_id=asset_id)
    ic.sign_query(query, user_private_key)
    response = net.send_query(query)
    data = MessageToJson(response)
    pprint(data, indent=2)
Exemplo n.º 14
0
def get_detail_from_generator(iroha, network, account_id, private_key,
                              generator_id, detail_id):
    """
    Consult a single detail writen by some generator
    :param iroha: (Iroha(name@domain)) Address for connecting to a domain
    :param network: (IrohaGrpc(IP address)) Physical address of one node running the BSMD
    :param account_id: (name@domain) Id of the user in the domain
    :param private_key: (str) Private key of the user
    :param generator_id: (name@domain) Id of the user who create de detail
    :param detail_id: (string) Name of the detail
    :return: data: (json) solicited details of the user

    Usage example:
    get_detail_from_generator(Iroha('david@federated'),IrohaGrpc('127.0.0.1'), 'david@federated', 'key',
                                'david@federated', 'Address')

    Return example:
    {
       "nodeA@domain":{
             "Age":"35"
        }
    }
    """
    query = iroha.query('GetAccountDetail',
                        account_id=account_id,
                        writer=generator_id,
                        key=detail_id)
    IrohaCrypto.sign_query(query, private_key)

    response = network.send_query(query)
    data = response.account_detail_response
    # print('Account id = {}, details = {}'.format(account_id, data.detail))
    return data.detail
Exemplo n.º 15
0
    def get_all_account_transactions(self, gov_id):
        query = self.iroha.query("GetAccountTransactions",
                                 account_id=f"{gov_id}@afyamkononi",
                                 page_size=30)
        IrohaCrypto.sign_query(query, self.creator_account_details.private_key)

        return self.net.send_query(query)
Exemplo n.º 16
0
    def get_woods_balance(self):
        query = self.iroha.query('GetAccountAssets', account_id=self.full_name)
        IrohaCrypto.sign_query(query, self.__private_key)

        response = self.ledger.net.send_query(query)
        data = response.account_assets_response.account_assets
        return {asset.asset_id.split('#')[0]: asset.balance for asset in data}
Exemplo n.º 17
0
def get_user_details(name, domain):

    query = iroha.query('GetAccountDetail', account_id=name+'@'+domain)
    IrohaCrypto.sign_query(query, ADMIN_PRIVATE_KEY)

    response = net.send_query(query)
    data = response.account_detail_response
    return jsonify('Account id = {}, details = {}'.format(name+'@'+domain, data.detail))
Exemplo n.º 18
0
def get_block(blockNum):
    # create Query
    get_block_query = iroha.query('GetBlock', height=blockNum)
    # sign Query
    IrohaCrypto.sign_query(get_block_query, admin_priv_key)
    # send Query
    response = net.send_query(get_block_query)
    return response
Exemplo n.º 19
0
def get_tx_info(txid):
    '''
    Gets transaction info from Iroha for a transaction ID hash.
    '''
    qry = iroha.query('GetTransactions', tx_hashes=[get_txid_bytes(txid)])
    IrohaCrypto.sign_query(qry, admin_private_key)
    status = net.send_query()
    return status
Exemplo n.º 20
0
def transactions_query():
    hashes = [
        binascii.hexlify(alice_tx1_hash),
        binascii.hexlify(alice_tx2_hash)
    ]
    query = iroha.query('GetTransactions', creator_account=alice['id'], tx_hashes=hashes)
    IrohaCrypto.sign_query(query, alice['key'])
    return query
 def get_account(self, account_id):
     """
     List Account user@domain
     """
     query = self.iroha.query('GetAccount', account_id=account_id)
     ic.sign_query(query, self.user_private_key)
     response = self.net.send_query(query)
     data = MessageToDict(response)
     return data
 def get_role_permissions(self, role_id):
     """
     List Role Permissions for specified Role
     """
     query = self.iroha.query('GetRolePermissions', role_id=role_id)
     ic.sign_query(query, self.user_private_key)
     response = self.net.send_query(query)
     data = MessageToDict(response)
     return data
 def get_signatories(self, account_id):
     """
     List signatories by public key for specified user@domain
     """
     query = self.iroha.query('GetSignatories', account_id=account_id)
     ic.sign_query(query, self.user_private_key)
     response = self.net.send_query(query)
     data = MessageToDict(response)
     return data
Exemplo n.º 24
0
def get_account(account_id):
    """
    List Account user@domain
    """
    query = iroha.query('GetAccount', account_id=account_id)
    ic.sign_query(query, user_private_key)
    response = net.send_query(query)
    data = MessageToDict(response)
    pprint(data, indent=2)
 def get_roles(self):
     """
     List Roles
     """
     query = self.iroha.query('GetRoles')
     ic.sign_query(query, self.user_private_key)
     response = self.net.send_query(query)
     data = MessageToDict(response)
     return data
Exemplo n.º 26
0
def get_signatories(account_id):
    """
    List signatories by public key for specified user@domain
    """
    query = iroha.query('GetSignatories', account_id=account_id)
    ic.sign_query(query, user_private_key)
    response = net.send_query(query)
    data = MessageToDict(response)
    pprint(data, indent=2)
Exemplo n.º 27
0
def get_role_permissions(role_id):
    """
    List Role Permissions for specified Role
    """
    query = iroha.query('GetRolePermissions', role_id=role_id)
    ic.sign_query(query, user_private_key)
    response = net.send_query(query)
    data = MessageToDict(response)
    pprint(data, indent=2)
Exemplo n.º 28
0
def get_roles():
    """
    List Roles
    """
    query = iroha.query('GetRoles')
    ic.sign_query(query, user_private_key)
    response = net.send_query(query)
    data = MessageToDict(response)
    pprint(data, indent=2)
Exemplo n.º 29
0
def get_account_assets(name, domain):

    query = iroha.query('GetAccountAssets', account_id=name+'@'+domain)
    IrohaCrypto.sign_query(query, ADMIN_PRIVATE_KEY)

    response = net.send_query(query)
    data = response.account_assets_response.account_assets
    for asset in data:
        return jsonify('id = {}, balance = {}'.format(asset.asset_id, asset.balance))
Exemplo n.º 30
0
def get_engine_receipts_result(tx_hash: str):
    query = iroha.query("GetEngineReceipts", tx_hash=tx_hash)
    IrohaCrypto.sign_query(query, ADMIN_PRIVATE_KEY)
    response = net.send_query(query)
    result = response.engine_receipts_response.engine_receipts[
        0].call_result.result_data
    bytes_object = bytes.fromhex(result)
    ascii_string = bytes_object.decode('ASCII', 'ignore')
    print(ascii_string)