update wallet section
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <amount.h>
|
||||
|
||||
#include <boost/signals2/last_value.hpp>
|
||||
#include <boost/signals2/signal.hpp>
|
||||
@@ -105,6 +106,10 @@ public:
|
||||
|
||||
/** Banlist did change. */
|
||||
boost::signals2::signal<void (void)> BannedListChanged;
|
||||
|
||||
/** Update the staked stats in the wallet header */
|
||||
|
||||
boost::signals2::signal<void(const CAmount& all, const CAmount& today, const CAmount& week)> SetStaked;
|
||||
};
|
||||
|
||||
/** Show warning message **/
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "db.h"
|
||||
#include <wallet/db.h>
|
||||
|
||||
#include "addrman.h"
|
||||
#include "hash.h"
|
||||
#include "protocol.h"
|
||||
#include "util.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include <init.h>
|
||||
#include <addrman.h>
|
||||
#include <hash.h>
|
||||
#include <protocol.h>
|
||||
#include <util.h>
|
||||
#include <utilstrencodings.h>
|
||||
#include <ui_interface.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -63,7 +65,7 @@ CDBEnv::~CDBEnv()
|
||||
{
|
||||
EnvShutdown();
|
||||
delete dbenv;
|
||||
dbenv = NULL;
|
||||
dbenv = nullptr;
|
||||
}
|
||||
|
||||
void CDBEnv::Close()
|
||||
@@ -154,10 +156,11 @@ CDBEnv::VerifyResult CDBEnv::Verify(const std::string& strFile, bool (*recoverFu
|
||||
assert(mapFileUseCount.count(strFile) == 0);
|
||||
|
||||
Db db(dbenv, 0);
|
||||
int result = db.verify(strFile.c_str(), NULL, NULL, 0);
|
||||
int result = db.verify(strFile.c_str(), nullptr, nullptr, 0);
|
||||
|
||||
if (result == 0)
|
||||
return VERIFY_OK;
|
||||
else if (recoverFunc == NULL)
|
||||
else if (recoverFunc == nullptr)
|
||||
return RECOVER_FAIL;
|
||||
|
||||
// Try to recover:
|
||||
@@ -182,7 +185,7 @@ bool CDBEnv::Salvage(const std::string& strFile, bool fAggressive, std::vector<C
|
||||
stringstream strDump;
|
||||
|
||||
Db db(dbenv, 0);
|
||||
int result = db.verify(strFile.c_str(), NULL, &strDump, flags);
|
||||
int result = db.verify(strFile.c_str(), nullptr, &strDump, flags);
|
||||
if (result == DB_VERIFY_BAD) {
|
||||
LogPrintf("CDBEnv::Salvage: Database salvage found errors, all data may not be recoverable.\n");
|
||||
if (!fAggressive) {
|
||||
@@ -239,8 +242,7 @@ void CDBEnv::CheckpointLSN(const std::string& strFile)
|
||||
dbenv->lsn_reset(strFile.c_str(), 0);
|
||||
}
|
||||
|
||||
|
||||
CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnCloseIn) : pdb(NULL), activeTxn(NULL)
|
||||
CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr)
|
||||
{
|
||||
int ret;
|
||||
fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
|
||||
@@ -248,7 +250,7 @@ CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnClose
|
||||
if (strFilename.empty())
|
||||
return;
|
||||
|
||||
bool fCreate = strchr(pszMode, 'c') != NULL;
|
||||
bool fCreate = strchr(pszMode, 'c') != nullptr;
|
||||
unsigned int nFlags = DB_THREAD;
|
||||
if (fCreate)
|
||||
nFlags |= DB_CREATE;
|
||||
@@ -261,7 +263,7 @@ CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnClose
|
||||
strFile = strFilename;
|
||||
++bitdb.mapFileUseCount[strFile];
|
||||
pdb = bitdb.mapDb[strFile];
|
||||
if (pdb == NULL) {
|
||||
if (pdb == nullptr) {
|
||||
pdb = new Db(bitdb.dbenv, 0);
|
||||
|
||||
bool fMockDb = bitdb.IsMock();
|
||||
@@ -281,7 +283,7 @@ CDB::CDB(const std::string& strFilename, const char* pszMode, bool fFlushOnClose
|
||||
|
||||
if (ret != 0) {
|
||||
delete pdb;
|
||||
pdb = NULL;
|
||||
pdb = nullptr;
|
||||
--bitdb.mapFileUseCount[strFile];
|
||||
strFile = "";
|
||||
throw runtime_error(strprintf("CDB: Error %d, can't open database %s", ret, strFilename));
|
||||
@@ -318,8 +320,8 @@ void CDB::Close()
|
||||
return;
|
||||
if (activeTxn)
|
||||
activeTxn->abort();
|
||||
activeTxn = NULL;
|
||||
pdb = NULL;
|
||||
activeTxn = nullptr;
|
||||
pdb = nullptr;
|
||||
|
||||
if (fFlushOnClose)
|
||||
Flush();
|
||||
@@ -334,12 +336,12 @@ void CDBEnv::CloseDb(const string& strFile)
|
||||
{
|
||||
{
|
||||
LOCK(cs_db);
|
||||
if (mapDb[strFile] != NULL) {
|
||||
if (mapDb[strFile] != nullptr) {
|
||||
// Close the database handle
|
||||
Db* pdb = mapDb[strFile];
|
||||
pdb->close(0);
|
||||
delete pdb;
|
||||
mapDb[strFile] = NULL;
|
||||
mapDb[strFile] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,7 +351,7 @@ bool CDBEnv::RemoveDb(const string& strFile)
|
||||
this->CloseDb(strFile);
|
||||
|
||||
LOCK(cs_db);
|
||||
int rc = dbenv->dbremove(NULL, strFile.c_str(), NULL, DB_AUTO_COMMIT);
|
||||
int rc = dbenv->dbremove(NULL, strFile.c_str(), nullptr, DB_AUTO_COMMIT);
|
||||
return (rc == 0);
|
||||
}
|
||||
|
||||
@@ -420,10 +422,10 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
|
||||
}
|
||||
if (fSuccess) {
|
||||
Db dbA(bitdb.dbenv, 0);
|
||||
if (dbA.remove(strFile.c_str(), NULL, 0))
|
||||
if (dbA.remove(strFile.c_str(), nullptr, 0))
|
||||
fSuccess = false;
|
||||
Db dbB(bitdb.dbenv, 0);
|
||||
if (dbB.rename(strFileRes.c_str(), NULL, strFile.c_str(), 0))
|
||||
if (dbB.rename(strFileRes.c_str(), nullptr, strFile.c_str(), 0))
|
||||
fSuccess = false;
|
||||
}
|
||||
if (!fSuccess)
|
||||
@@ -431,8 +433,10 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
|
||||
return fSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
MilliSleep(100);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
#ifndef BITCOIN_WALLET_DB_H
|
||||
#define BITCOIN_WALLET_DB_H
|
||||
|
||||
#include "clientversion.h"
|
||||
#include "serialize.h"
|
||||
#include "streams.h"
|
||||
#include "sync.h"
|
||||
#include "version.h"
|
||||
#include <clientversion.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <sync.h>
|
||||
#include <version.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -100,7 +100,7 @@ protected:
|
||||
bool fReadOnly;
|
||||
bool fFlushOnClose;
|
||||
|
||||
explicit CDB(const std::string& strFilename, const char* pszMode = "r+", bool fFlushOnCloseIn=true);
|
||||
explicit CDB(const std::string& strFilename, const char* pszMode = "r+", bool fFlushOnCloseIn = true);
|
||||
~CDB() { Close(); }
|
||||
|
||||
public:
|
||||
@@ -306,7 +306,7 @@ public:
|
||||
return Write(std::string("version"), nVersion);
|
||||
}
|
||||
|
||||
bool static Rewrite(const std::string& strFile, const char* pszSkip = NULL);
|
||||
bool static Rewrite(const std::string& strFile, const char* pszSkip = nullptr);
|
||||
};
|
||||
|
||||
#endif // BITCOIN_WALLET_DB_H
|
||||
|
||||
@@ -2,20 +2,20 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "base58.h"
|
||||
#include "chain.h"
|
||||
#include "dstencode.h"
|
||||
#include "rpc/server.h"
|
||||
#include "init.h"
|
||||
#include "main.h"
|
||||
#include "script/script.h"
|
||||
#include "script/standard.h"
|
||||
#include "sync.h"
|
||||
#include "util.h"
|
||||
#include "utiltime.h"
|
||||
#include "wallet.h"
|
||||
#include "merkleblock.h"
|
||||
#include "core_io.h"
|
||||
#include <base58.h>
|
||||
#include <chain.h>
|
||||
#include <dstencode.h>
|
||||
#include <rpc/server.h>
|
||||
#include <init.h>
|
||||
#include <main.h>
|
||||
#include <script/script.h>
|
||||
#include <script/standard.h>
|
||||
#include <sync.h>
|
||||
#include <util.h>
|
||||
#include <utiltime.h>
|
||||
#include <wallet/wallet.h>
|
||||
#include <merkleblock.h>
|
||||
#include <core_io.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void EnsureWalletIsUnlocked();
|
||||
@@ -51,7 +49,7 @@ int64_t static DecodeDumpTime(const std::string &str) {
|
||||
|
||||
std::string static EncodeDumpString(const std::string &str) {
|
||||
std::stringstream ret;
|
||||
BOOST_FOREACH(unsigned char c, str) {
|
||||
for(unsigned char c: str) {
|
||||
if (c <= 32 || c >= 128 || c == '%') {
|
||||
ret << '%' << HexStr(&c, &c + 1);
|
||||
} else {
|
||||
@@ -66,7 +64,7 @@ std::string DecodeDumpString(const std::string &str) {
|
||||
for (unsigned int pos = 0; pos < str.length(); pos++) {
|
||||
unsigned char c = str[pos];
|
||||
if (c == '%' && pos+2 < str.length()) {
|
||||
c = (((str[pos+1]>>6)*9+((str[pos+1]-'0')&15)) << 4) |
|
||||
c = (((str[pos+1]>>6)*9+((str[pos+1]-'0')&15)) << 4) |
|
||||
((str[pos+2]>>6)*9+((str[pos+2]-'0')&15));
|
||||
pos += 2;
|
||||
}
|
||||
@@ -79,13 +77,13 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
|
||||
if (fHelp || params.size() < 1 || params.size() > 3)
|
||||
throw runtime_error(
|
||||
"importprivkey \"bitcoinprivkey\" ( \"label\" rescan )\n"
|
||||
"importprivkey \"blackcoinprivkey\" ( \"label\" rescan )\n"
|
||||
"\nAdds a private key (as returned by dumpprivkey) to your wallet.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"bitcoinprivkey\" (string, required) The private key (see dumpprivkey)\n"
|
||||
"1. \"blackcoinprivkey\" (string, required) The private key (see dumpprivkey)\n"
|
||||
"2. \"label\" (string, optional, default=\"\") An optional label\n"
|
||||
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
|
||||
"\nNote: This call can take minutes to complete if rescan is true.\n"
|
||||
@@ -213,7 +211,7 @@ UniValue importaddress(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
|
||||
if (fHelp || params.size() < 1 || params.size() > 4)
|
||||
throw runtime_error(
|
||||
"importaddress \"address\" ( \"label\" rescan p2sh )\n"
|
||||
@@ -258,11 +256,8 @@ UniValue importaddress(const UniValue& params, bool fHelp)
|
||||
|
||||
CTxDestination dest = DecodeDestination(params[0].get_str());
|
||||
if (IsValidDestination(dest)) {
|
||||
if (fP2SH) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,
|
||||
"Cannot use the p2sh flag with an address - use "
|
||||
"a script instead");
|
||||
}
|
||||
if (fP2SH)
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Cannot use the p2sh flag with an address - use a script instead");
|
||||
ImportAddress(dest, strLabel);
|
||||
} else if (IsHex(params[0].get_str())) {
|
||||
std::vector<uint8_t> data(ParseHex(params[0].get_str()));
|
||||
@@ -438,7 +433,7 @@ UniValue importwallet(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"importwallet \"filename\"\n"
|
||||
@@ -493,8 +488,7 @@ UniValue importwallet(const UniValue& params, bool fHelp)
|
||||
assert(key.VerifyPubKey(pubkey));
|
||||
CKeyID keyid = pubkey.GetID();
|
||||
if (pwalletMain->HaveKey(keyid)) {
|
||||
LogPrintf("Skipping import of %s (key already present)\n",
|
||||
EncodeDestination(keyid));
|
||||
LogPrintf("Skipping import of %s (key already present)\n", EncodeDestination(keyid));
|
||||
continue;
|
||||
}
|
||||
int64_t nTime = DecodeDumpTime(vstr[1]);
|
||||
@@ -546,7 +540,7 @@ UniValue dumpprivkey(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"dumpprivkey \"blackcoinaddress\"\n"
|
||||
@@ -589,7 +583,7 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"dumpwallet \"filename\"\n"
|
||||
@@ -624,13 +618,13 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
|
||||
std::sort(vKeyBirth.begin(), vKeyBirth.end());
|
||||
|
||||
// produce output
|
||||
file << strprintf("# Wallet dump created by Bitcoin %s\n", CLIENT_BUILD);
|
||||
file << strprintf("# Wallet dump created by Blackcoin %s\n", CLIENT_BUILD);
|
||||
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
|
||||
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
|
||||
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
|
||||
file << "\n";
|
||||
|
||||
// add the base58check encoded extended master if the wallet uses HD
|
||||
// add the base58check encoded extended master if the wallet uses HD
|
||||
CKeyID masterKeyID = pwalletMain->GetHDChain().masterKeyID;
|
||||
if (!masterKeyID.IsNull())
|
||||
{
|
||||
@@ -646,7 +640,6 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
|
||||
file << "# extended private masterkey: " << b58extkey.ToString() << "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
|
||||
const CKeyID &keyid = it->second;
|
||||
std::string strTime = EncodeDumpTime(it->first);
|
||||
|
||||
@@ -3,29 +3,35 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "amount.h"
|
||||
#include "chain.h"
|
||||
#include "core_io.h"
|
||||
#include "dstencode.h"
|
||||
#include "init.h"
|
||||
#include "main.h"
|
||||
#include "net.h"
|
||||
#include "rpc/server.h"
|
||||
#include "timedata.h"
|
||||
#include "util.h"
|
||||
#include "utilmoneystr.h"
|
||||
#include "wallet.h"
|
||||
#include "walletdb.h"
|
||||
#include <amount.h>
|
||||
#include <base58.h>
|
||||
#include <chain.h>
|
||||
#include <core_io.h>
|
||||
#include <dstencode.h>
|
||||
#include <init.h>
|
||||
#include <main.h>
|
||||
#include <net.h>
|
||||
#include <netbase.h>
|
||||
#include <pos.h>
|
||||
#include <rpc/server.h>
|
||||
#include <txdb.h>
|
||||
#include <timedata.h>
|
||||
#include <util.h>
|
||||
#include <utilmoneystr.h>
|
||||
#include <wallet/wallet.h>
|
||||
#include <wallet/walletdb.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/assign/list_of.hpp>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <univalue.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int64_t nWalletUnlockTime;
|
||||
int64_t nWalletFirstStakeTime = -1;
|
||||
static CCriticalSection cs_nWalletUnlockTime;
|
||||
|
||||
static void accountingDeprecationCheck()
|
||||
@@ -89,13 +95,13 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
|
||||
uint256 hash = wtx.GetHash();
|
||||
entry.push_back(Pair("txid", hash.GetHex()));
|
||||
UniValue conflicts(UniValue::VARR);
|
||||
BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts())
|
||||
for(const uint256& conflict: wtx.GetConflicts())
|
||||
conflicts.push_back(conflict.GetHex());
|
||||
entry.push_back(Pair("walletconflicts", conflicts));
|
||||
entry.push_back(Pair("time", wtx.GetTxTime()));
|
||||
entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
|
||||
|
||||
BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue)
|
||||
for(const PAIRTYPE(string,string)& item: wtx.mapValue)
|
||||
entry.push_back(Pair(item.first, item.second));
|
||||
}
|
||||
|
||||
@@ -224,6 +230,7 @@ UniValue getrawchangeaddress(const UniValue& params, bool fHelp)
|
||||
return EncodeDestination(keyID);
|
||||
}
|
||||
|
||||
|
||||
UniValue setaccount(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
@@ -244,10 +251,8 @@ UniValue setaccount(const UniValue& params, bool fHelp)
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
CTxDestination dest = DecodeDestination(params[0].get_str());
|
||||
if (!IsValidDestination(dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,
|
||||
"Invalid Blackcoin address");
|
||||
}
|
||||
if (!IsValidDestination(dest))
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Blackcoin address");
|
||||
|
||||
string strAccount;
|
||||
if (params.size() > 1)
|
||||
@@ -256,8 +261,7 @@ UniValue setaccount(const UniValue& params, bool fHelp)
|
||||
// Only add the account if the address is yours.
|
||||
if (IsMine(*pwalletMain, dest))
|
||||
{
|
||||
// Detect when changing the account of an address that is the 'unused
|
||||
// current key' of another account:
|
||||
// Detect when changing the account of an address that is the 'unused current key' of another account:
|
||||
if (pwalletMain->mapAddressBook.count(dest))
|
||||
{
|
||||
std::string strOldAccount = pwalletMain->mapAddressBook[dest].name;
|
||||
@@ -272,6 +276,7 @@ UniValue setaccount(const UniValue& params, bool fHelp)
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
|
||||
UniValue getaccount(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
@@ -293,17 +298,13 @@ UniValue getaccount(const UniValue& params, bool fHelp)
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
CTxDestination dest = DecodeDestination(params[0].get_str());
|
||||
if (!IsValidDestination(dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,
|
||||
"Invalid Blackcoin address");
|
||||
}
|
||||
if (!IsValidDestination(dest))
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Blackcoin address");
|
||||
|
||||
std::string strAccount;
|
||||
std::map<CTxDestination, CAddressBookData>::iterator mi =
|
||||
pwalletMain->mapAddressBook.find(dest);
|
||||
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty()) {
|
||||
std::map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(dest);
|
||||
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty())
|
||||
strAccount = (*mi).second.name;
|
||||
}
|
||||
return strAccount;
|
||||
}
|
||||
|
||||
@@ -334,13 +335,11 @@ UniValue getaddressesbyaccount(const UniValue& params, bool fHelp)
|
||||
|
||||
// Find all addresses that have the given account
|
||||
UniValue ret(UniValue::VARR);
|
||||
for (const std::pair<CTxDestination, CAddressBookData> &item :
|
||||
pwalletMain->mapAddressBook) {
|
||||
for(const std::pair<CTxDestination, CAddressBookData>& item: pwalletMain->mapAddressBook) {
|
||||
const CTxDestination &dest = item.first;
|
||||
const std::string &strName = item.second.name;
|
||||
if (strName == strAccount) {
|
||||
if (strName == strAccount)
|
||||
ret.push_back(EncodeDestination(dest));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -582,7 +581,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
// Bitcoin address
|
||||
// Blackcoin address
|
||||
CTxDestination dest = DecodeDestination(params[0].get_str());
|
||||
if (!IsValidDestination(dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Blackcoin address");
|
||||
@@ -601,10 +600,10 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||||
{
|
||||
const CWalletTx& wtx = (*it).second;
|
||||
if (wtx.IsCoinBase() || wtx.IsCoinStake() ||!CheckFinalTx(wtx))
|
||||
if (wtx.IsCoinBase() || wtx.IsCoinStake() || !CheckFinalTx(wtx))
|
||||
continue;
|
||||
|
||||
for (const CTxOut &txout : wtx.vout)
|
||||
for(const CTxOut& txout: wtx.vout)
|
||||
if (txout.scriptPubKey == scriptPubKey)
|
||||
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
||||
nAmount += txout.nValue;
|
||||
@@ -613,6 +612,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||
return ValueFromAmount(nAmount);
|
||||
}
|
||||
|
||||
|
||||
UniValue getreceivedbyaccount(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
@@ -656,10 +656,10 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp)
|
||||
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||||
{
|
||||
const CWalletTx& wtx = (*it).second;
|
||||
if (wtx.IsCoinBase() || !CheckFinalTx(wtx))
|
||||
if (wtx.IsCoinBase() || wtx.IsCoinStake() || !CheckFinalTx(wtx))
|
||||
continue;
|
||||
|
||||
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
|
||||
for(const CTxOut& txout: wtx.vout)
|
||||
{
|
||||
CTxDestination address;
|
||||
if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address))
|
||||
@@ -730,10 +730,10 @@ UniValue getbalance(const UniValue& params, bool fHelp)
|
||||
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
|
||||
if (wtx.GetDepthInMainChain() >= nMinDepth)
|
||||
{
|
||||
BOOST_FOREACH(const COutputEntry& r, listReceived)
|
||||
for(const COutputEntry& r: listReceived)
|
||||
nBalance += r.amount;
|
||||
}
|
||||
BOOST_FOREACH(const COutputEntry& s, listSent)
|
||||
for(const COutputEntry& s: listSent)
|
||||
nBalance -= s.amount;
|
||||
nBalance -= allFee;
|
||||
}
|
||||
@@ -849,10 +849,8 @@ UniValue sendfrom(const UniValue& params, bool fHelp)
|
||||
|
||||
std::string strAccount = AccountFromValue(params[0]);
|
||||
CTxDestination dest = DecodeDestination(params[1].get_str());
|
||||
if (!IsValidDestination(dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,
|
||||
"Invalid Blackcoin address");
|
||||
}
|
||||
if (!IsValidDestination(dest))
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Blackcoin address");
|
||||
CAmount nAmount = AmountFromValue(params[2]);
|
||||
if (nAmount <= 0)
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
|
||||
@@ -943,19 +941,14 @@ UniValue sendmany(const UniValue& params, bool fHelp)
|
||||
|
||||
CAmount totalAmount = 0;
|
||||
std::vector<std::string> keys = sendTo.getKeys();
|
||||
for (const std::string &name_ : keys) {
|
||||
for(const std::string& name_: keys)
|
||||
{
|
||||
CTxDestination dest = DecodeDestination(name_);
|
||||
if (!IsValidDestination(dest)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,
|
||||
std::string("Invalid Blackcoin address: ") +
|
||||
name_);
|
||||
}
|
||||
if (!IsValidDestination(dest))
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Blackcoin address: ")+name_);
|
||||
|
||||
if (destinations.count(dest)) {
|
||||
throw JSONRPCError(
|
||||
RPC_INVALID_PARAMETER,
|
||||
std::string("Invalid parameter, duplicated address: ") + name_);
|
||||
}
|
||||
if (destinations.count(dest))
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+name_);
|
||||
destinations.insert(dest);
|
||||
|
||||
CScript scriptPubKey = GetScriptForDestination(dest);
|
||||
@@ -1080,10 +1073,9 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
||||
|
||||
// Tally
|
||||
std::map<CTxDestination, tallyitem> mapTally;
|
||||
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
|
||||
it != pwalletMain->mapWallet.end(); ++it)
|
||||
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||||
{
|
||||
const CWalletTx &wtx = (*it).second;
|
||||
const CWalletTx& wtx = (*it).second;
|
||||
|
||||
// CValidationState state;
|
||||
if (wtx.IsCoinBase() || !CheckFinalTx(wtx))
|
||||
@@ -1093,7 +1085,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
||||
if (nDepth < nMinDepth)
|
||||
continue;
|
||||
|
||||
for (const CTxOut &txout : wtx.vout)
|
||||
for(const CTxOut& txout: wtx.vout)
|
||||
{
|
||||
CTxDestination address;
|
||||
if (!ExtractDestination(txout.scriptPubKey, address))
|
||||
@@ -1115,10 +1107,10 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
||||
// Reply
|
||||
UniValue ret(UniValue::VARR);
|
||||
std::map<std::string, tallyitem> mapAccountTally;
|
||||
for (const std::pair<CTxDestination, CAddressBookData> &item : pwalletMain->mapAddressBook)
|
||||
for(const std::pair<CTxDestination, CAddressBookData>& item: pwalletMain->mapAddressBook)
|
||||
{
|
||||
const CTxDestination &dest = item.first;
|
||||
const std::string &strAccount = item.second.name;
|
||||
const std::string& strAccount = item.second.name;
|
||||
std::map<CTxDestination, tallyitem>::iterator it = mapTally.find(dest);
|
||||
if (it == mapTally.end() && !fIncludeEmpty)
|
||||
continue;
|
||||
@@ -1144,23 +1136,17 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
if(fIsWatchonly)
|
||||
{
|
||||
obj.push_back(Pair("involvesWatchonly", true));
|
||||
}
|
||||
obj.push_back(Pair("address", EncodeDestination(dest)));
|
||||
obj.push_back(Pair("account", strAccount));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
|
||||
obj.push_back(
|
||||
Pair("confirmations",
|
||||
(nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
||||
obj.push_back(Pair("confirmations",(nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
||||
if (!fByAccounts)
|
||||
{
|
||||
obj.push_back(Pair("label", strAccount));
|
||||
}
|
||||
UniValue transactions(UniValue::VARR);
|
||||
if (it != mapTally.end())
|
||||
{
|
||||
for (const uint256 &item : (*it).second.txids)
|
||||
for(const uint256& item: (*it).second.txids)
|
||||
{
|
||||
transactions.push_back(item.GetHex());
|
||||
}
|
||||
@@ -1530,7 +1516,7 @@ UniValue listaccounts(const UniValue& params, bool fHelp)
|
||||
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
|
||||
|
||||
map<string, CAmount> mapAccountBalances;
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
|
||||
for(const PAIRTYPE(CTxDestination, CAddressBookData)& entry: pwalletMain->mapAddressBook) {
|
||||
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
|
||||
mapAccountBalances[entry.second.name] = 0;
|
||||
}
|
||||
@@ -1547,11 +1533,11 @@ UniValue listaccounts(const UniValue& params, bool fHelp)
|
||||
continue;
|
||||
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
|
||||
mapAccountBalances[strSentAccount] -= nFee;
|
||||
BOOST_FOREACH(const COutputEntry& s, listSent)
|
||||
for(const COutputEntry& s: listSent)
|
||||
mapAccountBalances[strSentAccount] -= s.amount;
|
||||
if (nDepth >= nMinDepth)
|
||||
{
|
||||
BOOST_FOREACH(const COutputEntry& r, listReceived)
|
||||
for(const COutputEntry& r: listReceived)
|
||||
if (pwalletMain->mapAddressBook.count(r.destination))
|
||||
mapAccountBalances[pwalletMain->mapAddressBook[r.destination].name] += r.amount;
|
||||
else
|
||||
@@ -1560,11 +1546,11 @@ UniValue listaccounts(const UniValue& params, bool fHelp)
|
||||
}
|
||||
|
||||
const list<CAccountingEntry> & acentries = pwalletMain->laccentries;
|
||||
BOOST_FOREACH(const CAccountingEntry& entry, acentries)
|
||||
for(const CAccountingEntry& entry: acentries)
|
||||
mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
|
||||
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
BOOST_FOREACH(const PAIRTYPE(string, CAmount)& accountBalance, mapAccountBalances) {
|
||||
for(const PAIRTYPE(string, CAmount)& accountBalance: mapAccountBalances) {
|
||||
ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
|
||||
}
|
||||
return ret;
|
||||
@@ -1852,13 +1838,13 @@ UniValue walletpassphrase(const UniValue& params, bool fHelp)
|
||||
|
||||
if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3))
|
||||
throw runtime_error(
|
||||
"walletpassphrase \"passphrase\" timeout ( stakingonly )\n"
|
||||
"walletpassphrase \"passphrase\" timeout [stakingonly]\n"
|
||||
"\nStores the wallet decryption key in memory for 'timeout' seconds.\n"
|
||||
"This is needed prior to performing transactions related to private keys such as sending blackcoins\n"
|
||||
"This is needed prior to performing transactions related to private keys such as sending blackcoin\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"passphrase\" (string, required) The wallet passphrase\n"
|
||||
"2. timeout (numeric, required) The time to keep the decryption key in seconds.\n"
|
||||
"3. stakingonly (bool, optional, default=false) Unlock wallet for staking only.\n"
|
||||
"3. stakingonly (bool, optional) If it is true sending functions are disabled.\n"
|
||||
"\nNote:\n"
|
||||
"Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n"
|
||||
"time that overrides the old one.\n"
|
||||
@@ -2051,7 +2037,7 @@ UniValue encryptwallet(const UniValue& params, bool fHelp)
|
||||
// slack space in .dat files; that is bad if the old data is
|
||||
// unencrypted private keys. So:
|
||||
StartShutdown();
|
||||
return "wallet encrypted; Blackcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.";
|
||||
return _("wallet encrypted; Blackcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.");
|
||||
}
|
||||
|
||||
UniValue reservebalance(const UniValue& params, bool fHelp)
|
||||
@@ -2102,7 +2088,7 @@ UniValue lockunspent(const UniValue& params, bool fHelp)
|
||||
"\nUpdates list of temporarily unspendable outputs.\n"
|
||||
"Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n"
|
||||
"If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n"
|
||||
"A locked transaction output will not be chosen by automatic coin selection, when spending blackcoins.\n"
|
||||
"A locked transaction output will not be chosen by automatic coin selection, when spending blackcoin.\n"
|
||||
"Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n"
|
||||
"is always cleared (by virtue of process exit) when a node stops or fails.\n"
|
||||
"Also see the listunspent call\n"
|
||||
@@ -2218,7 +2204,7 @@ UniValue listlockunspent(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
|
||||
BOOST_FOREACH(COutPoint &outpt, vOutpts) {
|
||||
for(COutPoint &outpt: vOutpts) {
|
||||
UniValue o(UniValue::VOBJ);
|
||||
|
||||
o.push_back(Pair("txid", outpt.hash.GetHex()));
|
||||
@@ -2302,7 +2288,7 @@ UniValue getwalletinfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
|
||||
CKeyID masterKeyID = pwalletMain->GetHDChain().masterKeyID;
|
||||
if (!masterKeyID.IsNull())
|
||||
obj.push_back(Pair("hdmasterkeyid", masterKeyID.GetHex()));
|
||||
obj.push_back(Pair("hdmasterkeyid", masterKeyID.GetHex()));
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -2324,7 +2310,7 @@ UniValue resendwallettransactions(const UniValue& params, bool fHelp)
|
||||
|
||||
std::vector<uint256> txids = pwalletMain->ResendWalletTransactionsBefore(GetTime());
|
||||
UniValue result(UniValue::VARR);
|
||||
BOOST_FOREACH(const uint256& txid, txids)
|
||||
for(const uint256& txid: txids)
|
||||
{
|
||||
result.push_back(txid.ToString());
|
||||
}
|
||||
@@ -2603,6 +2589,265 @@ UniValue burn(const UniValue& params, bool fHelp)
|
||||
return wtx.GetHash().GetHex();
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////// ** em52
|
||||
// new rpc added by Remy5
|
||||
|
||||
struct StakePeriodRange_T {
|
||||
int64_t Start;
|
||||
int64_t End;
|
||||
int64_t Total;
|
||||
int Count;
|
||||
std::string Name;
|
||||
};
|
||||
|
||||
typedef std::vector<StakePeriodRange_T> vStakePeriodRange_T;
|
||||
|
||||
// Check if we have a Tx that can be counted in staking report
|
||||
bool IsTxCountedAsStaked(const CWalletTx* tx)
|
||||
{
|
||||
// Make sure we have a lock
|
||||
LOCK(cs_main);
|
||||
|
||||
// orphan block or immature
|
||||
if ((!tx->GetDepthInMainChain()) || (tx->GetBlocksToMaturity() > 0) || !tx->IsInMainChain())
|
||||
return false;
|
||||
|
||||
// abandoned transactions
|
||||
if (tx->isAbandoned())
|
||||
return false;
|
||||
|
||||
// transaction other than POS block
|
||||
return tx->IsCoinStake();
|
||||
}
|
||||
|
||||
// Get the amount for a staked tx used in staking report
|
||||
CAmount GetTxStakeAmount(const CWalletTx* tx)
|
||||
{
|
||||
// use the cached amount if available
|
||||
if (tx->fCreditCached && tx->fDebitCached )
|
||||
return tx->nCreditCached - tx->nDebitCached;
|
||||
// Check for cold staking
|
||||
// else if (tx->vout[1].scriptPubKey.IsColdStaking() || tx->vout[1].scriptPubKey.IsColdStakingv2())
|
||||
//return tx->GetCredit(pwalletMain->IsMine(tx->vout[1])) - tx->GetDebit(pwalletMain->IsMine(tx->vout[1]));
|
||||
|
||||
return tx->GetCredit(ISMINE_SPENDABLE, 0) - tx->GetDebit(ISMINE_SPENDABLE) ;
|
||||
}
|
||||
|
||||
// Gets timestamp for first stake
|
||||
// Returns -1 (Zero) if has not staked yet
|
||||
int64_t GetFirstStakeTime()
|
||||
{
|
||||
// Check if we already know when
|
||||
if (nWalletFirstStakeTime > 0)
|
||||
return nWalletFirstStakeTime;
|
||||
|
||||
// Need a pointer for the tx
|
||||
const CWalletTx* tx;
|
||||
|
||||
// scan the entire wallet transactions
|
||||
for(auto& it: pwalletMain->wtxOrdered)
|
||||
{
|
||||
tx = it.second.first;
|
||||
|
||||
// Check if we have a useable tx
|
||||
if (IsTxCountedAsStaked(tx)) {
|
||||
nWalletFirstStakeTime = tx->GetTxTime(); // Save it for later use
|
||||
return nWalletFirstStakeTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Did not find the first stake
|
||||
return nWalletFirstStakeTime;
|
||||
}
|
||||
|
||||
// **em52: Get total coins staked on given period
|
||||
// inspired from CWallet::GetStake()
|
||||
// Parameter aRange = Vector with given limit date, and result
|
||||
// return int = Number of Wallet's elements analyzed
|
||||
int GetsStakeSubTotal(vStakePeriodRange_T& aRange)
|
||||
{
|
||||
// Lock cs_main before we try to call GetTxStakeAmount
|
||||
LOCK(cs_main);
|
||||
|
||||
int nElement = 0;
|
||||
int64_t nAmount = 0;
|
||||
|
||||
const CWalletTx* pcoin;
|
||||
|
||||
vStakePeriodRange_T::iterator vIt;
|
||||
|
||||
// scan the entire wallet transactions
|
||||
for (map<uint256, CWalletTx>::const_iterator it = pwalletMain->mapWallet.begin();
|
||||
it != pwalletMain->mapWallet.end();
|
||||
++it)
|
||||
{
|
||||
pcoin = &(*it).second;
|
||||
|
||||
// Check if we have a useable tx
|
||||
if (!IsTxCountedAsStaked(pcoin))
|
||||
continue;
|
||||
|
||||
nElement++;
|
||||
|
||||
// Get the stake tx amount from pcoin
|
||||
nAmount = GetTxStakeAmount(pcoin);
|
||||
|
||||
// scan the range
|
||||
for(vIt=aRange.begin(); vIt != aRange.end(); vIt++)
|
||||
{
|
||||
if (pcoin->GetTxTime() >= vIt->Start)
|
||||
{
|
||||
if (! vIt->End)
|
||||
{ // Manage Special case
|
||||
vIt->Start = pcoin->GetTxTime();
|
||||
vIt->Total = nAmount;
|
||||
}
|
||||
else if (pcoin->GetTxTime() <= vIt->End)
|
||||
{
|
||||
vIt->Count++;
|
||||
vIt->Total += nAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nElement;
|
||||
}
|
||||
|
||||
// prepare range for stake report
|
||||
vStakePeriodRange_T PrepareRangeForStakeReport()
|
||||
{
|
||||
vStakePeriodRange_T aRange;
|
||||
StakePeriodRange_T x;
|
||||
|
||||
|
||||
int64_t n1Hour = 60*60;
|
||||
int64_t n1Day = 24 * n1Hour;
|
||||
|
||||
int64_t nToday = GetTime();
|
||||
time_t CurTime = nToday;
|
||||
auto localTime = boost::posix_time::second_clock::local_time();
|
||||
struct tm Loc_MidNight = boost::posix_time::to_tm(localTime);
|
||||
|
||||
Loc_MidNight.tm_hour = 0;
|
||||
Loc_MidNight.tm_min = 0;
|
||||
Loc_MidNight.tm_sec = 0; // set midnight
|
||||
|
||||
x.Start = mktime(&Loc_MidNight);
|
||||
x.End = nToday;
|
||||
x.Count = 0;
|
||||
x.Total = 0;
|
||||
|
||||
// prepare last single 30 day Range
|
||||
for(int i=0; i<30; i++)
|
||||
{
|
||||
|
||||
x.Name = DateTimeStrFormat("%Y-%m-%d %H:%M:%S",x.Start);
|
||||
|
||||
aRange.push_back(x);
|
||||
|
||||
x.End = x.Start - 1;
|
||||
x.Start -= n1Day;
|
||||
|
||||
}
|
||||
|
||||
// prepare subtotal range of last 24H, 1 week, 30 days, 1 years
|
||||
int GroupDays[5][2] = { {1, 0}, {7, 0}, {30, 0}, {365, 0}, {99999999, 0}};
|
||||
std::string sGroupName[] = {"24H", "7 Days", "30 Days", "365 Days", "All" };
|
||||
|
||||
nToday = GetTime();
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
x.Start = nToday - GroupDays[i][0] * n1Day;
|
||||
x.End = nToday - GroupDays[i][1] * n1Day;
|
||||
x.Name = "Last " + sGroupName[i];
|
||||
|
||||
aRange.push_back(x);
|
||||
}
|
||||
|
||||
// Special case. not a subtotal, but last stake
|
||||
x.End = 0;
|
||||
x.Start = 0;
|
||||
x.Name = "Latest Stake";
|
||||
aRange.push_back(x);
|
||||
|
||||
return aRange;
|
||||
}
|
||||
|
||||
|
||||
// getstakereport: return SubTotal of the staked coin in last 24H, 7 days, etc.. of all owns address
|
||||
UniValue getstakereport(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ((params.size()>0) || (fHelp))
|
||||
throw runtime_error(
|
||||
"getstakereport\n"
|
||||
"List last single 30 day stake subtotal and last 24h, 7, 30, 365 day subtotal.\n");
|
||||
|
||||
vStakePeriodRange_T aRange = PrepareRangeForStakeReport();
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
// get subtotal calc
|
||||
int64_t nTook = GetTimeMillis();
|
||||
int nItemCounted = GetsStakeSubTotal(aRange);
|
||||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
|
||||
vStakePeriodRange_T::iterator vIt;
|
||||
|
||||
// Span of days to compute average over
|
||||
int nDays = 0;
|
||||
|
||||
// Get the wallet's staking age in days
|
||||
int nWalletDays = 0;
|
||||
|
||||
// Check if we have a stake already
|
||||
if (GetFirstStakeTime() != -1)
|
||||
nWalletDays = (GetTime() - GetFirstStakeTime()) / 86400;
|
||||
|
||||
// report it
|
||||
for(vIt = aRange.begin(); vIt != aRange.end(); vIt++)
|
||||
{
|
||||
// Add it to results
|
||||
result.pushKV(vIt->Name, FormatMoney(vIt->Total).c_str());
|
||||
|
||||
// Get the nDays value
|
||||
nDays = 0;
|
||||
if (vIt->Name == "Last 7 Days")
|
||||
nDays = 7;
|
||||
else if (vIt->Name == "Last 30 Days")
|
||||
nDays = 30;
|
||||
else if (vIt->Name == "Last 365 Days")
|
||||
nDays = 365;
|
||||
|
||||
// Check if we need to add the average
|
||||
if (nDays > 0) {
|
||||
// Check if nDays is larger than the wallet's staking age in days
|
||||
if (nDays > nWalletDays && nWalletDays > 0)
|
||||
nDays = nWalletDays;
|
||||
|
||||
// Add the Average
|
||||
result.pushKV(vIt->Name + " Avg", FormatMoney(vIt->Total / nDays).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
vIt--;
|
||||
result.pushKV("Latest Time",
|
||||
vIt->Start ? DateTimeStrFormat("%Y-%m-%d %H:%M:%S",vIt->Start).c_str() :
|
||||
"Never");
|
||||
|
||||
// Moved nTook call down here to be more accurate
|
||||
nTook = GetTimeMillis() - nTook;
|
||||
|
||||
// report element counted / time took
|
||||
result.pushKV("Stake counted", nItemCounted);
|
||||
result.pushKV("time took (ms)", nTook);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// ToDo: fix burnwallet
|
||||
|
||||
@@ -2695,6 +2940,7 @@ static const CRPCCommand commands[] =
|
||||
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, true },
|
||||
{ "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false },
|
||||
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false },
|
||||
{ "wallet", "getstakereport", &getstakereport, false },
|
||||
{ "wallet", "gettransaction", &gettransaction, false },
|
||||
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false },
|
||||
{ "wallet", "getwalletinfo", &getwalletinfo, false },
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,16 +6,17 @@
|
||||
#ifndef BITCOIN_WALLET_WALLET_H
|
||||
#define BITCOIN_WALLET_WALLET_H
|
||||
|
||||
#include "amount.h"
|
||||
#include "streams.h"
|
||||
#include "tinyformat.h"
|
||||
#include "ui_interface.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "validationinterface.h"
|
||||
#include "script/ismine.h"
|
||||
#include "wallet/crypter.h"
|
||||
#include "wallet/walletdb.h"
|
||||
#include "wallet/rpcwallet.h"
|
||||
#include <amount.h>
|
||||
#include <streams.h>
|
||||
#include <tinyformat.h>
|
||||
#include <ui_interface.h>
|
||||
#include <utilstrencodings.h>
|
||||
#include <validationinterface.h>
|
||||
#include <script/ismine.h>
|
||||
#include <wallet/crypter.h>
|
||||
#include <wallet/walletdb.h>
|
||||
#include <wallet/rpcwallet.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include "pos.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -28,6 +29,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
extern CWallet* pwalletMain;
|
||||
|
||||
/**
|
||||
@@ -45,7 +48,7 @@ static const unsigned int DEFAULT_KEYPOOL_SIZE = 100;
|
||||
//! -paytxfee default
|
||||
static const CAmount DEFAULT_TRANSACTION_FEE = 10000;
|
||||
//! -fallbackfee default
|
||||
static const CAmount DEFAULT_FALLBACK_FEE = 10000;
|
||||
static const CAmount DEFAULT_FALLBACK_FEE = 20000;
|
||||
//! -mintxfee default
|
||||
static const CAmount DEFAULT_TRANSACTION_MINFEE = 10000;
|
||||
//! minimum change amount
|
||||
@@ -59,7 +62,7 @@ static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
|
||||
//! -txconfirmtarget default
|
||||
static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 2;
|
||||
//! Largest (in bytes) free transaction we're willing to create
|
||||
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
|
||||
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 10000;
|
||||
static const bool DEFAULT_WALLETBROADCAST = true;
|
||||
|
||||
//! if set, all keys will be derived by using BIP32
|
||||
@@ -87,6 +90,7 @@ enum WalletFeature
|
||||
FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
|
||||
};
|
||||
|
||||
|
||||
/** A key pool entry */
|
||||
class CKeyPool
|
||||
{
|
||||
@@ -223,7 +227,7 @@ public:
|
||||
void setAbandoned() { hashBlock = ABANDON_HASH; }
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* A transaction with a bunch of additional info that only the owner cares about.
|
||||
* It includes any unrecorded transactions needed to link it back to the block chain.
|
||||
*/
|
||||
@@ -383,7 +387,7 @@ public:
|
||||
|
||||
//! filter decides which addresses will count towards the debit
|
||||
CAmount GetDebit(const isminefilter& filter) const;
|
||||
CAmount GetCredit(const isminefilter& filter) const;
|
||||
CAmount GetCredit(const isminefilter& filter, bool fCheckMaturity=true) const;
|
||||
CAmount GetImmatureCredit(bool fUseCache=true) const;
|
||||
CAmount GetImmatureStakeCredit(bool fUseCache=true) const;
|
||||
CAmount GetAvailableCredit(bool fUseCache=true) const;
|
||||
@@ -405,6 +409,7 @@ public:
|
||||
// True if only scriptSigs are different
|
||||
bool IsEquivalentTo(const CWalletTx& tx) const;
|
||||
|
||||
|
||||
bool InMempool() const;
|
||||
bool IsTrusted() const;
|
||||
|
||||
@@ -416,9 +421,6 @@ public:
|
||||
std::set<uint256> GetConflicts() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class COutput
|
||||
{
|
||||
public:
|
||||
@@ -436,7 +438,13 @@ public:
|
||||
std::string ToString() const;
|
||||
};
|
||||
|
||||
|
||||
struct sortByCoinAgeDescending
|
||||
{
|
||||
inline bool operator() (const COutput& cOutput1, const COutput& cOutput2)
|
||||
{
|
||||
return (cOutput1.tx->nTime > cOutput2.tx->nTime);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Private key that includes an expiration date in case it never gets used. */
|
||||
@@ -547,7 +555,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
|
||||
* and provides the ability to create new transactions.
|
||||
*/
|
||||
@@ -590,7 +598,6 @@ private:
|
||||
void AddToSpends(const uint256& wtxid);
|
||||
void RemoveFromSpends(const uint256& wtxid);
|
||||
|
||||
|
||||
/* Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
|
||||
void MarkConflicted(const uint256& hashBlock, const uint256& hashTx);
|
||||
|
||||
@@ -654,7 +661,6 @@ public:
|
||||
nTimeFirstKey = 0;
|
||||
fBroadcastTransactions = false;
|
||||
nConflictsReceived = 0;
|
||||
|
||||
fAbortRescan = false;
|
||||
fScanningWallet = false;
|
||||
}
|
||||
@@ -752,7 +758,7 @@ public:
|
||||
|
||||
void GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Increment the next transaction order id
|
||||
* @return next transaction order id
|
||||
*/
|
||||
@@ -864,7 +870,7 @@ public:
|
||||
LOCK(cs_wallet);
|
||||
mapRequestCount[hash] = 0;
|
||||
};
|
||||
|
||||
|
||||
unsigned int GetKeyPoolSize()
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // setKeyPool
|
||||
@@ -892,8 +898,8 @@ public:
|
||||
|
||||
//! Verify the wallet database and perform salvage if required
|
||||
static bool Verify();
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Address book entry changed.
|
||||
* @note called with lock cs_wallet held.
|
||||
*/
|
||||
@@ -902,7 +908,7 @@ public:
|
||||
const std::string &purpose,
|
||||
ChangeType status)> NotifyAddressBookChanged;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Wallet transaction added, removed or updated.
|
||||
* @note called with lock cs_wallet held.
|
||||
*/
|
||||
@@ -983,7 +989,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Account information.
|
||||
* Stored in wallet with key "acc"+string account name.
|
||||
*/
|
||||
|
||||
@@ -5,24 +5,23 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "wallet/walletdb.h"
|
||||
#include <wallet/walletdb.h>
|
||||
|
||||
#include "base58.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "main.h" // For CheckTransaction
|
||||
#include "dstencode.h"
|
||||
#include "protocol.h"
|
||||
#include "serialize.h"
|
||||
#include "sync.h"
|
||||
#include "util.h"
|
||||
#include "utiltime.h"
|
||||
#include "wallet/wallet.h"
|
||||
#include <base58.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <main.h> // For CheckTransaction
|
||||
#include <dstencode.h>
|
||||
#include <protocol.h>
|
||||
#include <serialize.h>
|
||||
#include <sync.h>
|
||||
#include <util.h>
|
||||
#include <utiltime.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
@@ -220,7 +219,7 @@ CAmount CWalletDB::GetAccountCreditDebit(const string& strAccount)
|
||||
ListAccountCreditDebit(strAccount, entries);
|
||||
|
||||
CAmount nCreditDebit = 0;
|
||||
BOOST_FOREACH (const CAccountingEntry& entry, entries)
|
||||
for(const CAccountingEntry& entry: entries)
|
||||
nCreditDebit += entry.nCreditDebit;
|
||||
|
||||
return nCreditDebit;
|
||||
@@ -287,7 +286,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
|
||||
}
|
||||
list<CAccountingEntry> acentries;
|
||||
ListAccountCreditDebit("", acentries);
|
||||
BOOST_FOREACH(CAccountingEntry& entry, acentries)
|
||||
for(CAccountingEntry& entry: acentries)
|
||||
{
|
||||
txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
|
||||
}
|
||||
@@ -318,7 +317,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
|
||||
else
|
||||
{
|
||||
int64_t nOrderPosOff = 0;
|
||||
BOOST_FOREACH(const int64_t& nOffsetStart, nOrderPosOffsets)
|
||||
for(const int64_t& nOffsetStart: nOrderPosOffsets)
|
||||
{
|
||||
if (nOrderPos >= nOffsetStart)
|
||||
++nOrderPosOff;
|
||||
@@ -415,7 +414,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
||||
if (wtx.nOrderPos == -1)
|
||||
wss.fAnyUnordered = true;
|
||||
|
||||
pwallet->AddToWallet(wtx, true, NULL);
|
||||
pwallet->AddToWallet(wtx, true, nullptr);
|
||||
}
|
||||
else if (strType == "acentry")
|
||||
{
|
||||
@@ -608,8 +607,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
||||
ssKey >> strAddress;
|
||||
ssKey >> strKey;
|
||||
ssValue >> strValue;
|
||||
if (!pwallet->LoadDestData(DecodeDestination(strAddress), strKey,
|
||||
strValue)) {
|
||||
if (!pwallet->LoadDestData(DecodeDestination(strAddress), strKey, strValue))
|
||||
{
|
||||
strErr = "Error reading wallet database: LoadDestData failed";
|
||||
return false;
|
||||
}
|
||||
@@ -722,7 +721,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
|
||||
if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
|
||||
pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
|
||||
|
||||
BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade)
|
||||
for(uint256 hash: wss.vWalletUpgrade)
|
||||
WriteTx(pwallet->mapWallet[hash]);
|
||||
|
||||
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
|
||||
@@ -737,7 +736,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
|
||||
|
||||
pwallet->laccentries.clear();
|
||||
ListAccountCreditDebit("*", pwallet->laccentries);
|
||||
BOOST_FOREACH(CAccountingEntry& entry, pwallet->laccentries) {
|
||||
for(CAccountingEntry& entry: pwallet->laccentries) {
|
||||
pwallet->wtxOrdered.insert(make_pair(entry.nOrderPos, CWallet::TxPair((CWalletTx*)0, &entry)));
|
||||
}
|
||||
|
||||
@@ -826,7 +825,7 @@ DBErrors CWalletDB::ZapSelectTx(CWallet* pwallet, vector<uint256>& vTxHashIn, ve
|
||||
// erase each matching wallet TX
|
||||
bool delerror = false;
|
||||
vector<uint256>::iterator it = vTxHashIn.begin();
|
||||
BOOST_FOREACH (uint256 hash, vTxHash) {
|
||||
for(uint256 hash: vTxHash) {
|
||||
while (it < vTxHashIn.end() && (*it) < hash) {
|
||||
it++;
|
||||
}
|
||||
@@ -858,7 +857,7 @@ DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, vector<CWalletTx>& vWtx)
|
||||
return err;
|
||||
|
||||
// erase each wallet TX
|
||||
BOOST_FOREACH (uint256& hash, vTxHash) {
|
||||
for(uint256& hash: vTxHash) {
|
||||
if (!EraseTx(hash))
|
||||
return DB_CORRUPT;
|
||||
}
|
||||
@@ -943,7 +942,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, const std::string& filename, bool fOnlyKe
|
||||
int64_t now = GetTime();
|
||||
std::string newFilename = strprintf("wallet.%d.bak", now);
|
||||
|
||||
int result = dbenv.dbenv->dbrename(NULL, filename.c_str(), NULL,
|
||||
int result = dbenv.dbenv->dbrename(NULL, filename.c_str(), nullptr,
|
||||
newFilename.c_str(), DB_AUTO_COMMIT);
|
||||
if (result == 0)
|
||||
LogPrintf("Renamed %s to %s\n", filename, newFilename);
|
||||
@@ -978,7 +977,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, const std::string& filename, bool fOnlyKe
|
||||
CWalletScanState wss;
|
||||
|
||||
DbTxn* ptxn = dbenv.TxnBegin();
|
||||
BOOST_FOREACH(CDBEnv::KeyValPair& row, salvagedData)
|
||||
for(CDBEnv::KeyValPair& row: salvagedData)
|
||||
{
|
||||
if (fOnlyKeys)
|
||||
{
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
#ifndef BITCOIN_WALLET_WALLETDB_H
|
||||
#define BITCOIN_WALLET_WALLETDB_H
|
||||
|
||||
#include "amount.h"
|
||||
#include "key.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "script/standard.h" // for CTxDestination
|
||||
#include "wallet/db.h"
|
||||
#include "key.h"
|
||||
#include <amount.h>
|
||||
#include <key.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <script/standard.h> // for CTxDestination
|
||||
#include <wallet/db.h>
|
||||
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
|
||||
Reference in New Issue
Block a user