MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ReadKeyValue

Function ReadKeyValue

src/wallet/walletdb.cpp:31–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29//
30
31bool ReadKeyValue(CWallet* pWallet, CDataStream& ssKey, CDataStream& ssValue, string& strType, string& strErr,
32 int32_t MinVersion) {
33 try {
34 // Unserialize
35 // Taking advantage of the fact that pair serialization
36 // is just the two items serialized one after the other
37 ssKey >> strType;
38
39 if (strType == "tx") {
40 uint256 hash;
41 ssKey >> hash;
42 std::shared_ptr<CBaseTx> pBaseTx; //= make_shared<CLuaContractInvokeTx>();
43 ssValue >> pBaseTx;
44 if (pBaseTx->GetHash() == hash) {
45 if (pWallet != nullptr)
46 pWallet->unconfirmedTx[hash] = pBaseTx->GetNewInstance();
47 } else {
48 strErr = "Error reading wallet database: tx corrupt";
49 return false;
50 }
51
52 } else if (strType == "keystore") {
53 if (-1 != MinVersion) {
54 ssKey.SetVersion(MinVersion);
55 ssValue.SetVersion(MinVersion);
56 }
57 CKeyCombi keyCombi;
58 CKeyID cKeyid;
59 ssKey >> cKeyid;
60 ssValue >> keyCombi;
61 if (keyCombi.HasMainKey()) {
62 if (cKeyid != keyCombi.GetCKeyID()) {
63 strErr = "Error reading wallet database: keystore corrupt";
64 return false;
65 }
66 }
67 if (pWallet != nullptr)
68 pWallet->LoadKeyCombi(cKeyid, keyCombi);
69
70 } else if (strType == "ckey") {
71 CPubKey pubKey;
72 std::vector<unsigned char> vchCryptedSecret;
73 ssKey >> pubKey;
74 ssValue >> vchCryptedSecret;
75 if (pWallet != nullptr)
76 pWallet->LoadCryptedKey(pubKey, vchCryptedSecret);
77
78 } else if (strType == "mkey") {
79 uint32_t ID;
80 CMasterKey kMasterKey;
81 ssKey >> ID;
82 ssValue >> kMasterKey;
83 if (pWallet != nullptr) {
84 pWallet->nMasterKeyMaxID = ID;
85 pWallet->mapMasterKeys.insert(make_pair(ID, kMasterKey));
86 }
87
88 } else if (strType == "blocktx") {

Callers 2

LoadWalletMethod · 0.85
RecoverMethod · 0.85

Calls 7

GetCKeyIDMethod · 0.80
LoadCryptedKeyMethod · 0.80
GetHashMethod · 0.45
GetNewInstanceMethod · 0.45
SetVersionMethod · 0.45
HasMainKeyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected