use std::convert::TryFrom;
use crate::data::identifier::DamlIdentifier;
use crate::data::value::DamlRecord;
use crate::data::{DamlError, DamlResult};
use crate::grpc_protobuf::com::daml::ledger::api::v2::CreateCommand;
use crate::grpc_protobuf::com::daml::ledger::api::v2::command::Command;
use crate::util::Required;
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct DamlCreateCommand {
template_id: DamlIdentifier,
create_arguments: DamlRecord,
}
impl DamlCreateCommand {
pub fn new(template_id: impl Into<DamlIdentifier>, create_arguments: impl Into<DamlRecord>) -> Self {
Self {
template_id: template_id.into(),
create_arguments: create_arguments.into(),
}
}
pub const fn template_id(&self) -> &DamlIdentifier {
&self.template_id
}
pub const fn create_arguments(&self) -> &DamlRecord {
&self.create_arguments
}
}
impl From<DamlCreateCommand> for Command {
fn from(daml_create_command: DamlCreateCommand) -> Self {
Command::Create(CreateCommand {
template_id: Some(daml_create_command.template_id.into()),
create_arguments: Some(daml_create_command.create_arguments.into()),
})
}
}
impl TryFrom<CreateCommand> for DamlCreateCommand {
type Error = DamlError;
fn try_from(c: CreateCommand) -> DamlResult<Self> {
Ok(Self::new(DamlIdentifier::from(c.template_id.req()?), DamlRecord::try_from(c.create_arguments.req()?)?))
}
}