0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

Merge bitcoin/bitcoin#22941: wallet: refactor: inline functions {Read,Write}OrderPos

98cf19ca32 wallet: refactor: avoid duplicate lookup on `mapValue["timesmart"]` (Sebastian Falbesoner)
973d8ba93d wallet: refactor: inline function WriteOrderPos() (Sebastian Falbesoner)
65ed198295 wallet: refactor: inline function ReadOrderPos() (Sebastian Falbesoner)

Pull request description:

  The functions `ReadOrderPos` and `WriteOrderPos` have been introduced in commit 9c7722b7c5 in 2012. Since accounts have been removed in #13825 (commit c9c32e6b84), they are only called at one place in `CWalletTx::{Serialize,Unserialize}` and thus can be directly inlined instead. Additionally, this PR aims to avoids duplicate lookups on the map `mapValue` (affects keys "n" and "timesmart").

ACKs for top commit:
  laanwj:
    Code review ACK 98cf19ca32
  achow101:
    Code Review ACK 98cf19ca32

Tree-SHA512: 8af63c174c79e589bd713f04e8e40caba9f93ec2978c805427cac50d48049808a8c23ff5eea9ef589c9bd79fc66087f43ff5ab28e3cda51dd03f37c0164e2e4c
This commit is contained in:
fanquake 2021-09-17 10:00:59 +08:00
commit f7189c4ce9
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -19,25 +19,6 @@
typedef std::map<std::string, std::string> mapValue_t;
static inline void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue)
{
if (!mapValue.count("n"))
{
nOrderPos = -1; // TODO: calculate elsewhere
return;
}
nOrderPos = atoi64(mapValue["n"]);
}
static inline void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
{
if (nOrderPos == -1)
return;
mapValue["n"] = ToString(nOrderPos);
}
/** Legacy class used for deserializing vtxPrev for backwards compatibility.
* vtxPrev was removed in commit 93a18a3650292afbb441a47d1fa1b94aeb0164e3,
* but old wallet.dat files may still contain vtxPrev vectors of CMerkleTxs.
@ -192,7 +173,9 @@ public:
mapValue_t mapValueCopy = mapValue;
mapValueCopy["fromaccount"] = "";
WriteOrderPos(nOrderPos, mapValueCopy);
if (nOrderPos != -1) {
mapValueCopy["n"] = ToString(nOrderPos);
}
if (nTimeSmart) {
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
}
@ -232,8 +215,10 @@ public:
setConfirmed();
}
ReadOrderPos(nOrderPos, mapValue);
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
const auto it_op = mapValue.find("n");
nOrderPos = (it_op != mapValue.end()) ? atoi64(it_op->second) : -1;
const auto it_ts = mapValue.find("timesmart");
nTimeSmart = (it_ts != mapValue.end()) ? static_cast<unsigned int>(atoi64(it_ts->second)) : 0;
mapValue.erase("fromaccount");
mapValue.erase("spent");