@@ -32,15 +32,16 @@ extern crate alloc;
3232
3333use alloc:: vec:: Vec ;
3434use codec:: { Decode , Encode , MaxEncodedLen } ;
35- use core:: result;
35+ use core:: { fmt :: Debug , result} ;
3636use frame_support:: {
3737 dispatch:: GetDispatchInfo ,
38+ pallet_prelude:: InvalidTransaction ,
3839 traits:: {
39- fungible:: { hold:: Balanced , Inspect , Mutate , MutateHold } ,
40- tokens:: fungible:: Credit ,
40+ fungible:: { hold:: Balanced , Credit , Inspect , Mutate , MutateHold } ,
4141 OnUnbalanced ,
4242 } ,
4343} ;
44+ use frame_system:: pallet_prelude:: BlockNumberFor ;
4445use sp_runtime:: traits:: { BlakeTwo256 , Dispatchable , Hash , One , Saturating , Zero } ;
4546use sp_transaction_storage_proof:: {
4647 encode_index, num_chunks, random_chunk, ChunkIndex , InherentError , TransactionStorageProof ,
@@ -56,25 +57,59 @@ pub type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, <T as Conf
5657pub use pallet:: * ;
5758pub use weights:: WeightInfo ;
5859
60+ // TODO: https://github.com/paritytech/polkadot-sdk/issues/10591 - Clarify purpose of allocator limits and decide whether to remove or use these constants.
5961/// Maximum bytes that can be stored in one transaction.
6062// Setting higher limit also requires raising the allocator limit.
6163pub const DEFAULT_MAX_TRANSACTION_SIZE : u32 = 8 * 1024 * 1024 ;
6264pub const DEFAULT_MAX_BLOCK_TRANSACTIONS : u32 = 512 ;
6365
66+ /// Encountered an impossible situation, implies a bug.
67+ pub const IMPOSSIBLE : InvalidTransaction = InvalidTransaction :: Custom ( 0 ) ;
68+ /// Data size is not in the allowed range.
69+ pub const BAD_DATA_SIZE : InvalidTransaction = InvalidTransaction :: Custom ( 1 ) ;
70+ /// Renewed extrinsic not found.
71+ pub const RENEWED_NOT_FOUND : InvalidTransaction = InvalidTransaction :: Custom ( 2 ) ;
72+ /// Authorization was not found.
73+ pub const AUTHORIZATION_NOT_FOUND : InvalidTransaction = InvalidTransaction :: Custom ( 3 ) ;
74+ /// Authorization has not expired.
75+ pub const AUTHORIZATION_NOT_EXPIRED : InvalidTransaction = InvalidTransaction :: Custom ( 4 ) ;
76+
77+ /// Number of transactions and bytes covered by an authorization.
78+ #[ derive( PartialEq , Eq , Debug , Encode , Decode , scale_info:: TypeInfo , MaxEncodedLen ) ]
79+ pub struct AuthorizationExtent {
80+ /// Number of transactions.
81+ pub transactions : u32 ,
82+ /// Number of bytes.
83+ pub bytes : u64 ,
84+ }
85+
6486/// Hash of a stored blob of data.
6587type ContentHash = [ u8 ; 32 ] ;
6688
89+ /// The scope of an authorization.
90+ #[ derive( Encode , Decode , scale_info:: TypeInfo , MaxEncodedLen ) ]
91+ enum AuthorizationScope < AccountId > {
92+ /// Authorization for the given account to store arbitrary data.
93+ Account ( AccountId ) ,
94+ /// Authorization for anyone to store data with a specific hash.
95+ Preimage ( ContentHash ) ,
96+ }
97+
98+ type AuthorizationScopeFor < T > = AuthorizationScope < <T as frame_system:: Config >:: AccountId > ;
99+
100+ /// An authorization to store data.
101+ #[ derive( Encode , Decode , scale_info:: TypeInfo , MaxEncodedLen ) ]
102+ struct Authorization < BlockNumber > {
103+ /// Extent of the authorization (number of transactions/bytes).
104+ extent : AuthorizationExtent ,
105+ /// The block at which this authorization expires.
106+ expiration : BlockNumber ,
107+ }
108+
109+ type AuthorizationFor < T > = Authorization < BlockNumberFor < T > > ;
110+
67111/// State data for a stored transaction.
68- #[ derive(
69- Encode ,
70- Decode ,
71- Clone ,
72- sp_runtime:: RuntimeDebug ,
73- PartialEq ,
74- Eq ,
75- scale_info:: TypeInfo ,
76- MaxEncodedLen ,
77- ) ]
112+ #[ derive( Encode , Decode , Clone , Debug , PartialEq , Eq , scale_info:: TypeInfo , MaxEncodedLen ) ]
78113pub struct TransactionInfo {
79114 /// Chunk trie root.
80115 chunk_root : <BlakeTwo256 as Hash >:: Output ,
@@ -86,7 +121,7 @@ pub struct TransactionInfo {
86121 /// is used to find transaction info by block chunk index using binary search.
87122 ///
88123 /// Cumulative value of all previous transactions in the block; the last transaction holds the
89- /// total chunks value .
124+ /// total chunks.
90125 block_chunks : ChunkIndex ,
91126}
92127
@@ -372,6 +407,11 @@ pub mod pallet {
372407 ExpiredPreimageAuthorizationRemoved { content_hash : ContentHash } ,
373408 }
374409
410+ /// Authorizations, keyed by scope.
411+ #[ pallet:: storage]
412+ pub ( super ) type Authorizations < T : Config > =
413+ StorageMap < _ , Blake2_128Concat , AuthorizationScopeFor < T > , AuthorizationFor < T > , OptionQuery > ;
414+
375415 /// Collection of transaction metadata by block number.
376416 #[ pallet:: storage]
377417 pub type Transactions < T : Config > = StorageMap <
0 commit comments