Skip to content

Commit c35ac6d

Browse files
author
Neil Booth
committed
Deprecate blockchain.block.get_header as of protocol 1.3
Use new blockchain.block.header instead.
1 parent 71b3d30 commit c35ac6d

File tree

4 files changed

+87
-35
lines changed

4 files changed

+87
-35
lines changed

docs/protocol-changes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,17 @@ Deprecated methods
8282
* :func:`blockchain.address.subscribe`. Switch to
8383
:func:`blockchain.scripthash.subscribe`.
8484
* :func:`blockchain.headers.subscribe` with *raw* other than :const:`True`.
85+
86+
Version 1.3
87+
===========
88+
89+
New methods
90+
-----------
91+
92+
* :func:`blockchain.block.header`
93+
94+
Deprecated methods
95+
------------------
96+
97+
* :func:`blockchain.block.get_header`. Switch to
98+
:func:`blockchain.block.header`.

docs/protocol-methods.rst

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
Protocol Methods
2-
================
1+
==================
2+
Protocol Methods
3+
==================
34

45
blockchain.address.get_balance
5-
------------------------------
6+
==============================
67

78
Return the confirmed and unconfirmed balances of a bitcoin address.
89

@@ -20,7 +21,7 @@ Return the confirmed and unconfirmed balances of a bitcoin address.
2021
See :func:`blockchain.scripthash.get_balance`.
2122

2223
blockchain.address.get_history
23-
------------------------------
24+
==============================
2425

2526
Return the confirmed and unconfirmed history of a bitcoin address.
2627

@@ -38,7 +39,7 @@ Return the confirmed and unconfirmed history of a bitcoin address.
3839
As for :func:`blockchain.scripthash.get_history`.
3940

4041
blockchain.address.get_mempool
41-
------------------------------
42+
==============================
4243

4344
Return the unconfirmed transactions of a bitcoin address.
4445

@@ -56,7 +57,7 @@ Return the unconfirmed transactions of a bitcoin address.
5657
As for :func:`blockchain.scripthash.get_mempool`.
5758

5859
blockchain.address.listunspent
59-
------------------------------
60+
==============================
6061

6162
Return an ordered list of UTXOs sent to a bitcoin address.
6263

@@ -74,7 +75,7 @@ Return an ordered list of UTXOs sent to a bitcoin address.
7475
As for :func:`blockchain.scripthash.listunspent`.
7576

7677
blockchain.address.subscribe
77-
----------------------------
78+
============================
7879

7980
Subscribe to a bitcoin address.
8081

@@ -100,14 +101,15 @@ Subscribe to a bitcoin address.
100101
.. function:: blockchain.address.subscribe(address, status)
101102

102103
blockchain.block.get_header
103-
---------------------------
104+
===========================
104105

105106
Return the :ref:`deserialized header <deserialized header>` of the
106107
block at the given height.
107108

108109
**Signature**
109110

110111
.. function:: blockchain.block.get_header(height)
112+
.. deprecated:: 1.3
111113

112114
*height*
113115

@@ -132,7 +134,7 @@ block at the given height.
132134
}
133135

134136
blockchain.block.get_chunk
135-
--------------------------
137+
==========================
136138

137139
Return a concatenated chunk of block headers from the main chain.
138140
Typically, a chunk consists of a fixed number of block headers over
@@ -161,8 +163,31 @@ bandwidth-intensive request.
161163
implied starting height will be returned; this may range from zero
162164
to the coin-specific chunk size.
163165

166+
blockchain.block.header
167+
=======================
168+
169+
Return the block header at the given height.
170+
171+
**Signature**
172+
173+
.. function:: blockchain.block.header(height)
174+
175+
*height*
176+
177+
The height of the block, an integer.
178+
179+
**Result**
180+
181+
The raw block header as a hexadecimal string.
182+
183+
**Example Result**
184+
185+
::
186+
187+
"0100000085144a84488ea88d221c8bd6c059da090e88f8a2c99690ee55dbba4e00000000e11c48fecdd9e72510ca84f023370c9a38bf91ac5cae88019bee94d24528526344c36649ffff001d1d03e477"
188+
164189
blockchain.block.headers
165-
------------------------
190+
========================
166191

