From a9f3b9f9a236e15ff1b66037de05050623320a51 Mon Sep 17 00:00:00 2001 From: ngutech21 Date: Wed, 25 Oct 2023 18:10:20 +0200 Subject: [PATCH] chore: make split_amount() private --- flutter/native/Cargo.toml | 2 +- moksha-core/src/amount.rs | 13 +++++++++++-- moksha-wallet/src/wallet.rs | 11 +++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/flutter/native/Cargo.toml b/flutter/native/Cargo.toml index cadca9e4..985e9276 100644 --- a/flutter/native/Cargo.toml +++ b/flutter/native/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["cdylib", "staticlib"] [dependencies] moksha-wallet = { version = "0.1.2", path = "../../moksha-wallet" } -moksha-core = { ersion = "0.1.2", path = "../../moksha-core" } +moksha-core = { version = "0.1.2", path = "../../moksha-core" } moksha-fedimint = { version = "0.1.2", path = "../../moksha-fedimint" } tracing = "0.1.40" diff --git a/moksha-core/src/amount.rs b/moksha-core/src/amount.rs index f54f7a1c..3e11550f 100644 --- a/moksha-core/src/amount.rs +++ b/moksha-core/src/amount.rs @@ -11,7 +11,7 @@ impl Amount { } #[derive(Debug, Clone)] -pub struct SplitAmount(pub Vec); +pub struct SplitAmount(Vec); impl From> for SplitAmount { fn from(from: Vec) -> Self { @@ -33,8 +33,17 @@ impl From for Amount { } } +impl IntoIterator for SplitAmount { + type Item = u64; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + /// split a decimal amount into a vector of powers of 2 -pub fn split_amount(amount: u64) -> Vec { +fn split_amount(amount: u64) -> Vec { format!("{amount:b}") .chars() .rev() diff --git a/moksha-wallet/src/wallet.rs b/moksha-wallet/src/wallet.rs index 7e4590e7..0776c022 100644 --- a/moksha-wallet/src/wallet.rs +++ b/moksha-wallet/src/wallet.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use moksha_core::{ - amount::{split_amount, Amount}, + amount::Amount, blind::{BlindedMessage, BlindedSignature, TotalAmount}, dhke::Dhke, keyset::Keysets, @@ -216,13 +216,13 @@ impl Wallet { let total_token_amount = tokens.total_amount(); let first_amount: Amount = (total_token_amount - splt_amount.0).into(); let first_secrets = first_amount.split().create_secrets(); - let first_outputs = self.create_blinded_messages(first_amount.0, &first_secrets)?; + let first_outputs = self.create_blinded_messages(first_amount, &first_secrets)?; // ############################################################################ let second_amount = splt_amount.clone(); let second_secrets = second_amount.split().create_secrets(); - let second_outputs = self.create_blinded_messages(second_amount.0, &second_secrets)?; + let second_outputs = self.create_blinded_messages(second_amount, &second_secrets)?; let mut total_outputs = vec![]; total_outputs.extend(get_blinded_msg(first_outputs.clone())); @@ -302,7 +302,6 @@ impl Wallet { let secrets = split_amount.create_secrets(); let blinded_messages = split_amount - .0 .into_iter() .zip(secrets.clone()) .map(|(amount, secret)| { @@ -358,10 +357,10 @@ impl Wallet { // FIXME implement for Amount fn create_blinded_messages( &self, - amount: u64, + amount: Amount, secrets: &[String], ) -> Result, MokshaWalletError> { - let split_amount = split_amount(amount); + let split_amount = amount.split(); Ok(split_amount .into_iter()