provwasm_stdv1/
types.rs

1use cosmwasm_std::{Addr, Binary, Coin, Decimal};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5/// Supported provenance module router keys.
6#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
7#[serde(rename_all = "snake_case")]
8pub enum ProvenanceRoute {
9    Attribute,
10    Marker,
11    Name,
12    Metadata,
13    Msgfees,
14}
15
16/// A collection of bound names.
17#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
18#[serde(rename_all = "snake_case")]
19pub struct Names {
20    pub records: Vec<Name>,
21}
22
23/// A name bound to an address.
24#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
25#[serde(rename_all = "snake_case")]
26pub struct Name {
27    pub name: String,
28    pub address: Addr,
29    pub restricted: bool,
30}
31
32/// A type for name bindings
33#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq, JsonSchema)]
34#[serde(rename_all = "snake_case")]
35pub enum NameBinding {
36    Restricted,
37    Unrestricted,
38}
39
40/// Bind names as restricted by default
41impl Default for NameBinding {
42    fn default() -> Self {
43        NameBinding::Restricted
44    }
45}
46
47/// A collection of attributes associated with an account address.
48#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
49#[serde(rename_all = "snake_case")]
50pub struct Attributes {
51    pub address: Addr,
52    #[serde(default)]
53    pub attributes: Vec<Attribute>,
54}
55
56/// Allowed attribute value types.
57#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
58#[serde(rename_all = "snake_case")]
59pub enum AttributeValueType {
60    Uuid,
61    Json,
62    String,
63    Bytes,
64    Uri,
65    Int,
66    Float,
67    Proto,
68    Unspecified,
69}
70
71/// A typed key-value pair.
72#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
73#[serde(rename_all = "snake_case")]
74pub struct Attribute {
75    pub name: String,
76    pub value: Binary,
77    #[serde(rename(serialize = "type", deserialize = "type"))]
78    pub value_type: AttributeValueType,
79}
80
81/// A marker account
82#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
83#[serde(rename_all = "snake_case")]
84pub struct Marker {
85    pub address: Addr,
86    #[serde(default)]
87    pub coins: Vec<Coin>,
88    pub account_number: u64,
89    pub sequence: u64,
90    #[serde(default)]
91    pub manager: String,
92    pub permissions: Vec<AccessGrant>,
93    pub status: MarkerStatus,
94    pub denom: String,
95    pub total_supply: Decimal,
96    pub marker_type: MarkerType,
97    pub supply_fixed: bool,
98}
99
100impl Marker {
101    /// Determines whether a marker requires restricted transfers.
102    pub fn bank_sends_disabled(&self) -> bool {
103        matches!(self.marker_type, MarkerType::Restricted)
104    }
105}
106
107/// Marker permissions granted to another account.
108#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
109#[serde(rename_all = "snake_case")]
110pub struct AccessGrant {
111    pub permissions: Vec<MarkerAccess>,
112    pub address: Addr,
113}
114
115/// Marker permission types.
116#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
117#[serde(rename_all = "snake_case")]
118pub enum MarkerAccess {
119    Admin,
120    Burn,
121    Deposit,
122    Delete,
123    Mint,
124    Transfer,
125    Unspecified,
126    Withdraw,
127    Freeze,
128    UnFreeze,
129    ForceTransfer,
130}
131
132impl MarkerAccess {
133    /// A helper that returns all permissions that can be granted.
134    pub fn all() -> Vec<MarkerAccess> {
135        vec![
136            MarkerAccess::Admin,
137            MarkerAccess::Burn,
138            MarkerAccess::Deposit,
139            MarkerAccess::Delete,
140            MarkerAccess::Mint,
141            MarkerAccess::Transfer,
142            MarkerAccess::Withdraw,
143            MarkerAccess::Freeze,
144            MarkerAccess::UnFreeze,
145            MarkerAccess::ForceTransfer,
146        ]
147    }
148}
149
150/// Marker types.
151#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
152#[serde(rename_all = "snake_case")]
153pub enum MarkerType {
154    Coin,
155    Restricted,
156    Unspecified,
157}
158
159/// Marker status types.
160#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
161#[serde(rename_all = "snake_case")]
162pub enum MarkerStatus {
163    Active,
164    Cancelled,
165    Destroyed,
166    Finalized,
167    Proposed,
168    Unspecified,
169}
170
171/// A collection of records owned by one or more parties.
172#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
173#[serde(rename_all = "snake_case")]
174pub struct Scope {
175    pub scope_id: String,
176    pub specification_id: String,
177    #[serde(default)]
178    pub owners: Vec<Party>,
179    #[serde(default)]
180    pub data_access: Vec<Addr>,
181    pub value_owner_address: Addr,
182}
183
184/// The final state of an execution context for a specification instance.
185#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
186#[serde(rename_all = "snake_case")]
187pub struct Session {
188    pub name: String,
189    pub session_id: String,
190    pub specification_id: String,
191    #[serde(default)]
192    pub parties: Vec<Party>,
193    pub context: Binary,
194}
195
196/// A group of sessions.
197#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
198#[serde(rename_all = "snake_case")]
199pub struct Sessions {
200    pub sessions: Vec<Session>,
201}
202
203/// A record of fact for a session.
204#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
205#[serde(rename_all = "snake_case")]
206pub struct Record {
207    pub name: String,
208    pub session_id: String,
209    pub specification_id: String,
210    pub process: Process,
211    #[serde(default)]
212    pub inputs: Vec<RecordInput>,
213    #[serde(default)]
214    pub outputs: Vec<RecordOutput>,
215}
216
217/// A group of records.
218#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
219#[serde(rename_all = "snake_case")]
220pub struct Records {
221    pub records: Vec<Record>,
222}
223
224/// An address with an associated role.
225#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
226#[serde(rename_all = "snake_case")]
227pub struct Party {
228    pub address: Addr,
229    pub role: PartyType,
230}
231
232/// Roles that can be associated to a party.
233#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
234#[serde(rename_all = "snake_case")]
235pub enum PartyType {
236    Originator,
237    Servicer,
238    Investor,
239    Custodian,
240    Owner,
241    Affiliate,
242    Omnibus,
243    Provenance,
244    Unspecified,
245}
246
247/// The process that generated a record.
248#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
249#[serde(rename_all = "snake_case")]
250pub struct Process {
251    pub process_id: ProcessId,
252    pub method: String,
253    pub name: String,
254}
255
256/// The representations of a process id.
257#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
258#[serde(rename_all = "snake_case")]
259pub enum ProcessId {
260    /// The on-chain address of a process.
261    Address { address: String },
262    /// The hash of an off-chain process.
263    Hash { hash: String },
264}
265
266/// The inputs used to produce a record.
267#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
268#[serde(rename_all = "snake_case")]
269pub struct RecordInput {
270    pub name: String,
271    pub type_name: String,
272    pub source: RecordInputSource,
273    pub status: RecordInputStatus,
274}
275
276/// The representations of a record input source.
277#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
278#[serde(rename_all = "snake_case")]
279pub enum RecordInputSource {
280    /// The address of a record on chain (established records).
281    Record { record_id: String },
282    /// The hash of an off-chain piece of information (proposed records).
283    Hash { hash: String },
284}
285
286/// Record input types.
287#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
288#[serde(rename_all = "snake_case")]
289pub enum RecordInputStatus {
290    Proposed,
291    Record,
292    Unspecified,
293}
294
295/// The output of a process recorded on chain.
296#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
297#[serde(rename_all = "snake_case")]
298pub struct RecordOutput {
299    pub hash: String,
300    pub status: ResultStatus,
301}
302
303/// Result status types.
304#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
305#[serde(rename_all = "snake_case")]
306pub enum ResultStatus {
307    Pass,
308    Skip,
309    Fail,
310    Unspecified,
311}