示例#1
0
    def getNetworkLatestInfo(self) -> NetworkInfo:
        url = Globals.getHmyNetworkUrl()
        block_number = 0
        try:
            block_number = blockchain.get_block_number(url)
            #print(f"Block Number {block_number}")
        except Exception as ex:
            HmyBidderLog.error(
                f'Validator getNetworkLatestInfo get_block_number {ex}')

        try:
            response = staking.get_staking_network_info(url)
            #print(response)
            if response != None and not 'error' in response:
                epoch_last_block = int(response['epoch-last-block'])
                median_raw_stake = float(response['median-raw-stake']
                                         ) / Globals._oneAmountDenominator
                blocks_to_next_epoch = (epoch_last_block - block_number)
                network_info = NetworkInfo(epoch_last_block, median_raw_stake,
                                           block_number, blocks_to_next_epoch)
                return network_info
            else:
                return None
        except Exception as ex:
            HmyBidderLog.error(
                f'Validator getNetworkLatestInfo get network info {ex}')
示例#2
0
 def getValidatorInfo(self, validatorAddress):
     validator_info = None
     try:
         jsonResponse = staking.get_validator_information(
             validatorAddress, Globals.getHmyNetworkUrl())
         #print(jsonResponse)
         activeStatus = ''
         if 'active-status' in jsonResponse:
             activeStatus = jsonResponse['active-status']
         eposStatus = ''
         if 'epos-status' in jsonResponse:
             eposStatus = jsonResponse['epos-status']
         totalDelegation = 0
         if 'total-delegation' in jsonResponse:
             totalDelegation = float(jsonResponse['total-delegation'])
         blsKeys = []
         if 'validator' in jsonResponse:
             if jsonResponse['validator'] != None:
                 if 'bls-public-keys' in jsonResponse['validator']:
                     for bKey in jsonResponse['validator'][
                             'bls-public-keys']:
                         sId = HmyClient.getShardForBlsKey(bKey)
                         blsKeys.append(BlsKey(bKey, sId))
         validator_info = ValidatorInfo(activeStatus, eposStatus,
                                        totalDelegation, blsKeys)
     except Exception as ex:
         HmyBidderLog.error(f'Validator getValidatorInfo {ex}')
     finally:
         return validator_info
示例#3
0
 def getCurrentEpoch(self) -> int:
     url = Globals.getHmyNetworkUrl()
     epoch_number = 0
     try:
         epoch_number = blockchain.get_current_epoch(url)
         #print(f"Block Number {block_number}")
     except Exception as ex:
         HmyBidderLog.error(
             f'Validator getCurrentEpoch get_block_number {ex}')
     finally:
         return epoch_number
示例#4
0
 def getShardForBlsKey(self, key):
     shard = -1
     try:
         nodeUrl = Globals.getHmyNetworkUrl()
         response = HmyClient.__executeCommand(
             ['./hmy', '--node', nodeUrl, 'utility', 'shard-for-bls', key])
         shard = response['shard-id']
         return shard
     except Exception as ex:
         HmyBidderLog.error(f'HmyClient getShardForBlsKey {ex}')
         return shard
示例#5
0
 def getMedianRawStakeSnapshot(self) -> NetworkInfo:
     url = Globals.getHmyNetworkUrl()
     median_raw_stake_snapshot = {}
     try:
         median_raw_stake_snapshot = staking.get_raw_median_stake_snapshot(
             url)
         #print(median_raw_stake_snapshot)
         if median_raw_stake_snapshot != None and not 'error' in median_raw_stake_snapshot:
             return median_raw_stake_snapshot
         else:
             return None
     except Exception as ex:
         HmyBidderLog.error(f'Validator getMedianRawStakeSnapshot {ex}')
示例#6
0
 def getTotalStakedToValidator(self, validatorAddress):
     validator_info = {}
     totalDelegation = 0
     try:
         validator_info = staking.get_validator_information(
             validatorAddress, Globals.getHmyNetworkUrl())
         #print(validator_info)
         if 'total-delegation' in validator_info:
             totalDelegation = validator_info['total-delegation']
     except Exception as ex:
         HmyBidderLog.error(f'Validator getTotalStakedToValidator {ex}')
     finally:
         return (totalDelegation / Globals._oneAmountDenominator)
示例#7
0
 def __getParameters(self, blskey):
     baseParameters = [
         "./hmy", "--node",
         Globals.getHmyNetworkUrl(), "staking", "edit-validator",
         "--validator-addr", Globals._walletAddress, "--bls-pubkeys-dir",
         Globals._blsdirPath, "--true-nonce"
     ]
     if os.path.exists(Globals._passphraseFile):
         baseParameters = baseParameters + [
             "--passphrase-file", Globals._passphraseFile
         ]
     #print(baseParameters)
     return baseParameters
示例#8
0
 def checkIfAccountofWalletAddressExists(self, walletAddress):
     exists = False
     try:
         nodeUrl = Globals.getHmyNetworkUrl()
         response = HmyClient.__executeCommand(
             ['./hmy', '--node', nodeUrl, 'keys', 'list'])
         print(response)
         if walletAddress in json.dumps(response):
             exists = True
         return exists
     except Exception as ex:
         if walletAddress in str(ex):
             return True
         else:
             HmyBidderLog.error(
                 f'HmyClient checkIfAccountofWalletAddressExists {ex}')
             return exists