Skip to content

Commit 7d9ffbb

Browse files
author
Neil Booth
committed
Minimum supported protocol version is 1.1
1 parent 379fef1 commit 7d9ffbb

File tree

2 files changed

+18
-107
lines changed

2 files changed

+18
-107
lines changed

server/controller.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Controller(ServerBase):
4747
'''
4848

4949
CATCHING_UP, LISTENING, PAUSED, SHUTTING_DOWN = range(4)
50-
PROTOCOL_MIN = '1.0'
50+
PROTOCOL_MIN = '1.1'
5151
PROTOCOL_MAX = '1.2'
5252
VERSION = VERSION
5353

@@ -848,15 +848,6 @@ async def transaction_get(self, tx_hash, verbose=False):
848848
self.assert_tx_hash(tx_hash)
849849
return await self.daemon_request('getrawtransaction', tx_hash, verbose)
850850

851-
async def transaction_get_1_0(self, tx_hash, height=None):
852-
'''Return the serialized raw transaction given its hash
853-
854-
tx_hash: the transaction hash as a hexadecimal string
855-
height: ignored, do not use
856-
'''
857-
# For some reason Electrum protocol 1.0 passes a height.
858-
return await self.transaction_get(tx_hash)
859-
860851
async def transaction_get_merkle(self, tx_hash, height):
861852
'''Return the markle tree to a confirmed transaction given its hash
862853
and height.
@@ -867,23 +858,3 @@ async def transaction_get_merkle(self, tx_hash, height):
867858
self.assert_tx_hash(tx_hash)
868859
height = self.non_negative_integer(height)
869860
return await self.tx_merkle(tx_hash, height)
870-
871-
async def utxo_get_address(self, tx_hash, index):
872-
'''Returns the address sent to in a UTXO, or null if the UTXO
873-
cannot be found.
874-
875-
tx_hash: the transaction hash of the UTXO
876-
index: the index of the UTXO in the transaction'''
877-
# Used only for electrum client command-line requests. We no
878-
# longer index by address, so need to request the raw
879-
# transaction. So it works for any TXO not just UTXOs.
880-
self.assert_tx_hash(tx_hash)
881-
index = self.non_negative_integer(index)
882-
raw_tx = await self.daemon_request('getrawtransaction', tx_hash)
883-
if not raw_tx:
884-
return None
885-
raw_tx = util.hex_to_bytes(raw_tx)
886-
tx = self.coin.DESERIALIZER(raw_tx).read_tx()
887-
if index >= len(tx.outputs):
888-
return None
889-
return self.coin.address_from_script(tx.outputs[index].pk_script)

server/session.py

Lines changed: 17 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016-2017, Neil Booth
1+
# Copyright (c) 2016-2018, Neil Booth
22
#
33
# All rights reserved.
44
#
@@ -135,14 +135,13 @@ def __init__(self, *args, **kwargs):
135135
super().__init__(*args, **kwargs)
136136
self.subscribe_headers = False
137137
self.subscribe_headers_raw = False
138-
self.subscribe_height = False
139138
self.notified_height = None
140139
self.max_response_size = self.env.max_send
141140
self.max_subs = self.env.max_session_subs
142141
self.hashX_subs = {}
143142
self.mempool_statuses = {}
144143
self.protocol_version = None
145-
self.set_protocol_handlers((1, 0))
144+
self.set_protocol_handlers((1, 1))
146145

147146
def sub_count(self):
148147
return len(self.hashX_subs)
@@ -193,9 +192,6 @@ def notify(self, height, touched):
193192
if self.subscribe_headers:
194193
args = (self.subscribe_headers_result(height), )
195194
self.send_notification('blockchain.headers.subscribe', args)
196-
if self.subscribe_height:
197-
args = (height, )
198-
self.send_notification('blockchain.numblocks.subscribe', args)
199195

200196
our_touched = touched.intersection(self.hashX_subs)
201197
if our_touched or (height_changed and self.mempool_statuses):
@@ -227,11 +223,6 @@ def headers_subscribe(self, raw=False):
227223
self.notified_height = self.height()
228224
return self.subscribe_headers_result(self.height())
229225

230-
def numblocks_subscribe(self):
231-
'''Subscribe to get height of new blocks.'''
232-
self.subscribe_height = True
233-
return self.height()
234-
235226
async def add_peer(self, features):
236227
'''Add a peer (but only if the peer resolves to the source).'''
237228
peer_mgr = self.controller.peer_mgr
@@ -393,8 +384,7 @@ def server_version(self, client_name=None, protocol_version=None):
393384
# that protocol version in unsupported.
394385
ptuple = self.controller.protocol_tuple(protocol_version)
395386

396-
# From protocol version 1.1, protocol_version cannot be omitted
397-
if ptuple is None or (ptuple >= (1, 1) and protocol_version is None):
387+
if ptuple is None:
398388
self.logger.info('unsupported protocol version request {}'
399389
.format(protocol_version))
400390
self.close_after_send = True
@@ -403,11 +393,7 @@ def server_version(self, client_name=None, protocol_version=None):
403393

404394
self.set_protocol_handlers(ptuple)
405395

406-
# The return value depends on the protocol version
407-
if ptuple < (1, 1):
408-
return self.controller.VERSION
409-
else:
410-
return (self.controller.VERSION, self.protocol_version)
396+
return (self.controller.VERSION, self.protocol_version)
411397

