Skip to content

Commit

Permalink
Merge pull request #29 from projectmemetic/master
Browse files Browse the repository at this point in the history
version 2.8 Hardfork to staking only
  • Loading branch information
cryptopepe authored Oct 23, 2018
2 parents 42668bc + 02ae434 commit 6694fd1
Showing 15 changed files with 233 additions and 28 deletions.
15 changes: 14 additions & 1 deletion src/base58.cpp
Original file line number Diff line number Diff line change
@@ -211,6 +211,12 @@ bool CBase58Data::SetString(const std::string& str) {
return SetString(str.c_str());
}

std::string CBase58Data::ToKekdaqString() const {
std::vector<unsigned char> vch = Params().Base58Prefix(CChainParams::KEKDAQ_SECRET_KEY);
vch.insert(vch.end(), vchData.begin(), vchData.end());
return EncodeBase58Check(vch);
}

std::string CBase58Data::ToString() const {
std::vector<unsigned char> vch = vchVersion;
vch.insert(vch.end(), vchData.begin(), vchData.end());
@@ -296,6 +302,13 @@ void CBitcoinSecret::SetKey(const CKey& vchSecret) {
vchData.push_back(1);
}

void CBitcoinSecret::SetKekdaqKey(const CKey& vchSecret) {
assert(vchSecret.IsValid());
SetData(Params().Base58Prefix(CChainParams::KEKDAQ_SECRET_KEY), vchSecret.begin(), vchSecret.size());
if (vchSecret.IsCompressed())
vchData.push_back(1);
}

CKey CBitcoinSecret::GetKey() {
CKey ret;
ret.Set(&vchData[0], &vchData[32], vchData.size() > 32 && vchData[32] == 1);
@@ -304,7 +317,7 @@ CKey CBitcoinSecret::GetKey() {

bool CBitcoinSecret::IsValid() const {
bool fExpectedFormat = vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1);
bool fCorrectVersion = vchVersion == Params().Base58Prefix(CChainParams::SECRET_KEY);
bool fCorrectVersion = vchVersion == Params().Base58Prefix(CChainParams::SECRET_KEY) || vchVersion == Params().Base58Prefix(CChainParams::KEKDAQ_SECRET_KEY);
return fExpectedFormat && fCorrectVersion;
}

4 changes: 3 additions & 1 deletion src/base58.h
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ class CBase58Data
bool SetString(const char* psz, unsigned int nVersionBytes = 1);
bool SetString(const std::string& str);
std::string ToString() const;
std::string ToKekdaqString() const;
int CompareTo(const CBase58Data& b58) const;

bool operator==(const CBase58Data& b58) const { return CompareTo(b58) == 0; }
@@ -122,11 +123,12 @@ class CBitcoinSecret : public CBase58Data
{
public:
void SetKey(const CKey& vchSecret);
void SetKekdaqKey(const CKey& vchSecret);
CKey GetKey();
bool IsValid() const;
bool SetString(const char* pszSecret);
bool SetString(const std::string& strSecret);

CBitcoinSecret(const CKey& vchSecret) { SetKey(vchSecret); }
CBitcoinSecret() {}
};
2 changes: 2 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
@@ -106,6 +106,7 @@ class CMainParams : public CChainParams {
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,55); // pepecoin addresses start with P
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,85);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,153);
base58Prefixes[KEKDAQ_SECRET_KEY] = std::vector<unsigned char>(1,99);
base58Prefixes[STEALTH_ADDRESS] = std::vector<unsigned char>(1,40);
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >();;
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();;
@@ -169,6 +170,7 @@ class CTestNetParams : public CMainParams {
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,55);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[KEKDAQ_SECRET_KEY] = std::vector<unsigned char>(1,63);
base58Prefixes[STEALTH_ADDRESS] = std::vector<unsigned char>(1,40);
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();;
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();;
2 changes: 1 addition & 1 deletion src/chainparams.h
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ class CChainParams
STEALTH_ADDRESS,
EXT_PUBLIC_KEY,
EXT_SECRET_KEY,

KEKDAQ_SECRET_KEY,
MAX_BASE58_TYPES
};

