use super::state::Built;
use super::SendBatch;
use crate::error::Error;
use crate::send::payment_intent::state::Pending;
use crate::send::payment_intent::SendIntent;
use crate::storage::BdkStorage;
async fn compensate_pre_broadcast_batch<S>(
batch: SendBatch<S>,
storage: &BdkStorage,
) -> Result<Vec<SendIntent<Pending>>, Error> {
let mut reverted = Vec::new();
for intent in batch.intents {
reverted.push(intent.revert_to_pending(storage).await?);
}
storage.delete_send_batch(&batch.batch_id).await?;
Ok(reverted)
}
impl SendBatch<Built> {
pub async fn compensate(self, storage: &BdkStorage) -> Result<Vec<SendIntent<Pending>>, Error> {
compensate_pre_broadcast_batch(self, storage).await
}
}