Skip to content

Commit 8a67941

Browse files
committed
Remove legacy "unspentreport" RPC command
1 parent b31482e commit 8a67941

File tree

3 files changed

+2
-226
lines changed

3 files changed

+2
-226
lines changed

src/rpcblockchain.cpp

Lines changed: 0 additions & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "neuralnet/tally.h"
1818
#include "backup.h"
1919
#include "appcache.h"
20-
#include "contract/polls.h"
2120
#include "contract/contract.h"
2221
#include "util.h"
2322

@@ -30,23 +29,18 @@ using namespace std;
3029

3130
extern std::string YesNo(bool bin);
3231
extern double DoubleFromAmount(int64_t amount);
33-
std::string PubKeyToAddress(const CScript& scriptPubKey);
34-
const CBlockIndex* GetHistoricalMagnitude(const NN::MiningId mining_id);
35-
extern std::string GetProvableVotingWeightXML();
3632
bool AskForOutstandingBlocks(uint256 hashStart);
3733
bool ForceReorganizeToHash(uint256 NewHash);
3834
extern UniValue GetUpgradedBeaconReport();
3935
extern UniValue MagnitudeReport(const NN::Cpid cpid);
4036
extern std::string ExtractValue(std::string data, std::string delimiter, int pos);
4137
extern UniValue SuperblockReport(int lookback = 14, bool displaycontract = false, std::string cpid = "");
4238
bool LoadAdminMessages(bool bFullTableScan,std::string& out_errors);
43-
std::string ExtractXML(const std::string& XMLdata, const std::string& key, const std::string& key_end);
4439
extern bool AdvertiseBeacon(std::string &sOutPrivKey, std::string &sOutPubKey, std::string &sError, std::string &sMessage);
4540
extern bool ScraperSynchronizeDPOR();
4641
std::string ExplainMagnitude(std::string sCPID);
4742

4843
extern UniValue GetJSONVersionReport(const int64_t lookback, const bool full_version);
49-
extern UniValue GetJsonUnspentReport();
5044
extern UniValue GetJSONBeaconReport();
5145

5246
bool GetEarliestStakeTime(std::string grcaddress, std::string cpid);
@@ -721,21 +715,6 @@ UniValue rainbymagnitude(const UniValue& params, bool fHelp)
721715
return res;
722716
}
723717

724-
UniValue unspentreport(const UniValue& params, bool fHelp)
725-
{
726-
if (fHelp || params.size() != 0)
727-
throw runtime_error(
728-
"unspentreport\n"
729-
"\n"
730-
"Displays unspentreport\n");
731-
732-
LOCK2(cs_main, pwalletMain->cs_wallet);
733-
734-
UniValue aUnspentReport = GetJsonUnspentReport();
735-
736-
return aUnspentReport;
737-
}
738-
739718
UniValue advertisebeacon(const UniValue& params, bool fHelp)
740719
{
741720
if (fHelp || params.size() != 0)
@@ -1961,207 +1940,6 @@ double DoubleFromAmount(int64_t amount)
19611940
return (double)amount / (double)COIN;
19621941
}
19631942

