Skip to content

Commit

Permalink
refactor: resolve a few clippy warnings in dapi-grpc, rs-drive-proof-…
Browse files Browse the repository at this point in the history
…verifier, rs-platform-serialization, rs-platform-serialization-derive, rs-platform-value, rs-sdk, strategy-tests (#1756)
  • Loading branch information
PastaPastaPasta authored Mar 8, 2024
1 parent 3a84f7a commit 06fa6f5
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub(crate) fn derive_decode_inner(input: TokenStream) -> Result<TokenStream> {
generator.finish()
}

#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
pub(crate) fn derive_borrow_decode_inner(input: TokenStream) -> Result<TokenStream> {
let parse = Parse::new(input)?;
let (mut generator, attributes, body) = parse.into_generator();
Expand Down
2 changes: 2 additions & 0 deletions packages/rs-platform-serialization-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ struct VersionAttributes {
unversioned: bool,
platform_serialize_into: Option<Path>,
platform_version_path: Option<LitStr>,
#[allow(dead_code)] // TODO this is never read
allow_prepend_version: bool,
#[allow(dead_code)] // TODO this is never read
force_prepend_version: bool,
}

Expand Down
6 changes: 6 additions & 0 deletions packages/rs-platform-serialization/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ where
}
}

#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
const UTF8_CHAR_WIDTH: [u8; 256] = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, // 0x1F
Expand All @@ -709,6 +712,9 @@ const UTF8_CHAR_WIDTH: [u8; 256] = [
];

