Improved handler handling
- move server.donation_address to the session from controller - session controls handler map, no longer lives partly on controller
This commit is contained in:
parent
a978ca6df7
commit
2a955a922a
@ -94,19 +94,6 @@ class Controller(util.LoggedClass):
|
||||
cmds = ('add_peer daemon_url disconnect getinfo groups log peers reorg '
|
||||
'sessions stop'.split())
|
||||
self.rpc_handlers = {cmd: getattr(self, 'rpc_' + cmd) for cmd in cmds}
|
||||
# Set up the ElectrumX request handlers
|
||||
rpcs = [
|
||||
('blockchain',
|
||||
'address.get_balance address.get_history address.get_mempool '
|
||||
'address.get_proof address.listunspent '
|
||||
'block.get_header estimatefee relayfee '
|
||||
'transaction.get_merkle utxo.get_address'),
|
||||
('server', 'donation_address'),
|
||||
]
|
||||
self.electrumx_handlers = {'.'.join([prefix, suffix]):
|
||||
getattr(self, suffix.replace('.', '_'))
|
||||
for prefix, suffixes in rpcs
|
||||
for suffix in suffixes.split()}
|
||||
|
||||
async def mempool_transactions(self, hashX):
|
||||
'''Generate (hex_hash, tx_fee, unconfirmed) tuples for mempool
|
||||
@ -917,12 +904,6 @@ class Controller(util.LoggedClass):
|
||||
return None
|
||||
return self.coin.address_from_script(tx.outputs[index].pk_script)
|
||||
|
||||
# Client RPC "server" command handlers
|
||||
|
||||
def donation_address(self):
|
||||
'''Return the donation address as a string, empty if there is none.'''
|
||||
return self.env.donation_address
|
||||
|
||||
# Signal, exception handlers.
|
||||
|
||||
def on_signal(self, signame):
|
||||
|
||||
@ -289,6 +289,10 @@ class ElectrumX(SessionBase):
|
||||
banner = banner.replace(*pair)
|
||||
return banner
|
||||
|
||||
def donation_address(self):
|
||||
'''Return the donation address as a string, empty if there is none.'''
|
||||
return self.env.donation_address
|
||||
|
||||
async def banner(self):
|
||||
'''Return the server banner text.'''
|
||||
banner = 'Welcome to Electrum!'
|
||||
@ -386,34 +390,42 @@ class ElectrumX(SessionBase):
|
||||
if protocol_version == self.protocol_version:
|
||||
return
|
||||
self.protocol_version = protocol_version
|
||||
|
||||
controller = self.controller
|
||||
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.block.get_header': controller.block_get_header,
|
||||
'blockchain.estimatefee': controller.estimatefee,
|
||||
'blockchain.headers.subscribe': self.headers_subscribe,
|
||||
'blockchain.numblocks.subscribe': self.numblocks_subscribe,
|
||||
'blockchain.transaction.broadcast': self.transaction_broadcast_1_0,
|
||||
'blockchain.transaction.get': controller.transaction_get_1_0,
|
||||
'blockchain.relayfee': controller.relayfee,
|
||||
'blockchain.transaction.get_merkle':
|
||||
controller.transaction_get_merkle,
|
||||
'server.add_peer': self.add_peer,
|
||||
'server.banner': self.banner,
|
||||
'server.donation_address': self.donation_address,
|
||||
'server.features': self.server_features,
|
||||
'server.peers.subscribe': self.peers_subscribe,
|
||||
'server.version': self.server_version,
|
||||
}
|
||||
|
||||
handlers.update(controller.electrumx_handlers)
|
||||
if ptuple < (1, 1):
|
||||
# Methods or semantics unique to 1.0 and earlier protocols
|
||||
handlers.update({
|
||||
'blockcahin.address.get_proof': controller.address_get_proof,
|
||||
'blockchain.numblocks.subscribe': self.numblocks_subscribe,
|
||||
'blockchain.utxo.get_address': controller.utxo_get_address,
|
||||
'blockchain.transaction.broadcast':
|
||||
self.transaction_broadcast_1_0,
|
||||
'blockchain.transaction.get': controller.transaction_get_1_0,
|
||||
})
|
||||
|
||||
if ptuple >= (1, 1):
|
||||
# Remove deprecated methods
|
||||
del handlers['blockchain.address.get_proof']
|
||||
del handlers['blockchain.numblocks.subscribe']
|
||||
del handlers['blockchain.utxo.get_address']
|
||||
# Add new handlers
|
||||
# New handlers as of 1.1, or different semantics
|
||||
handlers.update({
|
||||
'blockchain.scripthash.get_balance':
|
||||
controller.scripthash_get_balance,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user