aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2017-02-16 14:22:18 +0100
committerJonas Schnelli <dev@jonasschnelli.ch>2018-07-12 10:30:21 +0100
commit9995a602a639b64a749545b7c3bafbf67f97324f (patch)
tree2fd0c1cf77980214e7190642c842d1603f0ee530
parent5ba77df15de92deb35bfd501d4635aed3236af30 (diff)
downloadbitcoin-9995a602a639b64a749545b7c3bafbf67f97324f.tar.xz
Add facility to store wallet flags (64 bits)
-rw-r--r--src/wallet/wallet.cpp22
-rw-r--r--src/wallet/wallet.h10
-rw-r--r--src/wallet/walletdb.cpp11
-rw-r--r--src/wallet/walletdb.h1
4 files changed, 43 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index cdba6c6441..48ace544c4 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1526,6 +1526,28 @@ bool CWallet::IsHDEnabled() const
return !hdChain.seed_id.IsNull();
}
+void CWallet::SetWalletFlag(uint64_t flags)
+{
+ LOCK(cs_wallet);
+ m_wallet_flags |= flags;
+ if (!WalletBatch(*database).WriteWalletFlags(m_wallet_flags))
+ throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed");
+}
+
+bool CWallet::IsWalletFlagSet(uint64_t flag)
+{
+ return (m_wallet_flags & flag);
+}
+
+void CWallet::SetWalletFlags(uint64_t overwriteFlags, bool memonly)
+{
+ LOCK(cs_wallet);
+ m_wallet_flags = overwriteFlags;
+ if (!memonly && !WalletBatch(*database).WriteWalletFlags(m_wallet_flags)) {
+ throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed");
+ }
+}
+
int64_t CWalletTx::GetTxTime() const
{
int64_t n = nTimeSmart;
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index ef03a1eaed..c88fbe8b96 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -723,6 +723,7 @@ private:
std::set<int64_t> set_pre_split_keypool;
int64_t m_max_keypool_index = 0;
std::map<CKeyID, int64_t> m_pool_key_to_index;
+ std::atomic<uint64_t> m_wallet_flags{0};
int64_t nTimeFirstKey = 0;
@@ -1190,6 +1191,15 @@ public:
/** Whether a given output is spendable by this wallet */
bool OutputEligibleForSpending(const COutput& output, const CoinEligibilityFilter& eligibility_filter) const;
+
+ /** set a single wallet flag */
+ void SetWalletFlag(uint64_t flags);
+
+ /** check if a certain wallet flag is set */
+ bool IsWalletFlagSet(uint64_t flag);
+
+ /** overwrite all flags by the given uint64_t */
+ void SetWalletFlags(uint64_t overwriteFlags, bool memOnly);
};
/** A key allocated from the key pool. */
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 4b4460a794..8caf7e4e66 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -510,7 +510,11 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
strErr = "Error reading wallet database: SetHDChain failed";
return false;
}
- } else if (strType != "bestblock" && strType != "bestblock_nomerkle"){
+ } else if (strType == "flags") {
+ uint64_t flags;
+ ssValue >> flags;
+ pwallet->SetWalletFlags(flags, true);
+ } else if (strType != "bestblock" && strType != "bestblock_nomerkle") {
wss.m_unknown_records++;
}
} catch (...)
@@ -840,6 +844,11 @@ bool WalletBatch::WriteHDChain(const CHDChain& chain)
return WriteIC(std::string("hdchain"), chain);
}
+bool WalletBatch::WriteWalletFlags(const uint64_t flags)
+{
+ return WriteIC(std::string("flags"), flags);
+}
+
bool WalletBatch::TxnBegin()
{
return m_batch.TxnBegin();
diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h
index 3237376f63..674d1c2201 100644
--- a/src/wallet/walletdb.h
+++ b/src/wallet/walletdb.h
@@ -234,6 +234,7 @@ public:
//! write the hdchain model (external chain child index counter)
bool WriteHDChain(const CHDChain& chain);
+ bool WriteWalletFlags(const uint64_t flags);
//! Begin a new transaction
bool TxnBegin();
//! Commit current transaction