Skip to content

Commit ad87cf6

Browse files
committed
Fix clippy warnings in libsigner
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 4d6e86c commit ad87cf6

File tree

6 files changed

+14
-24
lines changed

6 files changed

+14
-24
lines changed

libsigner/src/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ impl NewBlockTransaction {
620620
Ok(None)
621621
} else {
622622
let tx_bytes = hex_bytes(&self.raw_tx).map_err(|e| {
623-
CodecError::DeserializeError(format!("Failed to deserialize raw tx: {}", e))
623+
CodecError::DeserializeError(format!("Failed to deserialize raw tx: {e}"))
624624
})?;
625625
let tx = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..])?;
626626
Ok(Some(tx))

libsigner/src/http.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ pub fn decode_http_request(payload: &[u8]) -> Result<SignerHttpRequest, EventErr
107107
let key = req.headers[i].name.to_string().to_lowercase();
108108
if headers.get(&key).is_some() {
109109
return Err(EventError::MalformedRequest(format!(
110-
"Invalid HTTP request: duplicate header \"{}\"",
111-
key
110+
"Invalid HTTP request: duplicate header \"{key}\""
112111
)));
113112
}
114113
headers.insert(key, value);
@@ -152,8 +151,7 @@ pub fn decode_http_response(payload: &[u8]) -> Result<(HashMap<String, String>,
152151
if let Some(version) = resp.version {
153152
if version != 0 && version != 1 {
154153
return Err(RPCError::MalformedResponse(format!(
155-
"Unrecognized HTTP code {}",
156-
version
154+
"Unrecognized HTTP code {version}"
157155
)));
158156
}
159157
} else {
@@ -180,8 +178,7 @@ pub fn decode_http_response(payload: &[u8]) -> Result<(HashMap<String, String>,
180178
let key = resp.headers[i].name.to_string().to_lowercase();
181179
if headers.contains_key(&key) {
182180
return Err(RPCError::MalformedResponse(format!(
183-
"Invalid HTTP respuest: duplicate header \"{}\"",
184-
key
181+
"Invalid HTTP respuest: duplicate header \"{key}\""
185182
)));
186183
}
187184
headers.insert(key, value);
@@ -237,13 +234,11 @@ pub fn run_http_request<S: Read + Write>(
237234

238235
let req_txt = if let Some(content_type) = content_type {
239236
format!(
240-
"{} {} HTTP/1.1\r\nHost: {}\r\nConnection: close\r\nContent-Type: {}\r\n{}User-Agent: libsigner/0.1\r\nAccept: */*\r\n\r\n",
241-
verb, path, host, content_type, content_length_hdr
237+
"{verb} {path} HTTP/1.1\r\nHost: {host}\r\nConnection: close\r\nContent-Type: {content_type}\r\n{content_length_hdr}User-Agent: libsigner/0.1\r\nAccept: */*\r\n\r\n"
242238
)
243239
} else {
244240
format!(
245-
"{} {} HTTP/1.1\r\nHost: {}\r\nConnection: close\r\n{}User-Agent: libsigner/0.1\r\nAccept: */*\r\n\r\n",
246-
verb, path, host, content_length_hdr
241+
"{verb} {path} HTTP/1.1\r\nHost: {host}\r\nConnection: close\r\n{content_length_hdr}User-Agent: libsigner/0.1\r\nAccept: */*\r\n\r\n"
247242
)
248243
};
249244
debug!("HTTP request\n{}", &req_txt);

libsigner/src/libsigner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ lazy_static! {
8888

8989
#[test]
9090
fn test_version_string() {
91-
assert!(VERSION_STRING.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str()));
91+
assert!(VERSION_STRING.contains(format!("stacks-signer {STACKS_SIGNER_VERSION}").as_str()));
9292
}

libsigner/src/runloop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn set_runloop_signal_handler<ST: EventStopSignaler + Send + 'static>(mut st
170170
}
171171
}
172172
_ => {
173-
let msg = format!("Graceful termination request received (signal `{}`), will complete the ongoing runloop cycles and terminate\n", sig_id);
173+
let msg = format!("Graceful termination request received (signal `{sig_id}`), will complete the ongoing runloop cycles and terminate\n");
174174
async_safe_write_stderr(&msg);
175175
stop_signaler.send();
176176
}

libsigner/src/tests/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,12 @@ fn test_status_endpoint() {
229229
let mut sock = match TcpStream::connect(endpoint) {
230230
Ok(sock) => sock,
231231
Err(e) => {
232-
eprint!("Error connecting to {}: {}", endpoint, e);
232+
eprint!("Error connecting to {endpoint}: {e}");
233233
sleep_ms(100);
234234
return;
235235
}
236236
};
237-
let req = format!(
238-
"GET /status HTTP/1.1\r\nHost: {}\r\nConnection: close\r\n\r\n",
239-
endpoint
240-
);
237+
let req = format!("GET /status HTTP/1.1\r\nHost: {endpoint}\r\nConnection: close\r\n\r\n");
241238

242239
sock.write_all(req.as_bytes()).unwrap();
243240
let mut buf = [0; 128];

libsigner/src/v0/messages.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ impl StacksMessageCodec for RejectReason {
17251725
impl std::fmt::Display for RejectCode {
17261726
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17271727
match self {
1728-
RejectCode::ValidationFailed(code) => write!(f, "Validation failed: {:?}", code),
1728+
RejectCode::ValidationFailed(code) => write!(f, "Validation failed: {code:?}"),
17291729
RejectCode::ConnectivityIssues(reason) => write!(
17301730
f,
17311731
"The block was rejected due to connectivity issues with the signer: {reason}"
@@ -1754,7 +1754,7 @@ impl std::fmt::Display for RejectCode {
17541754
impl std::fmt::Display for RejectReason {
17551755
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17561756
match self {
1757-
RejectReason::ValidationFailed(code) => write!(f, "Validation failed: {:?}", code),
1757+
RejectReason::ValidationFailed(code) => write!(f, "Validation failed: {code:?}"),
17581758
RejectReason::ConnectivityIssues(reason) => write!(
17591759
f,
17601760
"The block was rejected due to connectivity issues with the signer: {reason}"
@@ -1830,7 +1830,7 @@ impl std::fmt::Display for RejectReason {
18301830
)
18311831
}
18321832
RejectReason::Unknown(code) => {
1833-
write!(f, "Unknown reject code: {}", code)
1833+
write!(f, "Unknown reject code: {code}")
18341834
}
18351835
RejectReason::NotRejected => {
18361836
write!(f, "The block was approved, no rejection details needed.")
@@ -1870,9 +1870,7 @@ mod test {
18701870
let slot_identifiers_len = MessageSlotID::ALL.len();
18711871
assert!(
18721872
SIGNER_SLOTS_PER_USER as usize >= slot_identifiers_len,
1873-
"stacks_common::SIGNER_SLOTS_PER_USER ({}) must be >= slot identifiers ({})",
1874-
SIGNER_SLOTS_PER_USER,
1875-
slot_identifiers_len,
1873+
"stacks_common::SIGNER_SLOTS_PER_USER ({SIGNER_SLOTS_PER_USER}) must be >= slot identifiers ({slot_identifiers_len})"
18761874
);
18771875
}
18781876

0 commit comments

Comments
 (0)