Branch data Line data Source code
1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto
2 : : // Copyright (c) 2009-present The Bitcoin Core developers
3 : : // Distributed under the MIT software license, see the accompanying
4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 : :
6 : : //! @file
7 : : //! @brief Home for public enum and struct type definitions.
8 : : //!
9 : : //! These are used internally by wallet code, but also used externally by node
10 : : //! or GUI code.
11 : : //!
12 : : //! This file is intended to define only simple types that do not have external
13 : : //! dependencies. More complicated public wallet types like CCoinControl should
14 : : //! be defined in dedicated header files.
15 : :
16 : : #ifndef BITCOIN_WALLET_TYPES_H
17 : : #define BITCOIN_WALLET_TYPES_H
18 : :
19 : : #include <consensus/amount.h>
20 : : #include <policy/feerate.h>
21 : : #include <primitives/transaction.h>
22 : : #include <util/fees.h>
23 : : #include <util/translation.h>
24 : :
25 : : #include <optional>
26 : : #include <utility>
27 : :
28 : : namespace wallet {
29 : : struct MinimumFeeRateResult {
30 : : CFeeRate fee_rate;
31 : : FeeReason fee_reason;
32 : : std::optional<int> returned_target;
33 : :
34 : 15 : MinimumFeeRateResult(CFeeRate fee_rate, FeeReason fee_reason, std::optional<int> returned_target)
35 : 15 : : fee_rate{fee_rate}, fee_reason{fee_reason}, returned_target{std::move(returned_target)} {}
36 : : };
37 : :
38 : : /**
39 : : * Address purpose field that has been been stored with wallet sending and
40 : : * receiving addresses since BIP70 payment protocol support was added in
41 : : * https://github.com/bitcoin/bitcoin/pull/2539. This field is not currently
42 : : * used for any logic inside the wallet, but it is still shown in RPC and GUI
43 : : * interfaces and saved for new addresses. It is basically redundant with an
44 : : * address's IsMine() result.
45 : : */
46 : : enum class AddressPurpose {
47 : : RECEIVE,
48 : : SEND,
49 : : REFUND, //!< Never set in current code may be present in older wallet databases
50 : : };
51 : :
52 [ + + ][ # # : 48 : struct CreatedTransactionResult
# # # # #
# # # # #
# # ]
[ - - + - ]
53 : : {
54 : : CTransactionRef tx;
55 : : CAmount fee;
56 : : FeeReason fee_reason;
57 : : std::optional<unsigned int> change_pos;
58 : :
59 : 13 : CreatedTransactionResult(CTransactionRef _tx, CAmount _fee, std::optional<unsigned int> _change_pos, FeeReason _fee_reason)
60 [ + - + - ]: 26 : : tx(_tx), fee(_fee), fee_reason(_fee_reason), change_pos(_change_pos) {}
61 : : };
62 : :
63 : : //! Machine-readable wallet error codes.
64 : : //!
65 : : //! @note Add new codes only when callers need to handle the condition
66 : : //! differently. For errors that should only be displayed to the user, use
67 : : //! WalletErrorCode::GenericError and provide the user-facing details in WalletError::message.
68 : : enum class WalletErrorCode {
69 : : //! Generic wallet error. Callers may present the accompanying message to
70 : : //! the user.
71 : : GenericError,
72 : :
73 : : //! The wallet is locked and the operation requires access to private keys.
74 : : //! Callers may ask the user to unlock the wallet and retry the operation.
75 : : UnlockNeeded,
76 : :
77 : : //! The passphrase does not decrypt the wallet. Callers may ask the user to enter it again.
78 : : PassphraseIncorrect,
79 : :
80 : : //! TODO Add correct descriptions to each error.
81 : : //! At the moment only used by ImportDescriptors.
82 : : InvalidDescriptor,
83 : : InvalidParameter,
84 : : MiscError,
85 : : };
86 : :
87 : : //! Wallet-layer error with both programmatic and user-facing information.
88 : : //!
89 : : //! Wallet methods should return a specific WalletErrorCode only when callers
90 : : //! can handle that condition differently. Otherwise, use WalletErrorCode::GenericError
91 : : //! and describe the failure in `message`.
92 : 57 : struct WalletError {
93 : : //! Machine-readable error code for callers that need programmatic handling.
94 : : WalletErrorCode code;
95 : : //! User-facing translated error message
96 : : bilingual_str message;
97 : : };
98 : :
99 : : } // namespace wallet
100 : :
101 : : #endif // BITCOIN_WALLET_TYPES_H
|