daml_grpc/data/command/
create_and_exercise.rs

1use crate::data::identifier::DamlIdentifier;
2use crate::data::value::{DamlRecord, DamlValue};
3use crate::grpc_protobuf::com::daml::ledger::api::v1::command::Command;
4use crate::grpc_protobuf::com::daml::ledger::api::v1::CreateAndExerciseCommand;
5
6/// Create a contract and exercise a choice on it in the same transaction.
7#[derive(Debug, Eq, PartialEq, Clone)]
8pub struct DamlCreateAndExerciseCommand {
9    template_id: DamlIdentifier,
10    create_arguments: DamlRecord,
11    choice: String,
12    choice_argument: DamlValue,
13}
14
15impl DamlCreateAndExerciseCommand {
16    pub fn new(
17        template_id: impl Into<DamlIdentifier>,
18        create_arguments: impl Into<DamlRecord>,
19        choice: impl Into<String>,
20        choice_argument: impl Into<DamlValue>,
21    ) -> Self {
22        Self {
23            template_id: template_id.into(),
24            create_arguments: create_arguments.into(),
25            choice: choice.into(),
26            choice_argument: choice_argument.into(),
27        }
28    }
29
30    /// The template of the contract the client wants to create.
31    pub const fn template_id(&self) -> &DamlIdentifier {
32        &self.template_id
33    }
34
35    /// The arguments required for creating a contract from this template.
36    pub const fn create_arguments(&self) -> &DamlRecord {
37        &self.create_arguments
38    }
39
40    /// The name of the choice the client wants to exercise.
41    ///
42    /// Must match the regexp `[A-Za-z\$_][A-Za-z0-9\$_]*`
43    pub fn choice(&self) -> &str {
44        &self.choice
45    }
46
47    /// The argument for this choice.
48    pub const fn choice_argument(&self) -> &DamlValue {
49        &self.choice_argument
50    }
51}
52
53impl From<DamlCreateAndExerciseCommand> for Command {
54    fn from(daml_create_and_exercise_command: DamlCreateAndExerciseCommand) -> Self {
55        Command::CreateAndExercise(CreateAndExerciseCommand {
56            template_id: Some(daml_create_and_exercise_command.template_id.into()),
57            create_arguments: Some(daml_create_and_exercise_command.create_arguments.into()),
58            choice: daml_create_and_exercise_command.choice,
59            choice_argument: Some(daml_create_and_exercise_command.choice_argument.into()),
60        })
61    }
62}