Skip to content

Commit 3bd0443

Browse files
authored
chore: new Rust lints (0xMiden#1140)
1 parent 23a64aa commit 3bd0443

File tree

9 files changed

+44
-43
lines changed

9 files changed

+44
-43
lines changed

crates/rust-client/src/note/note_screener.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ where
9898
// p2ide
9999
let script_root = note.script().root();
100100

101-
if script_root == WellKnownNote::P2IDE.script_root() {
102-
if let Some(relevance) = Self::check_p2ide_recall_consumability(note, &id)?
103-
{
104-
note_relevances.push((id, relevance));
105-
}
101+
if script_root == WellKnownNote::P2IDE.script_root()
102+
&& let Some(relevance) = Self::check_p2ide_recall_consumability(note, &id)?
103+
{
104+
note_relevances.push((id, relevance));
106105
}
107106
},
108107
// If an error occurs while checking consumability, we count it as not relevant for

crates/rust-client/src/rpc/mod.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ pub trait NodeRpcClient: Send + Sync {
124124
/// the `/GetBlockByNumber` RPC endpoint.
125125
async fn get_block_by_number(&self, block_num: BlockNumber) -> Result<ProvenBlock, RpcError>;
126126

127-
/// Fetches note-related data for a list of [NoteId] using the `/GetNotesById` rpc endpoint.
127+
/// Fetches note-related data for a list of [`NoteId`] using the `/GetNotesById` rpc endpoint.
128128
///
129-
/// For any NoteType::Private note, the return data is only the
130-
/// [miden_objects::note::NoteMetadata], whereas for NoteType::Onchain notes, the return
131-
/// data includes all details.
129+
/// For any `[miden_objects::note::NoteType::Private]` note, the return data is only the
130+
/// [`miden_objects::note::NoteMetadata`], whereas for [`miden_objects::note::NoteType::Public`]
131+
/// notes, the return data includes all details.
132132
async fn get_notes_by_id(&self, note_ids: &[NoteId]) -> Result<Vec<FetchedNote>, RpcError>;
133133

134134
/// Fetches info from the node necessary to perform a state sync using the
135135
/// `/SyncState` RPC endpoint.
136136
///
137-
/// - `block_num` is the last block number known by the client. The returned [StateSyncInfo]
137+
/// - `block_num` is the last block number known by the client. The returned [`StateSyncInfo`]
138138
/// should contain data starting from the next block, until the first block which contains a
139139
/// note of matching the requested tag, or the chain tip if there are no notes.
140140
/// - `account_ids` is a list of account IDs and determines the accounts the client is
@@ -207,7 +207,8 @@ pub trait NodeRpcClient: Send + Sync {
207207
/// then `None` is returned.
208208
/// The `block_num` parameter is the block number to start the search from.
209209
///
210-
/// The default implementation of this method uses [NodeRpcClient::check_nullifiers_by_prefix].
210+
/// The default implementation of this method uses
211+
/// [`NodeRpcClient::check_nullifiers_by_prefix`].
211212
async fn get_nullifier_commit_height(
212213
&self,
213214
nullifier: &Nullifier,
@@ -221,11 +222,11 @@ pub trait NodeRpcClient: Send + Sync {
221222
.map(|update| update.block_num))
222223
}
223224

224-
/// Fetches public note-related data for a list of [NoteId] and builds [InputNoteRecord]s with
225-
/// it. If a note is not found or it's private, it is ignored and will not be included in the
226-
/// returned list.
225+
/// Fetches public note-related data for a list of [`NoteId`] and builds [`InputNoteRecord`]s
226+
/// with it. If a note is not found or it's private, it is ignored and will not be included
227+
/// in the returned list.
227228
///
228-
/// The default implementation of this method uses [NodeRpcClient::get_notes_by_id].
229+
/// The default implementation of this method uses [`NodeRpcClient::get_notes_by_id`].
229230
async fn get_public_note_records(
230231
&self,
231232
note_ids: &[NoteId],
@@ -256,7 +257,7 @@ pub trait NodeRpcClient: Send + Sync {
256257
/// The `local_accounts` parameter is a list of account headers that the client has
257258
/// stored locally and that it wants to check for updates. If an account is private or didn't
258259
/// change, it is ignored and will not be included in the returned list.
259-
/// The default implementation of this method uses [NodeRpcClient::get_account_details].
260+
/// The default implementation of this method uses [`NodeRpcClient::get_account_details`].
260261
async fn get_updated_public_accounts(
261262
&self,
262263
local_accounts: &[&AccountHeader],
@@ -280,7 +281,8 @@ pub trait NodeRpcClient: Send + Sync {
280281
/// Given a block number, fetches the block header corresponding to that height from the node
281282
/// along with the MMR proof.
282283
///
283-
/// The default implementation of this method uses [NodeRpcClient::get_block_header_by_number].
284+
/// The default implementation of this method uses
285+
/// [`NodeRpcClient::get_block_header_by_number`].
284286
async fn get_block_header_with_proof(
285287
&self,
286288
block_num: BlockNumber,
@@ -291,10 +293,10 @@ pub trait NodeRpcClient: Send + Sync {
291293

292294
/// Fetches the note with the specified ID.
293295
///
294-
/// The default implementation of this method uses [NodeRpcClient::get_notes_by_id].
296+
/// The default implementation of this method uses [`NodeRpcClient::get_notes_by_id`].
295297
///
296298
/// Errors:
297-
/// - [RpcError::NoteNotFound] if the note with the specified ID is not found.
299+
/// - [`RpcError::NoteNotFound`] if the note with the specified ID is not found.
298300
async fn get_note_by_id(&self, note_id: NoteId) -> Result<FetchedNote, RpcError> {
299301
let notes = self.get_notes_by_id(&[note_id]).await?;
300302
notes.into_iter().next().ok_or(RpcError::NoteNotFound(note_id))

crates/rust-client/src/rpc/tonic_client/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl NodeRpcClient for TonicRpcClient {
198198
}
199199

200200
/// Sends a sync state request to the Miden node, validates and converts the response
201-
/// into a [StateSyncInfo] struct.
201+
/// into a [`StateSyncInfo`] struct.
202202
async fn sync_state(
203203
&self,
204204
block_num: BlockNumber,
@@ -223,16 +223,16 @@ impl NodeRpcClient for TonicRpcClient {
223223
response.into_inner().try_into()
224224
}
225225

226-
/// Sends a `GetAccountDetailsRequest` to the Miden node, and extracts an [FetchedAccount] from
227-
/// the `GetAccountDetailsResponse` response.
226+
/// Sends a `GetAccountDetailsRequest` to the Miden node, and extracts an [`FetchedAccount`]
227+
/// from the `GetAccountDetailsResponse` response.
228228
///
229229
/// # Errors
230230
///
231231
/// This function will return an error if:
232232
///
233233
/// - There was an error sending the request to the node.
234-
/// - The answer had a `None` for one of the expected fields (account, summary,
235-
/// account_commitment, details).
234+
/// - The answer had a `None` for one of the expected fields (`account`, `summary`,
235+
/// `account_commitment`, `details`).
236236
/// - There is an error during [Account] deserialization.
237237
async fn get_account_details(&self, account_id: AccountId) -> Result<FetchedAccount, RpcError> {
238238
let request = proto::account::AccountId { id: account_id.to_bytes() };
@@ -359,7 +359,7 @@ impl NodeRpcClient for TonicRpcClient {
359359
Ok((block_num, account_proofs))
360360
}
361361

362-
/// Sends a `SyncNoteRequest` to the Miden node, and extracts a [NoteSyncInfo] from the
362+
/// Sends a `SyncNoteRequest` to the Miden node, and extracts a [`NoteSyncInfo`] from the
363363
/// response.
364364
async fn sync_notes(
365365
&self,

crates/rust-client/src/store/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub trait Store: Send + Sync {
130130

131131
/// Returns the nullifiers of all unspent input notes.
132132
///
133-
/// The default implementation of this method uses [Store::get_input_notes].
133+
/// The default implementation of this method uses [`Store::get_input_notes`].
134134
async fn get_unspent_input_note_nullifiers(&self) -> Result<Vec<Nullifier>, StoreError> {
135135
self.get_input_notes(NoteFilter::Unspent)
136136
.await?
@@ -162,7 +162,7 @@ pub trait Store: Send + Sync {
162162
/// that represents whether the block contains notes relevant to the client. Returns `None` if
163163
/// the block is not found.
164164
///
165-
/// The default implementation of this method uses [Store::get_block_headers].
165+
/// The default implementation of this method uses [`Store::get_block_headers`].
166166
async fn get_block_header_by_num(
167167
&self,
168168
block_number: BlockNumber,
@@ -175,7 +175,7 @@ pub trait Store: Send + Sync {
175175
/// Retrieves a list of [`BlockHeader`] that include relevant notes to the client.
176176
async fn get_tracked_block_headers(&self) -> Result<Vec<BlockHeader>, StoreError>;
177177

178-
/// Retrieves all MMR authentication nodes based on [PartialBlockchainFilter].
178+
/// Retrieves all MMR authentication nodes based on [`PartialBlockchainFilter`].
179179
async fn get_partial_blockchain_nodes(
180180
&self,
181181
filter: PartialBlockchainFilter,

crates/rust-client/src/store/note_record/output_note_record/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ impl OutputNoteRecord {
134134
nullifier: Nullifier,
135135
block_height: u32,
136136
) -> Result<bool, NoteRecordError> {
137-
if let Some(note_nullifier) = self.nullifier() {
138-
if note_nullifier != nullifier {
139-
return Err(NoteRecordError::StateTransitionError(
140-
"Nullifier does not match the expected value".to_string(),
141-
));
142-
}
137+
if let Some(note_nullifier) = self.nullifier()
138+
&& note_nullifier != nullifier
139+
{
140+
return Err(NoteRecordError::StateTransitionError(
141+
"Nullifier does not match the expected value".to_string(),
142+
));
143143
}
144144

145145
let new_state = self.state.nullifier_received(block_height)?;

crates/rust-client/src/store/web_store/account/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ impl WebStore {
342342
// Mismatched digests may be due to stale network data. If the mismatched digest is
343343
// tracked in the db and corresponds to the mismatched account, it means we
344344
// got a past update and shouldn't lock the account.
345-
if let Some(account) = self.get_account_header_by_commitment(*mismatched_digest).await? {
346-
if account.id() == *account_id {
347-
return Ok(());
348-
}
345+
if let Some(account) = self.get_account_header_by_commitment(*mismatched_digest).await?
346+
&& account.id() == *account_id
347+
{
348+
return Ok(());
349349
}
350350

351351
let account_id_str = account_id.to_string();

crates/rust-client/src/store/web_store/sync/js_bindings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ extern "C" {
6060
#[derive(Clone)]
6161
pub struct JsStateSyncUpdate {
6262
/// The block number for this update, stored as a string since it will be
63-
/// persisted in IndexedDB.
63+
/// persisted in `IndexedDB`.
6464
#[wasm_bindgen(js_name = "blockNum")]
6565
pub block_num: String,
6666

6767
/// The new block headers for this state update, serialized into a flattened byte array.
6868
#[wasm_bindgen(js_name = "flattenedNewBlockHeaders")]
6969
pub flattened_new_block_headers: FlattenedU8Vec,
7070

71-
/// The block numbers corresponding to each header in flattened_new_block_headers.
71+
/// The block numbers corresponding to each header in `flattened_new_block_headers`.
7272
/// This vec should have the same length as the number of headers, with each index
7373
/// representing the block number for the header at that same index.
7474
#[wasm_bindgen(js_name = "newBlockNums")]

crates/rust-client/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ async fn p2ide_transfer_consumed_by_target() {
11401140
InputNoteState::Committed { .. }
11411141
));
11421142

1143-
consume_notes(&mut client, from_account_id, &[note.clone()]).await;
1143+
consume_notes(&mut client, from_account_id, core::slice::from_ref(&note)).await;
11441144
mock_rpc_api.prove_block();
11451145
client.sync_state().await.unwrap();
11461146

crates/web-client/src/export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ impl WebClient {
4343
}
4444
}
4545

46-
/// Retrieves the entire underlying web store and returns it as a JsValue
46+
/// Retrieves the entire underlying web store and returns it as a `JsValue`
4747
///
48-
/// Meant to be used in conjunction with the force_import_store method
48+
/// Meant to be used in conjunction with the `force_import_store` method
4949
#[wasm_bindgen(js_name = "exportStore")]
5050
pub async fn export_store(&mut self) -> Result<JsValue, JsValue> {
5151
let store = self.store.as_ref().ok_or(JsValue::from_str("Store not initialized"))?;

0 commit comments

Comments
 (0)