Example #1
0
    def memorypool_update(store):

        ds = BCDataStream.BCDataStream()
        postdata = dumps({"method": 'getmemorypool', 'params': [], 'id':'jsonrpc'})

        respdata = urllib.urlopen(store.bitcoind_url, postdata).read()
        r = loads(respdata)
        if r['error'] != None:
            return

        v = r['result'].get('transactions')
        for hextx in v:
            ds.clear()
            ds.write(hextx.decode('hex'))
            tx = deserialize.parse_Transaction(ds)
            tx['hash'] = util.double_sha256(tx['tx'])
            tx_hash = store.hashin(tx['hash'])

            if store.tx_find_id_and_value(tx):
                pass
            else:
                tx_id = store.import_tx(tx, False)
                store.update_tx_cache(tx_id)
                #print tx_hash
    
        store.commit()
Example #2
0
    def memorypool_update(store):
        ds = BCDataStream.BCDataStream()
        postdata = dumps({
            "method": 'getrawmempool',
            'params': [],
            'id': 'jsonrpc'
        })
        respdata = urllib.urlopen(store.bitcoind_url, postdata).read()

        r = loads(respdata)
        if r['error'] is not None:
            print_log(r['error'])
            return

        mempool_hashes = r.get('result')
        num_new_tx = 0

        for tx_hash in mempool_hashes:

            if tx_hash in store.known_mempool_hashes:
                continue
            store.known_mempool_hashes.append(tx_hash)
            num_new_tx += 1

            postdata = dumps({
                "method": 'getrawtransaction',
                'params': [tx_hash],
                'id': 'jsonrpc'
            })
            respdata = urllib.urlopen(store.bitcoind_url, postdata).read()
            r = loads(respdata)
            if r['error'] is not None:
                continue
            hextx = r.get('result')
            ds.clear()
            ds.write(hextx.decode('hex'))
            tx = deserialize.parse_Transaction(ds)
            tx['hash'] = Hash(tx['tx'])

            if store.tx_find_id_and_value(tx):
                pass
            else:
                tx_id = store.import_tx(tx, False)
                store.update_tx_cache(tx_id)
                #print_log(tx_hash)

        store.commit()
        store.known_mempool_hashes = mempool_hashes
        return num_new_tx
    def memorypool_update(store):
        ds = BCDataStream.BCDataStream()
        postdata = dumps({"method": 'getrawmempool', 'params': [], 'id': 'jsonrpc'})
        respdata = urllib.urlopen(store.bitcoind_url, postdata).read()

        r = loads(respdata)
        if r['error'] is not None:
            print_log(r['error'])
            return

        mempool_hashes = r.get('result')
        num_new_tx = 0

        for tx_hash in mempool_hashes:

            if tx_hash in store.known_mempool_hashes:
                continue
            store.known_mempool_hashes.append(tx_hash)
            num_new_tx += 1

            postdata = dumps({"method": 'getrawtransaction', 'params': [tx_hash], 'id': 'jsonrpc'})
            respdata = urllib.urlopen(store.bitcoind_url, postdata).read()
            r = loads(respdata)
            if r['error'] is not None:
                continue
            hextx = r.get('result')
            ds.clear()
            ds.write(hextx.decode('hex'))
            tx = deserialize.parse_Transaction(ds)
            tx['hash'] = Hash(tx['tx'])

            if store.tx_find_id_and_value(tx):
                pass
            else:
                tx_id = store.import_tx(tx, False)
                store.update_tx_cache(tx_id)
                #print_log(tx_hash)

        store.commit()
        store.known_mempool_hashes = mempool_hashes
        return num_new_tx