Skip to content

Commit f9e9791

Browse files
authored
Merge pull request #4572 from ASuciuX/chore/fix-clippy-nursery-warnings
Chore/fix clippy nursery warning
2 parents 441b7ed + 9a6f698 commit f9e9791

File tree

8 files changed

+39
-42
lines changed

8 files changed

+39
-42
lines changed

stacks-signer/src/cli.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ pub struct StackingSignatureMethod(Pox4SignatureTopic);
192192

193193
impl StackingSignatureMethod {
194194
/// Get the inner `Pox4SignatureTopic`
195-
pub fn topic(&self) -> &Pox4SignatureTopic {
195+
pub const fn topic(&self) -> &Pox4SignatureTopic {
196196
&self.0
197197
}
198198
}
199199

200200
impl From<Pox4SignatureTopic> for StackingSignatureMethod {
201201
fn from(topic: Pox4SignatureTopic) -> Self {
202-
StackingSignatureMethod(topic)
202+
Self(topic)
203203
}
204204
}
205205

@@ -210,9 +210,9 @@ impl ValueEnum for StackingSignatureMethod {
210210

211211
fn value_variants<'a>() -> &'a [Self] {
212212
&[
213-
StackingSignatureMethod(Pox4SignatureTopic::StackStx),
214-
StackingSignatureMethod(Pox4SignatureTopic::StackExtend),
215-
StackingSignatureMethod(Pox4SignatureTopic::AggregationCommit),
213+
Self(Pox4SignatureTopic::StackStx),
214+
Self(Pox4SignatureTopic::StackExtend),
215+
Self(Pox4SignatureTopic::AggregationCommit),
216216
]
217217
}
218218

@@ -262,11 +262,10 @@ fn parse_contract(contract: &str) -> Result<QualifiedContractIdentifier, String>
262262

263263
/// Parse a BTC address argument and return a `PoxAddress`
264264
pub fn parse_pox_addr(pox_address_literal: &str) -> Result<PoxAddress, String> {
265-
if let Some(pox_address) = PoxAddress::from_b58(pox_address_literal) {
266-
Ok(pox_address)
267-
} else {
268-
Err(format!("Invalid pox address: {}", pox_address_literal))
269-
}
265+
PoxAddress::from_b58(pox_address_literal).map_or_else(
266+
|| Err(format!("Invalid pox address: {pox_address_literal}")),
267+
|pox_address| Ok(pox_address),
268+
)
270269
}
271270

272271
/// Parse the hexadecimal Stacks private key

stacks-signer/src/client/stackerdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct StackerDB {
4848

4949
impl From<&SignerConfig> for StackerDB {
5050
fn from(config: &SignerConfig) -> Self {
51-
StackerDB::new(
51+
Self::new(
5252
&config.node_host,
5353
config.stacks_private_key,
5454
config.mainnet,

stacks-signer/src/client/stacks_client.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl StacksClient {
117117
}
118118

119119
/// Get our signer address
120-
pub fn get_signer_address(&self) -> &StacksAddress {
120+
pub const fn get_signer_address(&self) -> &StacksAddress {
121121
&self.stacks_address
122122
}
123123

@@ -145,7 +145,7 @@ impl StacksClient {
145145
value: ClarityValue,
146146
) -> Result<Vec<(StacksAddress, u128)>, ClientError> {
147147
debug!("Parsing signer slots...");
148-
let value = value.clone().expect_result_ok()?;
148+
let value = value.expect_result_ok()?;
149149
let values = value.expect_list()?;
150150
let mut signer_slots = Vec::with_capacity(values.len());
151151
for value in values {
@@ -267,11 +267,10 @@ impl StacksClient {
267267
function_args,
268268
)?;
269269
let inner_data = value.expect_optional()?;
270-
if let Some(key_value) = inner_data {
271-
self.parse_aggregate_public_key(key_value)
272-
} else {
273-
Ok(None)
274-
}
270+
inner_data.map_or_else(
271+
|| Ok(None),
272+
|key_value| self.parse_aggregate_public_key(key_value),
273+
)
275274
}
276275

277276
/// Retrieve the current account nonce for the provided address
@@ -512,9 +511,9 @@ impl StacksClient {
512511
let path = self.read_only_path(contract_addr, contract_name, function_name);
513512
let response = self
514513
.stacks_node_client
515-
.post(path.clone())
514+
.post(path)
516515
.header("Content-Type", "application/json")
517-
.body(body.clone())
516+
.body(body)
518517
.send()?;
519518
if !response.status().is_success() {
520519
return Err(ClientError::RequestFailure(response.status()));
@@ -525,7 +524,7 @@ impl StacksClient {
525524
"{function_name}: {}",
526525
call_read_only_response
527526
.cause
528-
.unwrap_or("unknown".to_string())
527+
.unwrap_or_else(|| "unknown".to_string())
529528
)));
530529
}
531530
let hex = call_read_only_response.result.unwrap_or_default();

stacks-signer/src/config.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum ConfigError {
5454
UnsupportedAddressVersion,
5555
}
5656

57-
#[derive(serde::Deserialize, Debug, Clone, PartialEq)]
57+
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
5858
#[serde(rename_all = "lowercase")]
5959
/// The Stacks network to use.
6060
pub enum Network {
@@ -78,31 +78,31 @@ impl std::fmt::Display for Network {
7878

7979
impl Network {
8080
/// Converts a Network enum variant to a corresponding chain id
81-
pub fn to_chain_id(&self) -> u32 {
81+
pub const fn to_chain_id(&self) -> u32 {
8282
match self {
8383
Self::Mainnet => CHAIN_ID_MAINNET,
8484
Self::Testnet | Self::Mocknet => CHAIN_ID_TESTNET,
8585
}
8686
}
8787

8888
/// Convert a Network enum variant to a corresponding address version
89-
pub fn to_address_version(&self) -> u8 {
89+
pub const fn to_address_version(&self) -> u8 {
9090
match self {
9191
Self::Mainnet => C32_ADDRESS_VERSION_MAINNET_SINGLESIG,
9292
Self::Testnet | Self::Mocknet => C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
9393
}
9494
}
9595

9696
/// Convert a Network enum variant to a Transaction Version
97-
pub fn to_transaction_version(&self) -> TransactionVersion {
97+
pub const fn to_transaction_version(&self) -> TransactionVersion {
9898
match self {
9999
Self::Mainnet => TransactionVersion::Mainnet,
100100
Self::Testnet | Self::Mocknet => TransactionVersion::Testnet,
101101
}
102102
}
103103

104104
/// Check if the network is Mainnet or not
105-
pub fn is_mainnet(&self) -> bool {
105+
pub const fn is_mainnet(&self) -> bool {
106106
match self {
107107
Self::Mainnet => true,
108108
Self::Testnet | Self::Mocknet => false,
@@ -219,7 +219,7 @@ struct RawConfigFile {
219219
impl RawConfigFile {
220220
/// load the config from a string
221221
pub fn load_from_str(data: &str) -> Result<Self, ConfigError> {
222-
let config: RawConfigFile =
222+
let config: Self =
223223
toml::from_str(data).map_err(|e| ConfigError::ParseError(format!("{e:?}")))?;
224224
Ok(config)
225225
}
@@ -234,7 +234,7 @@ impl TryFrom<&PathBuf> for RawConfigFile {
234234
type Error = ConfigError;
235235

236236
fn try_from(path: &PathBuf) -> Result<Self, Self::Error> {
237-
RawConfigFile::load_from_str(&fs::read_to_string(path).map_err(|e| {
237+
Self::load_from_str(&fs::read_to_string(path).map_err(|e| {
238238
ConfigError::InvalidConfig(format!("failed to read config file: {e:?}"))
239239
})?)
240240
}
@@ -255,10 +255,9 @@ impl TryFrom<RawConfigFile> for GlobalConfig {
255255
.to_socket_addrs()
256256
.map_err(|_| ConfigError::BadField("endpoint".to_string(), raw_data.endpoint.clone()))?
257257
.next()
258-
.ok_or(ConfigError::BadField(
259-
"endpoint".to_string(),
260-
raw_data.endpoint.clone(),
261-
))?;
258+
.ok_or_else(|| {
259+
ConfigError::BadField("endpoint".to_string(), raw_data.endpoint.clone())
260+
})?;
262261

263262
let stacks_private_key =
264263
StacksPrivateKey::from_hex(&raw_data.stacks_private_key).map_err(|_| {

stacks-signer/src/coordinator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl From<PublicKeys> for CoordinatorSelector {
5151
/// Create a new Coordinator selector from the given list of public keys
5252
fn from(public_keys: PublicKeys) -> Self {
5353
let coordinator_ids =
54-
CoordinatorSelector::calculate_coordinator_ids(&public_keys, &ConsensusHash::empty());
54+
Self::calculate_coordinator_ids(&public_keys, &ConsensusHash::empty());
5555
let coordinator_id = *coordinator_ids
5656
.first()
5757
.expect("FATAL: No registered signers");

stacks-signer/src/runloop.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct RunLoopCommand {
4141
}
4242

4343
/// The runloop state
44-
#[derive(PartialEq, Debug, Clone, Copy)]
44+
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
4545
pub enum State {
4646
/// The runloop is uninitialized
4747
Uninitialized,
@@ -52,7 +52,7 @@ pub enum State {
5252
}
5353

5454
/// The current reward cycle info
55-
#[derive(PartialEq, Debug, Clone, Copy)]
55+
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
5656
pub struct RewardCycleInfo {
5757
/// The current reward cycle
5858
pub reward_cycle: u64,
@@ -68,7 +68,7 @@ pub struct RewardCycleInfo {
6868

6969
impl RewardCycleInfo {
7070
/// Check if the provided burnchain block height is part of the reward cycle
71-
pub fn is_in_reward_cycle(&self, burnchain_block_height: u64) -> bool {
71+
pub const fn is_in_reward_cycle(&self, burnchain_block_height: u64) -> bool {
7272
let blocks_mined = burnchain_block_height.saturating_sub(self.first_burnchain_block_height);
7373
let reward_cycle_length = self
7474
.reward_phase_block_length
@@ -109,7 +109,7 @@ impl From<GlobalConfig> for RunLoop {
109109
/// Creates new runloop from a config
110110
fn from(config: GlobalConfig) -> Self {
111111
let stacks_client = StacksClient::from(&config);
112-
RunLoop {
112+
Self {
113113
config,
114114
stacks_client,
115115
stacks_signers: HashMap::with_capacity(2),

stacks-signer/src/signer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub struct BlockInfo {
8080

8181
impl BlockInfo {
8282
/// Create a new BlockInfo
83-
pub fn new(block: NakamotoBlock) -> Self {
83+
pub const fn new(block: NakamotoBlock) -> Self {
8484
Self {
8585
block,
8686
vote: None,
@@ -91,7 +91,7 @@ impl BlockInfo {
9191
}
9292

9393
/// Create a new BlockInfo with an associated nonce request packet
94-
pub fn new_with_request(block: NakamotoBlock, nonce_request: NonceRequest) -> Self {
94+
pub const fn new_with_request(block: NakamotoBlock, nonce_request: NonceRequest) -> Self {
9595
Self {
9696
block,
9797
vote: None,
@@ -124,7 +124,7 @@ pub enum Command {
124124
}
125125

126126
/// The Signer state
127-
#[derive(PartialEq, Debug, Clone)]
127+
#[derive(PartialEq, Eq, Debug, Clone)]
128128
pub enum State {
129129
/// The signer is idle, waiting for messages and commands
130130
Idle,
@@ -284,7 +284,7 @@ impl From<SignerConfig> for Signer {
284284
coordinator_selector,
285285
approved_aggregate_public_key: None,
286286
miner_key: None,
287-
db_path: signer_config.db_path.clone(),
287+
db_path: signer_config.db_path,
288288
signer_db,
289289
}
290290
}

stacks-signer/src/signerdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl SignerDb {
4444
/// Create a new `SignerState` instance.
4545
/// This will create a new SQLite database at the given path
4646
/// or an in-memory database if the path is ":memory:"
47-
pub fn new(db_path: impl AsRef<Path>) -> Result<SignerDb, DBError> {
47+
pub fn new(db_path: impl AsRef<Path>) -> Result<Self, DBError> {
4848
let connection = Self::connect(db_path)?;
4949

5050
let signer_db = Self { db: connection };

0 commit comments

Comments
 (0)