Skip to content

Commit 766c5ee

Browse files
committed
refactor: Use rusqlite::params! + remove dead code
1 parent 844bc4b commit 766c5ee

File tree

1 file changed

+4
-42
lines changed

1 file changed

+4
-42
lines changed

stacks-signer/src/signerdb.rs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::path::Path;
1919
use blockstack_lib::util_lib::db::{
2020
query_row, sqlite_open, table_exists, u64_to_sql, Error as DBError,
2121
};
22-
use rusqlite::{Connection, Error as SqliteError, OpenFlags, ToSql, NO_PARAMS};
22+
use rusqlite::{params, Connection, Error as SqliteError, OpenFlags, NO_PARAMS};
2323
use slog::slog_debug;
2424
use stacks_common::debug;
2525
use stacks_common::util::hash::Sha512Trunc256Sum;
@@ -103,21 +103,11 @@ impl SignerDb {
103103
let serialized_state = serde_json::to_string(signer_state)?;
104104
self.db.execute(
105105
"INSERT OR REPLACE INTO signer_states (reward_cycle, state) VALUES (?1, ?2)",
106-
&[&u64_to_sql(reward_cycle)? as &dyn ToSql, &serialized_state],
106+
params![&u64_to_sql(reward_cycle)?, &serialized_state],
107107
)?;
108108
Ok(())
109109
}
110110

111-
/// Delete the signer state for the provided reward cycle and signer ID
112-
pub fn delete_signer_state(&self, reward_cycle: u64) -> Result<(), DBError> {
113-
self.db.execute(
114-
"DELETE FROM signer_states WHERE reward_cycle = ?",
115-
&[u64_to_sql(reward_cycle)?],
116-
)?;
117-
118-
Ok(())
119-
}
120-
121111
/// Fetch a block from the database using the block's
122112
/// `signer_signature_hash`
123113
pub fn block_lookup(
@@ -128,10 +118,7 @@ impl SignerDb {
128118
let result: Option<String> = query_row(
129119
&self.db,
130120
"SELECT block_info FROM blocks WHERE reward_cycle = ? AND signer_signature_hash = ?",
131-
&[
132-
&u64_to_sql(reward_cycle)? as &dyn ToSql,
133-
&format!("{}", hash),
134-
],
121+
params![&u64_to_sql(reward_cycle)?, hash.to_string()],
135122
)?;
136123

137124
try_deserialize(result)
@@ -162,30 +149,11 @@ impl SignerDb {
162149
self.db
163150
.execute(
164151
"INSERT OR REPLACE INTO blocks (reward_cycle, signer_signature_hash, block_info) VALUES (?1, ?2, ?3)",
165-
&[&u64_to_sql(reward_cycle)? as &dyn ToSql, &format!("{}", hash), &block_json],
152+
params![&u64_to_sql(reward_cycle)?, hash.to_string(), &block_json],
166153
)?;
167154

168155
Ok(())
169156
}
170-
171-
/// Remove a block
172-
pub fn remove_block(
173-
&mut self,
174-
reward_cycle: u64,
175-
hash: &Sha512Trunc256Sum,
176-
) -> Result<(), DBError> {
177-
debug!("Deleting block_info: sighash = {hash}");
178-
179-
self.db.execute(
180-
"DELETE FROM blocks WHERE reward_cycle = ? AND signer_signature_hash = ?",
181-
&[
182-
&u64_to_sql(reward_cycle)? as &dyn ToSql,
183-
&format!("{}", hash),
184-
],
185-
)?;
186-
187-
Ok(())
188-
}
189157
}
190158

191159
fn try_deserialize<T>(s: Option<String>) -> Result<Option<T>, DBError>
@@ -418,12 +386,6 @@ mod tests {
418386
db.insert_signer_state(11, &state_1)
419387
.expect("Failed to insert signer state");
420388

421-
db.delete_signer_state(11)
422-
.expect("Failed to delete signer state");
423-
424-
db.delete_signer_state(12)
425-
.expect("Failed to delete signer state");
426-
427389
assert_eq!(
428390
db.get_signer_state(10)
429391
.expect("Failed to get signer state")

0 commit comments

Comments
 (0)