def bitcoind(self, method, params=[]):
postdata = dumps({"method": method, 'params': params, 'id':'jsonrpc'})
- respdata = urllib.urlopen(self.bitcoind_url, postdata).read()
+ try:
+ respdata = urllib.urlopen(self.bitcoind_url, postdata).read()
+ except:
+ traceback.print_exc(file=sys.stdout)
+ self.shared.stop()
+
r = loads(respdata)
if r['error'] != None:
raise BaseException(r['error'])
return chunk
- def get_transaction(self, txid, block_height=-1, is_coinbase = False):
- raw_tx = self.bitcoind('getrawtransaction', [txid, 0, block_height])
+ def get_mempool_transaction(self, txid):
+ try:
+ raw_tx = self.bitcoind('getrawtransaction', [txid, 0, -1])
+ except:
+ return None
+
vds = deserialize.BCDataStream()
vds.write(raw_tx.decode('hex'))
- out = deserialize.parse_Transaction(vds, is_coinbase)
+ out = deserialize.parse_Transaction(vds, is_coinbase = False)
return out
# re-add them to the history
self.add_to_history( prevout_addr, x.get('prevout_hash'), x.get('prevout_n'), prevout_height)
- print_log( "new hist for", hash_160_to_bc_address(prevout_addr), self.deserialize(self.batch_list[prevout_addr]) )
+ # print_log( "new hist for", hash_160_to_bc_address(prevout_addr), self.deserialize(self.batch_list[prevout_addr]) )
# write
max_len = 0
print_log( "error:", error)
elif method == 'blockchain.transaction.broadcast':
- txo = self.bitcoind('sendrawtransaction', params)
- print_log( "sent tx:", txo )
- result = txo
+ try:
+ txo = self.bitcoind('sendrawtransaction', params)
+ print_log( "sent tx:", txo )
+ result = txo
+ except BaseException, e:
+ result = str(e) # do not send an error
+ print_log( "error:", str(e), params )
elif method == 'blockchain.transaction.get_merkle':
if cache_only:
for tx_hash in mempool_hashes:
if tx_hash in self.mempool_hashes: continue
- tx = self.get_transaction(tx_hash)
+ tx = self.get_mempool_transaction(tx_hash)
if not tx: continue
for x in tx.get('inputs'):