コード例 #1
0
def get_entity(currency, entity):
    db = get_connection()
    result = db.get_entity(currency, entity)

    if result is None:
        raise RuntimeError("Entity {} not found".format(entity))
    return Entity(entity=result.cluster,
                  first_tx=TxSummary(result.first_tx.height,
                                     result.first_tx.timestamp,
                                     result.first_tx.tx_hash.hex()),
                  last_tx=TxSummary(result.last_tx.height,
                                    result.last_tx.timestamp,
                                    result.last_tx.tx_hash.hex()),
                  no_addresses=result.no_addresses,
                  no_incoming_txs=result.no_incoming_txs,
                  no_outgoing_txs=result.no_outgoing_txs,
                  total_received=make_values(value=result.total_received.value,
                                             eur=result.total_received.eur,
                                             usd=result.total_received.usd),
                  total_spent=make_values(eur=result.total_spent.eur,
                                          usd=result.total_spent.usd,
                                          value=result.total_spent.value),
                  in_degree=result.in_degree,
                  out_degree=result.out_degree,
                  balance=convert_value(
                      compute_balance(
                          result.total_received.value,
                          result.total_spent.value,
                      ),
                      get_rates(currency)['rates']))
コード例 #2
0
def get_address(currency, address):
    db = get_connection()
    result = db.get_address(currency, address)

    if not result:
        raise RuntimeError("Address {} not found in currency {}".format(
            address, currency))
    return Address(
        address=result.address,
        first_tx=TxSummary(result.first_tx.height, result.first_tx.timestamp,
                           result.first_tx.tx_hash.hex()),
        last_tx=TxSummary(result.last_tx.height, result.last_tx.timestamp,
                          result.last_tx.tx_hash.hex()),
        no_incoming_txs=result.no_incoming_txs,
        no_outgoing_txs=result.no_outgoing_txs,
        total_received=make_values(value=result.total_received.value,
                                   eur=result.total_received.eur,
                                   usd=result.total_received.usd),
        total_spent=make_values(eur=result.total_spent.eur,
                                usd=result.total_spent.usd,
                                value=result.total_spent.value),
        in_degree=result.in_degree,
        out_degree=result.out_degree,
        balance=convert_value(
            compute_balance(
                result.total_received.value,
                result.total_spent.value,
            ),
            get_rates(currency)['rates']))
コード例 #3
0
def list_entity_addresses(currency, entity, page=None, pagesize=None):
    db = get_connection()
    addresses, paging_state = \
        db.list_entity_addresses(currency, entity, page, pagesize)

    rates = get_rates(currency)['rates']
    addresses = [
        Address(address=row['address'],
                first_tx=TxSummary(row['first_tx'].height,
                                   row['first_tx'].timestamp,
                                   row['first_tx'].tx_hash.hex()),
                last_tx=TxSummary(row['last_tx'].height,
                                  row['last_tx'].timestamp,
                                  row['last_tx'].tx_hash.hex()),
                no_incoming_txs=row['no_incoming_txs'],
                no_outgoing_txs=row['no_outgoing_txs'],
                total_received=make_values(value=row['total_received'].value,
                                           eur=row['total_received'].eur,
                                           usd=row['total_received'].usd),
                total_spent=make_values(eur=row['total_spent'].eur,
                                        usd=row['total_spent'].usd,
                                        value=row['total_spent'].value),
                in_degree=row['in_degree'],
                out_degree=row['out_degree'],
                balance=convert_value(
                    compute_balance(
                        row['total_received'].value,
                        row['total_spent'].value,
                    ), rates)) for row in addresses
    ]
    return EntityAddresses(next_page=paging_state, addresses=addresses)
コード例 #4
0
def list_address_neighbors(currency, address, direction, page=None,
                           pagesize=None):
    is_outgoing = "out" in direction
    db = get_connection()
    results, paging_state = db.list_address_relations(
                                    currency,
                                    address,
                                    is_outgoing,
                                    page,
                                    pagesize)
    dst = 'dst' if is_outgoing else 'src'
    rates = get_rates(currency)['rates']
    relations = []
    if results is None:
        return Neighbors()
    for row in results:
        balance = compute_balance(row[dst+'_properties'].total_received.value,
                                  row[dst+'_properties'].total_spent.value)
        relations.append(Neighbor(
            id=row['id'],
            node_type='address',
            labels=row[dst+'_labels']
            if row[dst+'_labels'] is not None else [],
            received=make_values(
                value=row[dst+'_properties'].total_received.value,
                eur=row[dst+'_properties'].total_received.eur,
                usd=row[dst+'_properties'].total_received.usd),
            estimated_value=make_values(
                value=row['estimated_value'].value,
                eur=row['estimated_value'].eur,
                usd=row['estimated_value'].usd),
            balance=convert_value(balance, rates),
            no_txs=row['no_transactions']))
    return Neighbors(next_page=paging_state,
                     neighbors=relations)
コード例 #5
0
def list_entity_neighbors(currency,
                          entity,
                          direction,
                          targets=None,
                          page=None,
                          pagesize=None):
    db = get_connection()
    is_outgoing = "out" in direction
    results, paging_state = db.list_entity_neighbors(currency, entity,
                                                     is_outgoing, targets,
                                                     page, pagesize)

    rates = get_rates(currency)['rates']
    relations = []
    dst = 'dst' if is_outgoing else 'src'
    for row in results:
        balance = compute_balance(
            getattr(row, dst + '_properties').total_received.value,
            getattr(row, dst + '_properties').total_spent.value)
        relations.append(
            Neighbor(
                id=getattr(row, dst + '_cluster'),
                node_type='entity',
                labels=getattr(row, dst + '_labels') if getattr(
                    row, dst + '_labels') is not None else [],
                received=make_values(
                    value=getattr(row,
                                  dst + '_properties').total_received.value,
                    eur=getattr(row, dst + '_properties').total_received.eur,
                    usd=getattr(row, dst + '_properties').total_received.usd),
                estimated_value=make_values(value=row.value.value,
                                            eur=row.value.eur,
                                            usd=row.value.usd),
                balance=convert_value(balance, rates),
                no_txs=row.no_transactions))
    return Neighbors(next_page=paging_state, neighbors=relations)