tx3_sdk/tii/spec.rs
1use schemars::schema::Schema;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5use crate::core::TirEnvelope;
6
7/// Root structure for TII (Transaction Invocation Interface) JSON files.
8///
9/// This structure represents the complete contents of a TII file, which defines
10/// a TX3 protocol including its transactions, parties, profiles, and configuration.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct TiiFile {
13 /// TII specification version information.
14 pub tii: TiiInfo,
15
16 /// Protocol metadata (name, version, description).
17 pub protocol: Protocol,
18
19 /// Optional JSON schema for environment parameters.
20 #[serde(default, skip_serializing_if = "Option::is_none")]
21 pub environment: Option<Schema>,
22
23 /// Map of party names to their definitions.
24 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
25 pub parties: HashMap<String, Party>,
26
27 /// Map of transaction names to their definitions.
28 pub transactions: HashMap<String, Transaction>,
29
30 /// Map of profile names to their environment configurations.
31 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
32 pub profiles: HashMap<String, Profile>,
33
34 /// Optional reusable components (schemas, etc.).
35 #[serde(default, skip_serializing_if = "Option::is_none")]
36 pub components: Option<Components>,
37}
38
39/// TII version information.
40///
41/// Specifies the version of the TII specification used by this file.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct TiiInfo {
44 /// The TII specification version (e.g., "1.0.0").
45 pub version: String,
46}
47
48/// Protocol metadata.
49///
50/// Contains descriptive information about the TX3 protocol.
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct Protocol {
53 /// The protocol name.
54 pub name: String,
55
56 /// The protocol version.
57 pub version: String,
58
59 /// The protocol scope (e.g., "mainnet", "public").
60 #[serde(default)]
61 pub scope: String,
62
63 /// Optional protocol description.
64 #[serde(skip_serializing_if = "Option::is_none")]
65 pub description: Option<String>,
66}
67
68/// Transaction definition.
69///
70/// Defines a single transaction within a TX3 protocol, including its
71/// intermediate representation and parameter schema.
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct Transaction {
74 /// The Transaction Intermediate Representation envelope.
75 pub tir: TirEnvelope,
76
77 /// JSON schema defining the transaction parameters.
78 pub params: Schema,
79
80 /// Optional transaction description.
81 #[serde(skip_serializing_if = "Option::is_none")]
82 pub description: Option<String>,
83}
84
85/// Party definition.
86///
87/// Represents a participant in a TX3 protocol (e.g., sender, receiver).
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct Party {
90 /// Optional party description.
91 #[serde(default, skip_serializing_if = "Option::is_none")]
92 pub description: Option<String>,
93}
94
95/// Environment profile definition.
96///
97/// Profiles allow pre-configuration of environment-specific values for different
98/// networks or contexts (mainnet, preview, testnet, etc.).
99#[derive(Debug, Clone, Serialize, Deserialize, Default)]
100pub struct Profile {
101 /// Optional profile description.
102 #[serde(skip_serializing_if = "Option::is_none")]
103 pub description: Option<String>,
104
105 /// Environment variables as JSON object.
106 #[serde(default)]
107 pub environment: serde_json::Value,
108
109 /// Party addresses for this profile.
110 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
111 pub parties: HashMap<String, String>,
112}
113
114/// Components section containing reusable schemas.
115///
116/// This section defines reusable components that can be referenced
117/// throughout the TII file.
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct Components {
120 /// Map of reusable JSON schemas.
121 #[serde(skip_serializing_if = "HashMap::is_empty")]
122 pub schemas: HashMap<String, Schema>,
123}