Example #1
0
def getHealth(conn, chatId, userId):
    setting = tgBotUtils.prepUserSettings(conn, chatId, userId, app)

    if setting["favPools"] is None or setting["favPools"] == "":
        message = "Favorite validators are not configured. Check /settings command"
    else:
        sql = harmonyData.listPoolsSqlWithIds(app, setting["favPools"])
        # logger.info(sql)
        validators = dbUtil.listResultsWithConn(sql, conn)
        lastUpdatedGap = commonUtils.getEventLastUpdated(
            conn, eventName.syncHarmonyValidators)

        i = 1
        message = "List of favorite validators: \n"
        message += "Last updated: <b>" + str(int(
            lastUpdatedGap / 60)) + "</b> minutes ago.\n\n"
        for validator in validators:
            message += "#" + str(i) + " - " + getTgValDetails(
                conn, validator, None)
            i += 1
            message += "\n"
        message += getToolsLink("") + " /health"

    # logger.info(message)
    return message
Example #2
0
def getSmartStake(conn):
    lastUpdatedGap = commonUtils.getEventLastUpdated(
        conn, eventName.syncHarmonyValidators)
    # logger.info(lastUpdatedGap)
    pool = harmonyData.getHPoolById(conn, SS_VAL_ID)
    # conn.close()

    message = "Smart Stake validator details:\n"
    message += getTgValDetails(conn, pool, lastUpdatedGap)
    message += getToolsLink("")

    return message
def getRichList(conn, app, count):
    # logger.info(sql)
    sql = getRichListSql()

    data = dbUtil.listResultsWithConn(sql, conn, count)
    # logger.info(data)
    coinStat = commonUtils.getCoinStat(conn, app)

    lastUpdated = commonUtils.getEventLastUpdated(
        conn, eventName.syncHarmonyAddresses)

    return dbUtil.combineResults3("data", data, "lastUpdated", lastUpdated,
                                  "coinStat", coinStat)
def listAddressEvents(conn, app, address):
    startTime = commonUtils.getCurrentTime()
    addressDetails = getAddressDetails(conn, app, address, None)
    commonUtils.logTimeDiff(startTime, "after getting address details")
    lastUpdated = commonUtils.getEventLastUpdated(
        conn, eventName.syncHarmonyDelegations)
    commonUtils.logTimeDiff(startTime, "after getting event last updated")

    addressEvents = harmonyEvents.listEventsByAddress(conn, address)
    commonUtils.logTimeDiff(startTime, "after getting event details")

    return dbUtil.combineResults3("addressDetails", addressDetails,
                                  "lastUpdated", lastUpdated, "data",
                                  addressEvents)
Example #5
0
def listKeyDetails(conn, app, event):
    # logger.info("in listKeys method")

    blsKey = event["queryStringParameters"]["blsKey"]
    keyDetails = getKeyDetails(conn, blsKey)
    val = harmonyData.getHPoolById(conn, keyDetails["hPoolId"])

    epoch = int(event["queryStringParameters"]["epoch"])

    data = listKeyDataByEpoch(conn, blsKey, epoch)
    lastUpdated = commonUtils.getEventLastUpdated(conn,
                                                  eventName.syncHarmonyBlsKeys)
    return dbUtil.combineResults4("val", val, "data", data, "keyDetails",
                                  keyDetails, "lastUpdated", lastUpdated)
Example #6
0
def listKeys(conn, app, event, hPoolId):
    # logger.info("in listKeys method")

    val = harmonyData.getHPoolById(conn, hPoolId)
    coinStat = commonUtils.getCoinStat(conn, app)

    epoch = coinStat["currentEpoch"]
    if "epoch" in event["queryStringParameters"]:
        epoch = int(event["queryStringParameters"]["epoch"])

    data = listLatestKeys(conn, hPoolId, epoch)
    lastUpdated = commonUtils.getEventLastUpdated(conn,
                                                  eventName.syncHarmonyBlsKeys)
    return dbUtil.combineResults5("val", val, "data", data, "epoch", epoch,
                                  "coinStat", coinStat, "lastUpdated",
                                  lastUpdated)
