refactor: rename 'SplitPayload' to 'PreSplit'

This commit is contained in:
thesimplekid
2023-11-28 07:29:13 +00:00
parent 210d6159c3
commit ce0ff46885
3 changed files with 16 additions and 22 deletions

View File

@@ -5,7 +5,7 @@ use cashu::dhke::{construct_proofs, unblind_message};
#[cfg(feature = "nut07")]
use cashu::nuts::nut00::mint;
use cashu::nuts::{
BlindedSignature, Keys, PreMintSecrets, Proof, Proofs, RequestMintResponse, SplitPayload,
BlindedSignature, Keys, PreMintSecrets, PreSplit, Proof, Proofs, RequestMintResponse,
SplitRequest, Token,
};
#[cfg(feature = "nut07")]
@@ -155,22 +155,19 @@ impl<C: Client> Wallet<C> {
// Sum amount of all proofs
let _amount: Amount = token.proofs.iter().map(|p| p.amount).sum();
let split_payload = self.create_split(None, token.proofs)?;
let pre_split = self.create_split(None, token.proofs)?;
let split_response = self
.client
.post_split(
self.mint_url.clone().try_into()?,
split_payload.split_payload,
)
.post_split(self.mint_url.clone().try_into()?, pre_split.split_request)
.await?;
if let Some(promises) = &split_response.promises {
// Proof to keep
let p = construct_proofs(
promises.to_owned(),
split_payload.pre_mint_secrets.rs(),
split_payload.pre_mint_secrets.secrets(),
pre_split.pre_mint_secrets.rs(),
pre_split.pre_mint_secrets.secrets(),
&keys,
)?;
proofs.push(p);
@@ -183,7 +180,7 @@ impl<C: Client> Wallet<C> {
}
/// Create Split Payload
fn create_split(&self, amount: Option<Amount>, proofs: Proofs) -> Result<SplitPayload, Error> {
fn create_split(&self, amount: Option<Amount>, proofs: Proofs) -> Result<PreSplit, Error> {
// Since split is used to get the needed combination of tokens for a specific
// amount first blinded messages are created for the amount
@@ -204,11 +201,11 @@ impl<C: Client> Wallet<C> {
PreMintSecrets::random((&self.mint_keys).into(), value)?
};
let split_payload = SplitRequest::new(proofs, pre_mint_secrets.blinded_messages());
let split_request = SplitRequest::new(proofs, pre_mint_secrets.blinded_messages());
Ok(SplitPayload {
Ok(PreSplit {
pre_mint_secrets,
split_payload,
split_request,
})
}
@@ -251,14 +248,11 @@ impl<C: Client> Wallet<C> {
return Err(Error::InsufficientFunds);
}
let split_payload = self.create_split(Some(amount), proofs)?;
let pre_split = self.create_split(Some(amount), proofs)?;
let split_response = self
.client
.post_split(
self.mint_url.clone().try_into()?,
split_payload.split_payload,
)
.post_split(self.mint_url.clone().try_into()?, pre_split.split_request)
.await?;
let mut keep_proofs = Proofs::new();
@@ -267,8 +261,8 @@ impl<C: Client> Wallet<C> {
if let Some(promises) = split_response.promises {
let mut proofs = construct_proofs(
promises,
split_payload.pre_mint_secrets.rs(),
split_payload.pre_mint_secrets.secrets(),
pre_split.pre_mint_secrets.rs(),
pre_split.pre_mint_secrets.secrets(),
&self.mint_keys,
)?;

View File

@@ -18,7 +18,7 @@ pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey};
pub use nut02::mint::KeySet as MintKeySet;
pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};
#[cfg(feature = "wallet")]
pub use nut03::SplitPayload;
pub use nut03::PreSplit;
pub use nut03::{RequestMintResponse, SplitRequest, SplitResponse};
pub use nut04::{MintRequest, PostMintResponse};
pub use nut05::{CheckFeesRequest, CheckFeesResponse};

View File

@@ -21,9 +21,9 @@ pub struct RequestMintResponse {
#[cfg(feature = "wallet")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct SplitPayload {
pub struct PreSplit {
pub pre_mint_secrets: PreMintSecrets,
pub split_payload: SplitRequest,
pub split_request: SplitRequest,
}
/// Split Request [NUT-06]