mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-20 06:05:09 +01:00
refactor: remove get single blinded sig
This commit is contained in:
@@ -647,27 +647,9 @@ impl MintDatabase for MintRedbDatabase {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_blinded_signature(
|
|
||||||
&self,
|
|
||||||
blinded_message: &PublicKey,
|
|
||||||
) -> Result<Option<BlindSignature>, Self::Err> {
|
|
||||||
let db = self.db.lock().await;
|
|
||||||
let read_txn = db.begin_read().map_err(Error::from)?;
|
|
||||||
let table = read_txn
|
|
||||||
.open_table(BLINDED_SIGNATURES)
|
|
||||||
.map_err(Error::from)?;
|
|
||||||
|
|
||||||
match table.get(blinded_message.to_bytes()).map_err(Error::from)? {
|
|
||||||
Some(blind_signature) => {
|
|
||||||
Ok(serde_json::from_str(blind_signature.value()).map_err(Error::from)?)
|
|
||||||
}
|
|
||||||
None => Ok(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_blinded_signatures(
|
async fn get_blinded_signatures(
|
||||||
&self,
|
&self,
|
||||||
blinded_messages: Vec<PublicKey>,
|
blinded_messages: &[PublicKey],
|
||||||
) -> Result<Vec<Option<BlindSignature>>, Self::Err> {
|
) -> Result<Vec<Option<BlindSignature>>, Self::Err> {
|
||||||
let db = self.db.lock().await;
|
let db = self.db.lock().await;
|
||||||
let read_txn = db.begin_read().map_err(Error::from)?;
|
let read_txn = db.begin_read().map_err(Error::from)?;
|
||||||
|
|||||||
@@ -657,34 +657,9 @@ VALUES (?, ?, ?, ?);
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn get_blinded_signature(
|
|
||||||
&self,
|
|
||||||
blinded_message: &PublicKey,
|
|
||||||
) -> Result<Option<BlindSignature>, Self::Err> {
|
|
||||||
let rec = sqlx::query(
|
|
||||||
r#"
|
|
||||||
SELECT *
|
|
||||||
FROM blind_signature
|
|
||||||
WHERE y=?;
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.bind(blinded_message.to_bytes().to_vec())
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let rec = match rec {
|
|
||||||
Ok(rec) => rec,
|
|
||||||
Err(err) => match err {
|
|
||||||
sqlx::Error::RowNotFound => return Ok(None),
|
|
||||||
_ => return Err(Error::SQLX(err).into()),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Some(sqlite_row_to_blind_signature(rec)?))
|
|
||||||
}
|
|
||||||
async fn get_blinded_signatures(
|
async fn get_blinded_signatures(
|
||||||
&self,
|
&self,
|
||||||
blinded_messages: Vec<PublicKey>,
|
blinded_messages: &[PublicKey],
|
||||||
) -> Result<Vec<Option<BlindSignature>>, Self::Err> {
|
) -> Result<Vec<Option<BlindSignature>>, Self::Err> {
|
||||||
let mut signatures = Vec::with_capacity(blinded_messages.len());
|
let mut signatures = Vec::with_capacity(blinded_messages.len());
|
||||||
for message in blinded_messages {
|
for message in blinded_messages {
|
||||||
|
|||||||
@@ -287,21 +287,9 @@ impl MintDatabase for MintMemoryDatabase {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_blinded_signature(
|
|
||||||
&self,
|
|
||||||
blinded_message: &PublicKey,
|
|
||||||
) -> Result<Option<BlindSignature>, Self::Err> {
|
|
||||||
Ok(self
|
|
||||||
.blinded_signatures
|
|
||||||
.read()
|
|
||||||
.await
|
|
||||||
.get(&blinded_message.to_bytes())
|
|
||||||
.cloned())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_blinded_signatures(
|
async fn get_blinded_signatures(
|
||||||
&self,
|
&self,
|
||||||
blinded_messages: Vec<PublicKey>,
|
blinded_messages: &[PublicKey],
|
||||||
) -> Result<Vec<Option<BlindSignature>>, Self::Err> {
|
) -> Result<Vec<Option<BlindSignature>>, Self::Err> {
|
||||||
let mut signatures = Vec::with_capacity(blinded_messages.len());
|
let mut signatures = Vec::with_capacity(blinded_messages.len());
|
||||||
|
|
||||||
|
|||||||
@@ -232,14 +232,9 @@ pub trait MintDatabase {
|
|||||||
blinded_messages: &[PublicKey],
|
blinded_messages: &[PublicKey],
|
||||||
blind_signatures: &[BlindSignature],
|
blind_signatures: &[BlindSignature],
|
||||||
) -> Result<(), Self::Err>;
|
) -> Result<(), Self::Err>;
|
||||||
/// Get [`BlindSignature`]
|
|
||||||
async fn get_blinded_signature(
|
|
||||||
&self,
|
|
||||||
blinded_message: &PublicKey,
|
|
||||||
) -> Result<Option<BlindSignature>, Self::Err>;
|
|
||||||
/// Get [`BlindSignature`]s
|
/// Get [`BlindSignature`]s
|
||||||
async fn get_blinded_signatures(
|
async fn get_blinded_signatures(
|
||||||
&self,
|
&self,
|
||||||
blinded_messages: Vec<PublicKey>,
|
blinded_messages: &[PublicKey],
|
||||||
) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
|
) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -470,27 +470,31 @@ impl Mint {
|
|||||||
MintQuoteState::Paid => (),
|
MintQuoteState::Paid => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
for blinded_message in &mint_request.outputs {
|
let blinded_messages: Vec<PublicKey> = mint_request
|
||||||
if self
|
.outputs
|
||||||
.localstore
|
.iter()
|
||||||
.get_blinded_signature(&blinded_message.blinded_secret)
|
.map(|b| b.blinded_secret)
|
||||||
.await?
|
.collect();
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
tracing::info!(
|
|
||||||
"Output has already been signed: {}",
|
|
||||||
blinded_message.blinded_secret
|
|
||||||
);
|
|
||||||
tracing::info!(
|
|
||||||
"Mint {} did not succeed returning quote to Paid state",
|
|
||||||
mint_request.quote
|
|
||||||
);
|
|
||||||
|
|
||||||
self.localstore
|
if self
|
||||||
.update_mint_quote_state(&mint_request.quote, MintQuoteState::Paid)
|
.localstore
|
||||||
.await?;
|
.get_blinded_signatures(&blinded_messages)
|
||||||
return Err(Error::BlindedMessageAlreadySigned);
|
.await?
|
||||||
}
|
.iter()
|
||||||
|
.flatten()
|
||||||
|
.next()
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
|
tracing::info!("Output has already been signed",);
|
||||||
|
tracing::info!(
|
||||||
|
"Mint {} did not succeed returning quote to Paid state",
|
||||||
|
mint_request.quote
|
||||||
|
);
|
||||||
|
|
||||||
|
self.localstore
|
||||||
|
.update_mint_quote_state(&mint_request.quote, MintQuoteState::Paid)
|
||||||
|
.await?;
|
||||||
|
return Err(Error::BlindedMessageAlreadySigned);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut blind_signatures = Vec::with_capacity(mint_request.outputs.len());
|
let mut blind_signatures = Vec::with_capacity(mint_request.outputs.len());
|
||||||
@@ -577,19 +581,24 @@ impl Mint {
|
|||||||
&self,
|
&self,
|
||||||
swap_request: SwapRequest,
|
swap_request: SwapRequest,
|
||||||
) -> Result<SwapResponse, Error> {
|
) -> Result<SwapResponse, Error> {
|
||||||
for blinded_message in &swap_request.outputs {
|
let blinded_messages: Vec<PublicKey> = swap_request
|
||||||
if self
|
.outputs
|
||||||
.localstore
|
.iter()
|
||||||
.get_blinded_signature(&blinded_message.blinded_secret)
|
.map(|b| b.blinded_secret)
|
||||||
.await?
|
.collect();
|
||||||
.is_some()
|
|
||||||
{
|
if self
|
||||||
tracing::error!(
|
.localstore
|
||||||
"Output has already been signed: {}",
|
.get_blinded_signatures(&blinded_messages)
|
||||||
blinded_message.blinded_secret
|
.await?
|
||||||
);
|
.iter()
|
||||||
return Err(Error::BlindedMessageAlreadySigned);
|
.flatten()
|
||||||
}
|
.next()
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
|
tracing::info!("Output has already been signed",);
|
||||||
|
|
||||||
|
return Err(Error::BlindedMessageAlreadySigned);
|
||||||
}
|
}
|
||||||
|
|
||||||
let proofs_total = swap_request.input_amount();
|
let proofs_total = swap_request.input_amount();
|
||||||
@@ -959,19 +968,21 @@ impl Mint {
|
|||||||
.ok_or(Error::UnknownQuote)?;
|
.ok_or(Error::UnknownQuote)?;
|
||||||
|
|
||||||
if let Some(outputs) = &melt_request.outputs {
|
if let Some(outputs) = &melt_request.outputs {
|
||||||
for blinded_message in outputs {
|
let blinded_messages: Vec<PublicKey> =
|
||||||
if self
|
outputs.iter().map(|b| b.blinded_secret).collect();
|
||||||
.localstore
|
|
||||||
.get_blinded_signature(&blinded_message.blinded_secret)
|
if self
|
||||||
.await?
|
.localstore
|
||||||
.is_some()
|
.get_blinded_signatures(&blinded_messages)
|
||||||
{
|
.await?
|
||||||
tracing::error!(
|
.iter()
|
||||||
"Output has already been signed: {}",
|
.flatten()
|
||||||
blinded_message.blinded_secret
|
.next()
|
||||||
);
|
.is_some()
|
||||||
return Err(Error::BlindedMessageAlreadySigned);
|
{
|
||||||
}
|
tracing::info!("Output has already been signed",);
|
||||||
|
|
||||||
|
return Err(Error::BlindedMessageAlreadySigned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1061,7 +1072,7 @@ impl Mint {
|
|||||||
|
|
||||||
let blinded_signatures = self
|
let blinded_signatures = self
|
||||||
.localstore
|
.localstore
|
||||||
.get_blinded_signatures(blinded_message)
|
.get_blinded_signatures(&blinded_message)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
assert_eq!(blinded_signatures.len(), output_len);
|
assert_eq!(blinded_signatures.len(), output_len);
|
||||||
|
|||||||
Reference in New Issue
Block a user