use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct DamlContractId(pub String);
impl DamlContractId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for DamlContractId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct DamlTemplateId {
pub package_id: String,
pub module_name: String,
pub entity_name: String,
}
impl DamlTemplateId {
pub fn new(
package_id: impl Into<String>,
module_name: impl Into<String>,
entity_name: impl Into<String>,
) -> Self {
Self {
package_id: package_id.into(),
module_name: module_name.into(),
entity_name: entity_name.into(),
}
}
pub fn qualified_name(&self) -> String {
format!("{}:{}:{}", self.package_id, self.module_name, self.entity_name)
}
}
impl std::fmt::Display for DamlTemplateId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}:{}", self.package_id, self.module_name, self.entity_name)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct DamlParty(pub String);
impl DamlParty {
pub fn new(party: impl Into<String>) -> Self {
Self(party.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for DamlParty {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct CantonSynchronizerId(pub String);
impl CantonSynchronizerId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for CantonSynchronizerId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
pub type CantonDomainId = CantonSynchronizerId;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", content = "value")]
pub enum DamlValue {
Record {
record_id: Option<DamlTemplateId>,
fields: Vec<(String, DamlValue)>,
},
Variant {
variant_id: Option<DamlTemplateId>,
constructor: String,
value: Box<DamlValue>,
},
List(Vec<DamlValue>),
Int64(i64),
Numeric(String),
Text(String),
Bool(bool),
Timestamp(i64),
Date(i32),
Party(DamlParty),
ContractId(DamlContractId),
Optional(Option<Box<DamlValue>>),
Map(Vec<(String, DamlValue)>),
Enum {
enum_id: Option<DamlTemplateId>,
constructor: String,
},
Unit,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "command_type")]
pub enum DamlCommand {
Create {
template_id: DamlTemplateId,
create_arguments: DamlValue,
},
Exercise {
template_id: DamlTemplateId,
contract_id: DamlContractId,
choice: String,
choice_argument: DamlValue,
},
CreateAndExercise {
template_id: DamlTemplateId,
create_arguments: DamlValue,
choice: String,
choice_argument: DamlValue,
},
ExerciseByKey {
template_id: DamlTemplateId,
contract_key: DamlValue,
choice: String,
choice_argument: DamlValue,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "event_type")]
pub enum DamlEvent {
Created {
event_id: String,
contract_id: DamlContractId,
template_id: DamlTemplateId,
create_arguments: DamlValue,
signatories: Vec<DamlParty>,
observers: Vec<DamlParty>,
},
Archived {
event_id: String,
contract_id: DamlContractId,
template_id: DamlTemplateId,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DamlTransaction {
pub transaction_id: String,
pub command_id: String,
pub workflow_id: Option<String>,
pub events: Vec<DamlEvent>,
pub effective_at: i64,
pub offset: String,
pub synchronizer_id: Option<CantonSynchronizerId>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CantonParticipantConfig {
pub host: String,
pub ledger_api_port: u16,
pub admin_api_port: u16,
pub use_tls: bool,
pub tls_cert_path: Option<String>,
pub act_as: Vec<DamlParty>,
pub read_as: Vec<DamlParty>,
pub application_id: String,
pub synchronizer_ids: Vec<CantonSynchronizerId>,
}
impl Default for CantonParticipantConfig {
fn default() -> Self {
Self {
host: "localhost".to_string(),
ledger_api_port: 5001,
admin_api_port: 5002,
use_tls: false,
tls_cert_path: None,
act_as: vec![],
read_as: vec![],
application_id: "tenzro-canton-participant".to_string(),
synchronizer_ids: vec![],
}
}
}
impl CantonParticipantConfig {
pub fn ledger_api_endpoint(&self) -> String {
let scheme = if self.use_tls { "https" } else { "http" };
format!("{}://{}:{}", scheme, self.host, self.ledger_api_port)
}
pub fn admin_api_endpoint(&self) -> String {
let scheme = if self.use_tls { "https" } else { "http" };
format!("{}://{}:{}", scheme, self.host, self.admin_api_port)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum CantonCommandStatus {
Accepted,
Committed,
Rejected { reason: String },
TimedOut,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DamlPackageInfo {
pub package_id: String,
pub package_name: Option<String>,
pub package_version: Option<String>,
pub size_bytes: u64,
pub modules: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum TopologyTransaction {
NamespaceDelegation {
namespace: String,
target_key: String,
is_root: bool,
},
PartyToParticipant {
party: DamlParty,
participant_id: String,
permission: ParticipantPermission,
},
OwnerToKeyMapping {
owner: String,
keys: Vec<String>,
},
VettedPackages {
participant_id: String,
package_ids: Vec<String>,
},
ParticipantSynchronizerPermission {
synchronizer_id: CantonSynchronizerId,
participant_id: String,
permission: ParticipantPermission,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ParticipantPermission {
Submission,
Confirmation,
Observation,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SynchronizerConfig {
pub synchronizer_id: CantonSynchronizerId,
pub sequencer_connections: Vec<String>,
pub is_global: bool,
pub finality_seconds: u32,
}
impl Default for SynchronizerConfig {
fn default() -> Self {
Self {
synchronizer_id: CantonSynchronizerId::new("default"),
sequencer_connections: vec!["http://localhost:5008".to_string()],
is_global: false,
finality_seconds: 5,
}
}
}