2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 2
#define CLIENT_VERSION_MINOR 7
#define CLIENT_VERSION_MINOR 8
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 0

50 changes: 45 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1611,6 +1611,16 @@ int64_t nSubsidy = 20 * COIN;
if (nHeight >= PEPE_JACKOLANTERN_FORK_HEIGHT)
nSubsidy = 1 * COIN; // Minimum 1 PEPE stake return for optimal KEKDAQ functionality.

if (nHeight >= PEPE_STAKEONLY_HEIGHT)
{
// adopt the proof-of-work reward schedule when swap over to stake only
// this will pick up the current pow reward of 3.25 at fork height with halving
nSubsidy = 15 * COIN;
nSubsidy >>= ((nHeight - PEPE_STAKEONLY_HEIGHT) / 525600); // block reward halves once a year

if(nSubsidy < 1 * COIN) // minimum 1 PEPE stake return
nSubsidy = 1 * COIN;
}

if(nHeight+1 == PEPE_REBRAND_PF_HEIGHT)
nSubsidy += (3 * PEPE_DEV_GRANT);
@@ -1622,6 +1632,8 @@ int64_t nSubsidy = 20 * COIN;
nSubsidy += (3 * PEPE_DEV_GRANT);
if(nHeight+1 == PEPE_KEKDAQ2_SWAP_HEIGHT)
nSubsidy += (3 * DEVFEE_OFF_SWAP_FINAL);
if(nHeight+1 == PEPE_STAKEONLY_HEIGHT)
nSubsidy += (4 * PEPE_SO_SWAP_GRANT);

return nSubsidy + nFees;
}
@@ -3046,7 +3058,7 @@ bool CBlock::AcceptBlock()
CBlockIndex* pindexPrev = (*mi).second;
int nHeight = pindexPrev->nHeight+1;

if (IsProofOfWork() && nHeight > STOP_POW_BLOCK && nHeight < RESTART_POW_BLOCK )
if (IsProofOfWork() && ((nHeight > STOP_POW_BLOCK && nHeight < RESTART_POW_BLOCK) || nHeight >= PEPE_STAKEONLY_HEIGHT))
return DoS(100, error("AcceptBlock() : reject proof-of-work at height %d", nHeight));

if (IsProofOfStake() && nHeight < Params().POSStartBlock() )
@@ -3148,9 +3160,14 @@ bool CBlock::CheckDevRewards(CTransaction tx, int64_t nHeight, int64_t nReward,
if (nHeight == PEPE_STAKE_CONF_HEIGHT)
nDevReward = PEPE_DEV_GRANT;
if (nHeight == PEPE_KEKDAQ2_SWAP_HEIGHT)
nDevReward = DEVFEE_OFF_SWAP_FINAL;
nDevReward = DEVFEE_OFF_SWAP_FINAL;
if (nHeight == PEPE_STAKEONLY_HEIGHT)
nDevReward = PEPE_SO_SWAP_GRANT;

int64_t nTotalDevRewards = 3 * nDevReward;
if(nHeight >= PEPE_STAKEONLY_HEIGHT)
nTotalDevRewards = 4 * nDevReward;

int64_t nFoundDevRewards = 0;

CBitcoinAddress addrDevOne;
@@ -3162,10 +3179,14 @@ bool CBlock::CheckDevRewards(CTransaction tx, int64_t nHeight, int64_t nReward,
CBitcoinAddress addrDevThree;
addrDevThree.SetString(DecodeBase64(PEPE_REBRAND_DEV_3));
CScript payeeDevThree = GetScriptForDestination(addrDevThree.Get());
CBitcoinAddress addrDevFour;
addrDevFour.SetString(DecodeBase64(PEPE_DEV_4));
CScript payeeDevFour = GetScriptForDestination(addrDevFour.Get());

bool bFoundDevOne = false;
bool bFoundDevTwo = false;
bool bFoundDevThree = false;
bool bFoundDevFour = false;
for(unsigned int i=0; i<tx.vout.size(); i++)
{
txnouttype type;
@@ -3204,14 +3225,33 @@ bool CBlock::CheckDevRewards(CTransaction tx, int64_t nHeight, int64_t nReward,
nFoundDevRewards += nDevReward;
}
}

if(addrFound == addrDevFour)
{
if(tx.vout[i].nValue >= nDevReward)
{
bFoundDevFour = true;
nFoundDevRewards += nDevReward;
}
}
}
}
}

