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

#ifndef BITCOIN_KEY_IO_H
#define BITCOIN_KEY_IO_H

#include <chainparams.h>
#include <key.h>
#include <pubkey.h>
#include <script/standard.h>

#include <string>

#include <key/extkey.h>
#include <key/stealth.h>
#include <script/script.h>
#include <support/allocators/zeroafterfree.h>
#include <bech32.h>
#include <base58.h>

CKey DecodeSecret(const std::string& str);
std::string EncodeSecret(const CKey& key);

CExtKey DecodeExtKey(const std::string& str);
std::string EncodeExtKey(const CExtKey& extkey);
CExtPubKey DecodeExtPubKey(const std::string& str);
std::string EncodeExtPubKey(const CExtPubKey& extpubkey);

std::string EncodeDestination(const CTxDestination& dest, bool fBech32=false, bool stake_only=false);
CTxDestination DecodeDestination(const std::string& str, bool allow_stake_only=false);
bool IsValidDestinationString(const std::string& str, bool allow_stake_only=false);
bool IsValidDestinationString(const std::string& str, const CChainParams& params, bool allow_stake_only=false);

/**
 * Base class for all base58-encoded data
 */
class CBase58Data
{
protected:
    //! the version byte(s)
    std::vector<unsigned char> vchVersion;

    //! the actually encoded data
    typedef std::vector<unsigned char, zero_after_free_allocator<unsigned char> > vector_uchar;
    vector_uchar vchData;
    bool fBech32;

    CBase58Data();
    void SetData(const std::vector<unsigned char> &vchVersionIn, const void* pdata, size_t nSize);
    void SetData(const std::vector<unsigned char> &vchVersionIn, const unsigned char *pbegin, const unsigned char *pend);

public:
    bool SetString(const char* psz, unsigned int nVersionBytes = 1);
    bool SetString(const std::string& str);
    std::string ToString() const;
    int CompareTo(const CBase58Data& b58) const;

    bool operator==(const CBase58Data& b58) const { return CompareTo(b58) == 0; }
    bool operator<=(const CBase58Data& b58) const { return CompareTo(b58) <= 0; }
    bool operator>=(const CBase58Data& b58) const { return CompareTo(b58) >= 0; }
    bool operator< (const CBase58Data& b58) const { return CompareTo(b58) <  0; }
    bool operator> (const CBase58Data& b58) const { return CompareTo(b58) >  0; }

    bool IsBech32() const {return fBech32;}
};

/** base58-encoded Bitcoin addresses.
 * Public-key-hash-addresses have version 0 (or 111 testnet).
 * The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key.
 * Script-hash-addresses have version 5 (or 196 testnet).
 * The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.
 */
class CBitcoinAddress : public CBase58Data {
public:
    bool Set(const CKeyID &id, bool fBech32 = false);
    bool Set(const CScriptID &id, bool fBech32 = false);
    bool Set(const CKeyID256 &id, bool fBech32 = false);
    bool Set(const CScriptID256 &id, bool fBech32 = false);
    bool Set(const CKeyID &id, CChainParams::Base58Type prefix, bool fBech32 = false);
    bool Set(const CStealthAddress &sx, bool fBech32 = false);
    bool Set(const CExtKeyPair &ek, bool fBech32 = false);
    bool Set(const CTxDestination &dest, bool fBech32 = false);

    bool IsValidStealthAddress() const;
    bool IsValidStealthAddress(const CChainParams &params) const;
    bool IsValid() const;
    bool IsValid(const CChainParams &params) const;
    bool IsValid(CChainParams::Base58Type prefix) const;

    CBitcoinAddress() {}
    explicit CBitcoinAddress(const CTxDestination &dest) { Set(dest); }
    explicit CBitcoinAddress(const CTxDestination &dest, bool fBech32) { Set(dest, fBech32); }
    explicit CBitcoinAddress(const std::string& strAddress) { SetString(strAddress); }
    explicit CBitcoinAddress(const char* pszAddress) { SetString(pszAddress); }

    CTxDestination Get() const;
    CTxDestination GetStakeOnly() const;
    bool GetKeyID(CKeyID &keyID) const;
    bool GetKeyID(CKeyID256 &keyID) const;
    bool GetKeyID(CKeyID &keyID, CChainParams::Base58Type prefix) const;
    bool IsScript() const;

