<commit_before>// Copyright (c) 2014-2016 The Dash developers
// Copyright (c) 2016-2020 The PIVX developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef SPORK_H
#define SPORK_H

#include "base58.h"
#include "hash.h"
#include "key.h"
#include "messagesigner.h"
#include "net.h"
#include "sporkid.h"
#include "sync.h"
#include "util.h"

#include "protocol.h"


class CSporkMessage;
class CSporkManager;

extern std::vector<CSporkDef> sporkDefs;
extern std::map<uint256, CSporkMessage> mapSporks;
extern CSporkManager sporkManager;

//
// Spork Classes
// Keep track of all of the network spork settings
//

class CSporkMessage : public CSignedMessage
{
public:
    SporkId nSporkID;
    int64_t nValue;
    int64_t nTimeSigned;

    CSporkMessage() :
        CSignedMessage(),
        nSporkID((SporkId)0),
        nValue(0),
        nTimeSigned(0)
    {}

    CSporkMessage(SporkId nSporkID, int64_t nValue, int64_t nTimeSigned) :
        CSignedMessage(),
        nSporkID(nSporkID),
        nValue(nValue),
        nTimeSigned(nTimeSigned)
    { }

    uint256 GetHash() const { return HashQuark(BEGIN(nSporkID), END(nTimeSigned)); }

    // override CSignedMessage functions
    uint256 GetSignatureHash() const override;
    std::string GetStrMessage() const override;

    // - gets Params().SporkPubkey()
    const CPubKey GetPublicKey() const;
    const CPubKey GetPublicKeyOld() const;

    void Relay();

    ADD_SERIALIZE_METHODS;

    template <typename Stream, typename Operation>
    inline void SerializationOp(Stream& s, Operation ser_action)
    {
        READWRITE(nSporkID);
        READWRITE(nValue);
        READWRITE(nTimeSigned);
        READWRITE(vchSig);
        try
        {
            READWRITE(nMessVersion);
        } catch (...) {
            nMessVersion = MessageVersion::MESS_VER_STRMESS;
        }
    }
};


class CSporkManager
{
private:
    mutable RecursiveMutex cs;
    std::string strMasterPrivKey;
    std::map<SporkId, CSporkDef*> sporkDefsById;
    std::map<std::string, CSporkDef*> sporkDefsByName;
    std::map<SporkId, CSporkMessage> mapSporksActive;

public:
    CSporkManager();

    ADD_SERIALIZE_METHODS;

    template <typename Stream, typename Operation>
    inline void SerializationOp(Stream& s, Operation ser_action)
    {
        READWRITE(mapSporksActive);
        // we don't serialize private key to prevent its leakage
    }

    void Clear();
    void LoadSporksFromDB();

    void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
    int64_t GetSporkValue(SporkId nSporkID);
    void ExecuteSpork(SporkId nSporkID, int nValue);
    // Create/Sign/Relay the spork message, and update the maps
    bool UpdateSpork(SporkId nSporkID, int64_t nValue);
    // Add spork message to mapSporks and mapSporksActive
    void AddSporkMessage(const CSporkMessage& spork);

    bool IsSporkActive(SporkId nSporkID);
    std::string GetSporkNameByID(SporkId id);
    SporkId GetSporkIDByName(std::string strName);

    bool SetPrivKey(std::string strPrivKey);
    std::string ToString() const;

    // Process SPORK message, returning the banning score (or 0 if no banning is needed)
    int ProcessSporkMsg(CDataStream& vRecv);
    int ProcessSporkMsg(CSporkMessage& spork);
    // Process GETSPORKS message
    void ProcessGetSporks(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
};

#endif<commit_msg>[Cleanup][Trivial] Remove un-implemented function ExecuteSpork<commit_after>// Copyright (c) 2014-2016 The Dash developers
// Copyright (c) 2016-2020 The PIVX developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef SPORK_H
#define SPORK_H

#include "base58.h"
#include "hash.h"
#include "key.h"
#include "messagesigner.h"
#include "net.h"
#include "sporkid.h"
#include "sync.h"
#include "util.h"

#include "protocol.h"


class CSporkMessage;
class CSporkManager;

extern std::vector<CSporkDef> sporkDefs;
extern std::map<uint256, CSporkMessage> mapSporks;
extern CSporkManager sporkManager;

//
// Spork Classes
// Keep track of all of the network spork settings
//

class CSporkMessage : public CSignedMessage
{
public:
    SporkId nSporkID;
    int64_t nValue;
    int64_t nTimeSigned;

    CSporkMessage() :
        CSignedMessage(),
        nSporkID((SporkId)0),
        nValue(0),
        nTimeSigned(0)
    {}

    CSporkMessage(SporkId nSporkID, int64_t nValue, int64_t nTimeSigned) :
        CSignedMessage(),
        nSporkID(nSporkID),
        nValue(nValue),
        nTimeSigned(nTimeSigned)
    { }

    uint256 GetHash() const { return HashQuark(BEGIN(nSporkID), END(nTimeSigned)); }

    // override CSignedMessage functions
    uint256 GetSignatureHash() const override;
    std::string GetStrMessage() const override;

    // - gets Params().SporkPubkey()
    const CPubKey GetPublicKey() const;
    const CPubKey GetPublicKeyOld() const;

    void Relay();

    ADD_SERIALIZE_METHODS;

    template <typename Stream, typename Operation>
    inline void SerializationOp(Stream& s, Operation ser_action)
    {
        READWRITE(nSporkID);
        READWRITE(nValue);
        READWRITE(nTimeSigned);
        READWRITE(vchSig);
        try
        {
            READWRITE(nMessVersion);
        } catch (...) {
            nMessVersion = MessageVersion::MESS_VER_STRMESS;
        }
    }
};


class CSporkManager
{
private:
    mutable RecursiveMutex cs;
    std::string strMasterPrivKey;
    std::map<SporkId, CSporkDef*> sporkDefsById;
    std::map<std::string, CSporkDef*> sporkDefsByName;
    std::map<SporkId, CSporkMessage> mapSporksActive;

public:
    CSporkManager();

    ADD_SERIALIZE_METHODS;

    template <typename Stream, typename Operation>
    inline void SerializationOp(Stream& s, Operation ser_action)
    {
        READWRITE(mapSporksActive);
        // we don't serialize private key to prevent its leakage
    }

    void Clear();
    void LoadSporksFromDB();

    void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
    int64_t GetSporkValue(SporkId nSporkID);
    // Create/Sign/Relay the spork message, and update the maps
    bool UpdateSpork(SporkId nSporkID, int64_t nValue);
    // Add spork message to mapSporks and mapSporksActive
    void AddSporkMessage(const CSporkMessage& spork);

    bool IsSporkActive(SporkId nSporkID);
    std::string GetSporkNameByID(SporkId id);
    SporkId GetSporkIDByName(std::string strName);

    bool SetPrivKey(std::string strPrivKey);
    std::string ToString() const;

    // Process SPORK message, returning the banning score (or 0 if no banning is needed)
    int ProcessSporkMsg(CDataStream& vRecv);
    int ProcessSporkMsg(CSporkMessage& spork);
    // Process GETSPORKS message
    void ProcessGetSporks(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
};

#endif
{'fraction_non_alphanumeric': 0.0994277539341917, 'fraction_numerical': 0.012875536480686695, 'mean_word_length': 3.5603392041748205, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6556858', 'n_tokens_mistral': 2417, 'n_tokens_neox': 2293, 'n_words': 556}