Branch data Line data Source code
1 : : // Copyright (c) 2026-present The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #ifndef BITCOIN_WALLET_IMPORTS_H
6 : : #define BITCOIN_WALLET_IMPORTS_H
7 : :
8 : : #include <cstdint>
9 : : #include <optional>
10 : : #include <string>
11 : : #include <vector>
12 : :
13 : : #include <util/translation.h>
14 : : #include <wallet/types.h>
15 : : #include <wallet/wallet.h>
16 : :
17 : : namespace wallet {
18 : :
19 : 0 : struct ImportError {
20 : : WalletError wallet_error;
21 : : //! Set to true when a wallet-wide precondition failed before any descriptor was
22 : : //! processed (e.g. wallet is already rescanning, or wallet is locked).
23 : : //! Callers that support top-level errors should surface this as a
24 : : //! top-level / call-wide error rather than a per-descriptor failure.
25 : : bool is_general_error;
26 : :
27 : 0 : ImportError(WalletErrorCode r, bilingual_str e, bool is_wallet_error)
28 : 0 : : wallet_error{r, std::move(e)},
29 : 0 : is_general_error{is_wallet_error}
30 : : {};
31 : : };
32 : :
33 : : struct ImportResult {
34 : : std::vector<std::string> warnings;
35 : : std::optional<ImportError> error;
36 : :
37 : 0 : bool has_error() const {
38 [ # # # # ]: 0 : return error.has_value();
39 : : }
40 : :
41 : : ImportResult() = default;
42 : 0 : ImportResult(WalletErrorCode code, std::string message, std::vector<std::string> warnings = {}, bool general_error = false)
43 [ # # ]: 0 : : warnings{std::move(warnings)},
44 [ # # # # ]: 0 : error{ImportError{code, Untranslated(message), general_error}}
45 : 0 : {}
46 : : };
47 : :
48 : : //! Information about a descriptor to be imported.
49 [ # # ]: 0 : struct ImportDescriptorRequest {
50 : : std::string descriptor;
51 : : std::string label;
52 : : std::optional<int64_t> timestamp; // Unset timestamps are treated as now.
53 : : bool active{false};
54 : : std::optional<bool> internal;
55 : : std::optional<std::pair<int64_t, int64_t>> range;
56 : : std::optional<int64_t> next_index;
57 : : };
58 : :
59 : : std::vector<ImportResult> ProcessDescriptorsImport(CWallet& wallet,
60 : : std::vector<ImportDescriptorRequest>& requests);
61 : :
62 : : } // namespace wallet
63 : :
64 : : #endif // BITCOIN_WALLET_IMPORTS_H
|