167192
Return a concatenated chunk of block headers from the main chain.
168193

@@ -211,7 +236,7 @@ Return a concatenated chunk of block headers from the main chain.
211236
}
212237

213238
blockchain.estimatefee
214-
----------------------
239+
======================
215240

216241
Return the estimated transaction fee per kilobyte for a transaction to
217242
be confirmed within a certain number of blocks.
@@ -237,7 +262,7 @@ be confirmed within a certain number of blocks.
237262
0.00101079
238263

239264
blockchain.headers.subscribe
240-
----------------------------
265+
============================
241266

242267
Subscribe to receive block headers when a new block is found.
243268

@@ -313,7 +338,7 @@ Subscribe to receive block headers when a new block is found.
313338

314339

315340
blockchain.numblocks.subscribe
316-
------------------------------
341+
==============================
317342

318343
Subscribe to receive the block height when a new block is found.
319344

@@ -335,7 +360,7 @@ Subscribe to receive the block height when a new block is found.
335360
.. function:: blockchain.numblocks.subscribe(height)
336361

337362
blockchain.relayfee
338-
-------------------
363+
===================
339364

340365
Return the minimum fee a low-priority transaction must pay in order to
341366
be accepted to the daemon's memory pool.
@@ -360,7 +385,7 @@ be accepted to the daemon's memory pool.
360385
0.0
361386

362387
blockchain.scripthash.get_balance
363-
---------------------------------
388+
=================================
364389

365390
Return the confirmed and unconfirmed balances of a :ref:`script hash
366391
<script hashes>`.
@@ -389,7 +414,7 @@ Return the confirmed and unconfirmed balances of a :ref:`script hash
389414
}
390415

391416
blockchain.scripthash.get_history
392-
---------------------------------
417+
=================================
393418

394419
Return the confirmed and unconfirmed history of a :ref:`script hash
395420
<script hashes>`.
@@ -447,7 +472,7 @@ Return the confirmed and unconfirmed history of a :ref:`script hash
447472
]
448473

449474
blockchain.scripthash.get_mempool
450-
---------------------------------
475+
=================================
451476

