611879aa6d
* Support passing CKeyID to CMessageSigner/CHashSigner * Use Dash addresses instead of raw public keys for sporks The spork addresses are identical to the previously used public keys. Also use CKeyID/CKey directly inside CSporkManager instead of parsing the addresses/keys over and over. The default spork key (from chainparams) is initialized with InitDefaultSporkAddress(). SetPrivKey parses the private key now and stores it in sporkPrivKey instead of parsing it in CSporkMessage::Sign(). * Allow setting of spork address via command line * Remove unused strMasternodePaymentsPubKey chainparam Traces from the past... * Review fixes 1. Remove the need for InitDefaultSporkAddress 2. Remove bogus checks for hex private keys 3. Alphabetical order for new include 4. Add . to help string * Add regtest spork key As this key is not meant to be private, the private key is also added in the form of a comment (for later use in regtests) * Review fixes
122 lines
4.0 KiB
C++
122 lines
4.0 KiB
C++
// Copyright (c) 2014-2017 The Dash Core 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 "hash.h"
|
|
#include "net.h"
|
|
#include "utilstrencodings.h"
|
|
#include "key.h"
|
|
|
|
class CSporkMessage;
|
|
class CSporkManager;
|
|
|
|
/*
|
|
Don't ever reuse these IDs for other sporks
|
|
- This would result in old clients getting confused about which spork is for what
|
|
*/
|
|
static const int SPORK_START = 10001;
|
|
static const int SPORK_END = 10013;
|
|
|
|
static const int SPORK_2_INSTANTSEND_ENABLED = 10001;
|
|
static const int SPORK_3_INSTANTSEND_BLOCK_FILTERING = 10002;
|
|
static const int SPORK_5_INSTANTSEND_MAX_VALUE = 10004;
|
|
static const int SPORK_6_NEW_SIGS = 10005;
|
|
static const int SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT = 10007;
|
|
static const int SPORK_9_SUPERBLOCKS_ENABLED = 10008;
|
|
static const int SPORK_10_MASTERNODE_PAY_UPDATED_NODES = 10009;
|
|
static const int SPORK_12_RECONSIDER_BLOCKS = 10011;
|
|
static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013;
|
|
|
|
static const int64_t SPORK_2_INSTANTSEND_ENABLED_DEFAULT = 0; // ON
|
|
static const int64_t SPORK_3_INSTANTSEND_BLOCK_FILTERING_DEFAULT = 0; // ON
|
|
static const int64_t SPORK_5_INSTANTSEND_MAX_VALUE_DEFAULT = 1000; // 1000 DASH
|
|
static const int64_t SPORK_6_NEW_SIGS_DEFAULT = 4070908800ULL;// OFF
|
|
static const int64_t SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT_DEFAULT = 4070908800ULL;// OFF
|
|
static const int64_t SPORK_9_SUPERBLOCKS_ENABLED_DEFAULT = 4070908800ULL;// OFF
|
|
static const int64_t SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT = 4070908800ULL;// OFF
|
|
static const int64_t SPORK_12_RECONSIDER_BLOCKS_DEFAULT = 0; // 0 BLOCKS
|
|
static const int64_t SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT = 4070908800ULL;// OFF
|
|
|
|
extern std::map<uint256, CSporkMessage> mapSporks;
|
|
extern CSporkManager sporkManager;
|
|
|
|
//
|
|
// Spork classes
|
|
// Keep track of all of the network spork settings
|
|
//
|
|
|
|
class CSporkMessage
|
|
{
|
|
private:
|
|
std::vector<unsigned char> vchSig;
|
|
|
|
public:
|
|
int nSporkID;
|
|
int64_t nValue;
|
|
int64_t nTimeSigned;
|
|
|
|
CSporkMessage(int nSporkID, int64_t nValue, int64_t nTimeSigned) :
|
|
nSporkID(nSporkID),
|
|
nValue(nValue),
|
|
nTimeSigned(nTimeSigned)
|
|
{}
|
|
|
|
CSporkMessage() :
|
|
nSporkID(0),
|
|
nValue(0),
|
|
nTimeSigned(0)
|
|
{}
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
template <typename Stream, typename Operation>
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
|
READWRITE(nSporkID);
|
|
READWRITE(nValue);
|
|
READWRITE(nTimeSigned);
|
|
if (!(s.GetType() & SER_GETHASH)) {
|
|
READWRITE(vchSig);
|
|
}
|
|
}
|
|
|
|
uint256 GetHash() const;
|
|
uint256 GetSignatureHash() const;
|
|
|
|
bool Sign(const CKey& key);
|
|
bool CheckSignature(const CKeyID& pubKeyId) const;
|
|
void Relay(CConnman& connman);
|
|
};
|
|
|
|
|
|
class CSporkManager
|
|
{
|
|
private:
|
|
std::vector<unsigned char> vchSig;
|
|
std::map<int, CSporkMessage> mapSporksActive;
|
|
|
|
CKeyID sporkPubKeyID;
|
|
CKey sporkPrivKey;
|
|
|
|
public:
|
|
|
|
CSporkManager() {}
|
|
|
|
void ProcessSpork(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
|
|
void ExecuteSpork(int nSporkID, int nValue);
|
|
bool UpdateSpork(int nSporkID, int64_t nValue, CConnman& connman);
|
|
|
|
bool IsSporkActive(int nSporkID);
|
|
int64_t GetSporkValue(int nSporkID);
|
|
int GetSporkIDByName(const std::string& strName);
|
|
std::string GetSporkNameByID(int nSporkID);
|
|
|
|
bool SetSporkAddress(const std::string& strAddress);
|
|
bool SetPrivKey(const std::string& strPrivKey);
|
|
};
|
|
|
|
#endif
|