// This function is a copy of core::str::utf8_char_width
#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
const fn utf8_char_width(b: u8) -> usize {
UTF8_CHAR_WIDTH[b as usize] as usize
}
5 changes: 5 additions & 0 deletions packages/rs-platform-serialization/src/enc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ pub(crate) struct VecWriter {

impl VecWriter {
/// Create a new vec writer with the given capacity
#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
pub fn with_capacity(cap: usize) -> Self {
Self {
inner: Vec::with_capacity(cap),
}
}
// May not be used in all feature combinations
#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
pub(crate) fn collect(self) -> Vec<u8> {
self.inner
}
Expand Down
16 changes: 15 additions & 1 deletion packages/rs-platform-serialization/src/features/impl_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ use std::{
///
/// [config]: config/index.html
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
pub fn platform_versioned_decode_from_std_read<D: Decode, C: Config, R: std::io::Read>(
src: &mut R,
config: C,
Expand All @@ -40,6 +43,9 @@ pub(crate) struct IoReader<R> {
}

impl<R> IoReader<R> {
#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
pub fn new(reader: R) -> Self {
Self { reader }
}
Expand All @@ -66,6 +72,9 @@ where
///
/// [config]: config/index.html
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
pub fn encode_into_std_write<E: Encode, C: Config, W: std::io::Write>(
val: E,
dst: &mut W,
Expand All @@ -83,13 +92,18 @@ pub(crate) struct IoWriter<'a, W: std::io::Write> {
}

impl<'a, W: std::io::Write> IoWriter<'a, W> {
#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
pub fn new(writer: &'a mut W) -> Self {
Self {
writer,
bytes_written: 0,
}
}

#[allow(dead_code)]
#[deprecated(note = "This function is marked as unused.")]
#[allow(deprecated)]
pub fn bytes_written(&self) -> usize {
self.bytes_written
}
Expand Down
30 changes: 14 additions & 16 deletions packages/rs-platform-value/src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,22 @@ impl Value {
/// ```
/// use platform_value::Value;
///
/// fn main() {
/// use platform_value::platform_value;
/// let mut value: Value = platform_value!({"x": 1.0, "y": 2.0});
/// use platform_value::platform_value;
/// let mut value: Value = platform_value!({"x": 1.0, "y": 2.0});
///
/// // Check value using read-only pointer
/// assert_eq!(value.pointer("/x"), Some(&1.0.into()));
/// // Change value with direct assignment
/// *value.pointer_mut("/x").unwrap() = 1.5.into();
/// // Check that new value was written
/// assert_eq!(value.pointer("/x"), Some(&1.5.into()));
/// // Or change the value only if it exists
/// value.pointer_mut("/x").map(|v| *v = 1.5.into());
/// // Check value using read-only pointer
/// assert_eq!(value.pointer("/x"), Some(&1.0.into()));
/// // Change value with direct assignment
/// *value.pointer_mut("/x").unwrap() = 1.5.into();
/// // Check that new value was written
/// assert_eq!(value.pointer("/x"), Some(&1.5.into()));
/// // Or change the value only if it exists
/// value.pointer_mut("/x").map(|v| *v = 1.5.into());
///
/// // "Steal" ownership of a value. Can replace with any valid Value.
/// let old_x = value.pointer_mut("/x").map(Value::take).unwrap();
/// assert_eq!(old_x, 1.5);
/// assert_eq!(value.pointer("/x").unwrap(), &Value::Null);
/// }
/// // "Steal" ownership of a value. Can replace with any valid Value.
/// let old_x = value.pointer_mut("/x").map(Value::take).unwrap();
/// assert_eq!(old_x, 1.5);
/// assert_eq!(value.pointer("/x").unwrap(), &Value::Null);
/// ```
pub fn pointer_mut(&mut self, pointer: &str) -> Option<&mut Value> {
if pointer.is_empty() {
Expand Down
26 changes: 11 additions & 15 deletions packages/rs-platform-value/src/value_serialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ pub mod ser;
/// ```
/// use std::collections::BTreeMap;
///
/// fn main() {
/// // The keys in this map are vectors, not strings.
/// let mut map = BTreeMap::new();
/// map.insert(vec![32, 64], "x86");
/// // The keys in this map are vectors, not strings.
/// let mut map = BTreeMap::new();
/// map.insert(vec![32, 64], "x86");
///
/// println!("{}", platform_value::to_value(map).unwrap_err());
/// }
/// println!("{}", platform_value::to_value(map).unwrap_err());
/// ```
pub fn to_value<T>(value: T) -> Result<Value, Error>
where
Expand All @@ -81,16 +79,14 @@ where
/// location: String,
/// }
///
/// fn main() {
/// // The type of `j` is `serde_json::Value`
/// let j = platform_value!({
/// "fingerprint": "0xF9BA143B95FF6D82",
/// "location": "Menlo Park, CA"
/// });
/// // The type of `j` is `serde_json::Value`
/// let j = platform_value!({
/// "fingerprint": "0xF9BA143B95FF6D82",
/// "location": "Menlo Park, CA"
/// });
///
/// let u: User = platform_value::from_value(j).unwrap();
/// println!("{:#?}", u);
/// }
/// let u: User = platform_value::from_value(j).unwrap();
/// println!("{:#?}", u);
/// ```
///
/// # Errors
Expand Down
1 change: 0 additions & 1 deletion packages/rs-sdk/src/core/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use dpp::prelude::AssetLockProof;
use rs_dapi_client::{DapiRequestExecutor, RequestSettings};
use std::time::Duration;
use tokio::time::{sleep, timeout};
use tracing::info;

impl Sdk {
/// Starts the stream to listen for instant send lock messages
Expand Down
2 changes: 0 additions & 2 deletions packages/rs-sdk/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@ pub use noop::MockResponse;
#[cfg(feature = "mocks")]
pub use requests::MockResponse;
#[cfg(feature = "mocks")]
pub use requests::*;
#[cfg(feature = "mocks")]
pub use sdk::MockDashPlatformSdk;
1 change: 0 additions & 1 deletion packages/rs-sdk/src/platform/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//! traits. The associated [Fetch::Request]` type needs to implement [TransportRequest].
use crate::mock::MockResponse;
use crate::platform::query;
use crate::{error::Error, platform::query::Query, Sdk};
use dapi_grpc::platform::v0::{self as platform_proto, ResponseMetadata};
use dpp::block::extended_epoch_info::ExtendedEpochInfo;
Expand Down
12 changes: 3 additions & 9 deletions packages/rs-sdk/tests/fetch/identity_contract_nonce.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use dpp::identity::accessors::IdentityGettersV0;
use dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0;
use dpp::prelude::{Identifier, IdentityPublicKey};
use dpp::{identity::hash::IdentityPublicKeyHashMethodsV0, prelude::Identity};
use drive_proof_verifier::types::{
IdentityBalance, IdentityBalanceAndRevision, IdentityContractNonceFetcher,
};
use rs_sdk::platform::types::identity::PublicKeyHash;
use rs_sdk::platform::{Fetch, FetchMany};
use dpp::prelude::Identifier;
use drive_proof_verifier::types::IdentityContractNonceFetcher;
use rs_sdk::platform::Fetch;

use super::{common::setup_logs, config::Config};

Expand Down
11 changes: 5 additions & 6 deletions packages/strategy-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use dpp::data_contract::{DataContract, DataContractFactory};

use dpp::document::{Document, DocumentV0Getters};
use dpp::identity::state_transition::asset_lock_proof::AssetLockProof;
use dpp::identity::{Identity, KeyID, KeyType, PartialIdentity, Purpose, SecurityLevel};
use dpp::identity::{Identity, KeyType, PartialIdentity, Purpose, SecurityLevel};
use dpp::platform_value::string_encoding::Encoding;
use dpp::serialization::{
PlatformDeserializableWithPotentialValidationFromVersionedStructure,
Expand All @@ -30,7 +30,7 @@ use operations::{DataContractUpdateAction, DataContractUpdateOp};
use platform_version::TryFromPlatformVersioned;
use rand::prelude::StdRng;
use rand::Rng;
use tracing::{error, info};
use tracing::error;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use bincode::{Decode, Encode};
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
Expand Down Expand Up @@ -421,7 +421,7 @@ impl Strategy {
}
}

let state_transition = DataContractCreateTransition::new_from_data_contract(
DataContractCreateTransition::new_from_data_contract(
contract.clone(),
*identity_nonce,
&identity,
Expand All @@ -430,8 +430,7 @@ impl Strategy {
platform_version,
None,
)
.expect("expected to create a create state transition from a data contract");
state_transition
.expect("expected to create a create state transition from a data contract")
})
.collect()
}
Expand Down Expand Up @@ -1110,7 +1109,7 @@ impl Strategy {
let state_transition =
crate::transitions::create_identity_credit_transfer_transition(
owner,
&recipient,
recipient,
identity_nonce_counter,
signer,
1000,
Expand Down
2 changes: 0 additions & 2 deletions packages/strategy-tests/src/transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ use dpp::dashcore::transaction::special_transaction::asset_lock::AssetLockPayloa
use dpp::dashcore::transaction::special_transaction::TransactionPayload;
use std::collections::{BTreeMap, HashSet};
use std::str::FromStr;
use tracing::error;
use tracing::info;

/// Constructs an `AssetLockProof` representing an instant asset lock proof.
///
Expand Down

0 comments on commit 06fa6f5

Please sign in to comment.