use anyhow::Result;
use penumbra_custody::{AuthorizeRequest, CustodyClient};
use penumbra_keys::FullViewingKey;
use penumbra_transaction::{AuthorizationData, Transaction, TransactionPlan};
use penumbra_view::ViewClient;
pub async fn build_transaction<V, C>(
fvk: &FullViewingKey,
view: &mut V,
custody: &mut C,
plan: TransactionPlan,
) -> Result<Transaction>
where
V: ViewClient,
C: CustodyClient,
{
let auth_data: AuthorizationData = custody
.authorize(AuthorizeRequest {
plan: plan.clone(),
pre_authorizations: Vec::new(),
})
.await?
.data
.ok_or_else(|| anyhow::anyhow!("empty AuthorizeResponse message"))?
.try_into()?;
let witness_data = view.witness(&plan).await?;
#[cfg(not(feature = "parallel"))]
{
let tx = plan.build(fvk, &witness_data, &auth_data)?;
return Ok(tx);
}
#[cfg(feature = "parallel")]
{
let tx = plan
.build_concurrent(fvk, &witness_data, &auth_data)
.await
.map_err(|_| tonic::Status::failed_precondition("Error building transaction"))?;
Ok(tx)
}
}