예제 #1
0
def deserialize_tx_data(data):
    h = data[0]
    offset = 1
    coinbase = True if h & 128 else False
    if coinbase & (h & 64):
        witnesshash = data[1:33]
        offset = 33
    else:
        witnesshash = None
    if h & 60 == 0:
        version = c_int_to_int(data[offset:])
        offset = offset + c_int_len(version)
    else:
        version = (h >> 2) & 0b1111
    if h & 2:
        locktime = c_int_to_int(data[offset:])
        offset = offset + c_int_len(locktime)
    else:
        locktime = 0
    if h & 1:
        tx_data = data[offset:]
    else:
        tx_data = None
    if coinbase:
        witnesshash = b"\x00" * 32
    return [coinbase, witnesshash, version, locktime, tx_data]
예제 #2
0
def decode_tx_map_data(b):
    r = c_int_to_int(b)
    f = c_int_len(r)
    rc = c_int_to_int(b[f:])
    f += c_int_len(rc)
    if f >= len(b):
        s = 0
        sc = 0
    else:
        s = c_int_to_int(b[f:])
        f += c_int_len(s)
        sc = c_int_to_int(b[f:])
    return r, rc, s, sc
예제 #3
0
def deserialize_input_script(data, coinbase):
    pubkey_script = b''
    sig_script = b''
    witness = []
    address = b""
    pubkey_script_type = None
    offset = 0
    l = c_int_to_int(data[offset:])
    offset += c_int_len(l)
    if l:
        pubkey_script = data[offset:offset + l]
        offset += l
    offset += 1
    l = c_int_to_int(data[offset:])
    offset += c_int_len(l)
    if l:
        sig_script = data[offset:offset + l]
        offset += l
    inverted_sequence = c_int_to_int(data[offset:])
    offset += c_int_len(inverted_sequence)
    sequence = 0xffffffff - inverted_sequence
    while data[offset:]:
        l = c_int_to_int(data[offset:])
        offset += c_int_len(l)
        # if l:
        witness.append(data[offset:offset + l])
        offset += l
    if pubkey_script:
        s = parse_script(pubkey_script)
        if "addressHash" in s:
            address = b''.join([int_to_bytes(s["nType"]), s["addressHash"]
                                ]) if "addressHash" in s else b''
        pubkey_script_type = s["type"]

    return {
        "pubkey_script": pubkey_script,
        "sig_script": sig_script,
        "sequence": sequence,
        "witness": witness if not coinbase else [],
        "address": address,
        "pubkey_script_type": pubkey_script_type
    }
예제 #4
0
async def test_filter(request):

    try:
        async with request.app["db_pool"].acquire() as conn:
            row = await conn.fetchrow("SELECT height, filter  "
                                          "FROM block_filters_checkpoints "
                                       "order by height asc limit 1;" )

        N = c_int_to_int(row["filter"])
        i = c_int_len(N)
        f = zlib.decompress(row["filter"][i:])
        h = row["height"]
        f = decode_gcs(f, N, P=request.app["block_filter_bits"])
        print(">>>",len(f), h)

        # 141788

        async with request.app["db_pool"].acquire() as conn:
            rows = await conn.fetch("SELECT distinct  address  "
                                    "FROM transaction_map "
                                    "where  pointer < $1;" ,  10000 << 39 )

        print("affected addresses ", len(rows))
        N = request.app["block_filter_fps"]
        M = request.app["block_filter_capacity"]
        elements = [map_into_range(siphash(e["address"]), N * M) for e in rows]

        for a in elements:
            if a not in f:
                print("false negative!")
                await asyncio.sleep(0)



        # print("positive ", i)
        # print("false positive ", e2)
        # print("errors ", e)

        resp = ["ok"]

    except Exception as err:
        print(str(traceback.format_exc()))
        return web.json_response([str(err)], dumps=json.dumps, status=200)
    return web.json_response(resp, dumps=json.dumps, status = 200)
