use std::convert::TryFrom;
use chrono::{DateTime, Utc};
use crate::data::event::DamlEvent;
use crate::data::offset::DamlLedgerOffset;
use crate::data::{DamlError, DamlResult};
use crate::grpc_protobuf::com::daml::ledger::api::v2::Transaction;
use crate::util;
use crate::util::Required;
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct DamlTransaction {
pub update_id: String,
pub command_id: String,
pub workflow_id: String,
pub effective_at: DateTime<Utc>,
pub events: Vec<DamlEvent>,
pub offset: DamlLedgerOffset,
pub synchronizer_id: String,
pub record_time: DateTime<Utc>,
pub external_transaction_hash: Option<Vec<u8>>,
pub paid_traffic_cost: Option<i64>,
}
impl TryFrom<Transaction> for DamlTransaction {
type Error = DamlError;
fn try_from(tx: Transaction) -> DamlResult<Self> {
Ok(Self {
update_id: tx.update_id,
command_id: tx.command_id,
workflow_id: tx.workflow_id,
effective_at: util::from_grpc_timestamp(&tx.effective_at.req()?)?,
events: tx.events.into_iter().map(DamlEvent::try_from).collect::<DamlResult<_>>()?,
offset: DamlLedgerOffset::new(tx.offset),
synchronizer_id: tx.synchronizer_id,
record_time: util::from_grpc_timestamp(&tx.record_time.req()?)?,
external_transaction_hash: tx.external_transaction_hash,
paid_traffic_cost: tx.paid_traffic_cost,
})
}
}