1964-
UniValue GetJsonUnspentReport()
1965-
{
1966-
// The purpose of this report is to list the details of unspent coins in the wallet, create a signed XML payload and then audit those coins as a third party
1967-
// Written on 5-28-2017 - R HALFORD
1968-
// We can use this as the basis for proving the total coin balance, and the current researcher magnitude in the voting system.
1969-
UniValue results(UniValue::VARR);
1970-
const NN::MiningId mining_id = NN::Researcher::Get()->Id();
1971-
1972-
//Retrieve the historical magnitude
1973-
if (const NN::CpidOption cpid = mining_id.TryCpid())
1974-
{
1975-
const CBlockIndex* pHistorical = GetHistoricalMagnitude(mining_id);
1976-
UniValue entry1(UniValue::VOBJ);
1977-
entry1.pushKV("Researcher Magnitude",pHistorical->nMagnitude);
1978-
results.push_back(entry1);
1979-
1980-
// Create the XML Magnitude Payload
1981-
if (pHistorical->nHeight > 1 && pHistorical->nMagnitude > 0)
1982-
{
1983-
std::string sBlockhash = pHistorical->GetBlockHash().GetHex();
1984-
std::string sError;
1985-
std::string sSignature;
1986-
bool bResult = SignBlockWithCPID(cpid->ToString(), pHistorical->GetBlockHash().GetHex(), sSignature, sError);
1987-
// Just because below comment it'll keep in line with that
1988-
if (!bResult)
1989-
sSignature = sError;
1990-
1991-
// Find the Magnitude from the last staked block, within the last 6 months, and ensure researcher has a valid current beacon (if the beacon is expired, the signature contain an error message)
1992-
1993-
std::string sMagXML = "<CPID>" + cpid->ToString() + "</CPID><INNERMAGNITUDE>" + RoundToString(pHistorical->nMagnitude,2) + "</INNERMAGNITUDE>" +
1994-
"<HEIGHT>" + ToString(pHistorical->nHeight) + "</HEIGHT><BLOCKHASH>" + sBlockhash + "</BLOCKHASH><SIGNATURE>" + sSignature + "</SIGNATURE>";
1995-
std::string sMagnitude = ExtractXML(sMagXML,"<INNERMAGNITUDE>","</INNERMAGNITUDE>");
1996-
std::string sXmlSigned = ExtractXML(sMagXML,"<SIGNATURE>","</SIGNATURE>");
1997-
std::string sXmlBlockHash = ExtractXML(sMagXML,"<BLOCKHASH>","</BLOCKHASH>");
1998-
std::string sXmlCPID = ExtractXML(sMagXML,"<CPID>","</CPID>");
1999-
UniValue entry(UniValue::VOBJ);
2000-
entry.pushKV("CPID Signature", sSignature);
2001-
entry.pushKV("Historical Magnitude Block #", pHistorical->nHeight);
2002-
entry.pushKV("Historical Blockhash", sBlockhash);
2003-
// Prove the magnitude from a 3rd party standpoint:
2004-
if (!sXmlBlockHash.empty() && !sMagnitude.empty() && !sXmlSigned.empty())
2005-
{
2006-
CBlockIndex* pblockindexMagnitude = mapBlockIndex[uint256S(sXmlBlockHash)];
2007-
if (pblockindexMagnitude)
2008-
{
2009-
bool fResult = VerifyCPIDSignature(sXmlCPID, sXmlBlockHash, sXmlSigned);
2010-
entry.pushKV("Historical Magnitude",pblockindexMagnitude->nMagnitude);
2011-
entry.pushKV("Signature Valid",fResult);
2012-
bool fAudited = (RoundFromString(RoundToString(pblockindexMagnitude->nMagnitude,2),0)==RoundFromString(sMagnitude,0) && fResult);
2013-
entry.pushKV("Magnitude Audited",fAudited);
2014-
results.push_back(entry);
2015-
}
2016-
}
2017-
2018-
2019-
}
2020-
2021-
2022-
}
2023-
2024-
// Now we move on to proving the coins we own are ours
2025-
2026-
vector<COutput> vecOutputs;
2027-
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
2028-
std::string sXML = "";
2029-
std::string sRow = "";
2030-
double dTotal = 0;
2031-
double dBloatThreshhold = 100;
2032-
double dCurrentItemCount = 0;
2033-
double dItemBloatThreshhold = 50;
2034-
// Iterate unspent coins from transactions owned by me that total over 100GRC (this prevents XML bloat)
2035-
for (auto const& out : vecOutputs)
2036-
{
2037-
int64_t nValue = out.tx->vout[out.i].nValue;
2038-
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
2039-
UniValue entry(UniValue::VOBJ);
2040-
CTxDestination address;
2041-
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
2042-
{
2043-
if (CoinToDouble(nValue) > dBloatThreshhold)
2044-
{
2045-
entry.pushKV("TXID", out.tx->GetHash().GetHex());
2046-
entry.pushKV("Address", CBitcoinAddress(address).ToString());
2047-
std::string sScriptPubKey1 = HexStr(pk.begin(), pk.end());
2048-
entry.pushKV("Amount",ValueFromAmount(nValue));
2049-
std::string strAddress=CBitcoinAddress(address).ToString();
2050-
CKeyID keyID;
2051-
const CBitcoinAddress& bcAddress = CBitcoinAddress(address);
2052-
if (bcAddress.GetKeyID(keyID))
2053-
{
2054-
bool IsCompressed;
2055-
CKey vchSecret;
2056-
if (pwalletMain->GetKey(keyID, vchSecret))
2057-
{
2058-
// Here we use the secret key to sign the coins, then we abandon the key.
2059-
CSecret csKey = vchSecret.GetSecret(IsCompressed);
2060-
CKey keyInner;
2061-
keyInner.SetSecret(csKey,IsCompressed);
2062-
std::string private_key = CBitcoinSecret(csKey,IsCompressed).ToString();
2063-
std::string public_key = HexStr(keyInner.GetPubKey().Raw());
2064-
std::vector<unsigned char> vchSig;
2065-
keyInner.Sign(out.tx->GetHash(), vchSig);
2066-
// Sign the coins we own
2067-
std::string sSig = std::string(vchSig.begin(), vchSig.end());
2068-
// Increment the total balance weight voting ability
2069-
dTotal += CoinToDouble(nValue);
2070-
sRow = "<ROW><TXID>" + out.tx->GetHash().GetHex() + "</TXID>" +
2071-
"<AMOUNT>" + RoundToString(CoinToDouble(nValue),2) + "</AMOUNT>" +
2072-
"<POS>" + RoundToString((double)out.i,0) + "</POS>" +
2073-
"<PUBKEY>" + public_key + "</PUBKEY>" +
2074-
"<SCRIPTPUBKEY>" + sScriptPubKey1 + "</SCRIPTPUBKEY>" +
2075-
"<SIG>" + EncodeBase64(sSig) + "</SIG>" +
2076-
"<MESSAGE></MESSAGE></ROW>";
2077-
sXML += sRow;
2078-
dCurrentItemCount++;
2079-
if (dCurrentItemCount >= dItemBloatThreshhold)
2080-
break;
2081-
}
2082-
2083-
}
2084-
results.push_back(entry);
2085-
}
2086-
}
2087-
}
2088-
2089-
// Now we will need to go back through the XML and Audit the claimed vote weight balance as a 3rd party
2090-
2091-
double dCounted = 0;
2092-
2093-
std::vector<std::string> vXML= split(sXML.c_str(),"<ROW>");
2094-
for (unsigned int x = 0; x < vXML.size(); x++)
2095-
{
2096-
// Prove the contents of the XML as a 3rd party
2097-
CTransaction tx2;
2098-
uint256 hashBlock;
2099-
uint256 uTXID = uint256S(ExtractXML(vXML[x],"<TXID>","</TXID>"));
2100-
std::string sAmt = ExtractXML(vXML[x],"<AMOUNT>","</AMOUNT>");
2101-
std::string sPos = ExtractXML(vXML[x],"<POS>","</POS>");
2102-
std::string sXmlSig = ExtractXML(vXML[x],"<SIG>","</SIG>");
2103-
std::string sXmlMsg = ExtractXML(vXML[x],"<MESSAGE>","</MESSAGE>");
2104-
std::string sScriptPubKeyXml = ExtractXML(vXML[x],"<SCRIPTPUBKEY>","</SCRIPTPUBKEY>");
2105-
2106-
int32_t iPos = RoundFromString(sPos,0);
2107-
std::string sPubKey = ExtractXML(vXML[x],"<PUBKEY>","</PUBKEY>");
2108-
2109-
if (!sPubKey.empty() && !sAmt.empty() && !sPos.empty() && !uTXID.IsNull())
2110-
{
2111-
2112-
if (GetTransaction(uTXID, tx2, hashBlock))
2113-
{
2114-
if (iPos >= 0 && iPos < (int32_t) tx2.vout.size())
2115-
{
2116-
int64_t nValue2 = tx2.vout[iPos].nValue;
2117-
const CScript& pk2 = tx2.vout[iPos].scriptPubKey;
2118-
CTxDestination address2;
2119-
std::string sVotedPubKey = HexStr(pk2.begin(), pk2.end());
2120-
std::string sVotedGRCAddress = CBitcoinAddress(address2).ToString();
2121-
std::string sCoinOwnerAddress = PubKeyToAddress(pk2);
2122-
double dAmount = CoinToDouble(nValue2);
2123-
if (ExtractDestination(tx2.vout[iPos].scriptPubKey, address2))
2124-
{
2125-
if (sScriptPubKeyXml == sVotedPubKey && RoundToString(dAmount,2) == sAmt)
2126-
{
2127-
UniValue entry(UniValue::VOBJ);
2128-
entry.pushKV("Audited Amount",ValueFromAmount(nValue2));
2129-
std::string sDecXmlSig = DecodeBase64(sXmlSig);
2130-
CKey keyVerify;
2131-
if (keyVerify.SetPubKey(ParseHex(sPubKey)))
2132-
{
2133-
std::vector<unsigned char> vchMsg1 = vector<unsigned char>(sXmlMsg.begin(), sXmlMsg.end());
2134-
std::vector<unsigned char> vchSig1 = vector<unsigned char>(sDecXmlSig.begin(), sDecXmlSig.end());
2135-
bool bValid = keyVerify.Verify(uTXID,vchSig1);
2136-
// Unspent Balance is proven to be owned by the voters public key, count the vote
2137-
if (bValid) dCounted += dAmount;
2138-
entry.pushKV("Verified",bValid);
2139-
}
2140-
2141-
results.push_back(entry);
2142-
}
2143-
}
2144-
}
2145-
}
2146-
}
2147-
}
2148-
2149-
UniValue entry(UniValue::VOBJ);
2150-
// Note that the voter needs to have the wallet at least unlocked for staking in order for the coins to be signed, otherwise the coins-owned portion of the vote balance will be 0.
2151-
// In simpler terms: The wallet must be unlocked to cast a provable vote.
2152-
2153-
entry.pushKV("Total Voting Balance Weight", dTotal);
2154-
entry.pushKV("Grand Verified Amount",dCounted);
2155-
2156-
std::string sBalCheck2 = GetProvableVotingWeightXML();
2157-
double dVerifiedBalance = ReturnVerifiedVotingBalance(sBalCheck2,true);
2158-
double dVerifiedMag = ReturnVerifiedVotingMagnitude(sBalCheck2, true);
2159-
entry.pushKV("Balance check",dVerifiedBalance);
2160-
entry.pushKV("Mag check",dVerifiedMag);
2161-
results.push_back(entry);
2162-
return results;
2163-
}
2164-
21651943
UniValue GetUpgradedBeaconReport()
21661944
{
21671945
UniValue results(UniValue::VARR);

src/rpcserver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ static const CRPCCommand vRPCCommands[] =
331331
{ "settxfee", &settxfee, cat_wallet },
332332
{ "signmessage", &signmessage, cat_wallet },
333333
{ "signrawtransaction", &signrawtransaction, cat_wallet },
334-
{ "unspentreport", &unspentreport, cat_wallet },
335334
{ "validateaddress", &validateaddress, cat_wallet },
336335
{ "validatepubkey", &validatepubkey, cat_wallet },
337336
{ "verifymessage", &verifymessage, cat_wallet },
@@ -670,7 +669,7 @@ void StartRPCThreads()
670669
StartShutdown();
671670
return;
672671
}
673-
672+
674673
rpc_worker_group = new boost::thread_group();
675674
for (int i = 0; i < GetArg("-rpcthreads", 4); i++)
676675
rpc_worker_group->create_thread(boost::bind(&ioContext::run, rpc_io_service));
@@ -688,7 +687,7 @@ void StopRPCThreads()
688687
rpc_io_service->stop();
689688
if (rpc_worker_group != NULL)
690689
rpc_worker_group->join_all();
691-
690+
692691
delete rpc_worker_group;
693692
rpc_worker_group = NULL;
694693
delete rpc_ssl_context;

src/rpcserver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ extern UniValue setaccount(const UniValue& params, bool fHelp);
149149
extern UniValue settxfee(const UniValue& params, bool fHelp);
150150
extern UniValue signmessage(const UniValue& params, bool fHelp);
151151
extern UniValue signrawtransaction(const UniValue& params, bool fHelp);
152-
extern UniValue unspentreport(const UniValue& params, bool fHelp);
153152
extern UniValue validateaddress(const UniValue& params, bool fHelp);
154153
extern UniValue validatepubkey(const UniValue& params, bool fHelp);
155154
extern UniValue verifymessage(const UniValue& params, bool fHelp);

0 commit comments

Comments
 (0)