use crate::msa::{MessageSourceId, SchemaId};
#[cfg(feature = "std")]
use crate::utils;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_std::prelude::*;
#[cfg(feature = "std")]
use utils::*;
pub type PageId = u16;
pub type PageHash = u32;
pub type PageNonce = u16;
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
pub struct PaginatedStorageResponse {
pub page_id: PageId,
pub msa_id: MessageSourceId,
pub schema_id: SchemaId,
pub content_hash: PageHash,
pub nonce: PageNonce,
#[cfg_attr(feature = "std", serde(with = "as_hex", default))]
pub payload: Vec<u8>,
}
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
pub struct ItemizedStoragePageResponse {
pub msa_id: MessageSourceId,
pub schema_id: SchemaId,
pub content_hash: PageHash,
pub nonce: PageNonce,
pub items: Vec<ItemizedStorageResponse>,
}
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Default, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
pub struct ItemizedStorageResponse {
pub index: u16,
#[cfg_attr(feature = "std", serde(with = "as_hex", default))]
pub payload: Vec<u8>,
}
impl PaginatedStorageResponse {
pub fn new(
index_number: u16,
msa_id: MessageSourceId,
schema_id: SchemaId,
content_hash: PageHash,
nonce: PageNonce,
payload: Vec<u8>,
) -> Self {
PaginatedStorageResponse {
page_id: index_number,
msa_id,
schema_id,
payload,
content_hash,
nonce,
}
}
}
impl ItemizedStorageResponse {
pub fn new(index: u16, payload: Vec<u8>) -> Self {
ItemizedStorageResponse { index, payload }
}
}
impl ItemizedStoragePageResponse {
pub fn new(
msa_id: MessageSourceId,
schema_id: SchemaId,
content_hash: PageHash,
nonce: PageNonce,
items: Vec<ItemizedStorageResponse>,
) -> Self {
ItemizedStoragePageResponse { msa_id, schema_id, content_hash, items, nonce }
}
}