common_primitives/
stateful_storage.rs1use crate::msa::{MessageSourceId, SchemaId};
2#[cfg(feature = "std")]
3use crate::utils;
4use parity_scale_codec::{Decode, Encode};
5use scale_info::TypeInfo;
6#[cfg(feature = "std")]
7use serde::{Deserialize, Serialize};
8extern crate alloc;
9use alloc::vec::Vec;
10#[cfg(feature = "std")]
11use utils::*;
12
13pub type PageId = u16;
15pub type PageHash = u32;
17pub type PageNonce = u16;
19
20#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
22#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
23pub struct PaginatedStorageResponse {
24 pub page_id: PageId,
26 pub msa_id: MessageSourceId,
28 pub schema_id: SchemaId,
30 pub content_hash: PageHash,
32 pub nonce: PageNonce,
34 #[cfg_attr(feature = "std", serde(with = "as_hex", default))]
36 pub payload: Vec<u8>,
37}
38
39#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
41#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
42pub struct ItemizedStoragePageResponse {
43 pub msa_id: MessageSourceId,
45 pub schema_id: SchemaId,
47 pub content_hash: PageHash,
49 pub nonce: PageNonce,
51 pub items: Vec<ItemizedStorageResponse>,
53}
54
55#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
57#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
58pub struct ItemizedStorageResponse {
59 pub index: u16,
61 #[cfg_attr(feature = "std", serde(with = "as_hex", default))]
63 pub payload: Vec<u8>,
64}
65
66impl PaginatedStorageResponse {
67 pub fn new(
69 index_number: u16,
70 msa_id: MessageSourceId,
71 schema_id: SchemaId,
72 content_hash: PageHash,
73 nonce: PageNonce,
74 payload: Vec<u8>,
75 ) -> Self {
76 PaginatedStorageResponse {
77 page_id: index_number,
78 msa_id,
79 schema_id,
80 payload,
81 content_hash,
82 nonce,
83 }
84 }
85}
86
87impl ItemizedStorageResponse {
88 pub fn new(index: u16, payload: Vec<u8>) -> Self {
90 ItemizedStorageResponse { index, payload }
91 }
92}
93
94impl ItemizedStoragePageResponse {
95 pub fn new(
97 msa_id: MessageSourceId,
98 schema_id: SchemaId,
99 content_hash: PageHash,
100 nonce: PageNonce,
101 items: Vec<ItemizedStorageResponse>,
102 ) -> Self {
103 ItemizedStoragePageResponse { msa_id, schema_id, content_hash, items, nonce }
104 }
105}