daml_grpc/data/command/
exercise_by_key.rs

1use crate::data::identifier::DamlIdentifier;
2use crate::data::value::DamlValue;
3use crate::grpc_protobuf::com::daml::ledger::api::v1::command::Command;
4use crate::grpc_protobuf::com::daml::ledger::api::v1::ExerciseByKeyCommand;
5
6/// Exercise a choice on an existing contract specified by its key.
7#[derive(Debug, Eq, PartialEq, Clone)]
8pub struct DamlExerciseByKeyCommand {
9    template_id: DamlIdentifier,
10    contract_key: DamlValue,
11    choice: String,
12    choice_argument: DamlValue,
13}
14
15impl DamlExerciseByKeyCommand {
16    pub fn new(
17        template_id: impl Into<DamlIdentifier>,
18        contract_key: impl Into<DamlValue>,
19        choice: impl Into<String>,
20        choice_argument: impl Into<DamlValue>,
21    ) -> Self {
22        Self {
23            template_id: template_id.into(),
24            contract_key: contract_key.into(),
25            choice: choice.into(),
26            choice_argument: choice_argument.into(),
27        }
28    }
29
30    /// The template of contract the client wants to exercise.
31    pub const fn template_id(&self) -> &DamlIdentifier {
32        &self.template_id
33    }
34
35    /// The key of the contract the client wants to exercise upon.
36    pub const fn contract_key(&self) -> &DamlValue {
37        &self.contract_key
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<DamlExerciseByKeyCommand> for Command {
54    fn from(daml_exercise_command: DamlExerciseByKeyCommand) -> Self {
55        Command::ExerciseByKey(ExerciseByKeyCommand {
56            template_id: Some(daml_exercise_command.template_id.into()),
57            contract_key: Some(daml_exercise_command.contract_key.into()),
58            choice: daml_exercise_command.choice,
59            choice_argument: Some(daml_exercise_command.choice_argument.into()),
60        })
61    }
62}