use std::convert::TryFrom;
use crate::data::identifier::DamlIdentifier;
use crate::data::offset::DamlLedgerOffset;
use crate::data::value::DamlValue;
use crate::data::{DamlError, DamlResult};
use crate::grpc_protobuf::com::daml::ledger::api::v2::ExercisedEvent;
use crate::util::Required;
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct DamlExercisedEvent {
pub offset: DamlLedgerOffset,
pub node_id: i32,
pub contract_id: String,
pub template_id: DamlIdentifier,
pub interface_id: Option<DamlIdentifier>,
pub choice: String,
pub choice_argument: DamlValue,
pub acting_parties: Vec<String>,
pub consuming: bool,
pub witness_parties: Vec<String>,
pub last_descendant_node_id: i32,
pub exercise_result: Option<DamlValue>,
pub package_name: String,
pub implemented_interfaces: Vec<DamlIdentifier>,
pub acs_delta: bool,
}
impl TryFrom<ExercisedEvent> for DamlExercisedEvent {
type Error = DamlError;
fn try_from(e: ExercisedEvent) -> DamlResult<Self> {
Ok(Self {
offset: DamlLedgerOffset::new(e.offset),
node_id: e.node_id,
contract_id: e.contract_id,
template_id: DamlIdentifier::from(e.template_id.req()?),
interface_id: e.interface_id.map(DamlIdentifier::from),
choice: e.choice,
choice_argument: DamlValue::try_from(e.choice_argument.req()?)?,
acting_parties: e.acting_parties,
consuming: e.consuming,
witness_parties: e.witness_parties,
last_descendant_node_id: e.last_descendant_node_id,
exercise_result: e.exercise_result.map(DamlValue::try_from).transpose()?,
package_name: e.package_name,
implemented_interfaces: e.implemented_interfaces.into_iter().map(DamlIdentifier::from).collect(),
acs_delta: e.acs_delta,
})
}
}