Skip to content

Commit

Permalink
fix: more clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Jan 22, 2024
1 parent d0841f6 commit 4db2f8c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions moksha-core/src/blind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl BlindedMessage {
pub fn blank(
fee_reserve: Amount,
keyset_id: String,
) -> Result<Vec<(BlindedMessage, SecretKey, String)>, MokshaCoreError> {
) -> Result<Vec<(Self, SecretKey, String)>, MokshaCoreError> {
if fee_reserve.0 == 0 {
return Ok(vec![]);
}
Expand All @@ -54,7 +54,7 @@ impl BlindedMessage {
let secret = generate_random_string();
let (b_, alice_secret_key) = dhke.step1_alice(secret.clone(), None).unwrap(); // FIXME
(
BlindedMessage {
Self {
amount: 1,
b_,
id: keyset_id.clone(),
Expand All @@ -63,7 +63,7 @@ impl BlindedMessage {
secret,
)
})
.collect::<Vec<(BlindedMessage, SecretKey, String)>>();
.collect::<Vec<(Self, SecretKey, String)>>();

Ok(blinded_messages)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ mod tests {
println!("{:?}", result);
assert!(result.is_ok());
let result = result.unwrap();
assert!(result.clone().len() == 10);
assert!(result.len() == 10);
assert!(result.first().unwrap().0.amount == 1);
}

Expand Down
6 changes: 3 additions & 3 deletions moksha-core/src/dhke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Dhke {
let mut point: Option<PublicKey> = None;
let mut msg_to_hash = message.to_vec();
while point.is_none() {
let hash = Dhke::get_hash(&msg_to_hash);
let hash = Self::get_hash(&msg_to_hash);
let input = &[0x02]
.iter()
.chain(hash.iter())
Expand All @@ -95,7 +95,7 @@ impl Dhke {
) -> Result<(PublicKey, SecretKey), MokshaCoreError> {
let mut rng = rand::thread_rng();

let y = Dhke::hash_to_curve(secret_msg.into().as_bytes());
let y = Self::hash_to_curve(secret_msg.into().as_bytes());
let secret_key = match blinding_factor {
Some(f) => SecretKey::from_slice(f)?,
None => SecretKey::new(&mut rng),
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Dhke {
c: PublicKey,
secret_msg: impl Into<String>,
) -> Result<bool, MokshaCoreError> {
let y = Dhke::hash_to_curve(secret_msg.into().as_bytes());
let y = Self::hash_to_curve(secret_msg.into().as_bytes());
Some(c == y.mul_tweak(&self.secp, &Scalar::from(a))?).ok_or(
MokshaCoreError::Secp256k1Error(secp256k1::Error::InvalidPublicKey),
)
Expand Down
10 changes: 5 additions & 5 deletions moksha-core/src/keyset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ pub struct MintKeyset {
}

impl MintKeyset {
pub fn legacy_new(seed: &str, derivation_path: &str) -> MintKeyset {
pub fn legacy_new(seed: &str, derivation_path: &str) -> Self {
let priv_keys = derive_keys(seed, derivation_path);
let pub_keys = derive_pubkeys(&priv_keys);
MintKeyset {
Self {
private_keys: priv_keys,
keyset_id: legacy_derive_keyset_id(&pub_keys),
public_keys: pub_keys,
mint_pubkey: derive_pubkey(seed).expect("invalid seed"),
}
}

pub fn new(seed: &str, derivation_path: &str) -> MintKeyset {
pub fn new(seed: &str, derivation_path: &str) -> Self {
let priv_keys = derive_keys(seed, derivation_path);
let pub_keys = derive_pubkeys(&priv_keys);
MintKeyset {
Self {
private_keys: priv_keys,
keyset_id: derive_keyset_id(&pub_keys),
public_keys: pub_keys,
Expand All @@ -65,7 +65,7 @@ impl MintKeyset {
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct Keysets {
pub keysets: Vec<String>,
}
Expand Down
16 changes: 8 additions & 8 deletions moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ pub enum CurrencyUnit {
impl Display for CurrencyUnit {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CurrencyUnit::Sat => write!(f, "sat"),
CurrencyUnit::Usd => write!(f, "usd"),
Self::Sat => write!(f, "sat"),
Self::Usd => write!(f, "usd"),
}
}
}
Expand All @@ -155,8 +155,8 @@ pub enum PaymentMethod {
impl Display for PaymentMethod {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PaymentMethod::Bolt11 => write!(f, "Lightning"),
PaymentMethod::Onchain => write!(f, "Onchain"),
Self::Bolt11 => write!(f, "Lightning"),
Self::Onchain => write!(f, "Onchain"),
}
}
}
Expand Down Expand Up @@ -214,15 +214,15 @@ pub struct PostMeltQuoteBolt11Response {
pub expiry: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Bolt11MintQuote {
pub quote_id: Uuid,
pub payment_request: String,
pub expiry: u64,
pub paid: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Bolt11MeltQuote {
pub quote_id: Uuid,
pub amount: u64,
Expand Down Expand Up @@ -272,7 +272,7 @@ pub struct MintInfoResponse {
pub nuts: Nuts,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct OnchainMintQuote {
pub quote_id: Uuid,
pub address: String,
Expand All @@ -293,7 +293,7 @@ impl From<OnchainMintQuote> for PostMintQuoteOnchainResponse {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct OnchainMeltQuote {
pub quote_id: Uuid,
pub amount: u64,
Expand Down
12 changes: 6 additions & 6 deletions moksha-core/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use utoipa::ToSchema;
use crate::error::MokshaCoreError;

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, ToSchema)]
pub struct Proof {
pub amount: u64,
#[serde(rename = "id")]
Expand All @@ -31,7 +31,7 @@ pub struct Proof {
}

impl Proof {
pub fn new(amount: u64, secret: String, c: PublicKey, id: String) -> Self {
pub const fn new(amount: u64, secret: String, c: PublicKey, id: String) -> Self {
Self {
amount,
secret,
Expand All @@ -42,10 +42,10 @@ impl Proof {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ToSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, ToSchema)]
pub struct P2SHScript;

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, ToSchema)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, ToSchema)]
pub struct Proofs(pub(super) Vec<Proof>);

impl Proofs {
Expand All @@ -57,7 +57,7 @@ impl Proofs {
Self(vec![proof])
}

pub fn empty() -> Self {
pub const fn empty() -> Self {
Self(vec![])
}

Expand All @@ -77,7 +77,7 @@ impl Proofs {
self.0.is_empty()
}

pub fn proofs_for_amount(&self, amount: u64) -> Result<Proofs, MokshaCoreError> {
pub fn proofs_for_amount(&self, amount: u64) -> Result<Self, MokshaCoreError> {
let mut all_proofs = self.0.clone();
if amount > self.total_amount() {
return Err(MokshaCoreError::NotEnoughTokens);
Expand Down
18 changes: 9 additions & 9 deletions moksha-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{error::MokshaCoreError, primitives::CurrencyUnit, proof::Proofs};
const TOKEN_PREFIX_V3: &str = "cashuA";

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Token {
#[serde(serialize_with = "serialize_url", deserialize_with = "deserialize_url")]
pub mint: Option<Url>,
Expand All @@ -24,10 +24,10 @@ where
D: Deserializer<'de>,
{
let url_str: Option<String> = Option::deserialize(deserializer)?;
match url_str {
Some(s) => Url::parse(&s).map_err(serde::de::Error::custom).map(Some),
None => Ok(None),
}
url_str.map_or_else(
|| Ok(None),
|s| Url::parse(&s).map_err(serde::de::Error::custom).map(Some),
)
}

fn serialize_url<S>(url: &Option<Url>, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -47,7 +47,7 @@ where
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct TokenV3 {
#[serde(rename = "token")]
pub tokens: Vec<Token>,
Expand All @@ -64,7 +64,7 @@ impl TokenV3 {
}
}

pub fn empty() -> Self {
pub const fn empty() -> Self {
Self {
tokens: vec![],
memo: None,
Expand Down Expand Up @@ -104,14 +104,14 @@ impl TokenV3 {
))
}

pub fn deserialize(data: impl Into<String>) -> Result<TokenV3, MokshaCoreError> {
pub fn deserialize(data: impl Into<String>) -> Result<Self, MokshaCoreError> {
let json = general_purpose::URL_SAFE.decode(
data.into()
.strip_prefix(TOKEN_PREFIX_V3)
.ok_or(MokshaCoreError::InvalidTokenPrefix)?
.as_bytes(),
)?;
Ok(serde_json::from_slice::<TokenV3>(&json)?)
Ok(serde_json::from_slice::<Self>(&json)?)
}

pub fn mint(&self) -> Option<Url> {
Expand Down
10 changes: 5 additions & 5 deletions moksha-wallet/src/config_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ pub const ENV_DB_PATH: &str = "WALLET_DB_PATH";
/// println!("Database path: {}", db_path);
/// ```
pub fn db_path() -> String {
match std::env::var(ENV_DB_PATH) {
Ok(val) => val,
Err(_) => {
std::env::var(ENV_DB_PATH).map_or_else(
|_| {
let home = home_dir()
.expect("home dir not found")
.to_str()
Expand All @@ -39,8 +38,9 @@ pub fn db_path() -> String {
}

format!("{moksha_dir}/wallet.db")
}
}
},
|val| val,
)
}

pub fn config_dir() -> PathBuf {
Expand Down
2 changes: 1 addition & 1 deletion moksha-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct WalletBuilder<C: Client, L: LocalStore> {
}

impl<C: Client, L: LocalStore> WalletBuilder<C, L> {
fn new() -> Self {
const fn new() -> Self {
Self {
client: None,
localstore: None,
Expand Down

0 comments on commit 4db2f8c

Please sign in to comment.