Skip to content

Commit 43f9971

Browse files
authored
Merge pull request #185 from sr-gi/clippy-inline
Formats strings to use inline params when possible
2 parents 125709b + 4bcfbf7 commit 43f9971

File tree

24 files changed

+165
-258
lines changed

24 files changed

+165
-258
lines changed

teos-common/src/appointment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl std::str::FromStr for AppointmentStatus {
9595
"being_watched" => Ok(AppointmentStatus::BeingWatched),
9696
"dispute_responded" => Ok(AppointmentStatus::DisputeResponded),
9797
"not_found" => Ok(AppointmentStatus::NotFound),
98-
_ => Err(format!("Unknown status: {}", s)),
98+
_ => Err(format!("Unknown status: {s}")),
9999
}
100100
}
101101
}
@@ -107,7 +107,7 @@ impl fmt::Display for AppointmentStatus {
107107
AppointmentStatus::DisputeResponded => "dispute_responded",
108108
AppointmentStatus::NotFound => "not_found",
109109
};
110-
write!(f, "{}", s)
110+
write!(f, "{s}")
111111
}
112112
}
113113

teos-common/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,15 @@ impl TryFrom<serde_json::Value> for UserId {
7575
UserId::try_from(a.pop().unwrap())
7676
} else {
7777
Err(format!(
78-
"Unexpected json format. Expected a single parameter. Received: {}",
79-
param_count
78+
"Unexpected json format. Expected a single parameter. Received: {param_count}"
8079
))
8180
}
8281
}
8382
serde_json::Value::Object(mut m) => {
8483
let param_count = m.len();
8584
if param_count > 1 {
8685
Err(format!(
87-
"Unexpected json format. Expected a single parameter. Received: {}",
88-
param_count
86+
"Unexpected json format. Expected a single parameter. Received: {param_count}"
8987
))
9088
} else {
9189
UserId::try_from(json!(m
@@ -95,8 +93,7 @@ impl TryFrom<serde_json::Value> for UserId {
9593
}
9694
}
9795
_ => Err(format!(
98-
"Unexpected request format. Expected: user_id/tower_id. Received: '{}'",
99-
value
96+
"Unexpected request format. Expected: user_id/tower_id. Received: '{value}'"
10097
)),
10198
}
10299
}

teos-common/src/net/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ impl std::fmt::Display for Endpoint {
2222

2323
impl Endpoint {
2424
pub fn path(&self) -> String {
25-
format!("/{}", self)
25+
format!("/{self}")
2626
}
2727
}

teos-common/src/net/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl std::str::FromStr for AddressType {
2727
match s {
2828
"ipv4" => Ok(AddressType::IpV4),
2929
"torv3" => Ok(AddressType::TorV3),
30-
_ => Err(format!("Unknown type: {}", s)),
30+
_ => Err(format!("Unknown type: {s}")),
3131
}
3232
}
3333
}
@@ -38,7 +38,7 @@ impl fmt::Display for AddressType {
3838
AddressType::IpV4 => "ipv4",
3939
AddressType::TorV3 => "torv3",
4040
};
41-
write!(f, "{}", s)
41+
write!(f, "{s}")
4242
}
4343
}
4444

