def getDelegations(inputData, address): # logger.info("in getDelegations for: {}".format(address)) delegations = [] delegateAddresses = set() selfStake = 0 delegateCount = 0 for d in inputData: delAddress = d["delegator-address"] if address == delAddress: selfStake = commonUtils.divideByTenPower18(d["amount"]) amount = commonUtils.divideByTenPower18(d["amount"]) delegation = { "address": d["delegator-address"], "amount": amount, "validator": address, "reward": commonUtils.divideByTenPower18(d["reward"]), } if amount > 0: delegateCount += 1 delegations.append(delegation) delegateAddresses.add(delAddress) return delegations, selfStake, delegateAddresses, delegateCount
def getSlots(slotsData, valByAddMap): slotsList = [] i = 1 for slot in slotsData: # logger.info(slot) address = slot["address"] if address not in valByAddMap: continue validator = valByAddMap[address] details = {} details["index"] = i details["hPoolId"] = validator["hPoolId"] details["slot"] = slot["slot"] details["address"] = slot["address"] details["bid"] = commonUtils.divideByTenPower18(slot["bid"]) if "effective_stake" in slot: details["effectiveStake"] = commonUtils.divideByTenPower18( slot["effective_stake"]) else: details["effectiveStake"] = None details["totalStake"] = commonUtils.divideByTenPower18( slot["total_stake"]) details["actualStake"] = validator["totalStaked"] details["slotsRequested"] = round(validator["totalStaked"] / details["bid"]) currentSlot = getSlotDetails(slot["slot"], details) details["slotDetails"] = currentSlot details["slotDetails"]["bid"] = details["bid"] details["totalSlots"] = currentSlot["slotCount"] details["status"] = currentSlot["status"] slotsList.append(details) # del valByAddMap[address] i += 1 # logger.info("unelected validators: {}".format(valByAddMap)) # , valByAddMap.values() return slotsList
def getValBidMessage(name, valDetails): # logger.info("in getValBidMessage") # logger.info(name) # logger.info(valDetails) valName = name if valName and len(valName) > 11: valName = valName[:11] message = "<b>" + valDetails["slot"] + "</b> | " message += valName + " | " + str(valDetails["num"]) + " | " message += str(int(commonUtils.divideByTenPower18(int( valDetails["bid"])))) + " | " if "effective_stake" in valDetails: message += str( int( commonUtils.divideByTenPower18( int(valDetails["effective_stake"])))) + " | " else: message += "\t-\t| " message += str( int(commonUtils.divideByTenPower18(int( valDetails["total_stake"])))) + "\n" return message
def getStakingNetworkInfo(session, delegateCount): logger.info("getting staking information") data = commonUtils.getHarmonyDataFromPost(session, constants.STAKING_NETWORK_INFO, []) stakingData = data["result"] stakingInfo = { "totalSupply": stakingData["total-supply"], "circulatingSupply": stakingData["circulating-supply"], "totalStake": commonUtils.divideByTenPower18(stakingData["total-staking"]), "medianRawStake": commonUtils.divideByTenPower18(stakingData["median-raw-stake"]), "epochLastBlock": stakingData["epoch-last-block"], "uniqueDelegates": delegateCount, } return stakingInfo
def handleFeeChange(e, validatorDetails, poolMap, coinStat): # logger.info("in handlefeechange") fee = round( commonUtils.divideByTenPower18(validatorDetails["commissionRate"]), 4) validator = poolMap[e["validatorAddress"]] if not validator: # logger.info("in handlefeechange - returning no validator") return None eventType = None # logger.info("e: {}, coinStat: {}, validator: {}".format(e, coinStat, validator)) if e["blockNumber"] < coinStat["recentBlock"]: # logger.info("fee change already updated in db, dig up previous fee and use that") #fee change already updated in db, dig up previous fee and use that if fee > validator["prevFee"]: # logger.info("fee > validator[prevFee]") eventType = hConstants.H_EVENT_FEE_INCREASE elif fee < validator["prevFee"]: # logger.info("fee < validator[prevFee]") eventType = hConstants.H_EVENT_FEE_DECREASE else: logger.info("in else: fee : {} < validator[prevFee]: {}".format( fee, validator["prevFee"])) else: # logger.info("fee change not yet updated in db") #fee change not yet updated in db if fee > validator["fee"]: # logger.info("fee > validator[fee]") eventType = hConstants.H_EVENT_FEE_INCREASE elif fee < validator["fee"]: # logger.info("fee < validator[fee]") eventType = hConstants.H_EVENT_FEE_DECREASE else: logger.info("in else: fee : {} < validator[fee]: {}".format( fee, validator["fee"])) if eventType: # logger.info("in handlefeechange - returning : " + eventType) return (eventType, e["blockNumber"], e["txHash"], e["address"], validator["hPoolId"], (fee * 100), e["epochTimestamp"], None) # logger.info("in handlefeechange - returning none in end") return None
def getAllValidators(session): logger.info("obtaining list of all validators and delegations") inputData = [-1] data = commonUtils.getHarmonyDataFromPost( session, "hmyv2_getAllValidatorInformation", inputData) # data = {} # logger.info(data) logger.info("starting processing") vData = data["result"] validators = [] i = 0 allDelegates = set() allDelegations = [] minValData = 110 currentValData = 0 skippedVal = 0 for validatorData in vData: # if i >= 0: # continue validator = validatorData["validator"] # logger.info(str(i) + " - processing validator ") # logger.info(validator) i += 1 # validator = json.loads(validatorData) currentPerf = { "currentEpochSigned": 0, "currentEpochToSign": 0, "currentEpochSigningPercentage": 0 } if validatorData["current-epoch-performance"]: perf = validatorData["current-epoch-performance"][ "current-epoch-signing-percent"] signPercent = float(perf["current-epoch-signing-percentage"]) * 100 currentPerf = { "currentEpochSigned": perf["current-epoch-signed"], "currentEpochToSign": perf["current-epoch-to-sign"], "currentEpochSigningPercentage": signPercent, } lifetimePerf = { "totalRewards": 0, "lifetimeToSign": 0, "lifetimeSigned": 0, "lifetimeApr": 0 } if validatorData["lifetime"]: perf = validatorData["lifetime"] lifetimePerf = { "totalRewards": commonUtils.divideByTenPower18(perf["reward-accumulated"]), "lifetimeToSign": perf["blocks"]["to-sign"], "lifetimeSigned": perf["blocks"]["signed"], "lifetimeApr": perf["apr"], } # logger.info("lifetime is: ") # logger.info(lifetimePerf) elected = "False" if validatorData["epos-status"] == "currently elected": elected = "True" booted = "False" if validatorData["booted-status"] is not None: booted = "True" # "elected": validatorData["currently-in-committee"], delegations, selfStake, delegateAddresses, delegateCount = getDelegations( validator["delegations"], validator["address"]) vReq = { "address": validator["address"], "name": validator["name"], "identity": validator["identity"], "blsPublicKeys": validator["bls-public-keys"], "minSelfDelegation": commonUtils.divideByTenPower18(validator["min-self-delegation"]), "maxTotalDelegation": commonUtils.divideByTenPower18(validator["max-total-delegation"]), "website": validator["website"], "currentPerf": currentPerf, "securityContact": validator["security-contact"], "details": validator["details"], "fee": validator["rate"], "maxFee": validator["max-rate"], "feeChangeRate": validator["max-change-rate"], "lastUpdateBlock": validator["update-height"], "creationBlock": validator["creation-height"], "totalStaked": commonUtils.divideByTenPower18(validatorData["total-delegation"]), "elected": elected, "booted": booted, "uniqueDelegates": delegateCount, "lifetimePerf": lifetimePerf, "selfStake": selfStake, "activeStatus": validatorData["active-status"], "status": commonUtils.getStatus(validatorData["epos-status"]) } currentValData += 1 # if constants.syncAllValidators or vReq["status"] != constants.H_STATUS_NOT_ELIGIBLE: if constants.syncAllValidators or vReq["status"] == constants.H_STATUS_ELECTED \ or vReq["status"] == constants.H_STATUS_ELIGIBLE or currentValData < minValData: validators.append(vReq) allDelegates = allDelegates.union(delegateAddresses) allDelegations.append(delegations) else: skippedVal += 1 logger.info("looped through all validators : " + str(len(validators))) logger.info("skipped validators : " + str(skippedVal)) return validators, len(allDelegates), allDelegations
def getBalance(session, address): balance = commonUtils.getHarmonyResultDataFromPost(session, constants.BALANCE_URL, [address]) return commonUtils.divideByTenPower18(balance)