コード例 #1
0
ファイル: validator.py プロジェクト: yelllowsin/hmybidder
    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
ファイル: validator.py プロジェクト: yelllowsin/hmybidder
 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
ファイル: validator.py プロジェクト: yelllowsin/hmybidder
 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
ファイル: hmyclient.py プロジェクト: yelllowsin/hmybidder
 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
ファイル: validator.py プロジェクト: yelllowsin/hmybidder
 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
ファイル: validator.py プロジェクト: yelllowsin/hmybidder
 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
ファイル: hmyclient.py プロジェクト: yelllowsin/hmybidder
 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
ファイル: hmyclient.py プロジェクト: yelllowsin/hmybidder
 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