use canton_proto::com::daml::ledger::api::v2 as pb;
use crate::choice::Choice;
use crate::primitives::ContractId;
use crate::template::{Contract, Template, WithKey};
use crate::value::ToValue;
#[must_use]
pub fn create_command<T: Template>(payload: &T) -> pb::Command {
wrap(pb::command::Command::Create(pb::CreateCommand {
template_id: Some(T::template_id()),
create_arguments: Some(payload.to_record()),
}))
}
#[must_use]
pub fn exercise_command<T, C>(contract_id: &ContractId<T>, argument: &C) -> pb::Command
where
T: Contract,
C: Choice<T> + ToValue,
{
wrap(pb::command::Command::Exercise(pb::ExerciseCommand {
template_id: Some(T::template_id()),
contract_id: contract_id.as_str().to_string(),
choice: C::NAME.to_string(),
choice_argument: Some(argument.to_value()),
}))
}
#[must_use]
pub fn exercise_by_key_command<T, C>(key: &T::Key, argument: &C) -> pb::Command
where
T: WithKey,
C: Choice<T> + ToValue,
{
wrap(pb::command::Command::ExerciseByKey(
pb::ExerciseByKeyCommand {
template_id: Some(T::template_id()),
contract_key: Some(key.to_value()),
choice: C::NAME.to_string(),
choice_argument: Some(argument.to_value()),
},
))
}
fn wrap(command: pb::command::Command) -> pb::Command {
pb::Command {
command: Some(command),
}
}