Skip to content

Commit 9995a60

Browse files
committed
Add facility to store wallet flags (64 bits)
1 parent 5ba77df commit 9995a60

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,28 @@ bool CWallet::IsHDEnabled() const
15261526
return !hdChain.seed_id.IsNull();
15271527
}
15281528

1529+
void CWallet::SetWalletFlag(uint64_t flags)
1530+
{
1531+
LOCK(cs_wallet);
1532+
m_wallet_flags |= flags;
1533+
if (!WalletBatch(*database).WriteWalletFlags(m_wallet_flags))
1534+
throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed");
1535+
}
1536+
1537+
bool CWallet::IsWalletFlagSet(uint64_t flag)
1538+
{
1539+
return (m_wallet_flags & flag);
1540+
}
1541+
1542+
void CWallet::SetWalletFlags(uint64_t overwriteFlags, bool memonly)
1543+
{
1544+
LOCK(cs_wallet);
1545+
m_wallet_flags = overwriteFlags;
1546+
if (!memonly && !WalletBatch(*database).WriteWalletFlags(m_wallet_flags)) {
1547+
throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed");
1548+
}
1549+
}
1550+
15291551
int64_t CWalletTx::GetTxTime() const
15301552
{
15311553
int64_t n = nTimeSmart;

src/wallet/wallet.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
723723
std::set<int64_t> set_pre_split_keypool;
724724
int64_t m_max_keypool_index = 0;
725725
std::map<CKeyID, int64_t> m_pool_key_to_index;
726+
std::atomic<uint64_t> m_wallet_flags{0};
726727

727728
int64_t nTimeFirstKey = 0;
728729

@@ -1190,6 +1191,15 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
11901191

11911192
/** Whether a given output is spendable by this wallet */
11921193
bool OutputEligibleForSpending(const COutput& output, const CoinEligibilityFilter& eligibility_filter) const;
1194+
1195+
/** set a single wallet flag */
1196+
void SetWalletFlag(uint64_t flags);
1197+
1198+
/** check if a certain wallet flag is set */
1199+
bool IsWalletFlagSet(uint64_t flag);
1200+
1201+
/** overwrite all flags by the given uint64_t */
1202+
void SetWalletFlags(uint64_t overwriteFlags, bool memOnly);
11931203
};
11941204

11951205
/** A key allocated from the key pool. */

src/wallet/walletdb.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,11 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
510510
strErr = "Error reading wallet database: SetHDChain failed";
511511
return false;
512512
}
513-
} else if (strType != "bestblock" && strType != "bestblock_nomerkle"){
513+
} else if (strType == "flags") {
514+
uint64_t flags;
515+
ssValue >> flags;
516+
pwallet->SetWalletFlags(flags, true);
517+
} else if (strType != "bestblock" && strType != "bestblock_nomerkle") {
514518
wss.m_unknown_records++;
515519
}
516520
} catch (...)
@@ -840,6 +844,11 @@ bool WalletBatch::WriteHDChain(const CHDChain& chain)
840844
return WriteIC(std::string("hdchain"), chain);
841845
}
842846

847+
bool WalletBatch::WriteWalletFlags(const uint64_t flags)
848+
{
849+
return WriteIC(std::string("flags"), flags);
850+
}
851+
843852
bool WalletBatch::TxnBegin()
844853
{
845854
return m_batch.TxnBegin();

src/wallet/walletdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class WalletBatch
234234
//! write the hdchain model (external chain child index counter)
235235
bool WriteHDChain(const CHDChain& chain);
236236

237+
bool WriteWalletFlags(const uint64_t flags);
237238
//! Begin a new transaction
238239
bool TxnBegin();
239240
//! Commit current transaction

0 commit comments

Comments
 (0)