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()
def import_block(self, b, chain_ids=frozenset()): #print "import block" block_id = super(AbeStore, self).import_block(b, chain_ids) for pos in xrange(len(b['transactions'])): tx = b['transactions'][pos] if 'hash' not in tx: tx['hash'] = util.double_sha256(tx['tx']) tx_id = self.tx_find_id_and_value(tx) if tx_id: self.update_tx_cache(tx_id) else: print "error: import_block: no tx_id" return block_id
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'] != None: print 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'] != None: continue hextx = r.get('result') ds.clear() ds.write(hextx.decode('hex')) tx = deserialize.parse_Transaction(ds) tx['hash'] = util.double_sha256(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 tx_hash store.commit() store.known_mempool_hashes = mempool_hashes return num_new_tx