def list_address_links(currency, address, neighbor):
    db = get_connection()
    links = db.list_address_links(currency, address, neighbor)

    heights = [row['height'] for row in links]
    rates = list_rates(currency, heights)

    return [Link(tx_hash=e['tx_hash'],
                 height=e['height'],
                 timestamp=e['timestamp'],
                 input_value=convert_value(
                     e['input_value'], rates[e['height']]),
                 output_value=convert_value(
                     e['output_value'], rates[e['height']]),
                 ) for e in links]
Ejemplo n.º 2
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']))
Ejemplo n.º 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)
Ejemplo n.º 4
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']))
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)
Ejemplo n.º 6
0
def from_row(row, rates):
    return Tx(
            tx_hash=row.tx_hash.hex(),
            coinbase=row.coinbase,
            height=row.height,
            inputs=[TxValue(address=i.address,
                            value=convert_value(i.value, rates))
                    for i in row.inputs]
            if row.inputs else [],
            outputs=[TxValue(address=i.address,
                             value=convert_value(i.value, rates))
                     for i in row.outputs]
            if row.outputs else [],
            timestamp=row.timestamp,
            total_input=convert_value(row.total_input, rates),
            total_output=convert_value(row.total_output, rates))
Ejemplo n.º 7
0
def test_converted_value():
    rates = {'eur': 0.4, 'usd': 0.7}

    value = convert_value(175000000000, rates)

    assert value.value == 175000000000
    assert value.eur == 700
    assert value.usd == 1225
Ejemplo n.º 8
0
def list_block_txs(currency, height):
    db = get_connection()
    result = db.list_block_txs(currency, height)

    if result is None:
        raise RuntimeError("Block {} not found".format(height))
    rates = get_rates(currency, height)

    tx_summaries = \
        [BlockTxSummary(
         no_inputs=tx.no_inputs,
         no_outputs=tx.no_outputs,
         total_input=convert_value(tx.total_input, rates['rates']),
         total_output=convert_value(tx.total_output, rates['rates']),
         tx_hash=tx.tx_hash.hex()
         )
         for tx in result.txs]

    return BlockTxs(height, tx_summaries)
def list_address_txs(test_case):
    """Test case for list_address_txs

    Get all transactions an address has been involved in
    """
    rates = list_rates(currency='btc', heights=[2])

    address_txs = AddressTxs(
        next_page=None,
        address_txs=[
            AddressTx(tx_hash="123456",
                      value=convert_value(1260000, rates[2]),
                      height=2,
                      address=addressWithoutTags.address,
                      timestamp=1510347493),
            AddressTx(tx_hash="abcdef",
                      value=convert_value(-1260000, rates[2]),
                      height=2,
                      address=addressWithoutTags.address,
                      timestamp=1511153263)
        ])

    result = service.list_address_txs('btc', addressWithoutTags.address)
    assertEqual(address_txs, result)
Ejemplo n.º 10
0
def list_address_txs(currency, address, page=None, pagesize=None):
    db = get_connection()
    results, paging_state = \
        db.list_address_txs(currency, address, page, pagesize)
    address_txs = []
    if results:
        heights = [row.height for row in results]
        rates = list_rates(currency, heights)
        address_txs = [AddressTx(
                        address=address,
                        height=row.height,
                        timestamp=row.timestamp,
                        tx_hash=row.tx_hash.hex(),
                        value=convert_value(row.value, rates[row.height])
                        )
                       for row in results]
    return AddressTxs(next_page=paging_state, address_txs=address_txs)
Ejemplo n.º 11
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)