pallet_messages/migration/v2/
mod.rs

1use crate::{Config, MessageIndex, Pallet};
2use common_primitives::{msa::MessageSourceId, schema::SchemaId};
3use core::fmt::Debug;
4use frame_support::{pallet_prelude::*, storage_alias};
5use frame_system::pallet_prelude::BlockNumberFor;
6use sp_runtime::codec::{Decode, Encode};
7
8// Type aliases for readability
9#[allow(type_alias_bounds)]
10pub(crate) type K1Type<T: Config> = BlockNumberFor<T>;
11#[allow(type_alias_bounds)]
12pub(crate) type K2Type = SchemaId;
13#[allow(type_alias_bounds)]
14pub(crate) type K3Type = MessageIndex;
15
16/// Storage for messages in v2 and lower
17/// - Key: (block_number, schema_id, message_index)
18/// - Value: Message
19#[storage_alias]
20pub(crate) type MessagesV2<T: Config> = StorageNMap<
21	Pallet<T>,
22	(
23		storage::Key<Twox64Concat, K1Type<T>>,
24		storage::Key<Twox64Concat, K2Type>,
25		storage::Key<Twox64Concat, K3Type>,
26	),
27	Message<<T as Config>::MessagesMaxPayloadSizeBytes>,
28	OptionQuery,
29>;
30
31/// Ephemeral storage key for tracking the completion status of the migration
32/// in order to perform the final step and for try-runtime. MUST be killed at
33/// the end of the migration!
34#[storage_alias]
35pub(crate) type DoneV3Migration<T: Config> = StorageValue<Pallet<T>, bool, ValueQuery>;
36
37/// A single message type definition for V2 storage
38#[derive(Clone, Default, Encode, Decode, PartialEq, Debug, TypeInfo, Eq, MaxEncodedLen)]
39#[scale_info(skip_type_params(MaxDataSize))]
40#[codec(mel_bound(MaxDataSize: MaxEncodedLen))]
41pub struct Message<MaxDataSize>
42where
43	MaxDataSize: Get<u32> + Debug,
44{
45	///  Data structured by the associated schema's model.
46	pub payload: BoundedVec<u8, MaxDataSize>,
47	/// Message source account id of the Provider. This may be the same id as contained in `msa_id`,
48	/// indicating that the original source MSA is acting as its own provider. An id differing from that
49	/// of `msa_id` indicates that `provider_msa_id` was delegated by `msa_id` to send this message on
50	/// its behalf.
51	pub provider_msa_id: MessageSourceId,
52	///  Message source account id (the original source).
53	pub msa_id: Option<MessageSourceId>,
54}