X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=blobdiff_plain;f=backends%2Fbitcoind%2Fblockchain_processor.py;h=421f385cb7859bd82098bbf53046ff331d4e1d0b;hp=1de5db643846ef92787611e26d132e483f78c53d;hb=6adb33a7221351f84357c89bc7ae0d17b1d73ffa;hpb=dec881f99cdda62dfe0459d55a2be129ba491bae diff --git a/backends/bitcoind/blockchain_processor.py b/backends/bitcoind/blockchain_processor.py index 1de5db6..421f385 100644 --- a/backends/bitcoind/blockchain_processor.py +++ b/backends/bitcoind/blockchain_processor.py @@ -490,10 +490,10 @@ class BlockchainProcessor(Processor): error = str(e) + ': ' + address print_log("error:", error) - elif method == 'blockchain.address.get_path': + elif method == 'blockchain.address.get_proof': try: address = str(params[0]) - result = self.storage.get_address_path(address) + result = self.storage.get_proof(address) except BaseException, e: error = str(e) + ': ' + address print_log("error:", error) @@ -506,12 +506,22 @@ class BlockchainProcessor(Processor): error = str(e) + ': ' + address print_log("error:", error) + elif method == 'blockchain.utxo.get_address': + try: + txid = str(params[0]) + pos = int(params[1]) + txi = (txid + int_to_hex(pos, 4)).decode('hex') + result = self.storage.get_address(txi) + except BaseException, e: + error = str(e) + print_log("error:", error, txid, pos) + elif method == 'blockchain.block.get_header': if cache_only: result = -1 else: try: - height = params[0] + height = int(params[0]) result = self.get_header(height) except BaseException, e: error = str(e) + ': %d' % height @@ -522,7 +532,7 @@ class BlockchainProcessor(Processor): result = -1 else: try: - index = params[0] + index = int(params[0]) result = self.get_chunk(index) except BaseException, e: error = str(e) + ': %d' % index @@ -602,7 +612,7 @@ class BlockchainProcessor(Processor): def catch_up(self, sync=True): - prh = None + prev_root_hash = None while not self.shared.stopped(): self.mtime('') @@ -626,6 +636,8 @@ class BlockchainProcessor(Processor): if (next_block.get('previousblockhash') == self.storage.last_hash) and not revert: + prev_root_hash = self.storage.get_root_hash() + self.import_block(next_block, next_block_hash, self.storage.height+1, sync) self.storage.height = self.storage.height + 1 self.write_header(self.block2header(next_block), sync) @@ -639,15 +651,7 @@ class BlockchainProcessor(Processor): self.mtimes['daemon'] = 0 self.mtimes['import'] = 0 - if prh: - if prh != self.storage.get_root_hash().encode('hex'): - print_log("root hash error", prh) - self.shared.stop() - raise - prh = None - else: - prh = self.storage.get_root_hash().encode('hex') # revert current block block = self.getfullblock(self.storage.last_hash) @@ -662,8 +666,13 @@ class BlockchainProcessor(Processor): self.header = self.read_header(self.storage.height) self.storage.last_hash = self.hash_header(self.header) + if prev_root_hash: + assert prev_root_hash == self.storage.get_root_hash() + prev_root_hash = None + self.header = self.block2header(self.bitcoind('getblock', [self.storage.last_hash])) + self.header['utxo_root'] = self.storage.get_root_hash().encode('hex') if self.shared.stopped(): print_log( "closing database" )