scripted-diff: Use DataStream in most places

The remaining places are handled easier outside a scripted-diff.

-BEGIN VERIFY SCRIPT-
 sed --regexp-extended -i 's/CDataStream ([0-9a-zA-Z_]+)\(SER_[A-Z]+, [A-Z_]+_VERSION\);/DataStream \1{};/g' $( git grep -l CDataStream)
 sed -i 's/, CDataStream/, DataStream/g' src/wallet/walletdb.cpp
-END VERIFY SCRIPT-
This commit is contained in:
MarcoFalke 2023-11-19 14:58:00 +01:00
parent fac39b56b7
commit fae76a1f2a
No known key found for this signature in database
12 changed files with 53 additions and 53 deletions

View file

@ -74,7 +74,7 @@ UniValue ExternalSigner::GetDescriptors(const int account)
bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::string& error) bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::string& error)
{ {
// Serialize the PSBT // Serialize the PSBT
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
// parse ExternalSigner master fingerprint // parse ExternalSigner master fingerprint
std::vector<unsigned char> parsed_m_fingerprint = ParseHex(m_fingerprint); std::vector<unsigned char> parsed_m_fingerprint = ParseHex(m_fingerprint);

View file

@ -128,14 +128,14 @@ void PSBTOperationsDialog::broadcastTransaction()
} }
void PSBTOperationsDialog::copyToClipboard() { void PSBTOperationsDialog::copyToClipboard() {
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << m_transaction_data; ssTx << m_transaction_data;
GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str()); GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str());
showStatus(tr("PSBT copied to clipboard."), StatusLevel::INFO); showStatus(tr("PSBT copied to clipboard."), StatusLevel::INFO);
} }
void PSBTOperationsDialog::saveTransaction() { void PSBTOperationsDialog::saveTransaction() {
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << m_transaction_data; ssTx << m_transaction_data;
QString selected_filter; QString selected_filter;

View file

@ -397,7 +397,7 @@ bool SendCoinsDialog::PrepareSendText(QString& question_string, QString& informa
void SendCoinsDialog::presentPSBT(PartiallySignedTransaction& psbtx) void SendCoinsDialog::presentPSBT(PartiallySignedTransaction& psbtx)
{ {
// Serialize the PSBT // Serialize the PSBT
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str()); GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str());
QMessageBox msgBox(this); QMessageBox msgBox(this);

View file

@ -543,7 +543,7 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
return false; return false;
} }
// Serialize the PSBT // Serialize the PSBT
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str()); GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str());
Q_EMIT message(tr("PSBT copied"), tr("Copied to clipboard", "Fee-bump PSBT saved"), CClientUIInterface::MSG_INFORMATION); Q_EMIT message(tr("PSBT copied"), tr("Copied to clipboard", "Fee-bump PSBT saved"), CClientUIInterface::MSG_INFORMATION);

View file

@ -1493,7 +1493,7 @@ static RPCHelpMan combinepsbt()
throw JSONRPCTransactionError(error); throw JSONRPCTransactionError(error);
} }
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << merged_psbt; ssTx << merged_psbt;
return EncodeBase64(ssTx); return EncodeBase64(ssTx);
}, },
@ -1538,7 +1538,7 @@ static RPCHelpMan finalizepsbt()
bool complete = FinalizeAndExtractPSBT(psbtx, mtx); bool complete = FinalizeAndExtractPSBT(psbtx, mtx);
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
std::string result_str; std::string result_str;
if (complete && extract) { if (complete && extract) {
@ -1589,7 +1589,7 @@ static RPCHelpMan createpsbt()
} }
// Serialize the PSBT // Serialize the PSBT
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
return EncodeBase64(ssTx); return EncodeBase64(ssTx);
@ -1656,7 +1656,7 @@ static RPCHelpMan converttopsbt()
} }
// Serialize the PSBT // Serialize the PSBT
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
return EncodeBase64(ssTx); return EncodeBase64(ssTx);
@ -1703,7 +1703,7 @@ static RPCHelpMan utxoupdatepsbt()
/*sighash_type=*/SIGHASH_ALL, /*sighash_type=*/SIGHASH_ALL,
/*finalize=*/false); /*finalize=*/false);
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
return EncodeBase64(ssTx); return EncodeBase64(ssTx);
}, },
@ -1804,7 +1804,7 @@ static RPCHelpMan joinpsbts()
} }
shuffled_psbt.unknown.insert(merged_psbt.unknown.begin(), merged_psbt.unknown.end()); shuffled_psbt.unknown.insert(merged_psbt.unknown.begin(), merged_psbt.unknown.end());
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << shuffled_psbt; ssTx << shuffled_psbt;
return EncodeBase64(ssTx); return EncodeBase64(ssTx);
}, },
@ -1984,7 +1984,7 @@ RPCHelpMan descriptorprocesspsbt()
complete &= PSBTInputSigned(input); complete &= PSBTInputSigned(input);
} }
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);

