X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=backends%2Fbitcoind%2Fblockchain_processor.py;h=6fb36fb97a2a9008981616529359490409ca534e;hb=9ef61e849b689da9c90ddfcee796a370fd1d12eb;hp=cb64178bae9c547eb555706ea8db1d70db6fb991;hpb=c9c337a89a3f04d7a985a521ca552d421fd94fda;p=electrum-server.git diff --git a/backends/bitcoind/blockchain_processor.py b/backends/bitcoind/blockchain_processor.py index cb64178..6fb36fb 100644 --- a/backends/bitcoind/blockchain_processor.py +++ b/backends/bitcoind/blockchain_processor.py @@ -217,7 +217,7 @@ class BlockchainProcessor(Processor): def get_mempool_transaction(self, txid): try: - raw_tx = self.bitcoind('getrawtransaction', [txid, 0, -1]) + raw_tx = self.bitcoind('getrawtransaction', [txid, 0]) except: return None @@ -614,8 +614,7 @@ class BlockchainProcessor(Processor): elif method == 'blockchain.transaction.get': try: tx_hash = params[0] - height = params[1] - result = self.bitcoind('getrawtransaction', [tx_hash, 0, height]) + result = self.bitcoind('getrawtransaction', [tx_hash, 0]) except BaseException, e: error = str(e) + ': ' + tx_hash print_log("error:", error) @@ -636,6 +635,35 @@ class BlockchainProcessor(Processor): if addr not in self.watched_addresses: self.watched_addresses.append(addr) + def getfullblock(block_hash): + block = self.bitcoind('getblock', [block_hash]) + + rawtxreq = [] + i = 0 + for txid in block['tx']: + rawtxreq.append({ + "method": "getrawtransaction", + "params": [txid], + "id": i, + }) + i += 1 + + postdata = dumps(rawtxreq) + try: + respdata = urllib.urlopen(self.bitcoind_url, postdata).read() + except: + traceback.print_exc(file=sys.stdout) + self.shared.stop() + + r = loads(respdata) + rawtxdata = [] + for ir in r: + if r['error'] is not None: + raise BaseException(r['error']) + rawtxdata.append(r['result']) + block['tx'] = rawtxdata + return block + def catch_up(self, sync=True): t1 = time.time() @@ -651,7 +679,7 @@ class BlockchainProcessor(Processor): # not done.. self.up_to_date = False next_block_hash = self.bitcoind('getblockhash', [self.height + 1]) - next_block = self.bitcoind('getblock', [next_block_hash, 1]) + next_block = self.getfullblock(next_block_hash) # fixme: this is unsafe, if we revert when the undo info is not yet written revert = (random.randint(1, 100) == 1) if self.is_test else False @@ -670,7 +698,7 @@ class BlockchainProcessor(Processor): else: # revert current block - block = self.bitcoind('getblock', [self.last_hash, 1]) + block = self.getfullblock(self.last_hash) print_log("blockchain reorg", self.height, block.get('previousblockhash'), self.last_hash) self.import_block(block, self.last_hash, self.height, sync, revert=True) self.pop_header()