use std::convert::TryFrom;
use crate::data::event::{DamlArchivedEvent, DamlCreatedEvent};
use crate::data::{DamlError, DamlResult};
use crate::grpc_protobuf::com::daml::ledger::api::v2::{Archived, Created, GetEventsByContractIdResponse};
use crate::util::Required;
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct DamlCreated {
pub created_event: DamlCreatedEvent,
pub synchronizer_id: String,
}
impl TryFrom<Created> for DamlCreated {
type Error = DamlError;
fn try_from(c: Created) -> DamlResult<Self> {
Ok(Self {
created_event: DamlCreatedEvent::try_from(c.created_event.req()?)?,
synchronizer_id: c.synchronizer_id,
})
}
}
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct DamlArchived {
pub archived_event: DamlArchivedEvent,
pub synchronizer_id: String,
}
impl TryFrom<Archived> for DamlArchived {
type Error = DamlError;
fn try_from(a: Archived) -> DamlResult<Self> {
Ok(Self {
archived_event: DamlArchivedEvent::try_from(a.archived_event.req()?)?,
synchronizer_id: a.synchronizer_id,
})
}
}
#[derive(Debug, Eq, PartialEq, Clone, Default)]
pub struct DamlEventsByContractId {
pub created: Option<DamlCreated>,
pub archived: Option<DamlArchived>,
}
impl TryFrom<GetEventsByContractIdResponse> for DamlEventsByContractId {
type Error = DamlError;
fn try_from(r: GetEventsByContractIdResponse) -> DamlResult<Self> {
Ok(Self {
created: r.created.map(DamlCreated::try_from).transpose()?,
archived: r.archived.map(DamlArchived::try_from).transpose()?,
})
}
}