PRCYCoin  2.0.0.7rc1
P2P Digital Currency
hdchain.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2018 The Dash Core developers
2 // Distributed under the MIT software license, see the accompanying
3 #ifndef BITCOIN_HDCHAIN_H
4 #define BITCOIN_HDCHAIN_H
5 
6 #include "key.h"
7 #include "sync.h"
8 #include "pubkey.h"
9 
10 /* simple HD chain data model */
11 class CHDChain
12 {
13 private:
14  static const int CURRENT_VERSION = 1;
15  int nVersion;
16 
18 
19  bool fCrypted;
20 
24 
25 public:
26 
27  CHDChain() { SetNull(); }
28  CHDChain(const CHDChain& other) :
29  nVersion(other.nVersion),
30  id(other.id),
31  fCrypted(other.fCrypted),
32  vchSeed(other.vchSeed),
33  vchMnemonic(other.vchMnemonic),
35  {}
36 
38  template <typename Stream, typename Operation>
39  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
40  {
41  READWRITE(this->nVersion);
42  READWRITE(id);
47  }
48 
49  void swap(CHDChain& first, CHDChain& second) // nothrow
50  {
51  // enable ADL (not necessary in our case, but good practice)
52  using std::swap;
53 
54  // by swapping the members of two classes,
55  // the two classes are effectively swapped
56  swap(first.nVersion, second.nVersion);
57  swap(first.id, second.id);
58  swap(first.fCrypted, second.fCrypted);
59  swap(first.vchSeed, second.vchSeed);
60  swap(first.vchMnemonic, second.vchMnemonic);
62  }
64  {
65  swap(*this, from);
66  return *this;
67  }
68 
69  bool SetNull();
70  bool IsNull() const;
71 
72  void SetCrypted(bool fCryptedIn);
73  bool IsCrypted() const;
74 
75  void Debug(const std::string& strName) const;
76 
77  bool SetMnemonic(const SecureVector& vchMnemonic, const SecureVector& vchMnemonicPassphrase, bool fUpdateID);
78  bool SetMnemonic(const SecureString& ssMnemonic, const SecureString& ssMnemonicPassphrase, bool fUpdateID);
79  bool GetMnemonic(SecureVector& vchMnemonicRet, SecureVector& vchMnemonicPassphraseRet) const;
80  bool GetMnemonic(SecureString& ssMnemonicRet, SecureString& ssMnemonicPassphraseRet) const;
81 
82  bool SetSeed(const SecureVector& vchSeedIn, bool fUpdateID);
83  SecureVector GetSeed() const;
84 
85  uint256 GetID() const { return id; }
86 
88  void DeriveChildExtKey(uint32_t nAccountIndex, bool fInternal, uint32_t nChildIndex, CExtKey& extKeyRet);
89 };
90 
91 /* hd pubkey data model */
92 class CHDPubKey
93 {
94 private:
95  static const int CURRENT_VERSION = 1;
96  int nVersion;
97 
98 public:
101  uint32_t nAccountIndex;
102  uint32_t nChangeIndex;
103 
105 
107  template <typename Stream, typename Operation>
108  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
109  {
110  READWRITE(this->nVersion);
115  }
116 
117  std::string GetKeyPath() const;
118 };
119 
120 #endif // BITCOIN_HDCHAIN_H
CHDChain::GetID
uint256 GetID() const
Definition: hdchain.h:85
CHDPubKey::extPubKey
CExtPubKey extPubKey
Definition: hdchain.h:99
CHDChain::DeriveChildExtKey
void DeriveChildExtKey(uint32_t nAccountIndex, bool fInternal, uint32_t nChildIndex, CExtKey &extKeyRet)
Definition: hdchain.cpp:144
CHDChain::operator=
CHDChain & operator=(CHDChain from)
Definition: hdchain.h:63
CHDChain::GetSeedHash
uint256 GetSeedHash()
Definition: hdchain.cpp:139
CHDChain::vchMnemonicPassphrase
SecureVector vchMnemonicPassphrase
Definition: hdchain.h:23
CHDChain::IsNull
bool IsNull() const
Definition: hdchain.cpp:23
sync.h
CHDChain::nVersion
int nVersion
Definition: hdchain.h:15
CHDChain::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
Definition: hdchain.h:37
CHDPubKey::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: hdchain.h:108
CHDPubKey::hdchainID
uint256 hdchainID
Definition: hdchain.h:100
CHDChain::GetSeed
SecureVector GetSeed() const
Definition: hdchain.cpp:134
pubkey.h
CHDChain::SetMnemonic
bool SetMnemonic(const SecureVector &vchMnemonic, const SecureVector &vchMnemonicPassphrase, bool fUpdateID)
Definition: hdchain.cpp:65
CHDPubKey
Definition: hdchain.h:92
CHDChain::fCrypted
bool fCrypted
Definition: hdchain.h:19
CHDPubKey::CHDPubKey
CHDPubKey()
Definition: hdchain.h:104
CHDChain::CHDChain
CHDChain(const CHDChain &other)
Definition: hdchain.h:28
CExtKey
Definition: key.h:161
CHDChain::SetNull
bool SetNull()
Definition: hdchain.cpp:12
CHDChain::vchSeed
SecureVector vchSeed
Definition: hdchain.h:21
CHDChain::GetMnemonic
bool GetMnemonic(SecureVector &vchMnemonicRet, SecureVector &vchMnemonicPassphraseRet) const
Definition: hdchain.cpp:100
SecureString
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: allocators.h:262
CHDPubKey::CURRENT_VERSION
static const int CURRENT_VERSION
Definition: hdchain.h:95
CHDPubKey::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
Definition: hdchain.h:106
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
CHDPubKey::nChangeIndex
uint32_t nChangeIndex
Definition: hdchain.h:102
CHDChain::SetCrypted
void SetCrypted(bool fCryptedIn)
Definition: hdchain.cpp:28
CHDChain::swap
void swap(CHDChain &first, CHDChain &second)
Definition: hdchain.h:49
CHDPubKey::nVersion
int nVersion
Definition: hdchain.h:96
CHDChain::IsCrypted
bool IsCrypted() const
Definition: hdchain.cpp:33
key.h
READWRITE
#define READWRITE(obj)
Definition: serialize.h:164
SecureVector
std::vector< unsigned char, secure_allocator< unsigned char > > SecureVector
Definition: allocators.h:267
CHDChain::SetSeed
bool SetSeed(const SecureVector &vchSeedIn, bool fUpdateID)
Definition: hdchain.cpp:123
CHDChain
Definition: hdchain.h:11
CHDChain::id
uint256 id
Definition: hdchain.h:17
CHDPubKey::nAccountIndex
uint32_t nAccountIndex
Definition: hdchain.h:101
CHDChain::CURRENT_VERSION
static const int CURRENT_VERSION
Definition: hdchain.h:14
CHDChain::Debug
void Debug(const std::string &strName) const
Definition: hdchain.cpp:38
CHDChain::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: hdchain.h:39
CExtPubKey
Definition: pubkey.h:205
CHDChain::vchMnemonic
SecureVector vchMnemonic
Definition: hdchain.h:22
CHDPubKey::GetKeyPath
std::string GetKeyPath() const
Definition: hdchain.cpp:171
CHDChain::CHDChain
CHDChain()
Definition: hdchain.h:27