siera_agent/modules/
schema.rs

1use crate::error::Result;
2use async_trait::async_trait;
3use serde::{Deserialize, Serialize};
4
5/// Schema response from the ledger
6#[derive(Debug, Deserialize, Serialize, Default)]
7pub struct Schema {
8    /// Version of the schema
9    pub ver: String,
10
11    /// Id of the schema
12    pub id: String,
13
14    /// Name of the schema
15    pub name: String,
16
17    /// Version of the schema
18    pub version: String,
19
20    /// Names of the attributes registered with the schema
21    #[serde(rename(deserialize = "attrNames"))]
22    pub attr_names: Vec<String>,
23
24    /// seqNo as on the ledger that is unique to each schema
25    #[serde(rename(deserialize = "seqNo"))]
26    pub seq_no: Option<i32>,
27}
28
29/// Options supplied by the frontend to create a schema
30#[derive(Debug, Serialize)]
31pub struct SchemaCreateOptions {
32    /// The name of the schema
33    pub name: String,
34
35    /// The version of the schema
36    pub version: String,
37
38    /// The attributed that must be registered with the schema
39    pub attributes: Vec<String>,
40}
41
42/// Response from the cloudagent when requesting every schema
43/// the cloudagent has registered
44#[derive(Debug, Deserialize, Serialize)]
45pub struct SchemasGetAllResponse {
46    /// List of all the ids of every schema that the cloudagent has registered
47    pub schema_ids: Vec<String>,
48}
49
50/// Generic cloudagent schema module
51#[async_trait]
52pub trait SchemaModule {
53    /// Create a schema on the ledger
54    async fn create(&self, options: SchemaCreateOptions) -> Result<Schema>;
55
56    /// Request the schema by the id
57    async fn get_by_id(&self, id: String) -> Result<Schema>;
58
59    /// Get all the registerd schemas
60    async fn get_all(&self) -> Result<SchemasGetAllResponse>;
61}