diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9885cc6..9e0dd38 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -324,7 +324,7 @@ class CTestNetParams : public CChainParams { fRequireStandard = false; m_is_test_chain = true; m_is_mockable_chain = false; - strSporkKey = "04EA9AF53E4F12CE41F78B666EBDBE96C966ABDD8832979228BD3299E13089F117936EF97B7B9D4644B8B9D2BC7A30029BD7FDDCAC36E40AAC0E03891E493CF197"; + strSporkKey = "04fb22e1ca5304b7dd1e36dfdd03b61b82454573a02a86d875d98da840a33e86dc4709baf8aa2c45ccfcf31027451f6831dd080978fc90dbf411bf12fb15b60d7b"; strDevfundAddress = "mr59c3aniaN3qHXej5L8UBsssRZbiUUMnz"; strLegacySignerDummyAddress = "mr59c3aniaN3qHXej5L8UBsssRZbiUUMnz"; checkpointData = { diff --git a/src/crown/legacysigner.cpp b/src/crown/legacysigner.cpp index 8dc18ca..2db40d9 100755 --- a/src/crown/legacysigner.cpp +++ b/src/crown/legacysigner.cpp @@ -79,19 +79,13 @@ bool CLegacySigner::SetCollateralAddress(std::string strAddress) bool CLegacySigner::SetKey(std::string strSecret, CKey& key, CPubKey& pubkey) { - //auto m_wallet = GetMainWallet(); - //EnsureLegacyScriptPubKeyMan(*m_wallet, true); - key = DecodeSecret(strSecret); - if (!key.IsValid()) + if (!key.IsValid()){ + LogPrintf("CLegacySigner::SetKey - Failed Key is not valid\n"); return false; + } pubkey = key.GetPubKey(); - //auto spk_man = m_wallet->GetScriptPubKeyMan(GetScriptForDestination(PKHash(pubkey.GetID()))); - - //if(!spk_man) - // return false; - return true; } diff --git a/src/crown/spork.cpp b/src/crown/spork.cpp index 8331154..37daac3 100644 --- a/src/crown/spork.cpp +++ b/src/crown/spork.cpp @@ -233,8 +233,12 @@ bool CSporkManager::Sign(CSporkMessage& spork) CKey key2; CPubKey pubkey2; std::string errorMessage = ""; - - if (!legacySigner.SetKey(strMasterPrivKey, key2, pubkey2)) { + std::string privk = strMasterPrivKey; + + if (privk == "" && gArgs.IsArgSet("-sporkkey")) // spork priv key + privk = gArgs.GetArg("-sporkkey", ""); + + if (!legacySigner.SetKey(privk, key2, pubkey2)) { LogPrintf("CMasternodePayments::Sign - ERROR: Invalid masternodeprivkey: '%s'\n", errorMessage); return false; } @@ -280,12 +284,16 @@ void CSporkManager::Relay(CSporkMessage& msg) bool CSporkManager::SetPrivKey(std::string strPrivKey) { CSporkMessage msg; + LogPrintf("CSporkManager::SetPrivKey - setting private key %s\n", strPrivKey); // Test signing successful, proceed strMasterPrivKey = strPrivKey; - Sign(msg); - + if(!Sign(msg)){ + LogPrintf("CSporkManager::SetPrivKey - Failed to Sign\n"); + return false; + } + if (CheckSignature(msg)) { LogPrintf("CSporkManager::SetPrivKey - Successfully initialized as spork signer\n"); return true; diff --git a/src/init.cpp b/src/init.cpp index 0312ad8..dad4219 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -611,7 +611,8 @@ void SetupServerArgs(NodeContext& node) argsman.AddArg("-systemnode", "Run as systemnode", false, OptionsCategory::RPC); argsman.AddArg("-systemnodeprivkey", "Systemnode private key", false, OptionsCategory::RPC); argsman.AddArg("-systemnodeaddr", strprintf(_("Set external address:port to get to this systemnode (example: %s)").translated, "1.2.3.4:12345"), false, OptionsCategory::RPC); - + argsman.AddArg("-sporkkey", strprintf(_("Set spork key (example: %s)").translated, "xxxxxxxxxxxxxxxxxxxxxx"), false, OptionsCategory::RPC); + #if HAVE_DECL_DAEMON argsman.AddArg("-daemon", "Run in the background as a daemon and accept commands", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); #else @@ -1406,6 +1407,11 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA #if ENABLE_ZMQ RegisterZMQRPCCommands(tableRPC); #endif + if (args.IsArgSet("-sporkkey")) // spork priv key + { + if (!sporkManager.SetPrivKey(args.GetArg("-sporkkey", ""))) + return InitError(_("Unable to sign spork message, wrong key?")); + } /* Start the RPC server already. It will be started in "warmup" mode * and not really process calls already (but it will signify connections diff --git a/src/masternode/masternode-payments.cpp b/src/masternode/masternode-payments.cpp index f0b4b5b..f45d90a 100755 --- a/src/masternode/masternode-payments.cpp +++ b/src/masternode/masternode-payments.cpp @@ -179,17 +179,12 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe CAmount blockValue = GetBlockSubsidy(pindexPrev->nHeight, Params().GetConsensus()); CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight+1, blockValue); - if(txNew.nVersion >= TX_ELE_VERSION) - txNew.vpout[0].nValue = blockValue; - else - txNew.vout[0].nValue = blockValue; - - if(hasPayment){ if(txNew.nVersion >= TX_ELE_VERSION){ txNew.vpout.resize(2); txNew.vpout[MN_PMT_SLOT].scriptPubKey = payee; txNew.vpout[MN_PMT_SLOT].nValue = masternodePayment; + txNew.vpout[MN_PMT_SLOT].nAsset = txNew.vpout[0].nAsset; txNew.vpout[0].nValue -= masternodePayment; }else{ txNew.vout.resize(2); diff --git a/src/miner.cpp b/src/miner.cpp index b21862a..20333d0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -183,11 +183,6 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc coinbaseTx.vpout[0].nAsset = Params().GetConsensus().subsidy_asset; } - pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx)); - pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus()); - pblocktemplate->vTxFees[0] = -nFees; - - if (fProofOfStake && ::ChainActive().Height() + 1 >= Params().PoSStartHeight()) { pblock->nTime = GetAdjustedTime(); CBlockIndex* pindexPrev = ::ChainActive().Tip(); @@ -218,7 +213,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc } // Masternode and general budget payments - if (IsSporkActive(SPORK_4_ENABLE_MASTERNODE_PAYMENTS)) { + if (IsSporkActive(SPORK_4_ENABLE_MASTERNODE_PAYMENTS) || Params().NetworkIDString() == CBaseChainParams::TESTNET) { FillBlockPayee(coinbaseTx, nFees); SNFillBlockPayee(coinbaseTx, nFees); } @@ -252,6 +247,10 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc pblock->payeeSN = coinbaseTx.vout[SN_PMT_SLOT].scriptPubKey; } + pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx)); + pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus()); + pblocktemplate->vTxFees[0] = -nFees; + LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n %s\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost, pblock->ToString()); // Fill in header diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 7e9e6fe..b33972f 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -188,6 +188,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "unloadwallet", 1, "load_on_startup"}, { "getnodeaddresses", 0, "count"}, { "addpeeraddress", 1, "port"}, + { "spork", 1, "value" }, { "stop", 0, "wait" } }; // clang-format on diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 3e66933..8a61b20 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -3,11 +3,14 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include #include #include +#include +#include #include #include #include @@ -20,6 +23,7 @@ #include #include #include +#include #include #include @@ -696,6 +700,142 @@ static RPCHelpMan getindexinfo() }; } +static RPCHelpMan getstakepointers() +{ + return RPCHelpMan{"getstakepointers", + "\nReturns current stake pointers\n", + {}, + RPCResult{RPCResult::Type::NONE, "", ""}, + RPCExamples{ + HelpExampleCli("getstakepointers", "") + + HelpExampleRpc("getstakepointers", "") + }, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue +{ + std::vector vStakePointers; + currentNode.GetRecentStakePointers(vStakePointers); + + UniValue ret(UniValue::VARR); + + for (auto p : vStakePointers) { + UniValue obj(UniValue::VOBJ); + obj.pushKV("blockhash", p.hashBlock.GetHex()); + obj.pushKV("hashpubkey", p.pubKeyProofOfStake.GetID().GetHex()); + obj.pushKV("pos", (int64_t)p.nPos); + obj.pushKV("txid", p.txid.GetHex()); + ret.push_back(obj); + } + + return ret; +}, + }; +} + +static RPCHelpMan mnsync() +{ + return RPCHelpMan{"mnsync", + {"\nReturns the sync status, updates to the next step or resets it entirely.\n"}, + { + {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "The command to issue (status|next|reset)"}, + }, + RPCResult{RPCResult::Type::STR, "result", "Result"}, + RPCExamples{ + HelpExampleCli("mnsync", "status") + + HelpExampleRpc("mnsync", "status") + }, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue +{ + + NodeContext& node = EnsureNodeContext(request.context); + std::string strMode = request.params[0].get_str(); + + if(strMode == "status") { + UniValue objStatus(UniValue::VOBJ); + objStatus.pushKV("IsBlockchainSynced", masternodeSync.IsBlockchainSynced() && systemnodeSync.IsBlockchainSynced()); + objStatus.pushKV("IsSynced", masternodeSync.IsSynced() && systemnodeSync.IsSynced()); + return objStatus; + } + + if(strMode == "next") + { + ++masternodeSync.RequestedMasternodeAssets; + ++systemnodeSync.RequestedSystemnodeAssets; + return "success"; + } + + if(strMode == "reset") + { + masternodeSync.Reset(); + systemnodeSync.Reset(); + return "success"; + } + return "failure"; +}, + }; +} + +static RPCHelpMan spork() +{ + return RPCHelpMan{"spork", + "\nEnable/Disable sporks or show info\n", + { + {"mode", RPCArg::Type::STR, RPCArg::Optional::NO, "spork mode"}, + {"value", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "spork mode []"}, + }, + RPCResult{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::BOOL, "isvalid", "If the address is valid or not. If not, this is the only property returned."}, + {RPCResult::Type::STR, "address", "The crown address validated"}, + {RPCResult::Type::STR_HEX, "scriptPubKey", "The hex-encoded scriptPubKey generated by the address"}, + {RPCResult::Type::BOOL, "isscript", "If the key is a script"}, + {RPCResult::Type::BOOL, "iswitness", "If the address is a witness address"}, + {RPCResult::Type::NUM, "witness_version", /* optional */ true, "The version number of the witness program"}, + {RPCResult::Type::STR_HEX, "witness_program", /* optional */ true, "The hex value of the witness program"}, + } + }, + RPCExamples{ + HelpExampleCli("spork", "show") + + HelpExampleRpc("spork", "active") + }, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue +{ + UniValue ret(UniValue::VOBJ); + + if(request.params.size() == 1 && request.params[0].get_str() == "show"){ + for(int nSporkID = SPORK_START; nSporkID <= SPORK_END; nSporkID++){ + if(sporkManager.GetSporkNameByID(nSporkID) != "Unknown") + ret.pushKV(sporkManager.GetSporkNameByID(nSporkID), GetSporkValue(nSporkID)); + } + } else if(request.params.size() == 1 && request.params[0].get_str() == "active"){ + for(int nSporkID = SPORK_START; nSporkID <= SPORK_END; nSporkID++){ + if(sporkManager.GetSporkNameByID(nSporkID) != "Unknown") + ret.pushKV(sporkManager.GetSporkNameByID(nSporkID), IsSporkActive(nSporkID)); + } + } else if (request.params.size() == 2){ + std::string name = request.params[0].get_str(); + int nSporkID = sporkManager.GetSporkIDByName(name); + if(nSporkID == -1){ + return "Invalid spork name"; + } + + // SPORK VALUE + int64_t nValue = request.params[1].get_int64(); + + //broadcast new spork + if(sporkManager.UpdateSpork(nSporkID, nValue)){ + ExecuteSpork(nSporkID, nValue); + ret.pushKV("result", "success"); + } else { + ret.pushKV("result", "failure"); + } + } + return ret; + +}, + }; +} + void RegisterMiscRPCCommands(CRPCTable &t) { // clang-format off @@ -711,6 +851,10 @@ static const CRPCCommand commands[] = { "util", "verifymessage", &verifymessage, {"address","signature","message"} }, { "util", "signmessagewithprivkey", &signmessagewithprivkey, {"privkey","message"} }, { "util", "getindexinfo", &getindexinfo, {"index_name"} }, + { "util", "getstakepointers", &getstakepointers, {} }, + + { "crown", "mnsync", &mnsync, {"command"} }, + { "crown", "spork", &spork, {"command"} }, /* Not shown in help */ { "hidden", "setmocktime", &setmocktime, {"timestamp"}}, diff --git a/src/systemnode/systemnode-payments.cpp b/src/systemnode/systemnode-payments.cpp index dfa324c..ab788fa 100755 --- a/src/systemnode/systemnode-payments.cpp +++ b/src/systemnode/systemnode-payments.cpp @@ -232,6 +232,7 @@ void CSystemnodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe // [0] is for miner, [1] masternode, [2] systemnode txNew.vpout[2].scriptPubKey = payee; txNew.vpout[2].nValue = systemnodePayment; + txNew.vpout[2].nAsset = txNew.vpout[0].nAsset; txNew.vpout[0].nValue -= systemnodePayment; } else{ diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 99a2292..49a9600 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2468,6 +2468,9 @@ void CWallet::AvailableCoins(std::vector& vCoins, bool fOnlySafe, const continue; } + if (out.nValue == 10000*COIN || out.nValue == 500*COIN) + continue; + std::unique_ptr provider = GetSolvingProvider(out.scriptPubKey); bool solvable = provider ? IsSolvable(*provider, out.scriptPubKey) : false; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index d860dc2..921a063 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1360,7 +1360,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati bool GetActiveSystemnode(CSystemnode*& activeStakingNode); uint256 GenerateStakeModifier(const CBlockIndex* prewardBlockIndex) const; bool CreateCoinStake(const int nHeight, const uint32_t& nBits, const uint32_t& nTime, CMutableTransaction& txCoinStake, uint32_t& nTxNewTime, StakePointer& stakePointer); - bool GetRecentStakePointers(std::vector& vStakePointers); void Stake(bool fStake); };