Skip to content

Commit 9a7d0fd

Browse files
committed
[Wallet] HD Wallet, staking chain counter.
1 parent 811fb29 commit 9a7d0fd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/wallet/hdchain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ bool CHDChain::SetNull()
1212
{
1313
nVersion = CURRENT_VERSION;
1414
seed_id = CKeyID();
15+
nExternalChainCounter = 0;
16+
nInternalChainCounter = 0;
17+
nStakingChainCounter = 0;
1518
return IsNull();
1619
}
1720

src/wallet/hdchain.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
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 */
917
class 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

Comments
 (0)