MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / WriteCryptedKey

Method WriteCryptedKey

src/wallet/walletdb.cpp:125–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125bool WalletBatch::WriteCryptedKey(const CPubKey& vchPubKey,
126 const std::vector<unsigned char>& vchCryptedSecret,
127 const CKeyMetadata &keyMeta)
128{
129 if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) {
130 return false;
131 }
132
133 // Compute a checksum of the encrypted key
134 uint256 checksum = Hash(vchCryptedSecret);
135
136 const auto key = std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey);
137 if (!WriteIC(key, std::make_pair(vchCryptedSecret, checksum), false)) {
138 // It may already exist, so try writing just the checksum
139 std::vector<unsigned char> val;
140 if (!m_batch->Read(key, val)) {
141 return false;
142 }
143 if (!WriteIC(key, std::make_pair(val, checksum), true)) {
144 return false;
145 }
146 }
147 EraseIC(std::make_pair(DBKeys::KEY, vchPubKey));
148 return true;
149}
150
151bool WalletBatch::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
152{

Callers 1

CheckDecryptionKeyMethod · 0.80

Calls 2

HashFunction · 0.50
ReadMethod · 0.45

Tested by

no test coverage detected