if((bFoundDevOne && bFoundDevTwo && bFoundDevThree) && (nFoundDevRewards >= nTotalDevRewards))
return true;
if(nHeight >= PEPE_STAKEONLY_HEIGHT)
{
if((bFoundDevOne && bFoundDevTwo && bFoundDevThree && bFoundDevFour) && (nFoundDevRewards >= nTotalDevRewards))
return true;
else
return false;
}
else
return false;
{
if((bFoundDevOne && bFoundDevTwo && bFoundDevThree) && (nFoundDevRewards >= nTotalDevRewards))
return true;
else
return false;
}
}

uint256 CBlockIndex::GetBlockTrust() const
3 changes: 3 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ static const int64_t PEPE_REBRAND_HEIGHT_TESTNET = 100;
static const std::string PEPE_REBRAND_DEV_1 = "UE5hSlMzbVBNY1FjNmdZc0xKMUg4endHSDZIMVh4VG40OA==";
static const std::string PEPE_REBRAND_DEV_2 = "UFJyeFZQWGNUQjN2TGNjZlBVRlRNVzJ6NTd3Skd3ZEd1ag==";
static const std::string PEPE_REBRAND_DEV_3 = "UExSY1ZHVmNZdkE2NmJNWGVQd2hSUTJleFdNdlBvVm83MQ==";
static const std::string PEPE_DEV_4 = "UFUxWm05N3R6NmRyQ0FuQmZNYjVFd2s3R0NSa3FYV2dZeA==";
static const int64_t PEPE_REBRAND_PF_HEIGHT = 600000;
static const int64_t PEPE_KEKDAQ_MID_HEIGHT = 733333;
static const int64_t PEPE_KEKDAQ_MID_FIX_HEIGHT = 738500;
@@ -87,8 +88,10 @@ static const int64_t PEPE_DEV_GRANT = 333333 * COIN;
static const int64_t PEPE_DEV_GRANT_MID = 333333 * COIN;
static const int64_t PEPE_DEV_GRANT_FINAL = 111111 * COIN;
static const int64_t DEVFEE_OFF_SWAP_FINAL = 777777 * COIN;
static const int64_t PEPE_SO_SWAP_GRANT = 888888 * COIN;
static const int64_t PEPE_STAKE_CONF_HEIGHT = 1021111;
static const int64_t PEPE_STAKE_CONF_TWEAK = 1177777;
static const int64_t PEPE_STAKEONLY_HEIGHT = 1700000;

/** The maximum allowed size for a serialized block, in bytes (network rule) */
static const unsigned int MAX_BLOCK_SIZE = 20000000;
2 changes: 1 addition & 1 deletion src/rpcclient.cpp
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "signrawtransaction", 1 },
{ "signrawtransaction", 2 },
{ "keypoolrefill", 0 },
{ "importprivkey", 2 },
{ "importprivkey", 2 },
{ "importaddress", 2 },
{ "checkkernel", 0 },
{ "checkkernel", 1 },
41 changes: 41 additions & 0 deletions src/rpcdump.cpp
Original file line number Diff line number Diff line change
@@ -339,6 +339,47 @@ Value dumpprivkey(const Array& params, bool fHelp)
return CBitcoinSecret(vchSecret).ToString();
}

Value dumpkekdaqprivkey(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"dumpkekdaqprivkey <pepecoinaddress>\n"
"Reveals the kekdaq format private key corresponding to <pepecoinaddress>.");

EnsureWalletIsUnlocked();

string strAddress = params[0].get_str();
CBitcoinAddress address;
if (!address.SetString(strAddress))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PepeCoin address");
if (fWalletUnlockStakingOnly)
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Wallet is unlocked for staking only.");
CKeyID keyID;
if (!address.GetKeyID(keyID))
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
CKey vchSecret;
if (!pwalletMain->GetKey(keyID, vchSecret))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
return CBitcoinSecret(vchSecret).ToKekdaqString();
}

