@ -1,17 +1,20 @@
"""
Interact with the Harmony blockchain to fetch
blocks , headers , transaction pool , node status , etc .
"""
# pylint: disable=too-many-lines
from . rpc . request import rpc_request
from . rpc . request import rpc_request
from . exceptions import InvalidRPCReplyError
from . exceptions import InvalidRPCReplyError
_default_endpoint = " http://localhost:9500 "
from . constants import DEFAULT_ENDPOINT , DEFAULT_TIMEOUT
_default_timeout = 30
#############################
#############################
# Node / network level RPCs #
# Node / network level RPCs #
#############################
#############################
def get_bad_blocks ( endpoint = _default_endpoint , timeout = _default_timeout ) - > list :
def get_bad_blocks ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > list :
"""
""" [WIP] Get list of bad blocks in memory of specific node Known issues
[ WIP ] Get list of bad blocks in memory of specific node
with RPC not returning correctly .
Known issues with RPC not returning correctly
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -36,13 +39,12 @@ def get_bad_blocks(endpoint=_default_endpoint, timeout=_default_timeout) -> list
method = " hmyv2_getCurrentBadBlocks "
method = " hmyv2_getCurrentBadBlocks "
try :
try :
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def chain_id ( endpoint = _default_endpoint , timeout = _default_timeout ) - > dict :
def chain_id ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > dict :
"""
""" Chain id of the chain.
Chain id of the chain
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -68,13 +70,12 @@ def chain_id(endpoint=_default_endpoint, timeout=_default_timeout) -> dict:
try :
try :
data = rpc_request ( method , endpoint = endpoint , timeout = timeout )
data = rpc_request ( method , endpoint = endpoint , timeout = timeout )
return data [ " result " ]
return data [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_node_metadata ( endpoint = _default_endpoint , timeout = _default_timeout ) - > dict :
def get_node_metadata ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > dict :
"""
""" Get config for the node.
Get config for the node
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -89,25 +90,8 @@ def get_node_metadata(endpoint=_default_endpoint, timeout=_default_timeout) -> d
blskey : : obj : ` list ` of BLS keys on the node
blskey : : obj : ` list ` of BLS keys on the node
version : : obj : ` str ` representing the Harmony binary version
version : : obj : ` str ` representing the Harmony binary version
network : : obj : ` str ` the Network name that the node is on ( Mainnet or Testnet )
network : : obj : ` str ` the Network name that the node is on ( Mainnet or Testnet )
chain - config : : obj : ` dict ` with the following keys ( more are added over time ) :
chain - config : : obj : ` dict ` with the hard fork epochs list , and ` chain - id `
chain - id : : obj : ` int ` Chain ID of the network
both as : obj : ` int `
cross - tx - epoch : : obj : ` int ` Epoch at which cross shard transactions were enabled
cross - link - epoch : : obj : ` int ` Epoch at which cross links were enabled
staking - epoch : : obj : ` int ` Epoch at which staking was enabled
prestaking - epoch : : obj : ` int ` Epoch at which staking features without election were allowed
quick - unlock - epoch : : obj : ` int ` Epoch at which undelegations unlocked in one epoch
eip155 - epoch : : obj : ` int ` Epoch at with EIP155 was enabled
s3 - epoch : : obj : ` int ` Epoch at which Mainnet V0 was launched
receipt - log - epoch : : obj : ` int ` Epoch at which receipt logs were enabled
eth - compatible - chain - id : : obj : ` int ` EVM network compatible chain ID
eth - compatible - epoch : : obj : ` int ` Epoch at which EVM compatibility was launched
eth - compatible - shard - 0 - chain - id : : obj : ` int ` EVM network compatible chain ID on shard 0
five - seconds - epoch : : obj : ` int ` Epoch at which five second finality was enabled and block rewards adjusted to 17.5 ONE / block
istanbul - epoch : : obj : ` int ` Epoch at which Ethereum ' s Istanbul upgrade was added to Harmony
no - early - unlock - epoch : : obj : ` int ` Epoch at which early unlock of tokens was disabled ( https : / / github . com / harmony - one / harmony / pull / 3605 )
redelegation - epoch : : obj : ` int ` Epoch at which redelegation was enabled ( staking )
sixty - percent - epoch : : obj : ` int ` Epoch when internal voting power reduced from 68 % to 60 %
two - seconds - epoch : : obj : ` int ` Epoch at which two second finality was enabled and block rewards adjusted to 7 ONE / block
is - leader : : obj : ` bool ` Whether the node is currently leader or not
is - leader : : obj : ` bool ` Whether the node is currently leader or not
shard - id : : obj : ` int ` Shard that the node is on
shard - id : : obj : ` int ` Shard that the node is on
current - epoch : : obj : ` int ` Current epoch
current - epoch : : obj : ` int ` Current epoch
@ -138,20 +122,19 @@ def get_node_metadata(endpoint=_default_endpoint, timeout=_default_timeout) -> d
API Reference
API Reference
- - - - - - - - - - - - -
- - - - - - - - - - - - -
https : / / api . hmny . io / #03c39b56-8dfc-48ce-bdad-f85776dd8aec
https : / / api . hmny . io / #03c39b56-8dfc-48ce-bdad-f85776dd8aec
https : / / github . com / harmony - one / harmony / blob / v1 .10 .2 / internal / params / config . go #L233 for chain-config dict
https : / / github . com / harmony - one / harmony / blob / v1 .10 .2 / internal / params / config . go #L233
https : / / github . com / harmony - one / harmony / blob / 9 f320436ff30d9babd957bc5f2e15a1818c86584 / node / api . go #L110 for consensus dict
https : / / github . com / harmony - one / harmony / blob / 9 f320436ff30d9babd957bc5f2e15a1818c86584 / node / api . go #L110
"""
"""
method = " hmyv2_getNodeMetadata "
method = " hmyv2_getNodeMetadata "
try :
try :
metadata = rpc_request ( method , endpoint = endpoint , timeout = timeout )
metadata = rpc_request ( method , endpoint = endpoint , timeout = timeout )
return metadata [ " result " ]
return metadata [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_peer_info ( endpoint = _default_endpoint , timeout = _default_timeout ) - > dict :
def get_peer_info ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > dict :
"""
""" Get peer info for the node.
Get peer info for the node
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -183,13 +166,12 @@ def get_peer_info(endpoint=_default_endpoint, timeout=_default_timeout) -> dict:
method = " hmyv2_getPeerInfo "
method = " hmyv2_getPeerInfo "
try :
try :
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def protocol_version ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def protocol_version ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get the current Harmony protocol version this node supports.
Get the current Harmony protocol version this node supports
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -216,13 +198,12 @@ def protocol_version(endpoint=_default_endpoint, timeout=_default_timeout) -> in
try :
try :
value = rpc_request ( method , endpoint = endpoint , timeout = timeout )
value = rpc_request ( method , endpoint = endpoint , timeout = timeout )
return value [ " result " ]
return value [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_num_peers ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_num_peers ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get number of peers connected to the node.
Get number of peers connected to the node
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -250,13 +231,12 @@ def get_num_peers(endpoint=_default_endpoint, timeout=_default_timeout) -> int:
return int (
return int (
rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] , 16
rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] , 16
)
)
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_version ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_version ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get version of the EVM network (https://chainid.network/)
Get version of the EVM network ( https : / / chainid . network / )
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -284,13 +264,12 @@ def get_version(endpoint=_default_endpoint, timeout=_default_timeout) -> int:
return int (
return int (
rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] , 16
rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] , 16
) # this is hexadecimal
) # this is hexadecimal
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def in_sync ( endpoint = _default_endpoint , timeout = _default_timeout ) - > bool :
def in_sync ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > bool :
"""
""" Whether the shard chain is in sync or syncing (not out of sync)
Whether the shard chain is in sync or syncing ( not out of sync )
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -315,13 +294,12 @@ def in_sync(endpoint=_default_endpoint, timeout=_default_timeout) -> bool:
method = " hmyv2_inSync "
method = " hmyv2_inSync "
try :
try :
return bool ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
return bool ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def beacon_in_sync ( endpoint = _default_endpoint , timeout = _default_timeout ) - > bool :
def beacon_in_sync ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > bool :
"""
""" Whether the beacon chain is in sync or syncing (not out of sync)
Whether the beacon chain is in sync or syncing ( not out of sync )
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -346,13 +324,12 @@ def beacon_in_sync(endpoint=_default_endpoint, timeout=_default_timeout) -> bool
method = " hmyv2_beaconInSync "
method = " hmyv2_beaconInSync "
try :
try :
return bool ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
return bool ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_staking_epoch ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_staking_epoch ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get epoch number when blockchain switches to EPoS election.
Get epoch number when blockchain switches to EPoS election
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -383,13 +360,13 @@ def get_staking_epoch(endpoint=_default_endpoint, timeout=_default_timeout) -> i
try :
try :
data = rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
data = rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return int ( data [ " chain-config " ] [ " staking-epoch " ] )
return int ( data [ " chain-config " ] [ " staking-epoch " ] )
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_prestaking_epoch ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_prestaking_epoch ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get epoch number when blockchain switches to allow staking features
Get epoch number when blockchain switches to allow staking features without election
without election .
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -420,16 +397,15 @@ def get_prestaking_epoch(endpoint=_default_endpoint, timeout=_default_timeout) -
try :
try :
data = rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
data = rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return int ( data [ " chain-config " ] [ " prestaking-epoch " ] )
return int ( data [ " chain-config " ] [ " prestaking-epoch " ] )
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
########################
########################
# Sharding information #
# Sharding information #
########################
########################
def get_shard ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_shard ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get shard ID of the node.
Get shard ID of the node
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -457,15 +433,14 @@ def get_shard(endpoint=_default_endpoint, timeout=_default_timeout) -> int:
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] [
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] [
" shard-id "
" shard-id "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_sharding_structure (
def get_sharding_structure (
endpoint = _default_endpoint , timeout = _default_timeout
endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > list :
) - > list :
"""
""" Get network sharding structure.
Get network sharding structure
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -494,16 +469,15 @@ def get_sharding_structure(
method = " hmyv2_getShardingStructure "
method = " hmyv2_getShardingStructure "
try :
try :
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
#############################
#############################
# Current status of network #
# Current status of network #
#############################
#############################
def get_leader_address ( endpoint = _default_endpoint , timeout = _default_timeout ) - > str :
def get_leader_address ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > str :
"""
""" Get current leader one address.
Get current leader one address
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -529,15 +503,14 @@ def get_leader_address(endpoint=_default_endpoint, timeout=_default_timeout) ->
method = " hmyv2_getLeader "
method = " hmyv2_getLeader "
try :
try :
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def is_last_block (
def is_last_block (
block_num , endpoint = _default_endpoint , timeout = _default_timeout
block_num , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > bool :
) - > bool :
"""
""" If the block at block_num is the last block.
If the block at block_num is the last block
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -571,15 +544,14 @@ def is_last_block(
" result "
" result "
]
]
)
)
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def epoch_last_block (
def epoch_last_block (
epoch , endpoint = _default_endpoint , timeout = _default_timeout
epoch , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > int :
) - > int :
"""
""" Returns the number of the last block in the epoch.
Returns the number of the last block in the epoch
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -613,13 +585,12 @@ def epoch_last_block(
" result "
" result "
]
]
)
)
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_circulating_supply ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_circulating_supply ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get current circulation supply of tokens in ONE.
Get current circulation supply of tokens in ONE
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -645,13 +616,12 @@ def get_circulating_supply(endpoint=_default_endpoint, timeout=_default_timeout)
method = " hmyv2_getCirculatingSupply "
method = " hmyv2_getCirculatingSupply "
try :
try :
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_total_supply ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_total_supply ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get total number of pre-mined tokens.
Get total number of pre - mined tokens
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -677,13 +647,12 @@ def get_total_supply(endpoint=_default_endpoint, timeout=_default_timeout) -> in
method = " hmyv2_getTotalSupply "
method = " hmyv2_getTotalSupply "
try :
try :
rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_number ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_block_number ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get current block number.
Get current block number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -709,13 +678,12 @@ def get_block_number(endpoint=_default_endpoint, timeout=_default_timeout) -> in
method = " hmyv2_blockNumber "
method = " hmyv2_blockNumber "
try :
try :
return int ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
return int ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_current_epoch ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_current_epoch ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get current epoch number.
Get current epoch number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -741,13 +709,12 @@ def get_current_epoch(endpoint=_default_endpoint, timeout=_default_timeout) -> i
method = " hmyv2_getEpoch "
method = " hmyv2_getEpoch "
try :
try :
return int ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
return int ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_last_cross_links ( endpoint = _default_endpoint , timeout = _default_timeout ) - > list :
def get_last_cross_links ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > list :
"""
""" Get last cross shard links.
Get last cross shard links
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -780,13 +747,12 @@ def get_last_cross_links(endpoint=_default_endpoint, timeout=_default_timeout) -
method = " hmyv2_getLastCrossLinks "
method = " hmyv2_getLastCrossLinks "
try :
try :
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_gas_price ( endpoint = _default_endpoint , timeout = _default_timeout ) - > int :
def get_gas_price ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > int :
"""
""" Get network gas price.
Get network gas price
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -812,16 +778,15 @@ def get_gas_price(endpoint=_default_endpoint, timeout=_default_timeout) -> int:
method = " hmyv2_gasPrice "
method = " hmyv2_gasPrice "
try :
try :
return int ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
return int ( rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ] )
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
##############
##############
# Block RPCs #
# Block RPCs #
##############
##############
def get_latest_header ( endpoint = _default_endpoint , timeout = _default_timeout ) - > dict :
def get_latest_header ( endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > dict :
"""
""" Get block header of latest block.
Get block header of latest block
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -836,14 +801,16 @@ def get_latest_header(endpoint=_default_endpoint, timeout=_default_timeout) -> d
blockHash : : obj : ` str ` Block hash
blockHash : : obj : ` str ` Block hash
blockNumber : : obj : ` int ` Block number
blockNumber : : obj : ` int ` Block number
shardID : : obj : ` int ` Shard ID
shardID : : obj : ` int ` Shard ID
leader : : obj : ` str ` Wallet address of leader that proposed this block if prestaking , otherwise sha256 hash of leader ' s public bls key
leader : : obj : ` str ` Wallet address of leader that proposed this block if prestaking
otherwise sha256 hash of leader ' s public bls key
viewID : : obj : ` int ` View ID of the block
viewID : : obj : ` int ` View ID of the block
epoch : : obj : ` int ` Epoch of block
epoch : : obj : ` int ` Epoch of block
timestamp : : obj : ` str ` Timestamp that the block was finalized in human readable format
timestamp : : obj : ` str ` Timestamp that the block was finalized in human readable format
unixtime : : obj : ` int ` Timestamp that the block was finalized in Unix time
unixtime : : obj : ` int ` Timestamp that the block was finalized in Unix time
lastCommitSig : : obj : ` str ` Hex representation of aggregated signatures of the previous block
lastCommitSig : : obj : ` str ` Hex representation of aggregated signatures of the previous block
lastCommitBitmap : : obj : ` str ` Hex representation of aggregated signature bitmap of the previous block
lastCommitBitmap : : obj : ` str `
crossLinks : list of dicts describing the cross shard links , each dict to have the following keys :
Hex representation of aggregated signature bitmap of the previous block
crossLinks : list of dicts describing the cross shard links :
block - number : : obj : ` int ` Number of the cross link block
block - number : : obj : ` int ` Number of the cross link block
epoch - number : : obj : ` int ` Epoch of the cross link block
epoch - number : : obj : ` int ` Epoch of the cross link block
hash : : obj : ` str ` Hash of the cross link block
hash : : obj : ` str ` Hash of the cross link block
@ -863,15 +830,14 @@ def get_latest_header(endpoint=_default_endpoint, timeout=_default_timeout) -> d
method = " hmyv2_latestHeader "
method = " hmyv2_latestHeader "
try :
try :
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_header_by_number (
def get_header_by_number (
block_num , endpoint = _default_endpoint , timeout = _default_timeout
block_num , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > dict :
) - > dict :
"""
""" Get block header of block at block_num.
Get block header of block at block_num
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -901,15 +867,14 @@ def get_header_by_number(
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_latest_chain_headers (
def get_latest_chain_headers (
endpoint = _default_endpoint , timeout = _default_timeout
endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > dict :
) - > dict :
"""
""" Get block header of latest block for beacon chain & shard chain.
Get block header of latest block for beacon chain & shard chain
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -921,7 +886,7 @@ def get_latest_chain_headers(
Returns
Returns
- - - - - - -
- - - - - - -
dict with two keys :
dict with two keys :
beacon - chain - header : : obj : ` dict ` with the following keys , applicable to the beacon chain ( cross shard links )
beacon - chain - header : : obj : ` dict ` with the following keys , applicable to the beacon chain
shard - chain - header : : obj : ` dict ` with the following keys , applicable to the shard chain
shard - chain - header : : obj : ` dict ` with the following keys , applicable to the shard chain
difficulty : legacy
difficulty : legacy
epoch : : obj : ` int ` Epoch of the block
epoch : : obj : ` int ` Epoch of the block
@ -955,21 +920,20 @@ def get_latest_chain_headers(
method = " hmyv2_getLatestChainHeaders "
method = " hmyv2_getLatestChainHeaders "
try :
try :
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
return rpc_request ( method , endpoint = endpoint , timeout = timeout ) [ " result " ]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_by_number (
def get_block_by_number ( # pylint: disable=too-many-arguments
block_num ,
block_num ,
full_tx = False ,
full_tx = False ,
include_tx = False ,
include_tx = False ,
include_staking_tx = False ,
include_staking_tx = False ,
include_signers = False ,
include_signers = False ,
endpoint = _default_endpoint ,
endpoint = DEFAULT_ENDPOINT ,
timeout = _default_timeout ,
timeout = DEFAULT_TIMEOUT ,
) - > dict :
) - > dict :
"""
""" Get block by number.
Get block by number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1007,12 +971,14 @@ def get_block_by_number(
signers : : obj : ` list ` List of signers ( only if include_signers is set to True )
signers : : obj : ` list ` List of signers ( only if include_signers is set to True )
size : : obj : ` int ` Block size in bytes
size : : obj : ` int ` Block size in bytes
stakingTransactions : : obj : ` list `
stakingTransactions : : obj : ` list `
if full_tx is True : List of dictionaries , each containing a staking transaction ( see account . get_staking_transaction_history )
if full_tx is True : List of dictionaries ,
each containing a staking transaction ( see account . get_staking_transaction_history )
if full_tx is False : List of staking transaction hashes
if full_tx is False : List of staking transaction hashes
stateRoot : : obj : ` str ` Hash of state root
stateRoot : : obj : ` str ` Hash of state root
timestamp : : obj : ` int ` Unix timestamp of the block
timestamp : : obj : ` int ` Unix timestamp of the block
transactions : : obj : ` list `
transactions : : obj : ` list `
if full_tx is True : List of dictionaries , each containing a transaction ( see account . get_transaction_history )
if full_tx is True : List of dictionaries ,
each containing a transaction ( see account . get_transaction_history )
if full_tx is False : List of transaction hashes
if full_tx is False : List of transaction hashes
transactionsRoot : : obj : ` str ` Hash of transactions root
transactionsRoot : : obj : ` str ` Hash of transactions root
uncles : : obj : ` str ` legacy
uncles : : obj : ` str ` legacy
@ -1042,21 +1008,20 @@ def get_block_by_number(
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_by_hash (
def get_block_by_hash ( # pylint: disable=too-many-arguments
block_hash ,
block_hash ,
full_tx = False ,
full_tx = False ,
include_tx = False ,
include_tx = False ,
include_staking_tx = False ,
include_staking_tx = False ,
include_signers = False ,
include_signers = False ,
endpoint = _default_endpoint ,
endpoint = DEFAULT_ENDPOINT ,
timeout = _default_timeout ,
timeout = DEFAULT_TIMEOUT ,
) - > dict :
) - > dict :
"""
""" Get block by hash.
Get block by hash
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1100,15 +1065,14 @@ def get_block_by_hash(
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_transaction_count_by_number (
def get_block_transaction_count_by_number (
block_num , endpoint = _default_endpoint , timeout = _default_timeout
block_num , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > int :
) - > int :
"""
""" Get transaction count for specific block number.
Get transaction count for specific block number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1143,15 +1107,14 @@ def get_block_transaction_count_by_number(
" result "
" result "
]
]
)
)
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_transaction_count_by_hash (
def get_block_transaction_count_by_hash (
block_hash , endpoint = _default_endpoint , timeout = _default_timeout
block_hash , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > int :
) - > int :
"""
""" Get transaction count for specific block hash.
Get transaction count for specific block hash
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1186,15 +1149,14 @@ def get_block_transaction_count_by_hash(
" result "
" result "
]
]
)
)
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_staking_transaction_count_by_number (
def get_block_staking_transaction_count_by_number (
block_num , endpoint = _default_endpoint , timeout = _default_timeout
block_num , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > int :
) - > int :
"""
""" Get staking transaction count for specific block number.
Get staking transaction count for specific block number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1229,15 +1191,14 @@ def get_block_staking_transaction_count_by_number(
" result "
" result "
]
]
)
)
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_staking_transaction_count_by_hash (
def get_block_staking_transaction_count_by_hash (
block_hash , endpoint = _default_endpoint , timeout = _default_timeout
block_hash , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > int :
) - > int :
"""
""" Get staking transaction count for specific block hash.
Get staking transaction count for specific block hash
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1272,22 +1233,21 @@ def get_block_staking_transaction_count_by_hash(
" result "
" result "
]
]
)
)
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_blocks (
def get_blocks ( # pylint: disable=too-many-arguments
start_block ,
start_block ,
end_block ,
end_block ,
full_tx = False ,
full_tx = False ,
include_tx = False ,
include_tx = False ,
include_staking_tx = False ,
include_staking_tx = False ,
include_signers = False ,
include_signers = False ,
endpoint = _default_endpoint ,
endpoint = DEFAULT_ENDPOINT ,
timeout = _default_timeout ,
timeout = DEFAULT_TIMEOUT ,
) - > list :
) - > list :
"""
""" Get list of blocks from a range.
Get list of blocks from a range
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1336,15 +1296,14 @@ def get_blocks(
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_signers (
def get_block_signers (
block_num , endpoint = _default_endpoint , timeout = _default_timeout
block_num , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > list :
) - > list :
"""
""" Get list of block signers for specific block number.
Get list of block signers for specific block number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1375,15 +1334,14 @@ def get_block_signers(
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_block_signers_keys (
def get_block_signers_keys (
block_num , endpoint = _default_endpoint , timeout = _default_timeout
block_num , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > list :
) - > list :
"""
""" Get list of block signer public bls keys for specific block number.
Get list of block signer public bls keys for specific block number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1414,15 +1372,15 @@ def get_block_signers_keys(
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def is_block_signer (
def is_block_signer (
block_num , address , endpoint = _default_endpoint , timeout = _default_timeout
block_num , address , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > bool :
) - > bool :
"""
""" Determine if the account at address is a signer for the block at
Determine if the account at address is a signer for the block at block_num
block_num .
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1454,15 +1412,15 @@ def is_block_signer(
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_signed_blocks (
def get_signed_blocks (
address , endpoint = _default_endpoint , timeout = _default_timeout
address , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > bool :
) - > bool :
"""
""" The number of blocks a particular validator signed for last blocksPeriod
The number of blocks a particular validator signed for last blocksPeriod ( 1 epoch )
( 1 epoch )
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1494,13 +1452,12 @@ def get_signed_blocks(
" result "
" result "
]
]
)
)
except ( KeyError , TypeError ) as e :
except ( KeyError , TypeError ) as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_validators ( epoch , endpoint = _default_endpoint , timeout = _default_timeout ) - > dict :
def get_validators ( epoch , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT ) - > dict :
"""
""" Get list of validators for specific epoch number.
Get list of validators for specific epoch number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1534,15 +1491,14 @@ def get_validators(epoch, endpoint=_default_endpoint, timeout=_default_timeout)
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception
def get_validator_keys (
def get_validator_keys (
epoch , endpoint = _default_endpoint , timeout = _default_timeout
epoch , endpoint = DEFAULT_ENDPOINT , timeout = DEFAULT_TIMEOUT
) - > list :
) - > list :
"""
""" Get list of validator public bls keys for specific epoch number.
Get list of validator public bls keys for specific epoch number
Parameters
Parameters
- - - - - - - - - -
- - - - - - - - - -
@ -1573,5 +1529,5 @@ def get_validator_keys(
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
return rpc_request ( method , params = params , endpoint = endpoint , timeout = timeout ) [
" result "
" result "
]
]
except KeyError as e :
except KeyError as exception :
raise InvalidRPCReplyError ( method , endpoint ) from e
raise InvalidRPCReplyError ( method , endpoint ) from exception