Skip to content

Commit

Permalink
chore: make split_amount() private
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Oct 25, 2023
1 parent 6bf6c52 commit a9f3b9f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion flutter/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 11 additions & 2 deletions moksha-core/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Amount {
}

#[derive(Debug, Clone)]
pub struct SplitAmount(pub Vec<u64>);
pub struct SplitAmount(Vec<u64>);

impl From<Vec<u64>> for SplitAmount {
fn from(from: Vec<u64>) -> Self {
Expand All @@ -33,8 +33,17 @@ impl From<u64> for Amount {
}
}

impl IntoIterator for SplitAmount {
type Item = u64;
type IntoIter = std::vec::IntoIter<Self::Item>;

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<u64> {
fn split_amount(amount: u64) -> Vec<u64> {
format!("{amount:b}")
.chars()
.rev()
Expand Down
11 changes: 5 additions & 6 deletions moksha-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -216,13 +216,13 @@ impl<C: Client, L: LocalStore> Wallet<C, L> {
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()));
Expand Down Expand Up @@ -302,7 +302,6 @@ impl<C: Client, L: LocalStore> Wallet<C, L> {
let secrets = split_amount.create_secrets();

let blinded_messages = split_amount
.0
.into_iter()
.zip(secrets.clone())
.map(|(amount, secret)| {
Expand Down Expand Up @@ -358,10 +357,10 @@ impl<C: Client, L: LocalStore> Wallet<C, L> {
// FIXME implement for Amount
fn create_blinded_messages(
&self,
amount: u64,
amount: Amount,
secrets: &[String],
) -> Result<Vec<(BlindedMessage, SecretKey)>, MokshaWalletError> {
let split_amount = split_amount(amount);
let split_amount = amount.split();

Ok(split_amount
.into_iter()
Expand Down

0 comments on commit a9f3b9f

Please sign in to comment.