daml_grpc/data/command/
create.rs

1use crate::data::identifier::DamlIdentifier;
2use crate::data::value::DamlRecord;
3use crate::grpc_protobuf::com::daml::ledger::api::v1::command::Command;
4use crate::grpc_protobuf::com::daml::ledger::api::v1::CreateCommand;
5
6/// Create a new contract instance based on a template.
7#[derive(Debug, Eq, PartialEq, Clone)]
8pub struct DamlCreateCommand {
9    template_id: DamlIdentifier,
10    create_arguments: DamlRecord,
11}
12
13/// Create a new contract instance based on a template.
14impl DamlCreateCommand {
15    pub fn new(template_id: impl Into<DamlIdentifier>, create_arguments: impl Into<DamlRecord>) -> Self {
16        Self {
17            template_id: template_id.into(),
18            create_arguments: create_arguments.into(),
19        }
20    }
21
22    /// The template of contract the client wants to create.
23    pub const fn template_id(&self) -> &DamlIdentifier {
24        &self.template_id
25    }
26
27    /// The arguments required for creating a contract from this template.
28    pub const fn create_arguments(&self) -> &DamlRecord {
29        &self.create_arguments
30    }
31}
32
33impl From<DamlCreateCommand> for Command {
34    fn from(daml_create_command: DamlCreateCommand) -> Self {
35        Command::Create(CreateCommand {
36            template_id: Some(daml_create_command.template_id.into()),
37            create_arguments: Some(daml_create_command.create_arguments.into()),
38        })
39    }
40}