use anyhow::{bail, Result};
use snarkvm::{console::types::Field, ledger::block::Transaction};
use crate::{Authorization, Network};
pub fn fee_from_auth<N: Network>(
fee_auth: &Authorization<N>,
) -> Result<snarkvm::ledger::block::Fee<N>> {
let Some(transition) = fee_auth.transitions().values().next().cloned() else {
bail!("No transitions found in fee authorization");
};
snarkvm::ledger::block::Fee::from(transition, N::StateRoot::default(), None)
}
pub fn auth_tx_id<N: Network>(
auth: &Authorization<N>,
fee_auth: Option<&Authorization<N>>,
) -> Result<N::TransactionID> {
let fee = fee_auth.map(fee_from_auth).transpose()?;
let field: Field<N> = *Transaction::transitions_tree(auth.transitions().values(), &fee)?.root();
Ok(field.into())
}
pub fn deploy_tx_id<N: Network>(
deployment: &snarkvm::ledger::block::Deployment<N>,
fee_auth: Option<&Authorization<N>>,
) -> Result<N::TransactionID> {
let fee = fee_auth.map(fee_from_auth).transpose()?;
let field: Field<N> = *Transaction::deployment_tree(deployment, fee.as_ref())?.root();
Ok(field.into())
}