412398
async def transaction_broadcast(self, raw_tx):
413399
'''Broadcast a raw transaction to the network.
@@ -427,27 +413,6 @@ async def transaction_broadcast(self, raw_tx):
427413
raise RPCError(BAD_REQUEST, 'the transaction was rejected by '
428414
f'network rules.\n\n{message}\n[{raw_tx}]')
429415

430-
async def transaction_broadcast_1_0(self, raw_tx):
431-
'''Broadcast a raw transaction to the network.
432-
433-
raw_tx: the raw transaction as a hexadecimal string'''
434-
# An ugly API: current Electrum clients only pass the raw
435-
# transaction in hex and expect error messages to be returned in
436-
# the result field. And the server shouldn't be doing the client's
437-
# user interface job here.
438-
try:
439-
return await self.transaction_broadcast(raw_tx)
440-
except RPCError as e:
441-
message = e.message
442-
if 'non-mandatory-script-verify-flag' in message:
443-
message = (
444-
'Your client produced a transaction that is not accepted '
445-
'by the network any more. Please upgrade to Electrum '
446-
'2.5.1 or newer.'
447-
)
448-
449-
return message
450-
451416
def set_protocol_handlers(self, ptuple):
452417
protocol_version = '.'.join(str(part) for part in ptuple)
453418
if protocol_version == self.protocol_version:
@@ -466,6 +431,17 @@ def set_protocol_handlers(self, ptuple):
466431
'blockchain.estimatefee': controller.estimatefee,
467432
'blockchain.headers.subscribe': self.headers_subscribe,
468433
'blockchain.relayfee': controller.relayfee,
434+
'blockchain.scripthash.get_balance':
435+
controller.scripthash_get_balance,
436+
'blockchain.scripthash.get_history':
437+
controller.scripthash_get_history,
438+
'blockchain.scripthash.get_mempool':
439+
controller.scripthash_get_mempool,
440+
'blockchain.scripthash.listunspent':
441+
controller.scripthash_listunspent,
442+
'blockchain.scripthash.subscribe': self.scripthash_subscribe,
443+
'blockchain.transaction.broadcast': self.transaction_broadcast,
444+
'blockchain.transaction.get': controller.transaction_get,
469445
'blockchain.transaction.get_merkle':
470446
controller.transaction_get_merkle,
471447
'server.add_peer': self.add_peer,
@@ -476,32 +452,6 @@ def set_protocol_handlers(self, ptuple):
476452
'server.version': self.server_version,
477453
}
478454

479-
if ptuple < (1, 1):
480-
# Methods or semantics unique to 1.0 and earlier protocols
481-
handlers.update({
482-
'blockchain.numblocks.subscribe': self.numblocks_subscribe,
483-
'blockchain.utxo.get_address': controller.utxo_get_address,
484-
'blockchain.transaction.broadcast':
485-
self.transaction_broadcast_1_0,
486-
'blockchain.transaction.get': controller.transaction_get_1_0,
487-
})
488-
489-
if ptuple >= (1, 1):
490-
# New handlers as of 1.1, or different semantics
491-
handlers.update({
492-
'blockchain.scripthash.get_balance':
493-
controller.scripthash_get_balance,
494-
'blockchain.scripthash.get_history':
495-
controller.scripthash_get_history,
496-
'blockchain.scripthash.get_mempool':
497-
controller.scripthash_get_mempool,
498-
'blockchain.scripthash.listunspent':
499-
controller.scripthash_listunspent,
500-
'blockchain.scripthash.subscribe': self.scripthash_subscribe,
501-
'blockchain.transaction.broadcast': self.transaction_broadcast,
502-
'blockchain.transaction.get': controller.transaction_get,
503-
})
504-
505455
if ptuple >= (1, 2):
506456
# New handler as of 1.2
507457
handlers.update({
@@ -541,10 +491,9 @@ def __init__(self, *args, **kwargs):
541491

542492
def set_protocol_handlers(self, ptuple):
543493
super().set_protocol_handlers(ptuple)
544-
mna_broadcast = (self.masternode_announce_broadcast if ptuple >= (1, 1)
545-
else self.masternode_announce_broadcast_1_0)
546494
self.electrumx_handlers.update({
547-
'masternode.announce.broadcast': mna_broadcast,
495+
'masternode.announce.broadcast':
496+
self.masternode_announce_broadcast,
548497
'masternode.subscribe': self.masternode_subscribe,
549498
})
550499

@@ -571,15 +520,6 @@ async def masternode_announce_broadcast(self, signmnb):
571520
raise RPCError(BAD_REQUEST, 'the masternode broadcast was '
572521
f'rejected.\n\n{message}\n[{signmnb}]')
573522

574-
async def masternode_announce_broadcast_1_0(self, signmnb):
575-
'''Pass through the masternode announce message to be broadcast
576-
by the daemon.'''
577-
# An ugly API, like the old Electrum transaction broadcast API
578-
try:
579-
return await self.masternode_announce_broadcast(signmnb)
580-
except RPCError as e:
581-
return e.message
582-
583523
async def masternode_subscribe(self, vin):
584524
'''Returns the status of masternode.'''
585525
result = await self.daemon.masternode_list(['status', vin])

0 commit comments

Comments
 (0)