452477
Return the unconfirmed transactions of a :ref:`script hash <script
453478
hashes>`.
@@ -491,7 +516,7 @@ hashes>`.
491516
]
492517

493518
blockchain.scripthash.listunspent
494-
---------------------------------
519+
=================================
495520

496521
Return an ordered list of UTXOs sent to a script hash.
497522

@@ -550,7 +575,7 @@ Return an ordered list of UTXOs sent to a script hash.
550575
]
551576

552577
blockchain.scripthash.subscribe
553-
-------------------------------
578+
===============================
554579

555580
Subscribe to a script hash.
556581

@@ -576,7 +601,7 @@ Subscribe to a script hash.
576601
.. function:: blockchain.scripthash.subscribe(scripthash, status)
577602

578603
blockchain.transaction.broadcast
579-
--------------------------------
604+
================================
580605

581606
Broadcast a transaction to the network.
582607

@@ -614,7 +639,7 @@ Protocol version 1.0 returning an error as the result:
614639
"258: txn-mempool-conflict"
615640

616641
blockchain.transaction.get
617-
--------------------------
642+
==========================
618643

619644
Return a raw transaction.
620645

@@ -690,7 +715,7 @@ When *verbose* is :const:`True`::
690715
"value": 0.1360904}]}
691716

692717
blockchain.transaction.get_merkle
693-
---------------------------------
718+
=================================
694719

695720
Return the markle branch to a confirmed transaction given its hash
696721
and height.
@@ -750,7 +775,7 @@ and height.
750775
}
751776

752777
blockchain.utxo.get_address
753-
---------------------------
778+
===========================
754779

755780
Return the address paid to by a UTXO.
756781

@@ -776,7 +801,7 @@ Return the address paid to by a UTXO.
776801
spent :const:`null` *may* be returned.
777802

778803
mempool.get_fee_histogram
779-
-------------------------
804+
=========================
780805

781806
Return a histogram of the fee rates paid by transactions in the memory
782807
pool, weighted by transaction size.
@@ -807,7 +832,7 @@ pool, weighted by transaction size.
807832

808833

809834
server.add_peer
810-
---------------
835+
===============
811836

812837
A newly-started server uses this call to get itself into other servers'
813838
peers lists. It sould not be used by wallet clients.
@@ -831,7 +856,7 @@ peers lists. It sould not be used by wallet clients.
831856

832857

833858
server.banner
834-
-------------
859+
=============
835860

836861
Return a banner to be shown in the Electrum console.
837862

@@ -851,7 +876,7 @@ Return a banner to be shown in the Electrum console.
851876

852877

853878
server.donation_address
854-
-----------------------
879+
=======================
855880

856881
Return a server donation address.
857882

@@ -871,7 +896,7 @@ Return a server donation address.
871896

872897

873898
server.features
874-
---------------
899+
===============
875900

876901
Return a list of features and services supported by the server.
877902

@@ -955,7 +980,7 @@ Return a list of features and services supported by the server.
955980

956981

957982
server.peers.subscribe
958-
----------------------
983+
======================
959984

960985
Return a list of peer servers. Despite the name this is not a
961986
subscription and the server must send no notifications.
@@ -983,7 +1008,7 @@ subscription and the server must send no notifications.
9831008
missing then the server does not support that transport.
9841009

9851010
server.ping
986-
-----------
1011+
===========
9871012

9881013
Ping the server to ensure it is responding, and to keep the session
9891014
alive. The server may disconnect clients that have sent no requests
@@ -999,7 +1024,7 @@ for roughly 10 minutes.
9991024
Returns :const:`null`.
10001025

10011026
server.version
1002-
--------------
1027+
==============
10031028

10041029
Identify the client to the server and negotiate the protocol version.
10051030

@@ -1057,7 +1082,7 @@ Identify the client to the server and negotiate the protocol version.
10571082
"ElectrumX 1.2.1"
10581083

10591084
masternode.announce.broadcast
1060-
-----------------------------
1085+
=============================
10611086

10621087
Pass through the masternode announce message to be broadcast by the daemon.
10631088

@@ -1084,7 +1109,7 @@ Whenever a masternode comes online or a client is syncing, they will send this m
10841109
True
10851110

10861111
masternode.subscribe
1087-
--------------------
1112+
====================
10881113

10891114
Returns the status of masternode.
10901115

@@ -1115,7 +1140,7 @@ Returns the status of masternode.
11151140
{'method': 'masternode.subscribe', u'jsonrpc': u'2.0', u'result': u'ENABLED', 'params': ['8c59133e714797650cf69043d05e409bbf45670eed7c4e4a386e52c46f1b5e24-0'], u'id': 19}
11161141

11171142
masternode.list
1118-
---------------
1143+
===============
11191144

11201145
Returns the list of masternodes.
11211146

electrumx/server/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Controller(ServerBase):
5050

5151
CATCHING_UP, LISTENING, PAUSED, SHUTTING_DOWN = range(4)
5252
PROTOCOL_MIN = '1.1'
53-
PROTOCOL_MAX = '1.2'
53+
PROTOCOL_MAX = '1.3'
5454
AIORPCX_MIN = (0, 5, 6)
5555
VERSION = VERSION
5656

electrumx/server/session.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ async def scripthash_subscribe(self, scripthash):
284284
hashX = self.controller.scripthash_to_hashX(scripthash)
285285
return await self.hashX_subscribe(hashX, scripthash)
286286

287+
def block_header(self, height):
288+
'''Return a raw block header as a hexadecimal string.
289+
290+
height: the header's height'''
291+
height = self.controller.non_negative_integer(height)
292+
raw_header = self.controller.raw_header(height)
293+
return raw_header.hex()
294+
287295
def block_headers(self, start_height, count):
288296
'''Return count concatenated block headers as hex for the main chain;
289297
starting at start_height.
@@ -462,6 +470,11 @@ def set_protocol_handlers(self, ptuple):
462470
'server.ping': self.ping,
463471
})
464472

473+
if ptuple >= (1, 3):
474+
handlers.update({
475+
'blockchain.block.header': self.block_header,
476+
})
477+
465478
self.electrumx_handlers = handlers
466479

467480
def request_handler(self, method):

0 commit comments

Comments
 (0)