Skip to content

Commit ea9d7bb

Browse files
author
Eunsoo Park
committed
Add APIs for BTP
- get_data_by_hash for icx_getDataByHash - get_block_header_by_height for icx_getBlockHeaderByHeight - get_votes_by_height for icx_getVotesByHeight - get_proof_for_result for icx_getProofForResult - get_proof_for_events for icx_getProofForEvents
1 parent 8a545dc commit ea9d7bb

File tree

1 file changed

+77
-2
lines changed

1 file changed

+77
-2
lines changed

iconsdk/icon_service.py

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
16-
from typing import Union, Tuple, Any
15+
from typing import Union, Tuple, Any, List
1716

1817
from iconsdk.builder.call_builder import Call
1918
from iconsdk.builder.transaction_builder import Transaction
@@ -337,3 +336,79 @@ def get_trace(self, tx_hash: str) -> dict:
337336
params = {'txHash': tx_hash}
338337
result = self.__provider.make_request('debug_getTrace', params)
339338
return result
339+
340+
def get_data_by_hash(self, _hash: str) -> str:
341+
"""
342+
Returns data by hash.
343+
It can be used to retrieve data based on the hash algorithm (SHA3-256).
344+
Following data can be retrieved by a hash.
345+
- BlockHeader with the hash of the block
346+
- Validators with BlockHeader.NextValidatorsHash
347+
- Votes with BlockHeader.VotesHash
348+
- etc…
349+
Delegates to icx_getDataByHash RPC method.
350+
https://github.com/icon-project/goloop/blob/master/doc/btp_extension.md#icx_getdatabyhash
351+
352+
:param _hash: The hash value of the data to retrieve
353+
:return: A data object
354+
"""
355+
params = {'hash': _hash}
356+
return self.__provider.make_request('icx_getDataByHash', params)
357+
358+
def get_block_header_by_height(self, height: int) -> str:
359+
"""
360+
Returns block header for specified height.
361+
Delegates to icx_getBlockHeaderByHeight RPC method.
362+
https://github.com/icon-project/goloop/blob/master/doc/btp_extension.md#icx_getblockheaderbyheight
363+
364+
:param height: The height of the block
365+
:return: A block header object
366+
"""
367+
params = {'height': hex(height)}
368+
return self.__provider.make_request('icx_getBlockHeaderByHeight', params)
369+
370+
def get_votes_by_height(self, height: int) -> str:
371+
"""
372+
Returns votes for the block specified by height.
373+
Delegates to icx_getVotesByHeight RPC method.
374+
https://github.com/icon-project/goloop/blob/master/doc/btp_extension.md#icx_getvotesbyheight
375+
376+
:param height: The height of the block for votes
377+
:return: A votes object
378+
"""
379+
params = {'height': hex(height)}
380+
return self.__provider.make_request('icx_getVotesByHeight', params)
381+
382+
def get_proof_for_result(self, _hash: str, index: int) -> str:
383+
"""
384+
Returns proof for the receipt. Proof, itself, may include the receipt.
385+
Delegates to icx_getProofForResult RPC method.
386+
https://github.com/icon-project/goloop/blob/master/doc/btp_extension.md#icx_getproofforresult
387+
388+
:param _hash: The hash value of the block including the result
389+
:param index: Index of the receipt in the block. 0 for the first
390+
:return: A proof object
391+
"""
392+
params = {
393+
'hash': _hash,
394+
'index': hex(index),
395+
}
396+
return self.__provider.make_request('icx_getProofForResult', params)
397+
398+
def get_proof_for_events(self, _hash: str, index: int, events: List[str] = []) -> str:
399+
"""
400+
Returns proof for the receipt and the events in it. The proof may include the data itself.
401+
Delegates to icx_getProofForEvents RPC method.
402+
https://github.com/icon-project/goloop/blob/master/doc/btp_extension.md#icx_getproofforevents
403+
404+
:param _hash: The hash value of the block including the result
405+
:param index: Index of the receipt in the block. 0 for the first
406+
:param events: List of indexes of the events in the receipt
407+
:return: A proof object
408+
"""
409+
params = {
410+
'hash': _hash,
411+
'index': hex(index),
412+
'events': events,
413+
}
414+
return self.__provider.make_request('icx_getProofForEvents', params)

0 commit comments

Comments
 (0)