teos/src/api/http.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ impl ApiError {
3636

3737
fn missing_field(field_name: &str) -> Rejection {
3838
reject::custom(Self::new(
39-
format!("missing field `{}`", field_name),
39+
format!("missing field `{field_name}`"),
4040
errors::MISSING_FIELD,
4141
))
4242
}
4343

4444
fn empty_field(field_name: &str) -> Rejection {
4545
reject::custom(Self::new(
46-
format!("`{}` field is empty", field_name),
46+
format!("`{field_name}` field is empty"),
4747
errors::EMPTY_FIELD,
4848
))
4949
}
5050

5151
fn wrong_field_length(field_name: &str, field_size: usize, expected_size: usize) -> Rejection {
5252
reject::custom(Self::new(
5353
format!(
54-
"Wrong `{}` field size. Expected {}, received {}",
55-
field_name, expected_size, field_size
54+
"Wrong `{field_name}` field size. Expected {expected_size}, received {field_size}"
5655
),
5756
errors::WRONG_FIELD_SIZE,
5857
))
@@ -104,7 +103,7 @@ fn parse_grpc_response<T: serde::Serialize>(
104103
}
105104
Err(s) => {
106105
let (status_code, error_code) = match_status(&s);
107-
log::debug!("Request failed, error_code={}", error_code);
106+
log::debug!("Request failed, error_code={error_code}");
108107
log::debug!("Response: {}", serde_json::json!(s.message()));
109108
(
110109
reply::json(&ApiError::new(s.message().into(), error_code)),

teos/src/api/internal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl PublicTowerServices for Arc<InternalAPI> {
133133
)),
134134
AddAppointmentFailure::SubscriptionExpired(x) => Err(Status::new(
135135
Code::Unauthenticated,
136-
format!("Your subscription expired at {}", x),
136+
format!("Your subscription expired at {x}"),
137137
)),
138138
AddAppointmentFailure::AlreadyTriggered => Err(Status::new(
139139
Code::AlreadyExists,
@@ -191,7 +191,7 @@ impl PublicTowerServices for Arc<InternalAPI> {
191191
)),
192192
GetAppointmentFailure::SubscriptionExpired(x) => Err(Status::new(
193193
Code::Unauthenticated,
194-
format!("Your subscription expired at {}", x),
194+
format!("Your subscription expired at {x}"),
195195
)),
196196
},
197197
}
@@ -213,7 +213,7 @@ impl PublicTowerServices for Arc<InternalAPI> {
213213
),
214214
GetSubscriptionInfoFailure::SubscriptionExpired(x) => Status::new(
215215
Code::Unauthenticated,
216-
format!("Your subscription expired at {}", x),
216+
format!("Your subscription expired at {x}"),
217217
),
218218
})?;
219219

