use bsv::wallet::error::WalletError;
use bsv::wallet::interfaces::{
ActionResultStatus, CreateActionResult, InternalizeActionResult, SignActionResult,
};
pub fn throw_if_any_unsuccessful_create_actions(r: &CreateActionResult) -> Result<(), WalletError> {
let failures: Vec<String> = r
.send_with_results
.iter()
.filter(|swr| !matches!(swr.status, ActionResultStatus::Unproven))
.map(|swr| format!("txid={} status={}", swr.txid, swr.status.as_str()))
.collect();
if !failures.is_empty() {
return Err(WalletError::Internal(format!(
"WERR_REVIEW_ACTIONS: createAction had unsuccessful results: {}",
failures.join(", ")
)));
}
Ok(())
}
pub fn throw_if_any_unsuccessful_sign_actions(r: &SignActionResult) -> Result<(), WalletError> {
let failures: Vec<String> = r
.send_with_results
.iter()
.filter(|swr| !matches!(swr.status, ActionResultStatus::Unproven))
.map(|swr| format!("txid={} status={}", swr.txid, swr.status.as_str()))
.collect();
if !failures.is_empty() {
return Err(WalletError::Internal(format!(
"WERR_REVIEW_ACTIONS: signAction had unsuccessful results: {}",
failures.join(", ")
)));
}
Ok(())
}
pub fn throw_if_unsuccessful_internalize_action(
r: &InternalizeActionResult,
) -> Result<(), WalletError> {
if !r.accepted {
return Err(WalletError::Internal(
"WERR_REVIEW_ACTIONS: internalizeAction was not accepted".to_string(),
));
}
Ok(())
}