Skip to content

Commit 4c45571

Browse files
committed
Feature-gate proxy-related error types to avoid unused warnings
1 parent f30086a commit 4c45571

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

bitreq/src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ pub enum Error {
5858
HttpsFeatureNotEnabled,
5959
/// The provided proxy information was not properly formatted. See
6060
/// [Proxy::new](crate::Proxy::new) for the valid format.
61+
#[cfg(feature = "proxy")]
6162
BadProxy,
6263
/// The provided credentials were rejected by the proxy server.
64+
#[cfg(feature = "proxy")]
6365
BadProxyCreds,
6466
/// The provided proxy credentials were malformed.
67+
#[cfg(feature = "proxy")]
6568
ProxyConnect,
6669
/// The provided credentials were rejected by the proxy server.
70+
#[cfg(feature = "proxy")]
6771
InvalidProxyCreds,
6872
/// The response body size surpasses
6973
/// [Request::with_max_body_size](crate::request::Request::with_max_body_size).
@@ -105,9 +109,13 @@ impl fmt::Display for Error {
105109
TooManyRedirections => write!(f, "too many redirections (over the max)"),
106110
InvalidUtf8InResponse => write!(f, "response contained invalid utf-8 where valid utf-8 was expected"),
107111
HttpsFeatureNotEnabled => write!(f, "request url contains https:// but the https feature is not enabled"),
112+
#[cfg(feature = "proxy")]
108113
BadProxy => write!(f, "the provided proxy information is malformed"),
114+
#[cfg(feature = "proxy")]
109115
BadProxyCreds => write!(f, "the provided proxy credentials are malformed"),
116+
#[cfg(feature = "proxy")]
110117
ProxyConnect => write!(f, "could not connect to the proxy server"),
118+
#[cfg(feature = "proxy")]
111119
InvalidProxyCreds => write!(f, "the provided proxy credentials are invalid"),
112120
BodyOverflow => write!(f, "the response body size surpassed max_body_size"),
113121
// TODO: Uncomment these two for 3.0

bitreq/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//!
6060
//! ## `proxy`
6161
//!
62-
//! This feature enables HTTP proxy support. See [Proxy].
62+
//! This feature enables HTTP proxy support.
6363
//!
6464
//! # Examples
6565
//!

integration_test/tests/hidden.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
use std::collections::HashMap;
99

1010
#[cfg(not(feature = "v28_and_below"))]
11-
use bitcoin::{
12-
absolute, transaction, consensus, Amount, OutPoint, ScriptBuf, Sequence, Transaction,
13-
TxIn, TxOut, Txid, Witness,
14-
};
15-
11+
use bitcoin::hashes::Hash;
1612
#[cfg(not(feature = "v28_and_below"))]
1713
use bitcoin::hex::DisplayHex;
1814
#[cfg(not(feature = "v28_and_below"))]
19-
use bitcoin::hashes::Hash;
20-
15+
use bitcoin::{
16+
absolute, consensus, transaction, Amount, OutPoint, ScriptBuf, Sequence, Transaction, TxIn,
17+
TxOut, Txid, Witness,
18+
};
2119
use integration_test::{Node, NodeExt as _, Wallet};
2220
use node::mtype;
2321
use node::vtype::*; // All the version specific types.
@@ -85,8 +83,8 @@ fn hidden__get_orphan_txs__modelled() {
8583
// Generate a couple of orphan transactions by spending from non-existing UTXOs.
8684
const NUM_ORPHANS: u8 = 3;
8785
let address = node1.client.new_address().expect("failed to get new address");
88-
let orphans: Vec<Transaction> = (0..NUM_ORPHANS).map(|i| {
89-
Transaction {
86+
let orphans: Vec<Transaction> = (0..NUM_ORPHANS)
87+
.map(|i| Transaction {
9088
version: transaction::Version::ONE,
9189
lock_time: absolute::LockTime::ZERO,
9290
input: vec![TxIn {
@@ -102,8 +100,8 @@ fn hidden__get_orphan_txs__modelled() {
102100
value: Amount::from_sat(100_000),
103101
script_pubkey: address.script_pubkey(),
104102
}],
105-
}
106-
}).collect();
103+
})
104+
.collect();
107105

108106
// The receiving node needs to be out of IBD to start accepting transactions.
109107
node2.mine_a_block();
@@ -114,50 +112,50 @@ fn hidden__get_orphan_txs__modelled() {
114112
let tx_bytes = consensus::encode::serialize(orphan);
115113
let tx_hex: String = tx_bytes.as_hex().to_string();
116114
// HACK: We should use sendmsgtopeer directly but it's not implemented yet.
117-
node1.client
115+
node1
116+
.client
118117
.call::<HashMap<String, String>>(
119118
"sendmsgtopeer",
120119
&[PEER_ID.into(), "tx".into(), tx_hex.into()],
121-
).unwrap();
120+
)
121+
.unwrap();
122122
}
123123

124124
let json_v0: GetOrphanTxs = node2.client.get_orphan_txs().expect("getorphantxs");
125-
let json_v1: GetOrphanTxsVerboseOne = node2.client.get_orphan_txs_verbosity_1().expect("getorphantxs 1");
126-
let json_v2: GetOrphanTxsVerboseTwo = node2.client.get_orphan_txs_verbosity_2().expect("getorphantxs 2");
125+
let json_v1: GetOrphanTxsVerboseOne =
126+
node2.client.get_orphan_txs_verbosity_1().expect("getorphantxs 1");
127+
let json_v2: GetOrphanTxsVerboseTwo =
128+
node2.client.get_orphan_txs_verbosity_2().expect("getorphantxs 2");
127129

128130
let model_v0: mtype::GetOrphanTxs = json_v0.into_model();
129131
let model_v1: mtype::GetOrphanTxsVerboseOne = json_v1.into_model().unwrap();
130132
let model_v2: mtype::GetOrphanTxsVerboseTwo = json_v2.into_model().unwrap();
131133

132-
133134
assert_eq!(model_v0.0.len(), NUM_ORPHANS as usize);
134135
assert_eq!(model_v1.0.len(), NUM_ORPHANS as usize);
135136
assert_eq!(model_v2.0.len(), NUM_ORPHANS as usize);
136137

137138
for orphan in orphans.iter() {
138139
assert!(model_v0.0.contains(&orphan.compute_txid()));
139140

140-
match model_v1.0
141-
.iter()
142-
.filter(|e| e.txid == orphan.compute_txid())
143-
.next_back() {
141+
match model_v1.0.iter().filter(|e| e.txid == orphan.compute_txid()).next_back() {
144142
Some(e) => {
145143
assert_eq!(e.wtxid, orphan.compute_wtxid());
146144
assert_eq!(e.bytes as usize, orphan.total_size());
147145
assert_eq!(e.vsize as usize, orphan.vsize());
148146
assert_eq!(e.weight, orphan.weight().to_wu());
149147
// node2 received all orphans from node1, which is node2's peer=0
150148
assert_eq!(e.from, vec![0]);
151-
},
149+
}
152150
None => {
153-
panic!("Orphan with txid={} not found in `getorphantxs 1` response", orphan.compute_txid());
151+
panic!(
152+
"Orphan with txid={} not found in `getorphantxs 1` response",
153+
orphan.compute_txid()
154+
);
154155
}
155156
}
156157

157-
match model_v2.0
158-
.iter()
159-
.filter(|e| e.txid == orphan.compute_txid())
160-
.next_back() {
158+
match model_v2.0.iter().filter(|e| e.txid == orphan.compute_txid()).next_back() {
161159
Some(e) => {
162160
assert_eq!(e.wtxid, orphan.compute_wtxid());
163161
assert_eq!(e.bytes as usize, orphan.total_size());
@@ -166,9 +164,12 @@ fn hidden__get_orphan_txs__modelled() {
166164
// node2 received all orphans from node1, which is node2's peer=0
167165
assert_eq!(e.from, vec![0]);
168166
assert_eq!(e.transaction, *orphan);
169-
},
167+
}
170168
None => {
171-
panic!("Orphan with txid={} not found in `getorphantxs 2` response", orphan.compute_txid());
169+
panic!(
170+
"Orphan with txid={} not found in `getorphantxs 2` response",
171+
orphan.compute_txid()
172+
);
172173
}
173174
}
174175
}

0 commit comments

Comments
 (0)