Coverage Report

Created: 2026-09-02 14:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/wallet/types.h
Line
Count
Source
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 wallet/types.h is a home for public enum and struct type definitions
7
//! that are used by internally by wallet code, but also used externally by node
8
//! or GUI code.
9
//!
10
//! This file is intended to define only simple types that do not have external
11
//! dependencies. More complicated public wallet types like CCoinControl should
12
//! be defined in dedicated header files.
13
14
#ifndef BITCOIN_WALLET_TYPES_H
15
#define BITCOIN_WALLET_TYPES_H
16
17
#include <consensus/amount.h>
18
#include <policy/feerate.h>
19
#include <primitives/transaction.h>
20
#include <util/fees.h>
21
#include <util/translation.h>
22
23
#include <optional>
24
#include <utility>
25
26
namespace wallet {
27
struct MinimumFeeRateResult {
28
    CFeeRate fee_rate;
29
    FeeReason fee_reason;
30
    std::optional<int> returned_target;
31
32
    MinimumFeeRateResult(CFeeRate fee_rate, FeeReason fee_reason, std::optional<int> returned_target)
33
4.00k
        : fee_rate{fee_rate}, fee_reason{fee_reason}, returned_target{std::move(returned_target)} {}
34
};
35
36
/**
37
 * Address purpose field that has been been stored with wallet sending and
38
 * receiving addresses since BIP70 payment protocol support was added in
39
 * https://github.com/bitcoin/bitcoin/pull/2539. This field is not currently
40
 * used for any logic inside the wallet, but it is still shown in RPC and GUI
41
 * interfaces and saved for new addresses. It is basically redundant with an
42
 * address's IsMine() result.
43
 */
44
enum class AddressPurpose {
45
    RECEIVE,
46
    SEND,
47
    REFUND, //!< Never set in current code may be present in older wallet databases
48
};
49
50
struct CreatedTransactionResult
51
{
52
    CTransactionRef tx;
53
    CAmount fee;
54
    FeeReason fee_reason;
55
    std::optional<unsigned int> change_pos;
56
57
    CreatedTransactionResult(CTransactionRef _tx, CAmount _fee, std::optional<unsigned int> _change_pos, FeeReason _fee_reason)
58
3.61k
        : tx(_tx), fee(_fee), fee_reason(_fee_reason), change_pos(_change_pos) {}
59
};
60
61
//! Machine-readable wallet error codes.
62
//!
63
//! @note Add new codes only when callers need to handle the condition
64
//! differently. For errors that should only be displayed to the user, use
65
//! WalletErrorCode::GenericError and provide the user-facing details in WalletError::message.
66
enum class WalletErrorCode {
67
    //! Generic wallet error. Callers may present the accompanying message to
68
    //! the user.
69
    GenericError,
70
71
    //! The wallet is locked and the operation requires access to private keys.
72
    //! Callers may ask the user to unlock the wallet and retry the operation.
73
    UnlockNeeded,
74
};
75
76
//! Wallet-layer error with both programmatic and user-facing information.
77
//!
78
//! Wallet methods should return a specific WalletErrorCode only when callers
79
//! can handle that condition differently. Otherwise, use WalletErrorCode::GenericError
80
//! and describe the failure in `message`.
81
struct WalletError {
82
    //! Machine-readable error code for callers that need programmatic handling.
83
    WalletErrorCode code;
84
    //! User-facing translated error message
85
    bilingual_str message;
86
};
87
88
} // namespace wallet
89
90
#endif // BITCOIN_WALLET_TYPES_H