예제 #5
0
def deserialize_tx_map(s):
    offset = 0
    data = dict()
    data["received"] = c_int_to_int(s[offset:])
    offset += c_int_len(data["received"])
    data["sent"] = c_int_to_int(s[offset:])
    offset += c_int_len(data["sent"])
    data["countReceived"] = c_int_to_int(s[offset:])
    offset += c_int_len(data["countReceived"])
    data["totalReceived"] = c_int_to_int(s[offset:])
    offset += c_int_len(data["totalReceived"])
    if offset < len(s):
        data["countSent"] = c_int_to_int(s[offset:])
        offset += c_int_len(data["countSent"])
        data["totalSent"] = c_int_to_int(s[offset:])
    else:
        data["countSent"] = 0
        data["totalSent"] = 0
    return data
예제 #6
0
def deserialize_address_data(data):
    data = get_stream(data)
    received_count = c_int_to_int(read_c_int(data))
    received_amount = c_int_to_int(read_c_int(data))
    coins = c_int_to_int(read_c_int(data))
    frp = c_int_to_int(read_c_int(data))
    lra = c_int_to_int(read_c_int(data))
    lrp = c_int_to_int(read_c_int(data))
    try:
        sent_count = c_int_to_int(read_c_int(data))
        sent_amount = c_int_to_int(read_c_int(data))
        coins_destroyed = c_int_to_int(read_c_int(data))
        fsp = c_int_to_int(read_c_int(data))
        lsa = c_int_to_int(read_c_int(data))
        lsp = c_int_to_int(read_c_int(data))
    except:
        sent_count = 0
        sent_amount = 0
        coins_destroyed = 0
        fsp = None
        lsa = None
        lsp = None
    return (received_count, received_amount, coins, frp, lra, lrp, sent_count,
            sent_amount, coins_destroyed, fsp, lsa, lsp)
예제 #7
0
def deserialize_address_stat(data):
    offset = 0
    stat = dict()
    stat["receivedTxCount"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["receivedTxCount"])
    stat["receivedAmount"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["receivedAmount"])
    stat["outputsReceivedCount"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["outputsReceivedCount"])
    stat["firstReceivedTxBlock"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["firstReceivedTxBlock"])
    stat["lastReceivedTxBlock"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["lastReceivedTxBlock"])
    stat["largestTxAmount"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["largestTxAmount"])
    stat["largestTxId"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["largestTxId"])
    stat["sentTxCount"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["sentTxCount"])
    stat["sentAmount"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["sentAmount"])
    stat["outputsSpentCount"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["outputsSpentCount"])
    stat["firstSentTxBlock"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["firstSentTxBlock"])
    stat["lastSentTxBlock"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["lastSentTxBlock"])
    stat["mined"] = c_int_to_int(data[offset:])
    offset += c_int_len(stat["mined"])
    if offset < len(data):
        stat["invalidTx"] = c_int_to_int(data[offset:])
        offset += c_int_len(stat["invalidTx"])
        if offset < len(data):
            stat["pendingReceivedTxCount"] = c_int_to_int(data[offset:])
            offset += c_int_len(stat["pendingReceivedTxCount"])
            stat["pendingReceivedAmount"] = c_int_to_int(data[offset:])
            offset += c_int_len(stat["pendingReceivedAmount"])
            stat["outputsUnconfirmedReceivedCount"] = c_int_to_int(
                data[offset:])
            offset += c_int_len(stat["outputsUnconfirmedReceivedCount"])
            stat["pendingSentTxCount"] = c_int_to_int(data[offset:])
            offset += c_int_len(stat["pendingSentTxCount"])
            stat["pendingSentAmount"] = c_int_to_int(data[offset:])
            offset += c_int_len(stat["pendingSentAmount"])
            stat["outputsUnconfirmedSpentCount"] = c_int_to_int(data[offset:])
            offset += c_int_len(stat["outputsUnconfirmedSpentCount"])
        else:
            stat["pendingReceivedTxCount"] = 0
            stat["pendingReceivedAmount"] = 0
            stat["outputsUnconfirmedReceivedCount"] = 0
            stat["pendingSentTxCount"] = 0
            stat["pendingSentAmount"] = 0
            stat["outputsUnconfirmedSpentCount"] = 0
    else:
        stat["invalidTx"] = 0
        stat["pendingReceivedTxCount"] = 0
        stat["pendingReceivedAmount"] = 0
        stat["outputsUnconfirmedReceivedCount"] = 0
        stat["pendingSentTxCount"] = 0
        stat["pendingSentAmount"] = 0
        stat["outputsUnconfirmedSpentCount"] = 0
    return stat