[contracts] Derive useful traits for public types (#14723)

* Types in the pallet

* Primitives
This commit is contained in:
Piotr Mikołajczyk
2023-08-14 11:30:42 +02:00
committed by GitHub
parent adb9f6d71a
commit 90270c91c3
3 changed files with 29 additions and 13 deletions
@@ -20,7 +20,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use bitflags::bitflags;
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{Saturating, Zero},
@@ -39,7 +39,7 @@ use sp_weights::Weight;
/// It has been extended to include `events` at the end of the struct while not bumping the
/// `ContractsApi` version. Therefore when SCALE decoding a `ContractResult` its trailing data
/// should be ignored to avoid any potential compatibility issues.
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct ContractResult<R, Balance, EventRecord> {
/// How much weight was consumed during execution.
pub gas_consumed: Weight,
@@ -99,7 +99,7 @@ pub type CodeUploadResult<CodeHash, Balance> =
pub type GetStorageResult = Result<Option<Vec<u8>>, ContractAccessError>;
/// The possible errors that can happen querying the storage of a contract.
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub enum ContractAccessError {
/// The given address doesn't point to a contract.
DoesntExist,
@@ -119,7 +119,7 @@ bitflags! {
}
/// Output of a contract call or instantiation which ran to completion.
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct ExecReturnValue {
/// Flags passed along by `seal_return`. Empty when `seal_return` was never called.
pub flags: ReturnFlags,
@@ -135,7 +135,7 @@ impl ExecReturnValue {
}
/// The result of a successful contract instantiation.
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct InstantiateReturnValue<AccountId> {
/// The output of the called constructor.
pub result: ExecReturnValue,
@@ -144,7 +144,7 @@ pub struct InstantiateReturnValue<AccountId> {
}
/// The result of successfully uploading a contract.
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
pub struct CodeUploadReturnValue<CodeHash, Balance> {
/// The key under which the new code is stored.
pub code_hash: CodeHash,
@@ -153,7 +153,7 @@ pub struct CodeUploadReturnValue<CodeHash, Balance> {
}
/// Reference to an existing code hash or a new wasm module.
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub enum Code<Hash> {
/// A wasm module as raw bytes.
Upload(Vec<u8>),
@@ -162,7 +162,9 @@ pub enum Code<Hash> {
}
/// The amount of balance that was either charged or refunded in order to pay for storage.
#[derive(Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, Clone, TypeInfo)]
#[derive(
Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo,
)]
pub enum StorageDeposit<Balance> {
/// The transaction reduced storage consumption.
///
+11 -1
View File
@@ -346,7 +346,17 @@ pub trait Ext: sealing::Sealed {
}
/// Describes the different functions that can be exported by an [`Executable`].
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[derive(
Copy,
Clone,
PartialEq,
Eq,
sp_core::RuntimeDebug,
codec::Decode,
codec::Encode,
codec::MaxEncodedLen,
scale_info::TypeInfo,
)]
pub enum ExportedFunction {
/// The constructor function which is executed on deployment of a contract.
Constructor,
+8 -4
View File
@@ -108,7 +108,7 @@ use crate::{
storage::{meter::Meter as StorageMeter, ContractInfo, DeletionQueueManager},
wasm::{CodeInfo, WasmBlob},
};
use codec::{Codec, Decode, Encode, HasCompact};
use codec::{Codec, Decode, Encode, HasCompact, MaxEncodedLen};
use environmental::*;
use frame_support::{
dispatch::{
@@ -122,7 +122,7 @@ use frame_support::{
ConstU32, Contains, Get, Randomness, Time,
},
weights::Weight,
BoundedVec, RuntimeDebugNoBound,
BoundedVec, RuntimeDebug, RuntimeDebugNoBound,
};
use frame_system::{ensure_signed, pallet_prelude::OriginFor, EventRecord, Pallet as System};
use pallet_contracts_primitives::{
@@ -1119,7 +1119,9 @@ struct InstantiateInput<T: Config> {
}
/// Determines whether events should be collected during execution.
#[derive(PartialEq)]
#[derive(
Copy, Clone, PartialEq, Eq, RuntimeDebug, Decode, Encode, MaxEncodedLen, scale_info::TypeInfo,
)]
pub enum CollectEvents {
/// Collect events.
///
@@ -1135,7 +1137,9 @@ pub enum CollectEvents {
}
/// Determines whether debug messages will be collected.
#[derive(PartialEq)]
#[derive(
Copy, Clone, PartialEq, Eq, RuntimeDebug, Decode, Encode, MaxEncodedLen, scale_info::TypeInfo,
)]
pub enum DebugInfo {
/// Collect debug messages.
/// # Note