daml_json/
data.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4/// Daml JSON API representation of a ledger event.
5#[derive(Debug, Serialize, Deserialize)]
6pub enum DamlJsonEvent {
7    #[serde(rename = "created")]
8    Created(DamlJsonCreatedEvent),
9    #[serde(rename = "archived")]
10    Archived(DamlJsonArchivedEvent),
11}
12
13/// Daml JSON API representation of a ledger contract created event.
14#[derive(Debug, Serialize, Deserialize)]
15pub struct DamlJsonCreatedEvent {
16    pub observers: Vec<String>,
17    #[serde(rename = "agreementText")]
18    pub agreement_text: String,
19    pub payload: Value,
20    pub signatories: Vec<String>,
21    #[serde(rename = "contractId")]
22    pub contract_id: String,
23    #[serde(rename = "templateId")]
24    pub template_id: String,
25}
26
27impl DamlJsonCreatedEvent {
28    pub fn new(
29        observers: Vec<String>,
30        agreement_text: String,
31        payload: Value,
32        signatories: Vec<String>,
33        contract_id: String,
34        template_id: impl Into<String>,
35    ) -> Self {
36        Self {
37            observers,
38            agreement_text,
39            payload,
40            signatories,
41            contract_id,
42            template_id: template_id.into(),
43        }
44    }
45}
46
47/// Daml JSON API representation of a ledger contract archived event.
48#[derive(Debug, Serialize, Deserialize)]
49pub struct DamlJsonArchivedEvent {
50    #[serde(rename = "contractId")]
51    pub contract_id: String,
52    #[serde(rename = "templateId")]
53    pub template_id: String,
54}
55
56impl DamlJsonArchivedEvent {
57    pub const fn new(contract_id: String, template_id: String) -> Self {
58        Self {
59            contract_id,
60            template_id,
61        }
62    }
63}
64
65/// Daml JSON API representation of a ledger exercise result.
66#[derive(Debug, Serialize, Deserialize)]
67pub struct DamlJsonExerciseResult {
68    #[serde(rename = "exerciseResult")]
69    pub exercise_result: Value,
70    pub events: Vec<DamlJsonEvent>,
71}
72
73/// Daml JSON API representation of a ledger Party.
74#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
75pub struct DamlJsonParty {
76    pub identifier: String,
77    #[serde(rename = "displayName")]
78    pub display_name: Option<String>,
79    #[serde(rename = "isLocal")]
80    pub is_local: bool,
81}
82
83impl DamlJsonParty {
84    pub fn new<S: Into<String>>(identifier: impl Into<String>, display_name: Option<S>, is_local: bool) -> Self {
85        Self {
86            identifier: identifier.into(),
87            display_name: display_name.map(Into::into),
88            is_local,
89        }
90    }
91}
92
93/// Daml JSON API representation of a query.
94#[derive(Debug, Serialize, Deserialize)]
95pub struct DamlJsonQuery {
96    #[serde(rename = "templateIds")]
97    pub template_ids: Vec<String>,
98    pub query: Value,
99}
100
101impl DamlJsonQuery {
102    pub fn new(template_ids: Vec<String>, query: Value) -> Self {
103        Self {
104            template_ids,
105            query,
106        }
107    }
108}