src/rpcmining.cpp
Value GetNetworkHashPS(int lookup, int height) {
    CBlockIndex *pb = chainActive.Tip();

    if (height >= 0 && height < chainActive.Height())
        pb = chainActive[height];

    if (pb == NULL || !pb->nHeight || pb->nHeight > Params().LastProofOfWorkHeight())
        return 0;

    // If lookup is -1, then use blocks since last difficulty change.
    if (lookup <= 0)
        lookup = pb->nHeight % 2016 + 1;

    // If lookup is larger than chain, then set it to chain length.
    if (lookup > pb->nHeight)
        lookup = pb->nHeight;

    CBlockIndex *pb0 = pb;
    int64_t minTime = pb0->GetBlockTime();
    int64_t maxTime = minTime;
    for (int i = 0; i < lookup; i++) {
        pb0 = pb0->pprev;
        int64_t time = pb0->GetBlockTime();
        minTime = std::min(time, minTime);
        maxTime = std::max(time, maxTime);
    }

    // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.
    if (minTime == maxTime)
        return 0;

    uint256 workDiff = pb->nChainWork - pb0->nChainWork;
    int64_t timeDiff = maxTime - minTime;

    return (int64_t)(workDiff.getdouble() / timeDiff);
}
/**
 * Return average network hashes per second based on the last 'lookup' blocks,
 * or from the last difficulty change if 'lookup' is nonpositive.
 * If 'height' is nonnegative, compute the estimate at the time when a given block was found.
 */
Return average network hashes per second based on the last 'lookup' blocks,
or from the last difficulty change if 'lookup' is nonpositive.
If 'height' is nonnegative, compute the estimate at the time when a given block was found.
Return average network hashes per second based on the last ' lookup ' blocks or from the last difficulty change if ' lookup ' is nonpositive . If ' height ' is nonnegative compute the estimate at the time when a given block was found .
Value GetNetworkHashPS(int lookup, int height) {
    CBlockIndex *pb = chainActive.Tip();
    if (height >= 0 && height < chainActive.Height())
        pb = chainActive[height];
    if (pb == NULL || !pb->nHeight || pb->nHeight > Params().LastProofOfWorkHeight())
        return 0;
    if (lookup <= 0)
        lookup = pb->nHeight % 2016 + 1;
    if (lookup > pb->nHeight)
        lookup = pb->nHeight;
    CBlockIndex *pb0 = pb;
    int64_t minTime = pb0->GetBlockTime();
    int64_t maxTime = minTime;
    for (int i = 0; i < lookup; i++) {
        pb0 = pb0->pprev;
        int64_t time = pb0->GetBlockTime();
        minTime = std::min(time, minTime);
        maxTime = std::max(time, maxTime);
    }
    if (minTime == maxTime)
        return 0;
    uint256 workDiff = pb->nChainWork - pb0->nChainWork;
    int64_t timeDiff = maxTime - minTime;
    return (int64_t)(workDiff.getdouble() / timeDiff);
}
Value GetNetworkHashPS ( int lookup , int height ) { CBlockIndex * pb = chainActive . Tip ( ) ; if ( height >= 0 && height < chainActive . Height ( ) ) pb = chainActive [ height ] ; if ( pb == NULL || ! pb -> nHeight || pb -> nHeight > Params ( ) . LastProofOfWorkHeight ( ) ) return 0 ; if ( lookup <= 0 ) lookup = pb -> nHeight % 2016 + 1 ; if ( lookup > pb -> nHeight ) lookup = pb -> nHeight ; CBlockIndex * pb0 = pb ; int64_t minTime = pb0 -> GetBlockTime ( ) ; int64_t maxTime = minTime ; for ( int i = 0 ; i < lookup ; i ++ ) { pb0 = pb0 -> pprev ; int64_t time = pb0 -> GetBlockTime ( ) ; minTime = std :: min ( time , minTime ) ; maxTime = std :: max ( time , maxTime ) ; } if ( minTime == maxTime ) return 0 ; uint256 workDiff = pb -> nChainWork - pb0 -> nChainWork ; int64_t timeDiff = maxTime - minTime ; return ( int64_t ) ( workDiff . getdouble ( ) / timeDiff ) ; }
Return average network hashes per second based on the last 'lookup' blocks,
 or from the last difficulty change if 'lookup' is nonpositive.
Return average network hashes per second based on the last ' lookup ' blocks or from the last difficulty change if ' lookup ' is nonpositive .
// If lookup is -1, then use blocks since last difficulty change. // If lookup is larger than chain, then set it to chain length. // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.