diff --git a/src/serialize.h b/src/serialize.h --- a/src/serialize.h +++ b/src/serialize.h @@ -709,6 +709,14 @@ template void Unserialize(Stream &is, std::basic_string &str); +/** + * string_view + */ +template +void Serialize(Stream &os, const std::basic_string_view &str); +template +void Unserialize(Stream &is, std::basic_string_view &str); + /** * prevector * prevectors of uint8_t are a special case and are intended to be serialized as @@ -821,6 +829,26 @@ } } +/** + * string_view + */ +template +void Serialize(Stream &os, const std::basic_string_view &str) { + WriteCompactSize(os, str.size()); + if (!str.empty()) { + os.write((char *)str.data(), str.size() * sizeof(C)); + } +} + +template +void Unserialize(Stream &is, std::basic_string_view &str) { + size_t nSize = ReadCompactSize(is); + str.resize(nSize); + if (nSize != 0) { + is.read((char *)str.data(), nSize * sizeof(C)); + } +} + /** * prevector */ diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -56,35 +56,35 @@ }; namespace DBKeys { -extern const std::string ACENTRY; -extern const std::string ACTIVEEXTERNALSPK; -extern const std::string ACTIVEINTERNALSPK; -extern const std::string BESTBLOCK; -extern const std::string BESTBLOCK_NOMERKLE; -extern const std::string CRYPTED_KEY; -extern const std::string CSCRIPT; -extern const std::string DEFAULTKEY; -extern const std::string DESTDATA; -extern const std::string FLAGS; -extern const std::string HDCHAIN; -extern const std::string KEY; -extern const std::string KEYMETA; -extern const std::string MASTER_KEY; -extern const std::string MINVERSION; -extern const std::string NAME; -extern const std::string OLD_KEY; -extern const std::string ORDERPOSNEXT; -extern const std::string POOL; -extern const std::string PURPOSE; -extern const std::string SETTINGS; -extern const std::string TX; -extern const std::string VERSION; -extern const std::string WALLETDESCRIPTOR; -extern const std::string WALLETDESCRIPTORCACHE; -extern const std::string WALLETDESCRIPTORCKEY; -extern const std::string WALLETDESCRIPTORKEY; -extern const std::string WATCHMETA; -extern const std::string WATCHS; +constexpr std::string_view ACENTRY = "acentry"; +constexpr std::string_view ACTIVEEXTERNALSPK = "activeexternalspk"; +constexpr std::string_view ACTIVEINTERNALSPK = "activeinternalspk"; +constexpr std::string_view BESTBLOCK_NOMERKLE = "bestblock_nomerkle"; +constexpr std::string_view BESTBLOCK = "bestblock"; +constexpr std::string_view CRYPTED_KEY = "ckey"; +constexpr std::string_view CSCRIPT = "cscript"; +constexpr std::string_view DEFAULTKEY = "defaultkey"; +constexpr std::string_view DESTDATA = "destdata"; +constexpr std::string_view FLAGS = "flags"; +constexpr std::string_view HDCHAIN = "hdchain"; +constexpr std::string_view KEYMETA = "keymeta"; +constexpr std::string_view KEY = "key"; +constexpr std::string_view MASTER_KEY = "mkey"; +constexpr std::string_view MINVERSION = "minversion"; +constexpr std::string_view NAME = "name"; +constexpr std::string_view OLD_KEY = "wkey"; +constexpr std::string_view ORDERPOSNEXT = "orderposnext"; +constexpr std::string_view POOL = "pool"; +constexpr std::string_view PURPOSE = "purpose"; +constexpr std::string_view SETTINGS = "settings"; +constexpr std::string_view TX = "tx"; +constexpr std::string_view VERSION = "version"; +constexpr std::string_view WALLETDESCRIPTOR = "walletdescriptor"; +constexpr std::string_view WALLETDESCRIPTORCACHE = "walletdescriptorcache"; +constexpr std::string_view WALLETDESCRIPTORCKEY = "walletdescriptorckey"; +constexpr std::string_view WALLETDESCRIPTORKEY = "walletdescriptorkey"; +constexpr std::string_view WATCHMETA = "watchmeta"; +constexpr std::string_view WATCHS = "watchs"; } // namespace DBKeys /* simple HD chain data model */ diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -18,38 +18,6 @@ #include -namespace DBKeys { -const std::string ACENTRY{"acentry"}; -const std::string ACTIVEEXTERNALSPK{"activeexternalspk"}; -const std::string ACTIVEINTERNALSPK{"activeinternalspk"}; -const std::string BESTBLOCK_NOMERKLE{"bestblock_nomerkle"}; -const std::string BESTBLOCK{"bestblock"}; -const std::string CRYPTED_KEY{"ckey"}; -const std::string CSCRIPT{"cscript"}; -const std::string DEFAULTKEY{"defaultkey"}; -const std::string DESTDATA{"destdata"}; -const std::string FLAGS{"flags"}; -const std::string HDCHAIN{"hdchain"}; -const std::string KEYMETA{"keymeta"}; -const std::string KEY{"key"}; -const std::string MASTER_KEY{"mkey"}; -const std::string MINVERSION{"minversion"}; -const std::string NAME{"name"}; -const std::string OLD_KEY{"wkey"}; -const std::string ORDERPOSNEXT{"orderposnext"}; -const std::string POOL{"pool"}; -const std::string PURPOSE{"purpose"}; -const std::string SETTINGS{"settings"}; -const std::string TX{"tx"}; -const std::string VERSION{"version"}; -const std::string WALLETDESCRIPTOR{"walletdescriptor"}; -const std::string WALLETDESCRIPTORCACHE{"walletdescriptorcache"}; -const std::string WALLETDESCRIPTORCKEY{"walletdescriptorckey"}; -const std::string WALLETDESCRIPTORKEY{"walletdescriptorkey"}; -const std::string WATCHMETA{"watchmeta"}; -const std::string WATCHS{"watchs"}; -} // namespace DBKeys - // // WalletBatch // @@ -200,7 +168,7 @@ bool WalletBatch::WriteActiveScriptPubKeyMan(uint8_t type, const uint256 &id, bool internal) { - std::string key = + const auto key = internal ? DBKeys::ACTIVEINTERNALSPK : DBKeys::ACTIVEEXTERNALSPK; return WriteIC(make_pair(key, type), id); }