29 std::string descriptor;
51 if (destination.empty()) {
52 return util::Error{
_(
"Error: Export destination cannot be empty")};
62 if (!success) fs::remove(destination);
71 return util::Error{
_(
"Error: Wallet has no descriptors to export")};
78 std::vector<bilingual_str> warnings;
83 if (!watchonly_wallet) {
88 LOCK(watchonly_wallet->cs_wallet);
110 if (!
w_desc.descriptor->CanSelfExpand()) {
115 auto spkm_res = watchonly_wallet->AddWalletDescriptor(
w_desc, dummy_keys,
"",
false);
124 bool internal =
false;
128 watchonly_wallet->AddActiveScriptPubKeyMan(
spkm_res->get().GetID(), *
Assert(
w_desc.descriptor->GetOutputType()), internal);
135 watchonly_wallet->LockCoin(coin,
persisted);
142 return util::Error{
strprintf(
_(
"Error: database transaction cannot be executed for new watchonly wallet %s"), watchonly_wallet->GetName())};
153 return util::Error{
_(
"Error: Unable to read wallet's best block locator record")};
157 return util::Error{
_(
"Error: Unable to write watchonly wallet best block locator record")};
161 for (
const auto& [txid, wtx] :
wallet.mapWallet) {
165 if (!watchonly_wallet->LoadToWallet(std::move(
copy_wtx))) {
172 for (
const auto& [dest, entry] :
wallet.m_address_book) {
176 for (
const auto& [
id, request] : entry.receive_requests) {
179 if (entry.previously_spent)
watchonly_batch.WriteAddressPreviouslySpent(dest,
true);
183 return util::Error{
_(
"Error: cannot commit db transaction for watchonly wallet export")};
189 return util::Error{
_(
"Error: Unable to write the exported wallet")};
#define CHECK_NONFATAL(condition)
Identity function.
#define Assert(val)
Identity function.
#define Assume(val)
Assume is the identity function.
Double ended buffer combining vector and stream-like interfaces.
The util::Expected class provides a standard way for low-level functions to return either error value...
The util::Unexpected class represents an unexpected value stored in util::Expected.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
static std::shared_ptr< CWallet > CreateNew(WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bool born_encrypted, bilingual_str &error, std::vector< bilingual_str > &warnings)
A transaction with a bunch of additional info that only the owner cares about.
Access to the wallet database.
Descriptor with some wallet metadata.
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
std::string EncodeDestination(const CTxDestination &dest)
std::unique_ptr< Handler > MakeCleanupHandler(std::function< void()> cleanup)
Return handler wrapping a cleanup function.
bilingual_str ErrorString(const Result< T > &result)
std::unique_ptr< WalletDatabase > MakeInMemoryWalletDatabase()
std::string PurposeToString(AddressPurpose p)
util::Result< std::string > ExportWatchOnlyWallet(const CWallet &wallet, const fs::path &destination, WalletContext &context)
Make a new watchonly wallet file containing the public descriptors from this wallet The exported watc...
util::Expected< std::vector< WalletDescInfo >, std::string > ExportDescriptors(const CWallet &wallet, bool export_private)
Export the descriptors from a wallet so that they can be imported elsewhere.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
constexpr deserialize_type deserialize
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
std::map< CKeyID, CKey > keys
WalletContext struct containing references to state shared between CWallet instances,...
#define AssertLockHeld(cs)
consteval auto _(util::TranslatedLiteral str)
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.