1
- # Copyright (c) 2016-2017 , Neil Booth
1
+ # Copyright (c) 2016-2018 , Neil Booth
2
2
#
3
3
# All rights reserved.
4
4
#
@@ -135,14 +135,13 @@ def __init__(self, *args, **kwargs):
135
135
super ().__init__ (* args , ** kwargs )
136
136
self .subscribe_headers = False
137
137
self .subscribe_headers_raw = False
138
- self .subscribe_height = False
139
138
self .notified_height = None
140
139
self .max_response_size = self .env .max_send
141
140
self .max_subs = self .env .max_session_subs
142
141
self .hashX_subs = {}
143
142
self .mempool_statuses = {}
144
143
self .protocol_version = None
145
- self .set_protocol_handlers ((1 , 0 ))
144
+ self .set_protocol_handlers ((1 , 1 ))
146
145
147
146
def sub_count (self ):
148
147
return len (self .hashX_subs )
@@ -193,9 +192,6 @@ def notify(self, height, touched):
193
192
if self .subscribe_headers :
194
193
args = (self .subscribe_headers_result (height ), )
195
194
self .send_notification ('blockchain.headers.subscribe' , args )
196
- if self .subscribe_height :
197
- args = (height , )
198
- self .send_notification ('blockchain.numblocks.subscribe' , args )
199
195
200
196
our_touched = touched .intersection (self .hashX_subs )
201
197
if our_touched or (height_changed and self .mempool_statuses ):
@@ -227,11 +223,6 @@ def headers_subscribe(self, raw=False):
227
223
self .notified_height = self .height ()
228
224
return self .subscribe_headers_result (self .height ())
229
225
230
- def numblocks_subscribe (self ):
231
- '''Subscribe to get height of new blocks.'''
232
- self .subscribe_height = True
233
- return self .height ()
234
-
235
226
async def add_peer (self , features ):
236
227
'''Add a peer (but only if the peer resolves to the source).'''
237
228
peer_mgr = self .controller .peer_mgr
@@ -393,8 +384,7 @@ def server_version(self, client_name=None, protocol_version=None):
393
384
# that protocol version in unsupported.
394
385
ptuple = self .controller .protocol_tuple (protocol_version )
395
386
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 :
398
388
self .logger .info ('unsupported protocol version request {}'
399
389
.format (protocol_version ))
400
390
self .close_after_send = True
@@ -403,11 +393,7 @@ def server_version(self, client_name=None, protocol_version=None):
403
393
404
394
self .set_protocol_handlers (ptuple )
405
395
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 )
411
397
412
398
async def transaction_broadcast (self , raw_tx ):
413
399
'''Broadcast a raw transaction to the network.
@@ -427,27 +413,6 @@ async def transaction_broadcast(self, raw_tx):
427
413
raise RPCError (BAD_REQUEST , 'the transaction was rejected by '
428
414
f'network rules.\n \n { message } \n [{ raw_tx } ]' )
429
415
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
-
451
416
def set_protocol_handlers (self , ptuple ):
452
417
protocol_version = '.' .join (str (part ) for part in ptuple )
453
418
if protocol_version == self .protocol_version :
@@ -466,6 +431,17 @@ def set_protocol_handlers(self, ptuple):
466
431
'blockchain.estimatefee' : controller .estimatefee ,
467
432
'blockchain.headers.subscribe' : self .headers_subscribe ,
468
433
'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 ,
469
445
'blockchain.transaction.get_merkle' :
470
446
controller .transaction_get_merkle ,
471
447
'server.add_peer' : self .add_peer ,
@@ -476,32 +452,6 @@ def set_protocol_handlers(self, ptuple):
476
452
'server.version' : self .server_version ,
477
453
}
478
454
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
-
505
455
if ptuple >= (1 , 2 ):
506
456
# New handler as of 1.2
507
457
handlers .update ({
@@ -541,10 +491,9 @@ def __init__(self, *args, **kwargs):
541
491
542
492
def set_protocol_handlers (self , ptuple ):
543
493
super ().set_protocol_handlers (ptuple )
544
- mna_broadcast = (self .masternode_announce_broadcast if ptuple >= (1 , 1 )
545
- else self .masternode_announce_broadcast_1_0 )
546
494
self .electrumx_handlers .update ({
547
- 'masternode.announce.broadcast' : mna_broadcast ,
495
+ 'masternode.announce.broadcast' :
496
+ self .masternode_announce_broadcast ,
548
497
'masternode.subscribe' : self .masternode_subscribe ,
549
498
})
550
499
@@ -571,15 +520,6 @@ async def masternode_announce_broadcast(self, signmnb):
571
520
raise RPCError (BAD_REQUEST , 'the masternode broadcast was '
572
521
f'rejected.\n \n { message } \n [{ signmnb } ]' )
573
522
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
-
583
523
async def masternode_subscribe (self , vin ):
584
524
'''Returns the status of masternode.'''
585
525
result = await self .daemon .masternode_list (['status' , vin ])
0 commit comments