mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-21 10:14:30 +00:00
fix is_key_image_spent
This commit is contained in:
parent
78b3ff1925
commit
95ab9765e8
1 changed files with 33 additions and 11 deletions
|
@ -305,27 +305,49 @@ async fn is_key_image_spent(
|
||||||
|
|
||||||
let mut spent_status = Vec::with_capacity(key_images.len());
|
let mut spent_status = Vec::with_capacity(key_images.len());
|
||||||
|
|
||||||
|
// Check the blockchain for key image spend status.
|
||||||
blockchain::key_images_spent(&mut state.blockchain_read, key_images.clone())
|
blockchain::key_images_spent(&mut state.blockchain_read, key_images.clone())
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|ki| {
|
.for_each(|ki| {
|
||||||
if ki {
|
if ki {
|
||||||
spent_status.push(KeyImageSpentStatus::SpentInBlockchain.to_u8());
|
spent_status.push(KeyImageSpentStatus::SpentInBlockchain);
|
||||||
} else {
|
} else {
|
||||||
spent_status.push(KeyImageSpentStatus::Unspent.to_u8());
|
spent_status.push(KeyImageSpentStatus::Unspent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
txpool::key_images_spent(&mut state.txpool_read, key_images, !restricted)
|
assert_eq!(spent_status.len(), key_images.len(), "key_images_spent() should be returning a Vec with an equal length to the input, the below zip() relies on this.");
|
||||||
.await?
|
|
||||||
|
// Filter the remaining unspent key images out from the vector.
|
||||||
|
let key_images = key_images
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|ki| {
|
.zip(&spent_status)
|
||||||
if ki {
|
.filter_map(|(ki, status)| match status {
|
||||||
spent_status.push(KeyImageSpentStatus::SpentInPool.to_u8());
|
KeyImageSpentStatus::Unspent => Some(ki),
|
||||||
} else {
|
KeyImageSpentStatus::SpentInBlockchain => None,
|
||||||
spent_status.push(KeyImageSpentStatus::Unspent.to_u8());
|
KeyImageSpentStatus::SpentInPool => unreachable!(),
|
||||||
}
|
})
|
||||||
});
|
.collect();
|
||||||
|
|
||||||
|
// Check if the remaining unspent key images exist in the transaction pool.
|
||||||
|
if !key_images.is_empty() {
|
||||||
|
txpool::key_images_spent(&mut state.txpool_read, key_images, !restricted)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.for_each(|ki| {
|
||||||
|
if ki {
|
||||||
|
spent_status.push(KeyImageSpentStatus::SpentInPool);
|
||||||
|
} else {
|
||||||
|
spent_status.push(KeyImageSpentStatus::Unspent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let spent_status = spent_status
|
||||||
|
.into_iter()
|
||||||
|
.map(|status| status.to_u8())
|
||||||
|
.collect();
|
||||||
|
|
||||||
Ok(IsKeyImageSpentResponse {
|
Ok(IsKeyImageSpentResponse {
|
||||||
base: helper::access_response_base(false),
|
base: helper::access_response_base(false),
|
||||||
|
|
Loading…
Reference in a new issue