1use crate::msa::MessageSourceId;
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 crate::schema::{IntentId, SchemaId};
10use alloc::vec::Vec;
11#[cfg(feature = "std")]
12use utils::*;
13
14pub type PageId = u16;
16pub type PageHash = u32;
18pub type PageNonce = u16;
20
21#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
24#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
25pub struct PaginatedStorageResponse {
26 pub page_id: PageId,
28 pub msa_id: MessageSourceId,
30 pub schema_id: SchemaId,
32 pub content_hash: PageHash,
34 pub nonce: PageNonce,
36 #[cfg_attr(feature = "std", serde(with = "as_hex", default))]
38 pub payload: Vec<u8>,
39}
40
41#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
43#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
44pub struct PaginatedStorageResponseV2 {
45 pub intent_id: IntentId,
47 pub page_id: PageId,
49 pub msa_id: MessageSourceId,
51 pub schema_id: SchemaId,
53 pub content_hash: PageHash,
55 pub nonce: PageNonce,
57 #[cfg_attr(feature = "std", serde(with = "as_hex", default))]
59 pub payload: Vec<u8>,
60}
61
62#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
65#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
66pub struct ItemizedStoragePageResponse {
67 pub msa_id: MessageSourceId,
69 pub schema_id: SchemaId,
71 pub content_hash: PageHash,
73 pub nonce: PageNonce,
75 pub items: Vec<ItemizedStorageResponse>,
77}
78
79#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
81#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
82pub struct ItemizedStoragePageResponseV2 {
83 pub msa_id: MessageSourceId,
85 pub intent_id: IntentId,
87 pub content_hash: PageHash,
89 pub nonce: PageNonce,
91 pub items: Vec<ItemizedStorageResponseV2>,
93}
94
95#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
98#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
99pub struct ItemizedStorageResponse {
100 pub index: u16,
102 #[cfg_attr(feature = "std", serde(with = "as_hex", default))]
104 pub payload: Vec<u8>,
105}
106
107#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
109#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
110pub struct ItemizedStorageResponseV2 {
111 pub index: u16,
113 pub schema_id: SchemaId,
115 #[cfg_attr(feature = "std", serde(with = "as_hex", default))]
117 pub payload: Vec<u8>,
118}
119
120impl PaginatedStorageResponseV2 {
121 pub fn new(
123 index_number: u16,
124 msa_id: MessageSourceId,
125 intent_id: IntentId,
126 schema_id: SchemaId,
127 content_hash: PageHash,
128 nonce: PageNonce,
129 payload: Vec<u8>,
130 ) -> Self {
131 PaginatedStorageResponseV2 {
132 page_id: index_number,
133 msa_id,
134 intent_id,
135 schema_id,
136 payload,
137 content_hash,
138 nonce,
139 }
140 }
141}
142
143impl Into<PaginatedStorageResponse> for PaginatedStorageResponseV2 {
144 fn into(self) -> PaginatedStorageResponse {
145 PaginatedStorageResponse {
146 page_id: self.page_id,
147 msa_id: self.msa_id,
148 schema_id: self.schema_id,
149 payload: self.payload,
150 content_hash: self.content_hash,
151 nonce: self.nonce,
152 }
153 }
154}
155
156impl ItemizedStorageResponseV2 {
157 pub fn new(index: u16, schema_id: SchemaId, payload: Vec<u8>) -> Self {
159 ItemizedStorageResponseV2 { index, schema_id, payload }
160 }
161}
162
163impl Into<ItemizedStorageResponse> for ItemizedStorageResponseV2 {
164 fn into(self) -> ItemizedStorageResponse {
165 ItemizedStorageResponse { index: self.index, payload: self.payload }
166 }
167}
168
169impl ItemizedStoragePageResponseV2 {
170 pub fn new(
172 msa_id: MessageSourceId,
173 intent_id: IntentId,
174 content_hash: PageHash,
175 nonce: PageNonce,
176 items: Vec<ItemizedStorageResponseV2>,
177 ) -> Self {
178 ItemizedStoragePageResponseV2 { msa_id, intent_id, content_hash, items, nonce }
179 }
180}
181
182impl Into<ItemizedStoragePageResponse> for ItemizedStoragePageResponseV2 {
183 fn into(self) -> ItemizedStoragePageResponse {
184 ItemizedStoragePageResponse {
185 msa_id: self.msa_id,
186 schema_id: self.items.get(0).map(|item| item.schema_id).unwrap_or(0),
187 content_hash: self.content_hash,
188 nonce: self.nonce,
189 items: self.items.into_iter().map(|item| item.into()).collect(),
190 }
191 }
192}