/tmp/bitcoin/src/wallet/imports.h
Line | Count | Source |
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 | | 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 | | ImportError(WalletErrorCode r, bilingual_str e, bool is_wallet_error) |
28 | 42 | : wallet_error{r, std::move(e)}, |
29 | 42 | is_general_error{is_wallet_error} |
30 | 42 | {}; |
31 | | }; |
32 | | |
33 | | struct ImportResult { |
34 | | std::vector<std::string> warnings; |
35 | | std::optional<ImportError> error; |
36 | | |
37 | 2.15k | bool has_error() const { |
38 | 2.15k | return error.has_value(); |
39 | 2.15k | } |
40 | | |
41 | 730 | ImportResult() = default; |
42 | | ImportResult(WalletErrorCode code, std::string message, std::vector<std::string> warnings = {}, bool general_error = false) |
43 | 40 | : warnings{std::move(warnings)}, |
44 | 40 | error{ImportError{code, Untranslated(message), general_error}} |
45 | 40 | {} |
46 | | }; |
47 | | |
48 | | //! Information about a descriptor to be imported. |
49 | | 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 |