View file

@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
{ {
CBlockHeaderAndShortTxIDs shortIDs{block}; CBlockHeaderAndShortTxIDs shortIDs{block};
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); DataStream stream{};
stream << shortIDs; stream << shortIDs;
CBlockHeaderAndShortTxIDs shortIDs2; CBlockHeaderAndShortTxIDs shortIDs2;
@ -119,7 +119,7 @@ public:
std::vector<PrefilledTransaction> prefilledtxn; std::vector<PrefilledTransaction> prefilledtxn;
explicit TestHeaderAndShortIDs(const CBlockHeaderAndShortTxIDs& orig) { explicit TestHeaderAndShortIDs(const CBlockHeaderAndShortTxIDs& orig) {
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); DataStream stream{};
stream << orig; stream << orig;
stream >> *this; stream >> *this;
} }
@ -127,7 +127,7 @@ public:
TestHeaderAndShortIDs(CBlockHeaderAndShortTxIDs{block}) {} TestHeaderAndShortIDs(CBlockHeaderAndShortTxIDs{block}) {}
uint64_t GetShortID(const uint256& txhash) const { uint64_t GetShortID(const uint256& txhash) const {
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); DataStream stream{};
stream << *this; stream << *this;
CBlockHeaderAndShortTxIDs base; CBlockHeaderAndShortTxIDs base;
stream >> base; stream >> base;
@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest)
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetHash()); shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetHash());
shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetHash()); shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetHash());
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); DataStream stream{};
stream << shortIDs; stream << shortIDs;
CBlockHeaderAndShortTxIDs shortIDs2; CBlockHeaderAndShortTxIDs shortIDs2;
@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
shortIDs.shorttxids.resize(1); shortIDs.shorttxids.resize(1);
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetHash()); shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetHash());
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); DataStream stream{};
stream << shortIDs; stream << shortIDs;
CBlockHeaderAndShortTxIDs shortIDs2; CBlockHeaderAndShortTxIDs shortIDs2;
@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest)
{ {
CBlockHeaderAndShortTxIDs shortIDs{block}; CBlockHeaderAndShortTxIDs shortIDs{block};
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); DataStream stream{};
stream << shortIDs; stream << shortIDs;
CBlockHeaderAndShortTxIDs shortIDs2; CBlockHeaderAndShortTxIDs shortIDs2;

View file

@ -1126,7 +1126,7 @@ public:
void SendV1Version(const MessageStartChars& magic) void SendV1Version(const MessageStartChars& magic)
{ {
CMessageHeader hdr(magic, "version", 126 + InsecureRandRange(11)); CMessageHeader hdr(magic, "version", 126 + InsecureRandRange(11));
CDataStream ser(SER_NETWORK, CLIENT_VERSION); DataStream ser{};
ser << hdr; ser << hdr;
m_to_send.insert(m_to_send.end(), UCharCast(ser.data()), UCharCast(ser.data() + ser.size())); m_to_send.insert(m_to_send.end(), UCharCast(ser.data()), UCharCast(ser.data() + ser.size()));
} }

View file

@ -67,7 +67,7 @@ public:
ssKey.reserve(1000); ssKey.reserve(1000);
ssKey << key; ssKey << key;
CDataStream ssValue(SER_DISK, CLIENT_VERSION); DataStream ssValue{};
if (!ReadKey(std::move(ssKey), ssValue)) return false; if (!ReadKey(std::move(ssKey), ssValue)) return false;
try { try {
ssValue >> value; ssValue >> value;
@ -84,7 +84,7 @@ public:
ssKey.reserve(1000); ssKey.reserve(1000);
ssKey << key; ssKey << key;
CDataStream ssValue(SER_DISK, CLIENT_VERSION); DataStream ssValue{};
ssValue.reserve(10000); ssValue.reserve(10000);
ssValue << value; ssValue << value;

View file

@ -100,7 +100,7 @@ static UniValue FinishTransaction(const std::shared_ptr<CWallet> pwallet, const
bool add_to_wallet{options.exists("add_to_wallet") ? options["add_to_wallet"].get_bool() : true}; bool add_to_wallet{options.exists("add_to_wallet") ? options["add_to_wallet"].get_bool() : true};
if (psbt_opt_in || !complete || !add_to_wallet) { if (psbt_opt_in || !complete || !add_to_wallet) {
// Serialize the PSBT // Serialize the PSBT
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
result.pushKV("psbt", EncodeBase64(ssTx.str())); result.pushKV("psbt", EncodeBase64(ssTx.str()));
} }
@ -1165,7 +1165,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
const TransactionError err = pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, /*sign=*/false, /*bip32derivs=*/true); const TransactionError err = pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, /*sign=*/false, /*bip32derivs=*/true);
CHECK_NONFATAL(err == TransactionError::OK); CHECK_NONFATAL(err == TransactionError::OK);
CHECK_NONFATAL(!complete); CHECK_NONFATAL(!complete);
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
result.pushKV("psbt", EncodeBase64(ssTx.str())); result.pushKV("psbt", EncodeBase64(ssTx.str()));
} }
@ -1610,7 +1610,7 @@ RPCHelpMan walletprocesspsbt()
} }
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
result.pushKV("psbt", EncodeBase64(ssTx.str())); result.pushKV("psbt", EncodeBase64(ssTx.str()));
result.pushKV("complete", complete); result.pushKV("complete", complete);
@ -1737,7 +1737,7 @@ RPCHelpMan walletcreatefundedpsbt()
} }
// Serialize the PSBT // Serialize the PSBT
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);

