use std::collections::HashMap;
use crate::data::identifier::DamlIdentifier;
use crate::grpc_protobuf::com::daml::ledger::api::v2::cumulative_filter::IdentifierFilter;
use crate::grpc_protobuf::com::daml::ledger::api::v2::{
CumulativeFilter, EventFormat, Filters, InterfaceFilter, ParticipantAuthorizationTopologyFormat, TemplateFilter,
TopologyFormat, TransactionFormat, TransactionShape, UpdateFormat, WildcardFilter,
};
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct DamlWildcardFilter {
pub include_created_event_blob: bool,
}
impl From<DamlWildcardFilter> for WildcardFilter {
fn from(f: DamlWildcardFilter) -> Self {
Self {
include_created_event_blob: f.include_created_event_blob,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct DamlInterfaceFilter {
pub interface_id: DamlIdentifier,
pub include_interface_view: bool,
pub include_created_event_blob: bool,
}
impl From<DamlInterfaceFilter> for InterfaceFilter {
fn from(f: DamlInterfaceFilter) -> Self {
Self {
interface_id: Some(f.interface_id.into()),
include_interface_view: f.include_interface_view,
include_created_event_blob: f.include_created_event_blob,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct DamlTemplateFilter {
pub template_id: DamlIdentifier,
pub include_created_event_blob: bool,
}
impl From<DamlTemplateFilter> for TemplateFilter {
fn from(f: DamlTemplateFilter) -> Self {
Self {
template_id: Some(f.template_id.into()),
include_created_event_blob: f.include_created_event_blob,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum DamlCumulativeFilter {
Wildcard(DamlWildcardFilter),
Interface(DamlInterfaceFilter),
Template(DamlTemplateFilter),
}
impl From<DamlCumulativeFilter> for CumulativeFilter {
fn from(f: DamlCumulativeFilter) -> Self {
Self {
identifier_filter: Some(match f {
DamlCumulativeFilter::Wildcard(w) => IdentifierFilter::WildcardFilter(w.into()),
DamlCumulativeFilter::Interface(i) => IdentifierFilter::InterfaceFilter(i.into()),
DamlCumulativeFilter::Template(t) => IdentifierFilter::TemplateFilter(t.into()),
}),
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct DamlFilters {
pub cumulative: Vec<DamlCumulativeFilter>,
}
impl DamlFilters {
pub fn wildcard() -> Self {
Self {
cumulative: vec![DamlCumulativeFilter::Wildcard(DamlWildcardFilter::default())],
}
}
}
impl From<DamlFilters> for Filters {
fn from(f: DamlFilters) -> Self {
Self {
cumulative: f.cumulative.into_iter().map(Into::into).collect(),
}
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum DamlTransactionShape {
AcsDelta,
LedgerEffects,
}
impl From<DamlTransactionShape> for TransactionShape {
fn from(s: DamlTransactionShape) -> Self {
match s {
DamlTransactionShape::AcsDelta => TransactionShape::AcsDelta,
DamlTransactionShape::LedgerEffects => TransactionShape::LedgerEffects,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct DamlEventFormat {
pub filters_by_party: HashMap<String, DamlFilters>,
pub filters_for_any_party: Option<DamlFilters>,
pub verbose: bool,
}
impl From<DamlEventFormat> for EventFormat {
fn from(f: DamlEventFormat) -> Self {
Self {
filters_by_party: f.filters_by_party.into_iter().map(|(k, v)| (k, v.into())).collect(),
filters_for_any_party: f.filters_for_any_party.map(Into::into),
verbose: f.verbose,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct DamlTransactionFormat {
pub event_format: DamlEventFormat,
pub transaction_shape: DamlTransactionShape,
}
impl From<DamlTransactionFormat> for TransactionFormat {
fn from(f: DamlTransactionFormat) -> Self {
Self {
event_format: Some(f.event_format.into()),
transaction_shape: TransactionShape::from(f.transaction_shape) as i32,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct DamlParticipantAuthorizationTopologyFormat {
pub parties: Vec<String>,
}
impl From<DamlParticipantAuthorizationTopologyFormat> for ParticipantAuthorizationTopologyFormat {
fn from(f: DamlParticipantAuthorizationTopologyFormat) -> Self {
Self {
parties: f.parties,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct DamlTopologyFormat {
pub include_participant_authorization_events: Option<DamlParticipantAuthorizationTopologyFormat>,
}
impl From<DamlTopologyFormat> for TopologyFormat {
fn from(f: DamlTopologyFormat) -> Self {
Self {
include_participant_authorization_events: f.include_participant_authorization_events.map(Into::into),
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct DamlUpdateFormat {
pub include_transactions: Option<DamlTransactionFormat>,
pub include_reassignments: Option<DamlEventFormat>,
pub include_topology_events: Option<DamlTopologyFormat>,
}
impl From<DamlUpdateFormat> for UpdateFormat {
fn from(f: DamlUpdateFormat) -> Self {
Self {
include_transactions: f.include_transactions.map(Into::into),
include_reassignments: f.include_reassignments.map(Into::into),
include_topology_events: f.include_topology_events.map(Into::into),
}
}
}