Move address handlers from controller to session
This commit is contained in:
parent
4f99f254ea
commit
3dbc10bca0
@ -563,7 +563,7 @@ class Controller(ServerBase):
|
|||||||
'''Replace the daemon URL.'''
|
'''Replace the daemon URL.'''
|
||||||
daemon_url = daemon_url or self.env.daemon_url
|
daemon_url = daemon_url or self.env.daemon_url
|
||||||
try:
|
try:
|
||||||
self.daemon.set_urls(self.env.coin.daemon_urls(daemon_url))
|
self.daemon.set_urls(self.coin.daemon_urls(daemon_url))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RPCError(BAD_REQUEST, f'an error occured: {e}')
|
raise RPCError(BAD_REQUEST, f'an error occured: {e}')
|
||||||
return 'now using daemon at {}'.format(self.daemon.logged_url())
|
return 'now using daemon at {}'.format(self.daemon.logged_url())
|
||||||
@ -601,13 +601,6 @@ class Controller(ServerBase):
|
|||||||
|
|
||||||
# Helpers for RPC "blockchain" command handlers
|
# Helpers for RPC "blockchain" command handlers
|
||||||
|
|
||||||
def address_to_hashX(self, address):
|
|
||||||
try:
|
|
||||||
return self.coin.address_to_hashX(address)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
raise RPCError(BAD_REQUEST, f'{address} is not a valid address')
|
|
||||||
|
|
||||||
def assert_tx_hash(self, value):
|
def assert_tx_hash(self, value):
|
||||||
'''Raise an RPCError if the value is not a valid transaction
|
'''Raise an RPCError if the value is not a valid transaction
|
||||||
hash.'''
|
hash.'''
|
||||||
@ -702,21 +695,6 @@ class Controller(ServerBase):
|
|||||||
|
|
||||||
# Client RPC "blockchain" command handlers
|
# Client RPC "blockchain" command handlers
|
||||||
|
|
||||||
async def address_get_balance(self, address):
|
|
||||||
'''Return the confirmed and unconfirmed balance of an address.'''
|
|
||||||
hashX = self.address_to_hashX(address)
|
|
||||||
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 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 hashX_listunspent(self, hashX):
|
async def hashX_listunspent(self, hashX):
|
||||||
'''Return the list of UTXOs of a script hash, including mempool
|
'''Return the list of UTXOs of a script hash, including mempool
|
||||||
effects.'''
|
effects.'''
|
||||||
@ -731,11 +709,6 @@ class Controller(ServerBase):
|
|||||||
for utxo in utxos
|
for utxo in utxos
|
||||||
if (utxo.tx_hash, utxo.tx_pos) not in spends]
|
if (utxo.tx_hash, utxo.tx_pos) not in spends]
|
||||||
|
|
||||||
async def address_listunspent(self, address):
|
|
||||||
'''Return the list of UTXOs of an address.'''
|
|
||||||
hashX = self.address_to_hashX(address)
|
|
||||||
return await self.hashX_listunspent(hashX)
|
|
||||||
|
|
||||||
def block_get_header(self, height):
|
def block_get_header(self, height):
|
||||||
'''The deserialized header at a given height.
|
'''The deserialized header at a given height.
|
||||||
|
|
||||||
|
|||||||
@ -69,6 +69,7 @@ class SessionBase(ServerSession):
|
|||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.bp = controller.bp
|
self.bp = controller.bp
|
||||||
self.env = controller.env
|
self.env = controller.env
|
||||||
|
self.coin = self.env.coin
|
||||||
self.daemon = self.bp.daemon
|
self.daemon = self.bp.daemon
|
||||||
self.client = 'unknown'
|
self.client = 'unknown'
|
||||||
self.anon_logs = self.env.anon_logs
|
self.anon_logs = self.env.anon_logs
|
||||||
@ -325,11 +326,38 @@ class ElectrumX(SessionBase):
|
|||||||
self.hashX_subs[hashX] = alias
|
self.hashX_subs[hashX] = alias
|
||||||
return await self.address_status(hashX)
|
return await self.address_status(hashX)
|
||||||
|
|
||||||
|
def address_to_hashX(self, address):
|
||||||
|
try:
|
||||||
|
return self.coin.address_to_hashX(address)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
raise RPCError(BAD_REQUEST, f'{address} is not a valid address')
|
||||||
|
|
||||||
|
async def address_get_balance(self, address):
|
||||||
|
'''Return the confirmed and unconfirmed balance of an address.'''
|
||||||
|
hashX = self.address_to_hashX(address)
|
||||||
|
return await self.controller.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.controller.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.controller.unconfirmed_history(hashX)
|
||||||
|
|
||||||
|
async def address_listunspent(self, address):
|
||||||
|
'''Return the list of UTXOs of an address.'''
|
||||||
|
hashX = self.address_to_hashX(address)
|
||||||
|
return await self.controller.hashX_listunspent(hashX)
|
||||||
|
|
||||||
async def address_subscribe(self, address):
|
async def address_subscribe(self, address):
|
||||||
'''Subscribe to an address.
|
'''Subscribe to an address.
|
||||||
|
|
||||||
address: the address to subscribe to'''
|
address: the address to subscribe to'''
|
||||||
hashX = self.controller.address_to_hashX(address)
|
hashX = self.address_to_hashX(address)
|
||||||
return await self.hashX_subscribe(hashX, address)
|
return await self.hashX_subscribe(hashX, address)
|
||||||
|
|
||||||
async def scripthash_get_balance(self, scripthash):
|
async def scripthash_get_balance(self, scripthash):
|
||||||
@ -417,7 +445,7 @@ class ElectrumX(SessionBase):
|
|||||||
|
|
||||||
index: the chunk index'''
|
index: the chunk index'''
|
||||||
index = self.controller.non_negative_integer(index)
|
index = self.controller.non_negative_integer(index)
|
||||||
chunk_size = self.controller.coin.CHUNK_SIZE
|
chunk_size = self.coin.CHUNK_SIZE
|
||||||
start_height = index * chunk_size
|
start_height = index * chunk_size
|
||||||
hex_str, n = self.controller.block_headers(start_height, chunk_size)
|
hex_str, n = self.controller.block_headers(start_height, chunk_size)
|
||||||
return hex_str
|
return hex_str
|
||||||
@ -579,14 +607,10 @@ class ElectrumX(SessionBase):
|
|||||||
else:
|
else:
|
||||||
handlers.update({
|
handlers.update({
|
||||||
'blockchain.headers.subscribe': self.headers_subscribe_False,
|
'blockchain.headers.subscribe': self.headers_subscribe_False,
|
||||||
'blockchain.address.get_balance':
|
'blockchain.address.get_balance': self.address_get_balance,
|
||||||
controller.address_get_balance,
|
'blockchain.address.get_history': self.address_get_history,
|
||||||
'blockchain.address.get_history':
|
'blockchain.address.get_mempool': self.address_get_mempool,
|
||||||
controller.address_get_history,
|
'blockchain.address.listunspent': self.address_listunspent,
|
||||||
'blockchain.address.get_mempool':
|
|
||||||
controller.address_get_mempool,
|
|
||||||
'blockchain.address.listunspent':
|
|
||||||
controller.address_listunspent,
|
|
||||||
'blockchain.address.subscribe': self.address_subscribe,
|
'blockchain.address.subscribe': self.address_subscribe,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -752,7 +776,7 @@ class DashElectrumX(ElectrumX):
|
|||||||
balance = await self.controller.address_get_balance(
|
balance = await self.controller.address_get_balance(
|
||||||
mn_info['payee'])
|
mn_info['payee'])
|
||||||
mn_info['balance'] = (sum(balance.values())
|
mn_info['balance'] = (sum(balance.values())
|
||||||
/ self.controller.coin.VALUE_PER_COIN)
|
/ self.coin.VALUE_PER_COIN)
|
||||||
mn_list.append(mn_info)
|
mn_list.append(mn_info)
|
||||||
self.controller.mn_cache = mn_list
|
self.controller.mn_cache = mn_list
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user