def getAddressDisplayDetails(conn, app, address, alias, subType=None):
    startTime = commonUtils.getCurrentTime()
    # logger.info("subType : " + subType)
    if address is None and alias is not None:
        record = aliasUtils.getAddressFromAlias(conn, app, alias)
        commonUtils.logTimeDiff(startTime, "after getting address from alias")
        if not record:
            response = "'" + alias + "' - alias not found in server. Please enter the address, alias and use the 'Save Alias in Server' button to save the alias."
            return dbUtil.getResponse(dbUtil.jsondumps({"error": response}))
        address = record["address"]

    coinStats = dbUtil.getSingleRecordNoJsonWithConn(
        commonUtils.getCoinStatSql(), conn, app)
    commonUtils.logTimeDiff(startTime, "after getting coinstat")
    addressDetails = getAddressDetails(conn, app, address, alias)
    commonUtils.logTimeDiff(startTime, "after getting address details")
    lastUpdated = commonUtils.getEventLastUpdated(
        conn, eventName.syncHarmonyDelegations)
    commonUtils.logTimeDiff(startTime, "after getting event last updated")

    delegations = getDelegationDetails(conn, address)
    commonUtils.logTimeDiff(startTime, "after getting delegations details")

    smartStake = None
    if subType == "myAccount":
        # logger.info("checking if smart stake user")
        smartStake = isUsingSmartStake(delegations)
        commonUtils.logTimeDiff(startTime, "after getting is smart stake")

    rewards = harmonyEvents.getRewardsSummary(conn, address)
    commonUtils.logTimeDiff(startTime, "after getting rewards summary")
    stakeHistory = listAddressStakeHistoryChartData(conn, address,
                                                    coinStats["currentEpoch"])
    stakeHistory.sort(key=lambda item: item['epoch'], reverse=False)
    commonUtils.logTimeDiff(startTime, "after getting stake history chart")
    # addressEvents = harmonyEvents.listEventsByAddress(conn, address)
    addressEvents = []
    commonUtils.logTimeDiff(startTime, "after getting event details")
    # logger.info("after calling reportData.listRewardComparisonReportData")

    return dbUtil.combineResults8("addressDetails", addressDetails,
                                  "lastUpdated", lastUpdated, "delegations",
                                  delegations, "rewards", rewards,
                                  "stakeHistory", stakeHistory, "events",
                                  addressEvents, "coinStats", coinStats,
                                  "smartStake", smartStake)
def listHPools(conn, app, status):
    # logger.info("listing harmony pools")
    sql, args = listHPoolsSql(status)
    # logger.info(args)
    data = dbUtil.listResultsWithConn(sql, conn, args)
    # logger.info(data)
    coinStat = commonUtils.getCoinStat(conn, app)
    statusSummary = getHStatusMap(conn)
    statusSummary[constants.ALL_FEE_INCREASE] = getFeeIncreaseCount(conn)
    # logger.info(statusSummary)

    lastUpdated = commonUtils.getEventLastUpdated(
        conn, eventName.syncHarmonyValidators)
    notification = commonUtils.getNotification(conn, app)

    return dbUtil.combineResults5("data", data, "lastUpdated", lastUpdated,
                                  "notification", notification,
                                  "statusSummary", statusSummary, "coinStat",
                                  coinStat)
def getRichDelegates(conn, app):
    sql = " select ad.ranking, pd.address, round(sum(pd.stake),0) as totalStake,  "
    sql += " group_concat(p.name) as validators "
    sql += " from " + tables.hpool + " p "
    sql += " inner join " + tables.hpooldel + " pd on pd.hPoolId=p.hPoolId"
    sql += " inner join " + tables.haddress + " ad on ad.address=pd.address"
    sql += " where pd.stake > " + MIN_AMOUNT
    sql += " group by pd.address order by totalStake desc "
    sql += " limit 2000 "

    # logger.info(sql)

    data = dbUtil.listResultsWithConn(sql, conn)
    coinStat = commonUtils.getCoinStat(conn, app)

    lastUpdated = commonUtils.getEventLastUpdated(
        conn, eventName.syncHarmonyAddresses)

    return dbUtil.combineResults3("data", data, "lastUpdated", lastUpdated,
                                  "coinStat", coinStat)