use cap_sdk_core::GetTransactionResponse;
use crate::{CapEnv, GetTransactionError, Transaction, TransactionId};
pub async fn get_transaction(id: TransactionId) -> Result<Transaction, GetTransactionError> {
let context = CapEnv::get().await;
let bucket = context
.root
.get_bucket_for(id)
.await
.map_err(|(code, details)| GetTransactionError::Unexpected(code, details))?;
let transaction = bucket
.get_transaction(id)
.await
.map_err(|(code, details)| GetTransactionError::Unexpected(code, details))?;
if let GetTransactionResponse::Found(event, _) = transaction {
if let Some(event) = event {
Ok(event)
} else {
Err(GetTransactionError::InvalidId)
}
} else {
unimplemented!("This version of cap-sdk does not support multi-canister.")
}
}