View file

@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test)
BOOST_REQUIRE_EQUAL(TransactionError::OK, m_wallet.FillPSBT(psbtx, complete, SIGHASH_ALL, false, true)); BOOST_REQUIRE_EQUAL(TransactionError::OK, m_wallet.FillPSBT(psbtx, complete, SIGHASH_ALL, false, true));
// Get the final tx // Get the final tx
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); DataStream ssTx{};
ssTx << psbtx; ssTx << psbtx;
std::string final_hex = HexStr(ssTx); std::string final_hex = HexStr(ssTx);
BOOST_CHECK_EQUAL(final_hex, "70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001008a020000000158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8876500000001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000"); BOOST_CHECK_EQUAL(final_hex, "70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001008a020000000158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8876500000001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000");

View file

@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(walletdb_readkeyvalue)
* silently fail. The test here makes sure the type of exception thrown from CDataStream::read() * silently fail. The test here makes sure the type of exception thrown from CDataStream::read()
* matches the type we expect, otherwise we need to update the "key"/"wkey" exception type caught. * matches the type we expect, otherwise we need to update the "key"/"wkey" exception type caught.
*/ */
CDataStream ssValue(SER_DISK, CLIENT_VERSION); DataStream ssValue{};
uint256 dummy; uint256 dummy;
BOOST_CHECK_THROW(ssValue >> dummy, std::ios_base::failure); BOOST_CHECK_THROW(ssValue >> dummy, std::ios_base::failure);
} }

View file

