Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

hdchain.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2019 The Dash Core developers
2 // Distributed under the MIT software license, see the accompanying
3 #ifndef DASH_HDCHAIN_H
4 #define DASH_HDCHAIN_H
5 
6 #include <key.h>
7 #include <sync.h>
8 
9 /* hd account data model */
11 {
12 public:
15 
17 
19  template <typename Stream, typename Operation>
20  inline void SerializationOp(Stream& s, Operation ser_action)
21  {
24  }
25 };
26 
27 /* simple HD chain data model */
28 class CHDChain
29 {
30 private:
31  static const int CURRENT_VERSION = 1;
32  int nVersion;
33 
35 
36  bool fCrypted;
37 
41 
42  std::map<uint32_t, CHDAccount> mapAccounts;
43  // critical section to protect mapAccounts
45 
46 public:
47 
48  CHDChain() { SetNull(); }
49  CHDChain(const CHDChain& other) :
50  nVersion(other.nVersion),
51  id(other.id),
52  fCrypted(other.fCrypted),
53  vchSeed(other.vchSeed),
54  vchMnemonic(other.vchMnemonic),
57  {}
58 
60  template <typename Stream, typename Operation>
61  inline void SerializationOp(Stream& s, Operation ser_action)
62  {
64  READWRITE(this->nVersion);
65  READWRITE(id);
71  }
72 
73  void swap(CHDChain& first, CHDChain& second) // nothrow
74  {
75  // enable ADL (not necessary in our case, but good practice)
76  using std::swap;
77 
78  // by swapping the members of two classes,
79  // the two classes are effectively swapped
80  swap(first.nVersion, second.nVersion);
81  swap(first.id, second.id);
82  swap(first.fCrypted, second.fCrypted);
83  swap(first.vchSeed, second.vchSeed);
84  swap(first.vchMnemonic, second.vchMnemonic);
86  swap(first.mapAccounts, second.mapAccounts);
87  }
89  {
90  swap(*this, from);
91  return *this;
92  }
93 
94  bool SetNull();
95  bool IsNull() const;
96 
97  void SetCrypted(bool fCryptedIn);
98  bool IsCrypted() const;
99 
100  void Debug(const std::string& strName) const;
101 
102  bool SetMnemonic(const SecureVector& vchMnemonic, const SecureVector& vchMnemonicPassphrase, bool fUpdateID);
103  bool SetMnemonic(const SecureString& ssMnemonic, const SecureString& ssMnemonicPassphrase, bool fUpdateID);
104  bool GetMnemonic(SecureVector& vchMnemonicRet, SecureVector& vchMnemonicPassphraseRet) const;
105  bool GetMnemonic(SecureString& ssMnemonicRet, SecureString& ssMnemonicPassphraseRet) const;
106 
107  bool SetSeed(const SecureVector& vchSeedIn, bool fUpdateID);
108  SecureVector GetSeed() const;
109 
110  uint256 GetID() const { return id; }
111 
113  void DeriveChildExtKey(uint32_t nAccountIndex, bool fInternal, uint32_t nChildIndex, CExtKey& extKeyRet);
114 
115  void AddAccount();
116  bool GetAccount(uint32_t nAccountIndex, CHDAccount& hdAccountRet);
117  bool SetAccount(uint32_t nAccountIndex, const CHDAccount& hdAccount);
118  size_t CountAccounts();
119 };
120 
121 /* hd pubkey data model */
123 {
124 private:
125  static const int CURRENT_VERSION = 1;
126  int nVersion;
127 
128 public:
131  uint32_t nAccountIndex;
132  uint32_t nChangeIndex;
133 
135 
137  template <typename Stream, typename Operation>
138  inline void SerializationOp(Stream& s, Operation ser_action)
139  {
140  READWRITE(this->nVersion);
145  }
146 
147  std::string GetKeyPath() const;
148 };
149 
150 #endif // DASH_HDCHAIN_H
static const int CURRENT_VERSION
Definition: hdchain.h:31
void SerializationOp(Stream &s, Operation ser_action)
Definition: hdchain.h:138
void swap(CHDChain &first, CHDChain &second)
Definition: hdchain.h:73
std::map< uint32_t, CHDAccount > mapAccounts
Definition: hdchain.h:42
#define READWRITE(obj)
Definition: serialize.h:165
uint32_t nExternalChainCounter
Definition: hdchain.h:13
bool fCrypted
Definition: hdchain.h:36
Definition: key.h:141
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:57
uint256 GetID() const
Definition: hdchain.h:110
CHDChain & operator=(CHDChain from)
Definition: hdchain.h:88
uint256 hdchainID
Definition: hdchain.h:130
ADD_SERIALIZE_METHODS
Definition: hdchain.h:59
void Debug(const std::string &strName) const
Definition: hdchain.cpp:42
uint256 GetSeedHash()
Definition: hdchain.cpp:146
uint256 id
Definition: hdchain.h:34
void AddAccount()
Definition: hdchain.cpp:178
bool SetAccount(uint32_t nAccountIndex, const CHDAccount &hdAccount)
Definition: hdchain.cpp:193
void SerializationOp(Stream &s, Operation ser_action)
Definition: hdchain.h:61
uint32_t nInternalChainCounter
Definition: hdchain.h:14
void SetCrypted(bool fCryptedIn)
Definition: hdchain.cpp:32
SecureVector vchMnemonic
Definition: hdchain.h:39
#define LOCK(cs)
Definition: sync.h:178
CHDPubKey()
Definition: hdchain.h:134
ADD_SERIALIZE_METHODS
Definition: hdchain.h:18
CHDAccount()
Definition: hdchain.h:16
std::vector< unsigned char, secure_allocator< unsigned char > > SecureVector
Definition: secure.h:59
void DeriveChildExtKey(uint32_t nAccountIndex, bool fInternal, uint32_t nChildIndex, CExtKey &extKeyRet)
Definition: hdchain.cpp:151
SecureVector vchMnemonicPassphrase
Definition: hdchain.h:40
bool IsNull() const
Definition: hdchain.cpp:27
uint32_t nChangeIndex
Definition: hdchain.h:132
SecureVector vchSeed
Definition: hdchain.h:38
CHDChain(const CHDChain &other)
Definition: hdchain.h:49
void SerializationOp(Stream &s, Operation ser_action)
Definition: hdchain.h:20
static const int CURRENT_VERSION
Definition: hdchain.h:125
256-bit opaque blob.
Definition: uint256.h:123
bool GetMnemonic(SecureVector &vchMnemonicRet, SecureVector &vchMnemonicPassphraseRet) const
Definition: hdchain.cpp:107
SecureVector GetSeed() const
Definition: hdchain.cpp:141
int nVersion
Definition: hdchain.h:126
ADD_SERIALIZE_METHODS
Definition: hdchain.h:136
bool GetAccount(uint32_t nAccountIndex, CHDAccount &hdAccountRet)
Definition: hdchain.cpp:184
bool SetMnemonic(const SecureVector &vchMnemonic, const SecureVector &vchMnemonicPassphrase, bool fUpdateID)
Definition: hdchain.cpp:72
CHDChain()
Definition: hdchain.h:48
bool IsCrypted() const
Definition: hdchain.cpp:37
std::string GetKeyPath() const
Definition: hdchain.cpp:209
bool SetSeed(const SecureVector &vchSeedIn, bool fUpdateID)
Definition: hdchain.cpp:130
bool SetNull()
Definition: hdchain.cpp:12
CCriticalSection cs_accounts
Definition: hdchain.h:44
int nVersion
Definition: hdchain.h:32
CExtPubKey extPubKey
Definition: hdchain.h:129
size_t CountAccounts()
Definition: hdchain.cpp:203
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
uint32_t nAccountIndex
Definition: hdchain.h:131
Released under the MIT license