const auto *pindex = pindexPrev;
while (pindex && pindex->GetBlockTime() >= nSelectionIntervalStart)
{
- vSortedByTimestamp.push_back(make_pair(pindex->GetBlockTime(), pindex->GetBlockHash()));
+ vSortedByTimestamp.push_back({ pindex->GetBlockTime(), pindex->GetBlockHash() });
pindex = pindex->pprev;
}
int nHeightFirstCandidate = pindex ? (pindex->nHeight + 1) : 0;
// write the entropy bit of the selected block
nStakeModifierNew |= (((uint64_t)pindex->GetStakeEntropyBit()) << nRound);
// add the selected block from candidates to selected list
- mapSelectedBlocks.insert(make_pair(pindex->GetBlockHash(), pindex));
+ mapSelectedBlocks.insert({ pindex->GetBlockHash(), pindex });
if (fDebug && GetBoolArg("-printstakemodifier"))
printf("ComputeNextStakeModifier: selected round %d stop=%s height=%d bit=%d\n", nRound, DateTimeStrFormat(nSelectionIntervalStop).c_str(), pindex->nHeight, pindex->GetStakeEntropyBit());
}
CSecret secret = key.GetSecret(fCompressed);
{
LOCK(cs_KeyStore);
- mapKeys[key.GetPubKey().GetID()] = make_pair(secret, fCompressed);
+ mapKeys[key.GetPubKey().GetID()] = { secret, fCompressed };
}
return true;
}
if (!SetCrypted())
return false;
- mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret);
+ mapCryptedKeys[vchPubKey.GetID()] = { vchPubKey, vchCryptedSecret };
}
return true;
}
#include <list>
#include <map>
+using namespace std;
+
class CWallet;
class CBlock;
class CBlockIndex;
static const int64_t MIN_TX_FEE = CENT/10;
static const int64_t MIN_RELAY_TX_FEE = CENT/50;
-static const int64_t MAX_MONEY = std::numeric_limits<int64_t>::max();
+static const int64_t MAX_MONEY = numeric_limits<int64_t>::max();
static const int64_t MAX_MINT_PROOF_OF_WORK = 100 * COIN;
static const int64_t MAX_MINT_PROOF_OF_STAKE = 1 * COIN;
static const int64_t MIN_TXOUT_AMOUNT = CENT/100;
extern CScript COINBASE_FLAGS;
extern CCriticalSection cs_main;
-extern std::map<uint256, CBlockIndex*> mapBlockIndex;
-extern std::set<std::pair<COutPoint, unsigned int> > setStakeSeen;
+extern map<uint256, CBlockIndex*> mapBlockIndex;
+extern set<pair<COutPoint, unsigned int> > setStakeSeen;
extern CBlockIndex* pindexGenesisBlock;
extern unsigned int nNodeLifespan;
extern unsigned int nStakeMinAge;
extern uint64_t nLastBlockTx;
extern uint64_t nLastBlockSize;
extern uint32_t nLastCoinStakeSearchInterval;
-extern const std::string strMessageMagic;
+extern const string strMessageMagic;
extern int64_t nTimeBestReceived;
extern CCriticalSection cs_setpwalletRegistered;
-extern std::set<CWallet*> setpwalletRegistered;
+extern set<CWallet*> setpwalletRegistered;
extern unsigned char pchMessageStart[4];
-extern std::map<uint256, CBlock*> mapOrphanBlocks;
+extern map<uint256, CBlock*> mapOrphanBlocks;
// Settings
extern int64_t nTransactionFee;
unsigned int ComputeMinStake(unsigned int nBase, int64_t nTime, unsigned int nBlockTime);
int GetNumBlocksOfPeers();
bool IsInitialBlockDownload();
-std::string GetWarnings(std::string strFor);
+string GetWarnings(string strFor);
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock);
uint256 WantedByOrphan(const CBlock* pblockOrphan);
const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake);
-bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);
+bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut);
/** Position on disk for a particular transaction. */
class CDiskTxPos
}
IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
- void SetNull() { nFile = std::numeric_limits<uint32_t>::max(); nBlockPos = 0; nTxPos = 0; }
- bool IsNull() const { return (nFile == std::numeric_limits<uint32_t>::max()); }
+ void SetNull() { nFile = numeric_limits<uint32_t>::max(); nBlockPos = 0; nTxPos = 0; }
+ bool IsNull() const { return (nFile == numeric_limits<uint32_t>::max()); }
friend bool operator==(const CDiskTxPos& a, const CDiskTxPos& b)
{
}
- std::string ToString() const
+ string ToString() const
{
if (IsNull())
return "null";
CInPoint() { SetNull(); }
CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; }
- void SetNull() { ptx = NULL; n = std::numeric_limits<uint32_t>::max(); }
- bool IsNull() const { return (ptx == NULL && n == std::numeric_limits<uint32_t>::max()); }
+ void SetNull() { ptx = NULL; n = numeric_limits<uint32_t>::max(); }
+ bool IsNull() const { return (ptx == NULL && n == numeric_limits<uint32_t>::max()); }
};
COutPoint() { SetNull(); }
COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; }
IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
- void SetNull() { hash = 0; n = std::numeric_limits<uint32_t>::max(); }
- bool IsNull() const { return (hash == 0 && n == std::numeric_limits<uint32_t>::max()); }
+ void SetNull() { hash = 0; n = numeric_limits<uint32_t>::max(); }
+ bool IsNull() const { return (hash == 0 && n == numeric_limits<uint32_t>::max()); }
friend bool operator<(const COutPoint& a, const COutPoint& b)
{
return !(a == b);
}
- std::string ToString() const
+ string ToString() const
{
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n);
}
CTxIn()
{
- nSequence = std::numeric_limits<unsigned int>::max();
+ nSequence = numeric_limits<unsigned int>::max();
}
- explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max())
+ explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=numeric_limits<unsigned int>::max())
{
prevout = prevoutIn;
scriptSig = scriptSigIn;
nSequence = nSequenceIn;
}
- CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max())
+ CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=numeric_limits<unsigned int>::max())
{
prevout = COutPoint(hashPrevTx, nOut);
scriptSig = scriptSigIn;
bool IsFinal() const
{
- return (nSequence == std::numeric_limits<unsigned int>::max());
+ return (nSequence == numeric_limits<unsigned int>::max());
}
friend bool operator==(const CTxIn& a, const CTxIn& b)
return !(a == b);
}
- std::string ToStringShort() const
+ string ToStringShort() const
{
return strprintf(" %s %d", prevout.hash.ToString().c_str(), prevout.n);
}
- std::string ToString() const
+ string ToString() const
{
- std::string str;
+ string str;
str += "CTxIn(";
str += prevout.ToString();
if (prevout.IsNull())
str += strprintf(", coinbase %s", HexStr(scriptSig).c_str());
else
str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24).c_str());
- if (nSequence != std::numeric_limits<unsigned int>::max())
+ if (nSequence != numeric_limits<unsigned int>::max())
str += strprintf(", nSequence=%u", nSequence);
str += ")";
return str;
return !(a == b);
}
- std::string ToStringShort() const
+ string ToStringShort() const
{
return strprintf(" out %s %s", FormatMoney(nValue).c_str(), scriptPubKey.ToString(true).c_str());
}
- std::string ToString() const
+ string ToString() const
{
if (IsEmpty()) return "CTxOut(empty)";
if (scriptPubKey.size() < 6)
GMF_SEND
};
-typedef std::map<uint256, std::pair<CTxIndex, CTransaction> > MapPrevTx;
+typedef map<uint256, pair<CTxIndex, CTransaction> > MapPrevTx;
/** The basic transaction that is broadcasted on the network and contained in
* blocks. A transaction can contain multiple inputs and outputs.
static const int CURRENT_VERSION=1;
int nVersion;
uint32_t nTime;
- std::vector<CTxIn> vin;
- std::vector<CTxOut> vout;
+ vector<CTxIn> vin;
+ vector<CTxOut> vout;
uint32_t nLockTime;
// Denial-of-service detection:
return false;
bool fNewer = false;
- unsigned int nLowest = std::numeric_limits<unsigned int>::max();
+ unsigned int nLowest = numeric_limits<unsigned int>::max();
for (unsigned int i = 0; i < vin.size(); i++)
{
if (vin[i].nSequence != old.vin[i].nSequence)
/** Check for standard transaction types
@return True if all outputs (scriptPubKeys) use only standard transaction forms
*/
- bool IsStandard(std::string& strReason) const;
+ bool IsStandard(string& strReason) const;
bool IsStandard() const
{
- std::string strReason;
+ string strReason;
return IsStandard(strReason);
}
{
nValueOut += txout.nValue;
if (!MoneyRange(txout.nValue) || !MoneyRange(nValueOut))
- throw std::runtime_error("CTransaction::GetValueOut() : value out of range");
+ throw runtime_error("CTransaction::GetValueOut() : value out of range");
}
return nValueOut;
}
try {
filein >> *this;
}
- catch (const std::exception&) {
+ catch (const exception&) {
return error("%s() : deserialize or I/O error", BOOST_CURRENT_FUNCTION);
}
return !(a == b);
}
- std::string ToStringShort() const
+ string ToStringShort() const
{
- std::string str;
+ string str;
str += strprintf("%s %s", GetHash().ToString().c_str(), IsCoinBase()? "base" : (IsCoinStake()? "stake" : "user"));
return str;
}
- std::string ToString() const
+ string ToString() const
{
- std::string str;
+ string str;
str += IsCoinBase()? "Coinbase" : (IsCoinStake()? "Coinstake" : "CTransaction");
str += strprintf("(hash=%s, nTime=%d, ver=%d, vin.size=%" PRIszu ", vout.size=%" PRIszu ", nLockTime=%d)\n",
GetHash().ToString().substr(0,10).c_str(),
@param[out] fInvalid returns true if transaction is invalid
@return Returns true if all inputs are in txdb or mapTestPool
*/
- bool FetchInputs(CTxDB& txdb, const std::map<uint256, CTxIndex>& mapTestPool,
+ bool FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTestPool,
bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid);
/** Sanity check previous transactions, then, if all checks succeed,
@param[in] pvChecks NULL If pvChecks is not NULL, script checks are pushed onto it instead of being performed inline.
@return Returns true if all checks succeed
*/
- bool ConnectInputs(CTxDB& txdb, MapPrevTx inputs, std::map<uint256, CTxIndex>& mapTestPool, const CDiskTxPos& posThisTx, const CBlockIndex* pindexBlock,
+ bool ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map<uint256, CTxIndex>& mapTestPool, const CDiskTxPos& posThisTx, const CBlockIndex* pindexBlock,
bool fBlock, bool fMiner, bool fScriptChecks=true,
- unsigned int flags=STRICT_FLAGS, std::vector<CScriptCheck> *pvChecks = NULL);
+ unsigned int flags=STRICT_FLAGS, vector<CScriptCheck> *pvChecks = NULL);
bool ClientConnectInputs();
bool CheckTransaction() const;
bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);
{
public:
uint256 hashBlock;
- std::vector<uint256> vMerkleBranch;
+ vector<uint256> vMerkleBranch;
int32_t nIndex;
// memory only
{
public:
CDiskTxPos pos;
- std::vector<CDiskTxPos> vSpent;
+ vector<CDiskTxPos> vSpent;
CTxIndex()
{
uint32_t nNonce;
// network and disk
- std::vector<CTransaction> vtx;
+ vector<CTransaction> vtx;
// ppcoin: block signature - signed by one of the coin base txout[N]'s owner
- std::vector<unsigned char> vchBlockSig;
+ vector<unsigned char> vchBlockSig;
// memory only
- mutable std::vector<uint256> vMerkleTree;
+ mutable vector<uint256> vMerkleTree;
// Denial-of-service detection:
mutable int nDoS;
return !IsProofOfStake();
}
- std::pair<COutPoint, unsigned int> GetProofOfStake() const
+ pair<COutPoint, unsigned int> GetProofOfStake() const
{
- return IsProofOfStake()? std::make_pair(vtx[1].vin[0].prevout, vtx[1].nTime) : std::make_pair(COutPoint(), (unsigned int)0);
+ if (IsProofOfStake())
+ return { vtx[1].vin[0].prevout, vtx[1].nTime };
+
+ return { COutPoint(), (unsigned int)0 };
}
// ppcoin: get max transaction timestamp
{
int64_t maxTransactionTime = 0;
for(const auto& tx : vtx)
- maxTransactionTime = std::max(maxTransactionTime, (int64_t)tx.nTime);
+ maxTransactionTime = max(maxTransactionTime, (int64_t)tx.nTime);
return maxTransactionTime;
}
{
for (int i = 0; i < nSize; i += 2)
{
- int i2 = std::min(i+1, nSize-1);
+ int i2 = min(i+1, nSize-1);
vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j+i]), END(vMerkleTree[j+i]),
BEGIN(vMerkleTree[j+i2]), END(vMerkleTree[j+i2])));
}
return (vMerkleTree.empty() ? 0 : vMerkleTree.back());
}
- std::vector<uint256> GetMerkleBranch(int nIndex) const
+ vector<uint256> GetMerkleBranch(int nIndex) const
{
if (vMerkleTree.empty())
BuildMerkleTree();
- std::vector<uint256> vMerkleBranch;
+ vector<uint256> vMerkleBranch;
int j = 0;
for (int nSize = (int)vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
{
- int i = std::min(nIndex^1, nSize-1);
+ int i = min(nIndex^1, nSize-1);
vMerkleBranch.push_back(vMerkleTree[j+i]);
nIndex >>= 1;
j += nSize;
return vMerkleBranch;
}
- static uint256 CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex)
+ static uint256 CheckMerkleBranch(uint256 hash, const vector<uint256>& vMerkleBranch, int nIndex)
{
if (nIndex == -1)
return 0;
try {
filein >> *this;
}
- catch (const std::exception&) {
+ catch (const exception&) {
return error("%s() : deserialize or I/O error", BOOST_CURRENT_FUNCTION);
}
for (int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->pprev)
*(--pbegin) = pindex->GetBlockTime();
- std::sort(pbegin, pend);
+ sort(pbegin, pend);
return pbegin[(pend - pbegin)/2];
}
nFlags |= BLOCK_STAKE_MODIFIER;
}
- std::string ToString() const
+ string ToString() const
{
return strprintf("CBlockIndex(nprev=%p, pnext=%p, nFile=%u, nBlockPos=%-6d nHeight=%d, nMint=%s, nMoneySupply=%s, nFlags=(%s)(%d)(%s), nStakeModifier=%016" PRIx64 ", nStakeModifierChecksum=%08x, hashProofOfStake=%s, prevoutStake=(%s), nStakeTime=%d merkle=%s, hashBlock=%s)",
(const void*)pprev, (const void*)pnext, nFile, nBlockPos, nHeight,
return blockHash;
}
- std::string ToString() const
+ string ToString() const
{
- std::string str = "CDiskBlockIndex(";
+ string str = "CDiskBlockIndex(";
str += CBlockIndex::ToString();
str += strprintf("\n hashBlock=%s, hashPrev=%s, hashNext=%s)",
GetBlockHash().ToString().c_str(),
class CBlockLocator
{
protected:
- std::vector<uint256> vHave;
+ vector<uint256> vHave;
public:
CBlockLocator()
Set((*mi).second);
}
- CBlockLocator(const std::vector<uint256>& vHaveIn)
+ CBlockLocator(const vector<uint256>& vHaveIn)
{
vHave = vHaveIn;
}
{
public:
mutable CCriticalSection cs;
- std::map<uint256, CTransaction> mapTx;
- std::map<COutPoint, CInPoint> mapNextTx;
+ map<uint256, CTransaction> mapTx;
+ map<COutPoint, CInPoint> mapNextTx;
bool accept(CTxDB& txdb, CTransaction &tx,
bool fCheckInputs, bool* pfMissingInputs);
bool addUnchecked(const uint256& hash, CTransaction &tx);
bool remove(CTransaction &tx);
void clear();
- void queryHashes(std::vector<uint256>& vtxid);
+ void queryHashes(vector<uint256>& vtxid);
size_t size()
{
#include "addrman.h"
#include "hash.h"
+using namespace std;
+
class CRequestTracker;
class CNode;
class CBlockIndex;
inline uint64_t ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
inline uint64_t SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
-void AddOneShot(std::string strDest);
-bool RecvLine(SOCKET hSocket, std::string& strLine);
+void AddOneShot(string strDest);
+bool RecvLine(SOCKET hSocket, string& strLine);
bool GetMyExternalIP(CNetAddr& ipRet);
void AddressCurrentlyConnected(const CService& addr);
CNode* FindNode(const CNetAddr& ip);
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
void MapPort();
unsigned short GetListenPort();
-bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string()));
+bool BindListenPort(const CService &bindAddr, string& strError=REF(string()));
void StartNode(void* parg);
bool StopNode();
extern boost::array<int, THREAD_MAX> vnThreadsRunning;
extern CAddrMan addrman;
-extern std::vector<CNode*> vNodes;
+extern vector<CNode*> vNodes;
extern CCriticalSection cs_vNodes;
-extern std::vector<std::string> vAddedNodes;
+extern vector<string> vAddedNodes;
extern CCriticalSection cs_vAddedNodes;
-extern std::map<CInv, CDataStream> mapRelay;
-extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
+extern map<CInv, CDataStream> mapRelay;
+extern deque<pair<int64_t, CInv> > vRelayExpiration;
extern CCriticalSection cs_mapRelay;
-extern std::map<CInv, int64_t> mapAlreadyAskedFor;
+extern map<CInv, int64_t> mapAlreadyAskedFor;
int64_t nLastSend;
int64_t nLastRecv;
int64_t nTimeConnected;
- std::string addrName;
+ string addrName;
int32_t nVersion;
- std::string strSubVer;
+ string strSubVer;
bool fInbound;
int64_t nReleaseTime;
int32_t nStartingHeight;
int32_t nHeaderStart;
uint32_t nMessageStart;
CAddress addr;
- std::string addrName;
+ string addrName;
CService addrLocal;
int32_t nVersion;
- std::string strSubVer;
+ string strSubVer;
bool fOneShot;
bool fClient;
bool fInbound;
// Denial-of-service detection/prevention
// Key is IP address, value is banned-until-time
- static std::map<CNetAddr, int64_t> setBanned;
+ static map<CNetAddr, int64_t> setBanned;
static CCriticalSection cs_setBanned;
int nMisbehavior;
public:
int64_t nReleaseTime;
- std::map<uint256, CRequestTracker> mapRequests;
+ map<uint256, CRequestTracker> mapRequests;
CCriticalSection cs_mapRequests;
uint256 hashContinue;
CBlockIndex* pindexLastGetBlocksBegin;
bool fStartSync;
// flood relay
- std::vector<CAddress> vAddrToSend;
- std::set<CAddress> setAddrKnown;
+ vector<CAddress> vAddrToSend;
+ set<CAddress> setAddrKnown;
bool fGetAddr;
- std::set<uint256> setKnown;
+ set<uint256> setKnown;
uint256 hashCheckpointKnown; // ppcoin: known sent sync-checkpoint
int64_t nNextAddrSend;
int64_t nNextLocalAddrSend;
// inventory based relay
mruset<CInv> setInventoryKnown;
- std::vector<CInv> vInventoryToSend;
+ vector<CInv> vInventoryToSend;
CCriticalSection cs_inventory;
- std::multimap<int64_t, CInv> mapAskFor;
+ multimap<int64_t, CInv> mapAskFor;
- CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : vSend(SER_NETWORK, MIN_PROTO_VERSION), vRecv(SER_NETWORK, MIN_PROTO_VERSION)
+ CNode(SOCKET hSocketIn, CAddress addrIn, string addrNameIn = "", bool fInboundIn=false) : vSend(SER_NETWORK, MIN_PROTO_VERSION), vRecv(SER_NETWORK, MIN_PROTO_VERSION)
{
nServices = 0;
hSocket = hSocketIn;
nLastSendEmpty = GetTime();
nTimeConnected = GetTime();
nHeaderStart = -1;
- nMessageStart = std::numeric_limits<uint32_t>::max();
+ nMessageStart = numeric_limits<uint32_t>::max();
addr = addrIn;
addrName = addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn;
nVersion = 0;
int GetRefCount()
{
- return std::max(nRefCount, 0) + (GetTime() < nReleaseTime ? 1 : 0);
+ return max(nRefCount, 0) + (GetTime() < nReleaseTime ? 1 : 0);
}
CNode* AddRef(int64_t nTimeout=0)
{
if (nTimeout != 0)
- nReleaseTime = std::max(nReleaseTime, GetTime() + nTimeout);
+ nReleaseTime = max(nReleaseTime, GetTime() + nTimeout);
else
nRefCount++;
return this;
int64_t nNow = (GetTime() - 1) * 1000000;
static int64_t nLastTime;
++nLastTime;
- nNow = std::max(nNow, nLastTime);
+ nNow = max(nNow, nLastTime);
nLastTime = nNow;
// Each retry is 2 minutes after the last
- nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow);
- mapAskFor.insert(std::make_pair(nRequestTime, inv));
+ nRequestTime = max(nRequestTime + 2 * 60 * 1000000, nNow);
+ mapAskFor.insert({ nRequestTime, inv });
}
return;
vSend.resize(nHeaderStart);
nHeaderStart = -1;
- nMessageStart = std::numeric_limits<uint32_t>::max();
+ nMessageStart = numeric_limits<uint32_t>::max();
LEAVE_CRITICAL_SECTION(cs_vSend);
if (fDebug)
}
nHeaderStart = -1;
- nMessageStart = std::numeric_limits<uint32_t>::max();
+ nMessageStart = numeric_limits<uint32_t>::max();
LEAVE_CRITICAL_SECTION(cs_vSend);
}
{
CScript scriptPubKey;
scriptPubKey.SetAddress(CBitcoinAddress(rcp.address.toStdString()));
- vecSend.push_back(make_pair(scriptPubKey, rcp.amount));
+ vecSend.push_back({ scriptPubKey, rcp.amount });
}
CWalletTx wtx;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
// Save
- mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig);
+ mapNewBlock[pblock->hashMerkleRoot] = { pblock, pblock->vtx[0].vin[0].scriptSig };
// Prebuild hash buffers
char pmidstate[32];
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
// Save
- mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig);
+ mapNewBlock[pblock->hashMerkleRoot] = { pblock, pblock->vtx[0].vin[0].scriptSig };
// Pre-build hash buffers
char pmidstate[32];
totalAmount += nAmount;
- vecSend.push_back(make_pair(scriptPubKey, nAmount));
+ vecSend.push_back({ scriptPubKey, nAmount });
}
EnsureWalletIsUnlocked();
if (mTemplates.empty())
{
// Standard tx, sender provides pubkey, receiver adds signature
- mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG));
+ mTemplates.insert({ TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG });
// Malleable pubkey tx hack, sender provides generated pubkey combined with R parameter. The R parameter is dropped before checking a signature.
- mTemplates.insert(make_pair(TX_PUBKEY_DROP, CScript() << OP_PUBKEY << OP_PUBKEY << OP_DROP << OP_CHECKSIG));
+ mTemplates.insert({ TX_PUBKEY_DROP, CScript() << OP_PUBKEY << OP_PUBKEY << OP_DROP << OP_CHECKSIG });
// Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey
- mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG));
+ mTemplates.insert({ TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG });
// Sender provides N pubkeys, receivers provides M signatures
- mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG));
+ mTemplates.insert({ TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG });
// Empty, provably prunable, data-carrying output
- mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN << OP_SMALLDATA));
+ mTemplates.insert({ TX_NULL_DATA, CScript() << OP_RETURN << OP_SMALLDATA });
}
vSolutionsRet.clear();
#include <leveldb/db.h>
#include <leveldb/write_batch.h>
+using namespace std;
+
// Class that provides access to a LevelDB. Note that this class is frequently
// instantiated on the stack and then destroyed again, so instantiation has to
// be very cheap. Unfortunately that means, a CTxDB instance is actually just a
// Returns true and sets (value,false) if activeBatch contains the given key
// or leaves value alone and sets deleted = true if activeBatch contains a
// delete for it.
- bool ScanBatch(const CDataStream &key, std::string *value, bool *deleted) const;
+ bool ScanBatch(const CDataStream &key, string *value, bool *deleted) const;
template<typename K, typename T>
bool Read(const K& key, T& value)
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
- std::string strValue;
+ string strValue;
bool readFromDb = true;
if (activeBatch) {
SER_DISK, CLIENT_VERSION);
ssValue >> value;
}
- catch (const std::exception&) {
+ catch (const exception&) {
return false;
}
return true;
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
ssKey.reserve(1000);
ssKey << key;
- std::string unused;
+ string unused;
if (activeBatch) {
bool deleted;
bool ReadVersion(int& nVersion)
{
nVersion = 0;
- return Read(std::string("version"), nVersion);
+ return Read(string("version"), nVersion);
}
bool WriteVersion(int nVersion)
{
- return Write(std::string("version"), nVersion);
+ return Write(string("version"), nVersion);
}
bool ReadTxIndex(uint256 hash, CTxIndex& txindex);
bool WriteBestInvalidTrust(CBigNum bnBestInvalidTrust);
bool ReadSyncCheckpoint(uint256& hashCheckpoint);
bool WriteSyncCheckpoint(uint256 hashCheckpoint);
- bool ReadCheckpointPubKey(std::string& strPubKey);
- bool WriteCheckpointPubKey(const std::string& strPubKey);
+ bool ReadCheckpointPubKey(string& strPubKey);
+ bool WriteCheckpointPubKey(const string& strPubKey);
bool ReadModifierUpgradeTime(unsigned int& nUpgradeTime);
bool WriteModifierUpgradeTime(const unsigned int& nUpgradeTime);
bool LoadBlockIndex();
for (auto it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
CWalletTx* wtx = &((*it).second);
- txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)0)));
+ txOrdered.insert({ wtx->nOrderPos, { wtx, (CAccountingEntry*)0 } });
}
acentries.clear();
walletdb.ListAccountCreditDebit(strAccount, acentries);
for(auto& entry : acentries)
{
- txOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)0, &entry)));
+ txOrdered.insert({ entry.nOrderPos, { (CWalletTx*)0, &entry } });
}
return txOrdered;
{
LOCK(cs_wallet);
// Inserts only if not already there, returns tx inserted or tx found
- auto ret = mapWallet.insert(make_pair(hash, wtxIn));
+ auto ret = mapWallet.insert({ hash, wtxIn });
auto& wtx = (*ret.first).second;
wtx.BindWallet(this);
bool fInsertedNew = ret.second;
// If we are debited by the transaction, add the output as a "sent" entry
if (nDebit > 0)
- listSent.push_back(make_pair(address, txout.nValue));
+ listSent.push_back({ address, txout.nValue });
// If we are receiving the output, add it as a "received" entry
if (fIsMine & filter)
- listReceived.push_back(make_pair(address, txout.nValue));
+ listReceived.push_back({ address, txout.nValue });
}
}
// Don't rebroadcast if newer than nTime:
if (wtx.nTimeReceived > nTime)
continue;
- mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
+ mapSorted.insert({ wtx.nTimeReceived, &wtx });
}
for(auto& item : mapSorted)
{
continue;
auto n = pcoin->vout[i].nValue;
- auto coin = make_pair(n,make_pair(pcoin, i));
+ auto coin = make_pair(n, make_pair(pcoin, i));
if (n == nTargetValue)
{
if(!out.fSpendable)
continue;
nValueRet += out.tx->vout[out.i].nValue;
- setCoinsRet.insert(make_pair(out.tx, out.i));
+ setCoinsRet.insert({ out.tx, out.i });
}
return (nValueRet >= nTargetValue);
}
continue;
auto n = pcoin->vout[i].nValue;
- auto coin = make_pair(n,make_pair(pcoin, i));
+ auto coin = make_pair(n, make_pair(pcoin, i));
if (n >= nTargetValue)
{
bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl)
{
vector< pair<CScript, int64_t> > vecSend;
- vecSend.push_back(make_pair(scriptPubKey, nValue));
+ vecSend.push_back({ scriptPubKey, nValue });
return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, coinControl);
}
#define BITCOIN_WALLETDB_H
#include "db.h"
-//#include "base58.h"
#include "keystore.h"
+using namespace std;
+
class CKeyPool;
class CAccount;
class CAccountingEntry;
class CWalletDB : public CDB
{
public:
- CWalletDB(std::string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
+ CWalletDB(string strFilename, const char* pszMode="r+") : CDB(strFilename.c_str(), pszMode)
{
}
private:
CWalletDB(const CWalletDB&);
void operator=(const CWalletDB&);
public:
- bool WriteName(const std::string& strAddress, const std::string& strName);
+ bool WriteName(const string& strAddress, const string& strName);
- bool EraseName(const std::string& strAddress);
+ bool EraseName(const string& strAddress);
bool WriteTx(uint256 hash, const CWalletTx& wtx)
{
nWalletDBUpdated++;
- return Write(std::make_pair(std::string("tx"), hash), wtx);
+ return Write(make_pair(string("tx"), hash), wtx);
}
bool EraseTx(uint256 hash)
{
nWalletDBUpdated++;
- return Erase(std::make_pair(std::string("tx"), hash));
+ return Erase(make_pair(string("tx"), hash));
}
bool WriteKey(const CPubKey& key, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta)
{
nWalletDBUpdated++;
- if(!Write(std::make_pair(std::string("keymeta"), key), keyMeta))
+ if(!Write(make_pair(string("keymeta"), key), keyMeta))
return false;
- if(!Write(std::make_pair(std::string("key"), key), vchPrivKey, false))
+ if(!Write(make_pair(string("key"), key), vchPrivKey, false))
return false;
return true;
bool WriteMalleableKey(const CMalleableKeyView& keyView, const CSecret& vchSecretH, const CKeyMetadata &keyMeta)
{
nWalletDBUpdated++;
- if(!Write(std::make_pair(std::string("malmeta"), keyView.ToString()), keyMeta))
+ if(!Write(make_pair(string("malmeta"), keyView.ToString()), keyMeta))
return false;
- if(!Write(std::make_pair(std::string("malpair"), keyView.ToString()), vchSecretH, false))
+ if(!Write(make_pair(string("malpair"), keyView.ToString()), vchSecretH, false))
return false;
return true;
}
- bool WriteCryptedMalleableKey(const CMalleableKeyView& keyView, const std::vector<unsigned char>& vchCryptedSecretH, const CKeyMetadata &keyMeta)
+ bool WriteCryptedMalleableKey(const CMalleableKeyView& keyView, const vector<unsigned char>& vchCryptedSecretH, const CKeyMetadata &keyMeta)
{
nWalletDBUpdated++;
- if(!Write(std::make_pair(std::string("malmeta"), keyView.ToString()), keyMeta))
+ if(!Write(make_pair(string("malmeta"), keyView.ToString()), keyMeta))
return false;
- if(!Write(std::make_pair(std::string("malcpair"), keyView.ToString()), vchCryptedSecretH, false))
+ if(!Write(make_pair(string("malcpair"), keyView.ToString()), vchCryptedSecretH, false))
return false;
- Erase(std::make_pair(std::string("malpair"), keyView.ToString()));
+ Erase(make_pair(string("malpair"), keyView.ToString()));
return true;
}
- bool WriteCryptedKey(const CPubKey& key, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta)
+ bool WriteCryptedKey(const CPubKey& key, const vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta)
{
nWalletDBUpdated++;
bool fEraseUnencryptedKey = true;
- if(!Write(std::make_pair(std::string("keymeta"), key), keyMeta))
+ if(!Write(make_pair(string("keymeta"), key), keyMeta))
return false;
- if (!Write(std::make_pair(std::string("ckey"), key), vchCryptedSecret, false))
+ if (!Write(make_pair(string("ckey"), key), vchCryptedSecret, false))
return false;
if (fEraseUnencryptedKey)
{
- Erase(std::make_pair(std::string("key"), key));
- Erase(std::make_pair(std::string("wkey"), key));
+ Erase(make_pair(string("key"), key));
+ Erase(make_pair(string("wkey"), key));
}
return true;
}
bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
{
nWalletDBUpdated++;
- return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
+ return Write(make_pair(string("mkey"), nID), kMasterKey, true);
}
bool EraseMasterKey(unsigned int nID)
{
nWalletDBUpdated++;
- return Erase(std::make_pair(std::string("mkey"), nID));
+ return Erase(make_pair(string("mkey"), nID));
}
bool EraseCryptedKey(const CPubKey& key)
{
- return Erase(std::make_pair(std::string("ckey"), key));
+ return Erase(make_pair(string("ckey"), key));
}
bool EraseCryptedMalleableKey(const CMalleableKeyView& keyView)
{
- return Erase(std::make_pair(std::string("malcpair"), keyView.ToString()));
+ return Erase(make_pair(string("malcpair"), keyView.ToString()));
}
bool WriteCScript(const uint160& hash, const CScript& redeemScript)
{
nWalletDBUpdated++;
- return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false);
+ return Write(make_pair(string("cscript"), hash), redeemScript, false);
}
bool WriteWatchOnly(const CScript &dest)
{
nWalletDBUpdated++;
- return Write(std::make_pair(std::string("watchs"), dest), '1');
+ return Write(make_pair(string("watchs"), dest), '1');
}
bool EraseWatchOnly(const CScript &dest)
{
nWalletDBUpdated++;
- return Erase(std::make_pair(std::string("watchs"), dest));
+ return Erase(make_pair(string("watchs"), dest));
}
bool WriteBestBlock(const CBlockLocator& locator)
{
nWalletDBUpdated++;
- return Write(std::string("bestblock"), locator);
+ return Write(string("bestblock"), locator);
}
bool ReadBestBlock(CBlockLocator& locator)
{
- return Read(std::string("bestblock"), locator);
+ return Read(string("bestblock"), locator);
}
bool WriteOrderPosNext(int64_t nOrderPosNext)
{
nWalletDBUpdated++;
- return Write(std::string("orderposnext"), nOrderPosNext);
+ return Write(string("orderposnext"), nOrderPosNext);
}
bool WriteDefaultKey(const CPubKey& key)
{
nWalletDBUpdated++;
- return Write(std::string("defaultkey"), key);
+ return Write(string("defaultkey"), key);
}
bool ReadPool(int64_t nPool, CKeyPool& keypool)
{
- return Read(std::make_pair(std::string("pool"), nPool), keypool);
+ return Read(make_pair(string("pool"), nPool), keypool);
}
bool WritePool(int64_t nPool, const CKeyPool& keypool)
{
nWalletDBUpdated++;
- return Write(std::make_pair(std::string("pool"), nPool), keypool);
+ return Write(make_pair(string("pool"), nPool), keypool);
}
bool ErasePool(int64_t nPool)
{
nWalletDBUpdated++;
- return Erase(std::make_pair(std::string("pool"), nPool));
+ return Erase(make_pair(string("pool"), nPool));
}
bool WriteMinVersion(int nVersion)
{
- return Write(std::string("minversion"), nVersion);
+ return Write(string("minversion"), nVersion);
}
- bool ReadAccount(const std::string& strAccount, CAccount& account);
- bool WriteAccount(const std::string& strAccount, const CAccount& account);
+ bool ReadAccount(const string& strAccount, CAccount& account);
+ bool WriteAccount(const string& strAccount, const CAccount& account);
private:
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
public:
bool WriteAccountingEntry(const CAccountingEntry& acentry);
- int64_t GetAccountCreditDebit(const std::string& strAccount);
- void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
+ int64_t GetAccountCreditDebit(const string& strAccount);
+ void ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& acentries);
DBErrors ReorderTransactions(CWallet*);
DBErrors LoadWallet(CWallet* pwallet);
- DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash);
+ DBErrors FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash);
DBErrors ZapWalletTx(CWallet* pwallet);
- static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
- static bool Recover(CDBEnv& dbenv, std::string filename);
+ static bool Recover(CDBEnv& dbenv, string filename, bool fOnlyKeys);
+ static bool Recover(CDBEnv& dbenv, string filename);
};
#endif // BITCOIN_WALLETDB_H