@ -478,12 +478,12 @@ struct LoadResult
int m_records{0}; int m_records{0};
}; };
using LoadFunc = std::function<DBErrors(CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err)>; using LoadFunc = std::function<DBErrors(CWallet* pwallet, DataStream& key, DataStream& value, std::string& err)>;
static LoadResult LoadRecords(CWallet* pwallet, DatabaseBatch& batch, const std::string& key, DataStream& prefix, LoadFunc load_func) static LoadResult LoadRecords(CWallet* pwallet, DatabaseBatch& batch, const std::string& key, DataStream& prefix, LoadFunc load_func)
{ {
LoadResult result; LoadResult result;
DataStream ssKey; DataStream ssKey;
CDataStream ssValue(SER_DISK, CLIENT_VERSION); DataStream ssValue{};
Assume(!prefix.empty()); Assume(!prefix.empty());
std::unique_ptr<DatabaseCursor> cursor = batch.GetNewPrefixCursor(prefix); std::unique_ptr<DatabaseCursor> cursor = batch.GetNewPrefixCursor(prefix);
@ -532,7 +532,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { if (pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
for (const auto& type : DBKeys::LEGACY_TYPES) { for (const auto& type : DBKeys::LEGACY_TYPES) {
DataStream key; DataStream key;
CDataStream value(SER_DISK, CLIENT_VERSION); DataStream value{};
DataStream prefix; DataStream prefix;
prefix << type; prefix << type;
@ -555,28 +555,28 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
// Load HD Chain // Load HD Chain
// Note: There should only be one HDCHAIN record with no data following the type // Note: There should only be one HDCHAIN record with no data following the type
LoadResult hd_chain_res = LoadRecords(pwallet, batch, DBKeys::HDCHAIN, LoadResult hd_chain_res = LoadRecords(pwallet, batch, DBKeys::HDCHAIN,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
return LoadHDChain(pwallet, value, err) ? DBErrors:: LOAD_OK : DBErrors::CORRUPT; return LoadHDChain(pwallet, value, err) ? DBErrors:: LOAD_OK : DBErrors::CORRUPT;
}); });
result = std::max(result, hd_chain_res.m_result); result = std::max(result, hd_chain_res.m_result);
// Load unencrypted keys // Load unencrypted keys
LoadResult key_res = LoadRecords(pwallet, batch, DBKeys::KEY, LoadResult key_res = LoadRecords(pwallet, batch, DBKeys::KEY,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
return LoadKey(pwallet, key, value, err) ? DBErrors::LOAD_OK : DBErrors::CORRUPT; return LoadKey(pwallet, key, value, err) ? DBErrors::LOAD_OK : DBErrors::CORRUPT;
}); });
result = std::max(result, key_res.m_result); result = std::max(result, key_res.m_result);
// Load encrypted keys // Load encrypted keys
LoadResult ckey_res = LoadRecords(pwallet, batch, DBKeys::CRYPTED_KEY, LoadResult ckey_res = LoadRecords(pwallet, batch, DBKeys::CRYPTED_KEY,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
return LoadCryptedKey(pwallet, key, value, err) ? DBErrors::LOAD_OK : DBErrors::CORRUPT; return LoadCryptedKey(pwallet, key, value, err) ? DBErrors::LOAD_OK : DBErrors::CORRUPT;
}); });
result = std::max(result, ckey_res.m_result); result = std::max(result, ckey_res.m_result);
// Load scripts // Load scripts
LoadResult script_res = LoadRecords(pwallet, batch, DBKeys::CSCRIPT, LoadResult script_res = LoadRecords(pwallet, batch, DBKeys::CSCRIPT,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& strErr) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& strErr) {
uint160 hash; uint160 hash;
key >> hash; key >> hash;
CScript script; CScript script;
@ -599,7 +599,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
// Load keymeta // Load keymeta
std::map<uint160, CHDChain> hd_chains; std::map<uint160, CHDChain> hd_chains;
LoadResult keymeta_res = LoadRecords(pwallet, batch, DBKeys::KEYMETA, LoadResult keymeta_res = LoadRecords(pwallet, batch, DBKeys::KEYMETA,
[&hd_chains] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& strErr) { [&hd_chains] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& strErr) {
CPubKey vchPubKey; CPubKey vchPubKey;
key >> vchPubKey; key >> vchPubKey;
CKeyMetadata keyMeta; CKeyMetadata keyMeta;
@ -686,7 +686,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
// Load watchonly scripts // Load watchonly scripts
LoadResult watch_script_res = LoadRecords(pwallet, batch, DBKeys::WATCHS, LoadResult watch_script_res = LoadRecords(pwallet, batch, DBKeys::WATCHS,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
CScript script; CScript script;
key >> script; key >> script;
uint8_t fYes; uint8_t fYes;
@ -700,7 +700,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
// Load watchonly meta // Load watchonly meta
LoadResult watch_meta_res = LoadRecords(pwallet, batch, DBKeys::WATCHMETA, LoadResult watch_meta_res = LoadRecords(pwallet, batch, DBKeys::WATCHMETA,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
CScript script; CScript script;
key >> script; key >> script;
CKeyMetadata keyMeta; CKeyMetadata keyMeta;
@ -712,7 +712,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
// Load keypool // Load keypool
LoadResult pool_res = LoadRecords(pwallet, batch, DBKeys::POOL, LoadResult pool_res = LoadRecords(pwallet, batch, DBKeys::POOL,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
int64_t nIndex; int64_t nIndex;
key >> nIndex; key >> nIndex;
CKeyPool keypool; CKeyPool keypool;
@ -729,7 +729,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
// we want to make sure that it is valid so that we can detect corruption // we want to make sure that it is valid so that we can detect corruption
// Note: There should only be one DEFAULTKEY with nothing trailing the type // Note: There should only be one DEFAULTKEY with nothing trailing the type
LoadResult default_key_res = LoadRecords(pwallet, batch, DBKeys::DEFAULTKEY, LoadResult default_key_res = LoadRecords(pwallet, batch, DBKeys::DEFAULTKEY,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
CPubKey default_pubkey; CPubKey default_pubkey;
try { try {
value >> default_pubkey; value >> default_pubkey;
@ -747,7 +747,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
// "wkey" records are unsupported, if we see any, throw an error // "wkey" records are unsupported, if we see any, throw an error
LoadResult wkey_res = LoadRecords(pwallet, batch, DBKeys::OLD_KEY, LoadResult wkey_res = LoadRecords(pwallet, batch, DBKeys::OLD_KEY,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
err = "Found unsupported 'wkey' record, try loading with version 0.18"; err = "Found unsupported 'wkey' record, try loading with version 0.18";
return DBErrors::LOAD_FAIL; return DBErrors::LOAD_FAIL;
}); });
@ -787,7 +787,7 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
int num_keys = 0; int num_keys = 0;
int num_ckeys= 0; int num_ckeys= 0;
LoadResult desc_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTOR, LoadResult desc_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTOR,
[&batch, &num_keys, &num_ckeys, &last_client] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& strErr) { [&batch, &num_keys, &num_ckeys, &last_client] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& strErr) {
DBErrors result = DBErrors::LOAD_OK; DBErrors result = DBErrors::LOAD_OK;
uint256 id; uint256 id;
@ -817,7 +817,7 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
// Get key cache for this descriptor // Get key cache for this descriptor
DataStream prefix = PrefixStream(DBKeys::WALLETDESCRIPTORCACHE, id); DataStream prefix = PrefixStream(DBKeys::WALLETDESCRIPTORCACHE, id);
LoadResult key_cache_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTORCACHE, prefix, LoadResult key_cache_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTORCACHE, prefix,
[&id, &cache] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [&id, &cache] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
bool parent = true; bool parent = true;
uint256 desc_id; uint256 desc_id;
uint32_t key_exp_index; uint32_t key_exp_index;
@ -850,7 +850,7 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
// Get last hardened cache for this descriptor // Get last hardened cache for this descriptor
prefix = PrefixStream(DBKeys::WALLETDESCRIPTORLHCACHE, id); prefix = PrefixStream(DBKeys::WALLETDESCRIPTORLHCACHE, id);
LoadResult lh_cache_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTORLHCACHE, prefix, LoadResult lh_cache_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTORLHCACHE, prefix,
[&id, &cache] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [&id, &cache] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
uint256 desc_id; uint256 desc_id;
uint32_t key_exp_index; uint32_t key_exp_index;
key >> desc_id; key >> desc_id;
@ -874,7 +874,7 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
// Get unencrypted keys // Get unencrypted keys
prefix = PrefixStream(DBKeys::WALLETDESCRIPTORKEY, id); prefix = PrefixStream(DBKeys::WALLETDESCRIPTORKEY, id);
LoadResult key_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTORKEY, prefix, LoadResult key_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTORKEY, prefix,
[&id, &spk_man] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& strErr) { [&id, &spk_man] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& strErr) {
uint256 desc_id; uint256 desc_id;
CPubKey pubkey; CPubKey pubkey;
key >> desc_id; key >> desc_id;
@ -918,7 +918,7 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
// Get encrypted keys // Get encrypted keys
prefix = PrefixStream(DBKeys::WALLETDESCRIPTORCKEY, id); prefix = PrefixStream(DBKeys::WALLETDESCRIPTORCKEY, id);
LoadResult ckey_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTORCKEY, prefix, LoadResult ckey_res = LoadRecords(pwallet, batch, DBKeys::WALLETDESCRIPTORCKEY, prefix,
[&id, &spk_man] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [&id, &spk_man] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
uint256 desc_id; uint256 desc_id;
CPubKey pubkey; CPubKey pubkey;
key >> desc_id; key >> desc_id;
@ -957,7 +957,7 @@ static DBErrors LoadAddressBookRecords(CWallet* pwallet, DatabaseBatch& batch) E
// Load name record // Load name record
LoadResult name_res = LoadRecords(pwallet, batch, DBKeys::NAME, LoadResult name_res = LoadRecords(pwallet, batch, DBKeys::NAME,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
std::string strAddress; std::string strAddress;
key >> strAddress; key >> strAddress;
std::string label; std::string label;
@ -969,7 +969,7 @@ static DBErrors LoadAddressBookRecords(CWallet* pwallet, DatabaseBatch& batch) E
// Load purpose record // Load purpose record
LoadResult purpose_res = LoadRecords(pwallet, batch, DBKeys::PURPOSE, LoadResult purpose_res = LoadRecords(pwallet, batch, DBKeys::PURPOSE,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
std::string strAddress; std::string strAddress;
key >> strAddress; key >> strAddress;
std::string purpose_str; std::string purpose_str;
@ -985,7 +985,7 @@ static DBErrors LoadAddressBookRecords(CWallet* pwallet, DatabaseBatch& batch) E
// Load destination data record // Load destination data record
LoadResult dest_res = LoadRecords(pwallet, batch, DBKeys::DESTDATA, LoadResult dest_res = LoadRecords(pwallet, batch, DBKeys::DESTDATA,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
std::string strAddress, strKey, strValue; std::string strAddress, strKey, strValue;
key >> strAddress; key >> strAddress;
key >> strKey; key >> strKey;
@ -1019,7 +1019,7 @@ static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vecto
// Load tx record // Load tx record
any_unordered = false; any_unordered = false;
LoadResult tx_res = LoadRecords(pwallet, batch, DBKeys::TX, LoadResult tx_res = LoadRecords(pwallet, batch, DBKeys::TX,
[&any_unordered, &upgraded_txs] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { [&any_unordered, &upgraded_txs] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
DBErrors result = DBErrors::LOAD_OK; DBErrors result = DBErrors::LOAD_OK;
uint256 hash; uint256 hash;
key >> hash; key >> hash;
@ -1072,7 +1072,7 @@ static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vecto
// Load locked utxo record // Load locked utxo record
LoadResult locked_utxo_res = LoadRecords(pwallet, batch, DBKeys::LOCKED_UTXO, LoadResult locked_utxo_res = LoadRecords(pwallet, batch, DBKeys::LOCKED_UTXO,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
Txid hash; Txid hash;
uint32_t n; uint32_t n;
key >> hash; key >> hash;
@ -1085,7 +1085,7 @@ static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vecto
// Load orderposnext record // Load orderposnext record
// Note: There should only be one ORDERPOSNEXT record with nothing trailing the type // Note: There should only be one ORDERPOSNEXT record with nothing trailing the type
LoadResult order_pos_res = LoadRecords(pwallet, batch, DBKeys::ORDERPOSNEXT, LoadResult order_pos_res = LoadRecords(pwallet, batch, DBKeys::ORDERPOSNEXT,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
try { try {
value >> pwallet->nOrderPosNext; value >> pwallet->nOrderPosNext;
} catch (const std::exception& e) { } catch (const std::exception& e) {
@ -1108,7 +1108,7 @@ static DBErrors LoadActiveSPKMs(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIV
std::set<std::pair<OutputType, bool>> seen_spks; std::set<std::pair<OutputType, bool>> seen_spks;
for (const auto& spk_key : {DBKeys::ACTIVEEXTERNALSPK, DBKeys::ACTIVEINTERNALSPK}) { for (const auto& spk_key : {DBKeys::ACTIVEEXTERNALSPK, DBKeys::ACTIVEINTERNALSPK}) {
LoadResult spkm_res = LoadRecords(pwallet, batch, spk_key, LoadResult spkm_res = LoadRecords(pwallet, batch, spk_key,
[&seen_spks, &spk_key] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& strErr) { [&seen_spks, &spk_key] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& strErr) {
uint8_t output_type; uint8_t output_type;
key >> output_type; key >> output_type;
uint256 id; uint256 id;
@ -1134,7 +1134,7 @@ static DBErrors LoadDecryptionKeys(CWallet* pwallet, DatabaseBatch& batch) EXCLU
// Load decryption key (mkey) records // Load decryption key (mkey) records
LoadResult mkey_res = LoadRecords(pwallet, batch, DBKeys::MASTER_KEY, LoadResult mkey_res = LoadRecords(pwallet, batch, DBKeys::MASTER_KEY,
[] (CWallet* pwallet, DataStream& key, CDataStream& value, std::string& err) { [] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) {
if (!LoadEncryptionKey(pwallet, key, value, err)) { if (!LoadEncryptionKey(pwallet, key, value, err)) {
return DBErrors::CORRUPT; return DBErrors::CORRUPT;
} }