use crate::msa::MessageSourceId;
#[cfg(feature = "std")]
use crate::utils::*;
use frame_support::BoundedVec;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::ConstU32;
use sp_std::vec::Vec;
pub const HANDLE_CHARS_MIN: u32 = 3;
pub const HANDLE_BYTES_MIN: u32 = 1 * HANDLE_CHARS_MIN;
pub const HANDLE_CHARS_MAX: u32 = 20;
pub const HANDLE_BYTES_MAX: u32 = 32; pub const SUFFIX_MAX_DIGITS: usize = 5; pub const MAX_SUFFIXES_COUNT: u16 = 100;
pub const DEFAULT_SUFFIX_COUNT: u16 = 1;
type Handle = BoundedVec<u8, ConstU32<HANDLE_BYTES_MAX>>;
pub type BaseHandle = Handle;
pub type CanonicalBase = Handle;
pub type DisplayHandle =
BoundedVec<u8, ConstU32<{ HANDLE_BYTES_MAX + SUFFIX_MAX_DIGITS as u32 + 1u32 }>>;
pub type HandleSuffix = u16;
pub type SuffixRangeType = u16;
pub type SequenceIndex = u16;
#[derive(TypeInfo, Clone, Debug, Decode, Encode, PartialEq, Eq)]
pub struct ClaimHandlePayload<BlockNumber> {
pub base_handle: Vec<u8>,
pub expiration: BlockNumber,
}
impl<BlockNumber> ClaimHandlePayload<BlockNumber> {
pub fn new(base_handle: Vec<u8>, expiration: BlockNumber) -> Self {
ClaimHandlePayload { base_handle, expiration }
}
}
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
pub struct HandleResponse {
#[cfg_attr(feature = "std", serde(with = "as_string"))]
pub base_handle: Vec<u8>,
#[cfg_attr(feature = "std", serde(with = "as_string"))]
pub canonical_base: Vec<u8>,
pub suffix: HandleSuffix,
}
pub trait HandleProvider {
fn get_handle_for_msa(key: MessageSourceId) -> Option<HandleResponse>;
}
impl HandleProvider for () {
fn get_handle_for_msa(_key: MessageSourceId) -> Option<HandleResponse> {
None
}
}
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
pub struct PresumptiveSuffixesResponse {
#[cfg_attr(feature = "std", serde(with = "as_string"))]
pub base_handle: Vec<u8>,
pub suffixes: Vec<HandleSuffix>,
}