X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=backends%2Fbitcoind%2Fblockchain_processor.py;h=cf5f60964b244eb82c52e53ad5c91e147677cdbb;hb=f80e689bf86e7ca5998884bca0c7160e6ec81ce5;hp=459e37f5d43d472b628fa8989eb2f7cf50177c6d;hpb=36d4d33f87edeeb17bb3c03037e3b45afe21f2f2;p=electrum-server.git diff --git a/backends/bitcoind/blockchain_processor.py b/backends/bitcoind/blockchain_processor.py index 459e37f..cf5f609 100644 --- a/backends/bitcoind/blockchain_processor.py +++ b/backends/bitcoind/blockchain_processor.py @@ -238,6 +238,7 @@ class BlockchainProcessor(Processor): print_log("ERROR: cannot parse", txid) return None + def get_history(self, addr, cache_only=False): with self.cache_lock: hist = self.history_cache.get(addr) @@ -248,8 +249,7 @@ class BlockchainProcessor(Processor): with self.dblock: try: - h = self.storage.get_history(str((addr))) - hist = self.storage.deserialize(h) + hist = self.storage.get_history(addr) is_known = True except: self.shared.stop() @@ -260,19 +260,10 @@ class BlockchainProcessor(Processor): hist = [] is_known = False - # sort history, because redeeming transactions are next to the corresponding txout - hist.sort(key=lambda tup: tup[2]) - # add memory pool with self.mempool_lock: for txid in self.mempool_hist.get(addr, []): - hist.append((txid, 0, 0)) - - # uniqueness - hist = set(map(lambda x: (x[0], x[2]), hist)) - - # convert to dict - hist = map(lambda x: {'tx_hash': x[0], 'height': x[1]}, hist) + hist.append({'tx_hash':txid, 'height':0}) # add something to distinguish between unused and empty addresses if hist == [] and is_known: @@ -282,6 +273,7 @@ class BlockchainProcessor(Processor): self.history_cache[addr] = hist return hist + def get_status(self, addr, cache_only=False): tx_points = self.get_history(addr, cache_only) if cache_only and tx_points == -1: @@ -476,7 +468,7 @@ class BlockchainProcessor(Processor): elif method == 'blockchain.address.subscribe': try: - address = params[0] + address = str(params[0]) result = self.get_status(address, cache_only) except BaseException, e: error = str(e) + ': ' + address @@ -484,12 +476,36 @@ class BlockchainProcessor(Processor): elif method == 'blockchain.address.get_history': try: - address = params[0] + address = str(params[0]) result = self.get_history(address, cache_only) except BaseException, e: error = str(e) + ': ' + address print_log("error:", error) + elif method == 'blockchain.address.get_balance': + try: + address = str(params[0]) + result = self.storage.get_balance(address) + except BaseException, e: + error = str(e) + ': ' + address + print_log("error:", error) + + elif method == 'blockchain.address.get_path': + try: + address = str(params[0]) + result = self.storage.get_address_path(address) + except BaseException, e: + error = str(e) + ': ' + address + print_log("error:", error) + + elif method == 'blockchain.address.listunspent': + try: + address = str(params[0]) + result = self.storage.listunspent(address) + except BaseException, e: + error = str(e) + ': ' + address + print_log("error:", error) + elif method == 'blockchain.block.get_header': if cache_only: result = -1