From be2475f61765e1e0202f446a4137ba859b1c7fe8 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Thu, 3 Nov 2016 10:46:09 +0900 Subject: [PATCH] Handle utxo.get_address --- lib/coins.py | 5 +++++ server/block_processor.py | 9 +++++++++ server/controller.py | 7 +++---- server/protocol.py | 17 +++++++++++++++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/coins.py b/lib/coins.py index ec84b96..5c89832 100644 --- a/lib/coins.py +++ b/lib/coins.py @@ -77,6 +77,11 @@ class Coin(object): raise CoinError('invalid address: {}'.format(addr)) return result + @classmethod + def hash168_to_address(cls, hash168): + '''Return an address given a 21-byte hash.''' + return Base58.encode_check(hash168) + @classmethod def P2PKH_address_from_hash160(cls, hash_bytes): '''Return a P2PKH address given a public key.''' diff --git a/server/block_processor.py b/server/block_processor.py index 47aa0e1..908b245 100644 --- a/server/block_processor.py +++ b/server/block_processor.py @@ -762,3 +762,12 @@ class BlockProcessor(LoggedClass): '''Returns all the UTXOs for an address sorted by height and position in the block.''' return sorted(self.get_utxos(hash168, limit=None)) + + def get_utxo_hash168(self, tx_hash, index): + '''Returns the hash168 for a UTXO.''' + hash168 = None + if 0 <= index <= 65535: + hash168 = self.utxo_cache(tx_hash, struct.pack('