• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-server / 45029527386

22 Nov 2026 01:49PM UTC coverage: 93.877% (-0.5%) from 94.385%
45029527386

push

github

web-flow
Merge pull request #1212 from evoskuil/master

Interface and embedded site updates.

113 of 193 new or added lines in 6 files covered. (58.55%)

1 existing line in 1 file now uncovered.

13185 of 14045 relevant lines covered (93.88%)

449.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.83
/src/error/btcd_error_t.cpp
1
/**
2
 * Copyright (c) 2011-2026 libbitcoin developers
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/server/error/btcd_error_t.hpp>
20

21
#include <bitcoin/server/define.hpp>
22

23
namespace libbitcoin {
24
namespace server {
25
namespace error {
26
namespace btcd {
27

28
DEFINE_ERROR_T_MESSAGE_MAP(error)
29
{
30
    // general
31
    { success, "success" },
32

33
    // json-rpc
34
    { invalid_request, "invalid_request" },
35
    { method_not_found, "method_not_found" },
36
    { invalid_params, "invalid_params" },
37
    { internal_error, "internal_error" },
38
    { parse_error, "parse_error" },
39

40
    // application
41
    { misc_error, "misc_error" },
42
    { forbidden_by_safe_mode, "forbidden_by_safe_mode" },
43
    { type_error, "type_error" },
44
    { wallet_error, "wallet_error" },
45
    { invalid_address_or_key, "invalid_address_or_key" },
46
    { wallet_insufficient_funds, "wallet_insufficient_funds" },
47
    { out_of_memory, "out_of_memory" },
48
    { invalid_parameter, "invalid_parameter" },
49
    { client_not_connected, "client_not_connected" },
50
    { client_in_initial_download, "client_in_initial_download" },
51
    { wallet_invalid_account_name, "wallet_invalid_account_name" },
52
    { wallet_keypool_ran_out, "wallet_keypool_ran_out" },
53
    { wallet_unlock_needed, "wallet_unlock_needed" },
54
    { wallet_passphrase_incorrect, "wallet_passphrase_incorrect" },
55
    { wallet_wrong_enc_state, "wallet_wrong_enc_state" },
56
    { wallet_encryption_failed, "wallet_encryption_failed" },
57
    { wallet_already_unlocked, "wallet_already_unlocked" },
58
    { wallet_not_found, "wallet_not_found" },
59
    { wallet_not_specified, "wallet_not_specified" },
60
    { database_error, "database_error" },
61
    { deserialization_error, "deserialization_error" },
62
    { client_node_already_added, "client_node_already_added" },
63
    { client_node_not_added, "client_node_not_added" },
64
    { verify_error, "verify_error" },
65
    { verify_rejected, "verify_rejected" },
66
    { verify_already_in_chain, "verify_already_in_chain" },
67
    { in_warmup, "in_warmup" },
68
    { client_node_not_connected, "client_node_not_connected" },
69
    { client_invalid_ip_or_subnet, "client_invalid_ip_or_subnet" },
70
    { method_deprecated, "method_deprecated" },
71
    { client_mempool_disabled, "client_mempool_disabled" }
72
};
73

74
DEFINE_ERROR_T_CATEGORY(error, "btcd", "btcd code")
175 ✔
75

76
code translate(const code& ec, error_t failure) NOEXCEPT
15 ✔
77
{
78
    if (!ec)
15 ✔
79
        return success;
1 ✔
80

81
    if (error_category::contains(ec))
14 ✔
82
        return ec;
11 ✔
83

84
    if (database::error::error_category::contains(ec))
3 ✔
85
        return internal_error;
1 ✔
86

87
    return failure;
2 ✔
88
}
89

90
code parameter_error(const code& ec) NOEXCEPT
12 ✔
91
{
92
    return network::error::is_parameter_fault(ec) ? invalid_params : success;
14 ✔
93
}
94

95
struct rejection
96
{
97
    std::string_view text;
98
    error_t code;
99
};
100

101
// btcd reject texts by transaction code, without btcd's interpolated values.
102
// Chain rule failures are verify_error, mempool policy is verify_rejected.
103
static const std::unordered_map<system::error::transaction_error_t, rejection>
104
transaction_rejects
105
{
106
    {
107
        system::error::empty_transaction,
108
        { "transaction has no inputs", verify_error }
109
    },
110
    {
111
        system::error::previous_output_null,
112
        { "transaction input refers to previous output that is null", verify_error }
113
    },
114
    {
115
        system::error::spend_overflow,
116
        {
117
            "total value of all transaction outputs exceeds max allowed value",
118
            verify_error
119
        }
120
    },
121
    {
122
        system::error::coinbase_transaction,
123
        { "transaction is an invalid coinbase", verify_rejected }
124
    },
125
    {
126
        system::error::transaction_internal_double_spend,
127
        { "transaction contains duplicate inputs", verify_error }
128
    },
129
    {
130
        system::error::transaction_size_limit,
131
        { "serialized transaction is too big", verify_error }
132
    },
133
    {
134
        system::error::transaction_legacy_sigop_limit,
135
        { "sigop cost is too high", verify_rejected }
136
    },
137
    {
138
        system::error::coinbase_maturity,
139
        { "tried to spend coinbase transaction output", verify_error }
140
    },
141
    {
142
        system::error::spend_exceeds_value,
143
        {
144
            "total value of all transaction inputs is less than the amount spent",
145
            verify_error
146
        }
147
    },
148
    {
149
        system::error::transaction_sigop_limit,
150
        { "sigop cost is too high", verify_rejected }
151
    },
152
    {
153
        system::error::absolute_time_locked,
154
        { "transaction is not finalized", verify_rejected }
155
    },
156
    {
157
        system::error::relative_time_locked,
158
        { "transaction's sequence locks on inputs not met", verify_rejected }
159
    },
160
    {
161
        system::error::transaction_weight_limit,
162
        { "weight of transaction is larger than max allowed", verify_rejected }
163
    }
164
};
165

NEW
166
error_t reject(std::string& out, const code& ec) NOEXCEPT
×
167
{
NEW
168
    if (ec == node::error::insufficient_fee)
×
169
    {
NEW
170
        out = "transaction has fees which is under the required amount";
×
NEW
171
        return verify_rejected;
×
172
    }
173

174
    using namespace system::error;
NEW
175
    if (transaction_error_category::contains(ec))
×
176
    {
NEW
177
        const auto entry = transaction_rejects.find(
×
NEW
178
            static_cast<transaction_error_t>(ec.value()));
×
NEW
179
        if (entry != transaction_rejects.end())
×
180
        {
NEW
181
            out = entry->second.text;
×
NEW
182
            return entry->second.code;
×
183
        }
184
    }
185

NEW
186
    out = ec.message();
×
NEW
187
    return verify_rejected;
×
188
}
189

190
} // namespace btcd
191
} // namespace error
192
} // namespace server
193
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc