18 std::vector<std::string> warnings;
28 if (request.internal.has_value() &&
parsed_descs.size() > 1) {
31 "Cannot have multipath descriptor while also specifying 'internal'",
38 int64_t range_start = 0, range_end = 1, next_index = 0;
39 if (!
parsed_descs.at(0)->IsRange() && request.range.has_value()) {
42 "Range should not be specified for an un-ranged descriptor",
46 if (request.range.has_value()) {
56 warnings.emplace_back(
"Range not given, using default keypool range");
58 range_end =
wallet.m_keypool_size;
62 if (range_end > std::numeric_limits<int32_t>::max()) {
65 next_index = request.next_index.value_or(range_start);
71 "next_index is out of range",
81 "Active descriptors must be ranged",
90 "Multipath descriptors should not have a label",
96 if (
is_ranged && !request.label.empty()) {
99 "Ranged descriptors should not have a label",
109 "Internal addresses should not have a label",
115 if (request.active && !
parsed_descs.at(0)->IsSingleType()) {
118 "Combo descriptors cannot be set to active",
127 "Cannot import private keys to a wallet with private keys disabled",
141 std::vector<CScript> scripts;
145 "Cannot expand descriptor. Probably because of hardened derivations without private keys provided",
151 warnings.push_back(
w);
156 if (
keys.keys.empty()) {
159 "Cannot import descriptor without private keys to a wallet with private keys enabled",
164 warnings.emplace_back(
"Not all private keys provided. Some wallet functionality may return unexpected errors");
172 "Cannot import unused() to wallet without private keys enabled",
181 std::set<CPubKey> pubkeys;
184 std::transform(
extpubs.begin(),
extpubs.end(), std::inserter(pubkeys, pubkeys.begin()), [](
const CExtPubKey&
xpub) { return xpub.pubkey; });
186 if (
wallet.GetKey(pubkeys.begin()->GetID())) {
189 "Cannot import an unused() descriptor when its private key is already in the wallet",
195 Assume(request.timestamp.has_value());
212 if (request.active) {
213 if (!
w_desc.descriptor->GetOutputType()) {
214 warnings.emplace_back(
"Unknown output type, cannot set descriptor to active.");
219 if (
w_desc.descriptor->GetOutputType()) {
231 std::vector<ImportDescriptorRequest>& requests)
239 "Wallet is currently rescanning. Abort existing rescan or wait.",
247 wallet.BlockUntilSyncedToCurrentChain();
260 "Error: Please enter the wallet passphrase with walletpassphrase first.",
269 request.timestamp = request.timestamp.value_or(now);
281 wallet.ConnectScriptPubKeyManNotifiers();
289 if (
wallet.Scanner().IsAborting()) {
292 "Rescan aborted by user.",
300 for (
size_t i = 0; i < requests.size(); ++i) {
307 const int64_t timestamp{requests.at(i).timestamp.value()};
309 std::string
error_msg =
strprintf(
"Rescan failed for descriptor with timestamp %d. There "
310 "was an error reading a block from time %d, which is after or within %d seconds "
311 "of key creation, and could contain transactions pertaining to the desc. As a "
312 "result, transactions and coins using this desc may not appear in the wallet.",
314 if (
wallet.chain().havePruned()) {
316 "(see bitcoind log for details) and could be dealt with by downloading and "
317 "rescanning the relevant blocks (see -reindex option and rescanblockchain RPC).");
318 }
else if (
wallet.chain().hasAssumedValidChain()) {
320 "background sync. Check logs or getchainstates RPC for assumeutxo background "
321 "sync progress and try again later.");
324 "the issue persists you may want to reindex (see -reindex option).");
constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
#define CHECK_NONFATAL(condition)
Identity function.
#define Assume(val)
Assume is the identity function.
Helper for findBlock to selectively return pieces of block data.
FoundBlock & time(int64_t &time)
FoundBlock & mtpTime(int64_t &mtp_time)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Descriptor with some wallet metadata.
RAII object to check and reserve a wallet rescan.
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
@ MEMPOOL_NO_BROADCAST
Add the transaction to the mempool, but don't broadcast to anybody.
bilingual_str ErrorString(const Result< T > &result)
std::vector< ImportResult > ProcessDescriptorsImport(CWallet &wallet, std::vector< ImportDescriptorRequest > &requests)
@ UnlockNeeded
The wallet is locked and the operation requires access to private keys.
@ InvalidDescriptor
TODO Add correct descriptions to each error.
@ GenericError
Generic wallet error.
ImportResult ImportDescriptor(CWallet &wallet, const ImportDescriptorRequest &request) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
util::Expected< void, std::string > CheckDescriptorRangeBounds(int64_t low, int64_t high)
Validate the numeric bounds of a descriptor key-expression range [low, high] (high inclusive).
Information about a descriptor to be imported.
std::optional< ImportError > error
std::vector< std::string > warnings
#define AssertLockHeld(cs)
std::vector< uint16_t > keys
#define EXCLUSIVE_LOCKS_REQUIRED(...)
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.