    uint8_t getVersion()
    {
        // TODO: Fix for multibyte versions
        if (vchVersion.size() > 0)
            return vchVersion[0];
        return 0;
    }
    std::vector<uint8_t> &getVchVersion()
    {
        return vchVersion;
    }
    void setVersion(const std::vector<uint8_t> &version)
    {
        vchVersion = version;<commit_msg>Fix shadow field warning.<commit_after>// Copyright (c) 2009-2010 <NAME>
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_KEY_IO_H
#define BITCOIN_KEY_IO_H

#include <chainparams.h>
#include <key.h>
#include <pubkey.h>
#include <script/standard.h>

#include <string>

#include <key/extkey.h>
#include <key/stealth.h>
#include <script/script.h>
#include <support/allocators/zeroafterfree.h>
#include <bech32.h>
#include <base58.h>

CKey DecodeSecret(const std::string& str);
std::string EncodeSecret(const CKey& key);

CExtKey DecodeExtKey(const std::string& str);
std::string EncodeExtKey(const CExtKey& extkey);
CExtPubKey DecodeExtPubKey(const std::string& str);
std::string EncodeExtPubKey(const CExtPubKey& extpubkey);

std::string EncodeDestination(const CTxDestination& dest, bool fBech32=false, bool stake_only=false);
CTxDestination DecodeDestination(const std::string& str, bool allow_stake_only=false);
bool IsValidDestinationString(const std::string& str, bool allow_stake_only=false);
bool IsValidDestinationString(const std::string& str, const CChainParams& params, bool allow_stake_only=false);

/**
 * Base class for all base58-encoded data
 */
class CBase58Data
{
protected:
    //! the version byte(s)
    std::vector<unsigned char> vchVersion;

    //! the actually encoded data
    typedef std::vector<unsigned char, zero_after_free_allocator<unsigned char> > vector_uchar;
    vector_uchar vchData;
    bool fBech32;

    CBase58Data();
    void SetData(const std::vector<unsigned char> &vchVersionIn, const void* pdata, size_t nSize);
    void SetData(const std::vector<unsigned char> &vchVersionIn, const unsigned char *pbegin, const unsigned char *pend);

public:
    bool SetString(const char* psz, unsigned int nVersionBytes = 1);
    bool SetString(const std::string& str);
    std::string ToString() const;
    int CompareTo(const CBase58Data& b58) const;

    bool operator==(const CBase58Data& b58) const { return CompareTo(b58) == 0; }
    bool operator<=(const CBase58Data& b58) const { return CompareTo(b58) <= 0; }
    bool operator>=(const CBase58Data& b58) const { return CompareTo(b58) >= 0; }
    bool operator< (const CBase58Data& b58) const { return CompareTo(b58) <  0; }
    bool operator> (const CBase58Data& b58) const { return CompareTo(b58) >  0; }

    bool IsBech32() const {return fBech32;}
};

/** base58-encoded Bitcoin addresses.
 * Public-key-hash-addresses have version 0 (or 111 testnet).
 * The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key.
 * Script-hash-addresses have version 5 (or 196 testnet).
 * The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.
 */
class CBitcoinAddress : public CBase58Data {
public:
    bool Set(const CKeyID &id, bool fBech32 = false);
    bool Set(const CScriptID &id, bool fBech32 = false);
    bool Set(const CKeyID256 &id, bool fBech32 = false);
    bool Set(const CScriptID256 &id, bool fBech32 = false);
    bool Set(const CKeyID &id, CChainParams::Base58Type prefix, bool fBech32 = false);
    bool Set(const CStealthAddress &sx, bool fBech32 = false);
    bool Set(const CExtKeyPair &ek, bool fBech32 = false);
    bool Set(const CTxDestination &dest, bool fBech32 = false);

    bool IsValidStealthAddress() const;
    bool IsValidStealthAddress(const CChainParams &params) const;
    bool IsValid() const;
    bool IsValid(const CChainParams &params) const;
    bool IsValid(CChainParams::Base58Type prefix) const;

    CBitcoinAddress() {}
    explicit CBitcoinAddress(const CTxDestination &dest) { Set(dest); }
    explicit CBitcoinAddress(const CTxDestination &dest, bool bech32) { Set(dest, bech32); }
    explicit CBitcoinAddress(const std::string& strAddress) { SetString(strAddress); }
    explicit CBitcoinAddress(const char* pszAddress) { SetString(pszAddress); }

    CTxDestination Get() const;
    CTxDestination GetStakeOnly() const;
    bool GetKeyID(CKeyID &keyID) const;
    bool GetKeyID(CKeyID256 &keyID) const;
    bool GetKeyID(CKeyID &keyID, CChainParams::Base58Type prefix) const;
    bool IsScript() const;

    uint8_t getVersion()
    {
        // TODO: Fix for multibyte versions
        if (vchVersion.size() > 0)
            return vchVersion[0];
        return 0;
    }
    std::vector<uint8_t> &getVchVersion()
    {
        return vchVersion;
    }
    void setVersion(const std::vector<uint8_t> &version)
    {
        vchVersion = version;
{'fraction_non_alphanumeric': 0.1091991341991342, 'fraction_numerical': 0.030086580086580085, 'mean_word_length': 4.617629179331307, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 51, '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': '6108062', 'n_tokens_mistral': 3164, 'n_tokens_neox': 2988, 'n_words': 842}