<commit_before>// Copyright (c) 2010 <NAME>
// Copyright (c) 2009-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "rpcserver.h"
#include "main.h"
#include "sync.h"
#include "checkpoints.h"

#include <stdint.h>

#include "json/json_spirit_value.h"

using namespace json_spirit;
using namespace std;

void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex);

double GetDifficulty(const CBlockIndex* blockindex, int algo)
{
    unsigned int nBits;
    
    // Floating point number that is a multiple of the minimum difficulty,
    // minimum difficulty = 1.0.
    if (blockindex == NULL)
    {
        if (chainActive.Tip() == NULL)
            nBits = Params().ProofOfWorkLimit(ALGO_SHA256D).GetCompact();
        else
        {
            blockindex = GetLastBlockIndexForAlgo(chainActive.Tip(), algo);
            if (blockindex == NULL)
                nBits = Params().ProofOfWorkLimit(algo).GetCompact();
            else
                nBits = blockindex->nBits;
        }
    }
    else
        nBits = blockindex->nBits;
    
    int nShift = (nBits >> 24) & 0xff;

    double dDiff =
        (double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff);

    while (nShift < 29)
    {
        dDiff *= 256.0;
        nShift++;
    }
    while (nShift > 29)
    {
        dDiff /= 256.0;<commit_msg>update to set a holder for nBits when blockindex is null and there are no previous blocks for the algo on the chain, like during initial sync<commit_after>// Copyright (c) 2010 <NAME>
// Copyright (c) 2009-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "rpcserver.h"
#include "main.h"
#include "sync.h"
#include "checkpoints.h"

#include <stdint.h>

#include "json/json_spirit_value.h"

using namespace json_spirit;
using namespace std;

void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex);

double GetDifficulty(const CBlockIndex* blockindex, int algo)
{
    unsigned int nBits;
    unsigned int nBitsSync;
    
    // Floating point number that is a multiple of the minimum difficulty,
    // minimum difficulty = 1.0.
    if (blockindex == NULL)
    {
        if (chainActive.Tip() == NULL)
            nBits = Params().ProofOfWorkLimit(ALGO_SHA256D).GetCompact();
        else
        {
            blockindex = GetLastBlockIndexForAlgo(chainActive.Tip(), algo);
            if (blockindex == NULL)
                nBits = Params().ProofOfWorkLimit(algo).GetCompact();
            else
                nBits = blockindex->nBits;
        }
    }
    else
        nBits = blockindex->nBits;
    
    int nShift = (nBits >> 24) & 0xff;
    nBitsSync = (blockindex == NULL) ? nBits : blockindex->nBits;

    double dDiff =
        (double)0x0000ffff / (double)(nBitsSync & 0x00ffffff);

    while (nShift < 29)
    {
        dDiff *= 256.0;
        nShift++;
    }
    while (nShift > 29)
    {
        dDiff /= 256.0;
{'fraction_non_alphanumeric': 0.11223842739378567, 'fraction_numerical': 0.02663284717818643, 'mean_word_length': 2.5649717514124295, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6235733', 'n_tokens_mistral': 1056, 'n_tokens_neox': 972, 'n_words': 267}