Browse Source

Implement other address methods for scripthash

master
Neil Booth 8 years ago
parent
commit
e7601a23cd
  1. 22
      server/controller.py
  2. 13
      server/session.py

22
server/controller.py

@ -801,16 +801,31 @@ class Controller(util.LoggedClass):
hashX = self.address_to_hashX(address)
return await self.get_balance(hashX)
async def scripthash_get_balance(self, scripthash):
'''Return the confirmed and unconfirmed balance of a scripthash.'''
hashX = self.scripthash_to_hashX(scripthash)
return await self.get_balance(hashX)
async def address_get_history(self, address):
'''Return the confirmed and unconfirmed history of an address.'''
hashX = self.address_to_hashX(address)
return await self.confirmed_and_unconfirmed_history(hashX)
async def scripthash_get_history(self, scripthash):
'''Return the confirmed and unconfirmed history of a scripthash.'''
hashX = self.scripthash_to_hashX(scripthash)
return await self.confirmed_and_unconfirmed_history(hashX)
async def address_get_mempool(self, address):
'''Return the mempool transactions touching an address.'''
hashX = self.address_to_hashX(address)
return await self.unconfirmed_history(hashX)
async def scripthash_get_mempool(self, scripthash):
'''Return the mempool transactions touching a scripthash.'''
hashX = self.scripthash_to_hashX(scripthash)
return await self.unconfirmed_history(hashX)
async def address_get_proof(self, address):
'''Return the UTXO proof of an address.'''
hashX = self.address_to_hashX(address)
@ -823,6 +838,13 @@ class Controller(util.LoggedClass):
'height': utxo.height, 'value': utxo.value}
for utxo in sorted(await self.get_utxos(hashX))]
async def scripthash_listunspent(self, scripthash):
'''Return the list of UTXOs of a scripthash.'''
hashX = self.scripthash_to_hashX(scripthash)
return [{'tx_hash': hash_to_str(utxo.tx_hash), 'tx_pos': utxo.tx_pos,
'height': utxo.height, 'value': utxo.value}
for utxo in sorted(await self.get_utxos(hashX))]
def block_get_header(self, height):
'''The deserialized header at a given height.

13
server/session.py

@ -381,6 +381,11 @@ class ElectrumX(SessionBase):
.format(version_str), JSONRPC.FATAL_ERROR)
handlers = {
'blockchain.address.get_balance': controller.address_get_balance,
'blockchain.address.get_history': controller.address_get_history,
'blockchain.address.get_mempool': controller.address_get_mempool,
'blockcahin.address.get_proof': controller.address_get_proof,
'blockchain.address.listunspent': controller.address_listunspent,
'blockchain.address.subscribe': self.address_subscribe,
'blockchain.block.get_chunk': self.block_get_chunk,
'blockchain.headers.subscribe': self.headers_subscribe,
@ -403,6 +408,14 @@ class ElectrumX(SessionBase):
del handlers['blockchain.utxo.get_address']
# Add new handlers
handlers.update({
'blockchain.scripthash.get_balance':
controller.scripthash_get_balance,
'blockchain.scripthash.get_history':
controller.scripthash_get_history,
'blockchain.scripthash.get_mempool':
controller.scripthash_get_mempool,
'blockchain.scripthash.listunspent':
controller.scripthash_listunspent,
'blockchain.scripthash.subscribe': self.scripthash_subscribe,
'blockchain.transaction.broadcast': self.transaction_broadcast,
'blockchain.transaction.get': controller.transaction_get,

Loading…
Cancel
Save