teos/src/api/tor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl TorAPI {
4949
log::info!("Loading Tor secret key from disk");
5050
let key = fs::read(path.join("onion_v3_sk"))
5151
.await
52-
.map_err(|e| log::warn!("Tor secret key cannot be loaded. {}", e))
52+
.map_err(|e| log::warn!("Tor secret key cannot be loaded. {e}"))
5353
.ok()?;
5454
let key: [u8; 64] = key
5555
.try_into()
@@ -62,7 +62,7 @@ impl TorAPI {
6262
/// Stores a Tor key to disk.
6363
async fn store_sk(key: &TorSecretKeyV3, path: PathBuf) {
6464
if let Err(e) = fs::write(path.join("onion_v3_sk"), key.as_bytes()).await {
65-
log::error!("Cannot store Tor secret key. {}", e);
65+
log::error!("Cannot store Tor secret key. {e}");
6666
}
6767
}
6868

@@ -125,7 +125,7 @@ impl TorAPI {
125125
.map_err(|e| {
126126
Error::new(
127127
ErrorKind::Other,
128-
format!("failed to create onion hidden service: {}", e),
128+
format!("failed to create onion hidden service: {e}"),
129129
)
130130
})?;
131131

teos/src/bitcoin_cli.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a> BitcoindClient<'a> {
7979
teos_network: &'a str,
8080
) -> std::io::Result<BitcoindClient<'a>> {
8181
let http_endpoint = HttpEndpoint::for_host(host.to_owned()).with_port(port);
82-
let rpc_credentials = base64::encode(&format!("{}:{}", rpc_user, rpc_password));
82+
let rpc_credentials = base64::encode(&format!("{rpc_user}:{rpc_password}"));
8383
let bitcoind_rpc_client = RpcClient::new(&rpc_credentials, http_endpoint)?;
8484

8585
let client = Self {
@@ -97,10 +97,7 @@ impl<'a> BitcoindClient<'a> {
9797
if btc_network != teos_network {
9898
Err(Error::new(
9999
ErrorKind::InvalidInput,
100-
format!(
101-
"bitcoind is running on {} but teosd is set to run on {}",
102-
btc_network, teos_network
103-
),
100+
format!("bitcoind is running on {btc_network} but teosd is set to run on {teos_network}"),
104101
))
105102
} else {
106103
Ok(client)

teos/src/carrier.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ impl Carrier {
9696
Err(JsonRpcError(RpcError(rpcerr))) => match rpcerr.code {
9797
// Since we're pushing a raw transaction to the network we can face several rejections
9898
rpc_errors::RPC_VERIFY_REJECTED => {
99-
log::error!("Transaction couldn't be broadcast. {:?}", rpcerr);
99+
log::error!("Transaction couldn't be broadcast. {rpcerr:?}");
100100
ConfirmationStatus::Rejected(rpc_errors::RPC_VERIFY_REJECTED)
101101
}
102102
rpc_errors::RPC_VERIFY_ERROR => {
103-
log::error!("Transaction couldn't be broadcast. {:?}", rpcerr);
103+
log::error!("Transaction couldn't be broadcast. {rpcerr:?}");
104104
ConfirmationStatus::Rejected(rpc_errors::RPC_VERIFY_ERROR)
105105
}
106106
rpc_errors::RPC_VERIFY_ALREADY_IN_CHAIN => {
@@ -122,10 +122,7 @@ impl Carrier {
122122
}
123123
_ => {
124124
// If something else happens (unlikely but possible) log it so we can treat it in future releases.
125-
log::error!(
126-
"Unexpected rpc error when calling sendrawtransaction: {:?}",
127-
rpcerr
128-
);
125+
log::error!("Unexpected rpc error when calling sendrawtransaction: {rpcerr:?}");
129126
ConfirmationStatus::Rejected(errors::UNKNOWN_JSON_RPC_EXCEPTION)
130127
}
131128
},
@@ -137,7 +134,7 @@ impl Carrier {
137134
}
138135
Err(e) => {
139136
// TODO: This may need finer catching.
140-
log::error!("Unexpected error when calling sendrawtransaction: {:?}", e);
137+
log::error!("Unexpected error when calling sendrawtransaction: {e:?}");
141138
ConfirmationStatus::Rejected(errors::UNKNOWN_JSON_RPC_EXCEPTION)
142139
}
143140
};
@@ -159,15 +156,12 @@ impl Carrier {
159156
Ok(tx) => tx.blockhash.is_none(),
160157
Err(JsonRpcError(RpcError(rpcerr))) => match rpcerr.code {
161158
rpc_errors::RPC_INVALID_ADDRESS_OR_KEY => {
162-
log::info!("Transaction not found in mempool: {}", txid);
159+
log::info!("Transaction not found in mempool: {txid}");
163160
false
164161
}
165162
e => {
166163
// DISCUSS: This could result in a silent error with unknown consequences
167-
log::error!(
168-
"Unexpected error code when calling getrawtransaction: {}",
169-
e
170-
);
164+
log::error!("Unexpected error code when calling getrawtransaction: {e}");
171165
false
172166
}
173167
},
@@ -180,10 +174,7 @@ impl Carrier {
180174
// TODO: This may need finer catching.
181175
Err(e) => {
182176
// DISCUSS: This could result in a silent error with unknown consequences
183-
log::error!(
184-
"Unexpected JSONRPCError when calling getrawtransaction: {}",
185-
e
186-
);
177+
log::error!("Unexpected JSONRPCError when calling getrawtransaction: {e}");
187178
false
188179
}
189180
}

teos/src/chain_monitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ where
100100
Err(e) => match e.kind() {
101101
BlockSourceErrorKind::Persistent => {
102102
// FIXME: This may need finer catching
103-
log::error!("Unexpected persistent error: {:?}", e);
103+
log::error!("Unexpected persistent error: {e:?}");
104104
}
105105
BlockSourceErrorKind::Transient => {
106106
// Treating all transient as connection errors at least for now.

0 commit comments

Comments
 (0)