Value checkprivkey(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 1)
throw runtime_error(
"checkprivkey <pepecoinprivkey>\n"
"Check a private key for validity.");

string strSecret = params[0].get_str();

CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret);

if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");

return Value::null;
}

Value dumpwallet(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
9 changes: 6 additions & 3 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
@@ -265,7 +265,8 @@ Value getworkex(const Array& params, bool fHelp)
if (IsInitialBlockDownload())
throw JSONRPCError(-10, "PepeCoin is downloading blocks...");

if (pindexBest->nHeight >= Params().LastPOWBlock() && pindexBest->nHeight < Params().RestartPOWBlock())
if (pindexBest->nHeight >= Params().LastPOWBlock() &&
(pindexBest->nHeight < Params().RestartPOWBlock() || pindexBest->nHeight >= PEPE_STAKEONLY_HEIGHT))
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");

typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
@@ -399,7 +400,8 @@ Value getwork(const Array& params, bool fHelp)
if (IsInitialBlockDownload())
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "PepeCoin is downloading blocks...");

if (pindexBest->nHeight >= Params().LastPOWBlock() && pindexBest->nHeight < Params().RestartPOWBlock())
if (pindexBest->nHeight >= Params().LastPOWBlock() &&
(pindexBest->nHeight < Params().RestartPOWBlock() || pindexBest->nHeight >= PEPE_STAKEONLY_HEIGHT))
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");

typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
@@ -551,7 +553,8 @@ Value getblocktemplate(const Array& params, bool fHelp)
//if (IsInitialBlockDownload())
// throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "PepeCoin is downloading blocks...");

if (pindexBest->nHeight >= Params().LastPOWBlock() && pindexBest->nHeight < Params().RestartPOWBlock())
if (pindexBest->nHeight >= Params().LastPOWBlock() &&
(pindexBest->nHeight < Params().RestartPOWBlock() || pindexBest->nHeight >= PEPE_STAKEONLY_HEIGHT))
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");

// Update block
2 changes: 2 additions & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
@@ -296,6 +296,8 @@ static const CRPCCommand vRPCCommands[] =
{ "submitblock", &submitblock, false, false, false },
{ "listsinceblock", &listsinceblock, false, false, true },
{ "dumpprivkey", &dumpprivkey, false, false, true },
{ "dumpkekdaqprivkey", &dumpkekdaqprivkey, false, false, true },
{ "checkprivkey", &checkprivkey, false, false, true },
{ "dumpwallet", &dumpwallet, true, false, true },
{ "importprivkey", &importprivkey, false, false, true },
{ "importwallet", &importwallet, false, false, true },
3 changes: 2 additions & 1 deletion src/rpcserver.h
Original file line number Diff line number Diff line change
@@ -109,8 +109,9 @@ extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHel
extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value importaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value dumpkekdaqprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value checkprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
4 changes: 2 additions & 2 deletions src/version.cpp
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
// Name of client reported in the 'version' message. Report the same name
// for both bitcoind and bitcoin-qt, to make it harder for attackers to
// target servers or GUI users specifically.
const std::string CLIENT_NAME("PepeCoin-Memetic-2.7.0.0");
const std::string CLIENT_NAME("PepeCoin-Memetic-2.8.0.0");

// Client version number
#define CLIENT_VERSION_SUFFIX "-Stage"
@@ -37,7 +37,7 @@ const std::string CLIENT_NAME("PepeCoin-Memetic-2.7.0.0");
// git will put "#define GIT_ARCHIVE 1" on the next line inside archives.
#define GIT_ARCHIVE 1
#ifdef GIT_ARCHIVE
# define GIT_COMMIT_ID "61414"
# define GIT_COMMIT_ID "61415"
#endif

#define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ static const int DATABASE_VERSION = 70509;
// network protocol versioning
//

static const int PROTOCOL_VERSION = 61414;
static const int PROTOCOL_VERSION = 61415;

// intial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
Loading

0 comments on commit 6694fd1

Please sign in to comment.