55
66#include " key.h"
77
8+ namespace HDChain {
9+ namespace ChangeType {
10+ static const uint8_t EXTERNAL = 0 ;
11+ static const uint8_t INTERNAL = 1 ;
12+ static const uint8_t STAKING = 2 ;
13+ };
14+ }
15+
816/* Simple HD chain data model */
917class CHDChain
1018{
@@ -17,6 +25,7 @@ class CHDChain
1725 // Single account counters.
1826 uint32_t nExternalChainCounter{0 };
1927 uint32_t nInternalChainCounter{0 };
28+ uint32_t nStakingChainCounter{0 };
2029
2130 CHDChain () { SetNull (); }
2231
@@ -29,6 +38,7 @@ class CHDChain
2938 // Single account counters.
3039 READWRITE (nExternalChainCounter);
3140 READWRITE (nInternalChainCounter);
41+ READWRITE (nStakingChainCounter);
3242 }
3343
3444 bool SetNull ();
@@ -37,8 +47,17 @@ class CHDChain
3747 bool SetSeed (const CKeyID& seedId);
3848 CKeyID GetID () const { return seed_id; }
3949
40- uint32_t & GetChainCounter (const bool & internal = false ) {
41- return internal ? nInternalChainCounter : nExternalChainCounter;
50+ uint32_t & GetChainCounter (const uint8_t & type = HDChain::ChangeType::EXTERNAL) {
51+ switch (type) {
52+ case HDChain::ChangeType::EXTERNAL:
53+ return nExternalChainCounter;
54+ case HDChain::ChangeType::INTERNAL:
55+ return nInternalChainCounter;
56+ case HDChain::ChangeType::STAKING:
57+ return nStakingChainCounter;
58+ default :
59+ throw std::runtime_error (" HD chain type doesn't exist." );
60+ }
4261 }
4362};
4463
0 commit comments