Skip to content

Commit 417df65

Browse files
committed
[HDChain] Chain counter type supporting Standard and Sapling counters.
1 parent aabcda4 commit 417df65

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/wallet/hdchain.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ namespace HDChain {
1313
static const uint8_t INTERNAL = 1;
1414
static const uint8_t STAKING = 2;
1515
};
16+
17+
namespace ChainCounterType {
18+
static const uint8_t Standard = 0;
19+
static const uint8_t Sapling = 1;
20+
};
1621
}
1722

18-
/* Simple HD chain data model */
23+
/* Simple HD chain data model for regular and sapling addresses */
1924
class CHDChain
2025
{
2126
private:
@@ -28,19 +33,24 @@ class CHDChain
2833
uint32_t nExternalChainCounter{0};
2934
uint32_t nInternalChainCounter{0};
3035
uint32_t nStakingChainCounter{0};
36+
// Chain counter type
37+
uint8_t chainType;
3138

32-
CHDChain() { SetNull(); }
39+
CHDChain(const uint8_t& _chainType = HDChain::ChainCounterType::Standard) : chainType(_chainType) { SetNull(); }
3340

3441
ADD_SERIALIZE_METHODS;
3542
template <typename Stream, typename Operation>
3643
inline void SerializationOp(Stream& s, Operation ser_action)
3744
{
3845
READWRITE(nVersion);
3946
READWRITE(seed_id);
47+
READWRITE(chainType);
4048
// Single account counters.
4149
READWRITE(nExternalChainCounter);
42-
READWRITE(nInternalChainCounter);
43-
READWRITE(nStakingChainCounter);
50+
if (chainType != HDChain::ChainCounterType::Standard) {
51+
READWRITE(nInternalChainCounter);
52+
READWRITE(nStakingChainCounter);
53+
}
4454
}
4555

4656
bool SetNull();

src/wallet/walletdb.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ bool CWalletDB::WriteMinVersion(int nVersion)
284284
bool CWalletDB::WriteHDChain(const CHDChain& chain)
285285
{
286286
nWalletDBUpdated++;
287-
return Write(std::string("hdchain"), chain);
287+
std::string key = std::string("hdchain");
288+
if (chain.chainType == HDChain::ChainCounterType::Sapling)
289+
key += std::string("_sap");
290+
return Write(key, chain);
288291
}
289292

290293
bool CWalletDB::ReadAccount(const std::string& strAccount, CAccount& account)
@@ -682,7 +685,7 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, CW
682685
strErr = "Error reading wallet database: LoadDestData failed";
683686
return false;
684687
}
685-
} else if (strType == "hdchain") {
688+
} else if (strType == "hdchain") { // Regular key chain counter
686689
CHDChain chain;
687690
ssValue >> chain;
688691
pwallet->GetScriptPubKeyMan()->SetHDChain(chain, true);

0 commit comments

Comments
 (0)