Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit ca379d7

Browse files
[contracts] Derive useful traits for public types (#14723)
* Types in the pallet * Primitives
1 parent 48d4313 commit ca379d7

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

frame/contracts/primitives/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#![cfg_attr(not(feature = "std"), no_std)]
2121

2222
use bitflags::bitflags;
23-
use codec::{Decode, Encode};
23+
use codec::{Decode, Encode, MaxEncodedLen};
2424
use scale_info::TypeInfo;
2525
use sp_runtime::{
2626
traits::{Saturating, Zero},
@@ -39,7 +39,7 @@ use sp_weights::Weight;
3939
/// It has been extended to include `events` at the end of the struct while not bumping the
4040
/// `ContractsApi` version. Therefore when SCALE decoding a `ContractResult` its trailing data
4141
/// should be ignored to avoid any potential compatibility issues.
42-
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
42+
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
4343
pub struct ContractResult<R, Balance, EventRecord> {
4444
/// How much weight was consumed during execution.
4545
pub gas_consumed: Weight,
@@ -99,7 +99,7 @@ pub type CodeUploadResult<CodeHash, Balance> =
9999
pub type GetStorageResult = Result<Option<Vec<u8>>, ContractAccessError>;
100100

101101
/// The possible errors that can happen querying the storage of a contract.
102-
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
102+
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
103103
pub enum ContractAccessError {
104104
/// The given address doesn't point to a contract.
105105
DoesntExist,
@@ -119,7 +119,7 @@ bitflags! {
119119
}
120120

121121
/// Output of a contract call or instantiation which ran to completion.
122-
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
122+
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
123123
pub struct ExecReturnValue {
124124
/// Flags passed along by `seal_return`. Empty when `seal_return` was never called.
125125
pub flags: ReturnFlags,
@@ -135,7 +135,7 @@ impl ExecReturnValue {
135135
}
136136

137137
/// The result of a successful contract instantiation.
138-
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
138+
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
139139
pub struct InstantiateReturnValue<AccountId> {
140140
/// The output of the called constructor.
141141
pub result: ExecReturnValue,
@@ -144,7 +144,7 @@ pub struct InstantiateReturnValue<AccountId> {
144144
}
145145

146146
/// The result of successfully uploading a contract.
147-
#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
147+
#[derive(Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)]
148148
pub struct CodeUploadReturnValue<CodeHash, Balance> {
149149
/// The key under which the new code is stored.
150150
pub code_hash: CodeHash,
@@ -153,7 +153,7 @@ pub struct CodeUploadReturnValue<CodeHash, Balance> {
153153
}
154154

155155
/// Reference to an existing code hash or a new wasm module.
156-
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
156+
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
157157
pub enum Code<Hash> {
158158
/// A wasm module as raw bytes.
159159
Upload(Vec<u8>),
@@ -162,7 +162,9 @@ pub enum Code<Hash> {
162162
}
163163

164164
/// The amount of balance that was either charged or refunded in order to pay for storage.
165-
#[derive(Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, Clone, TypeInfo)]
165+
#[derive(
166+
Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo,
167+
)]
166168
pub enum StorageDeposit<Balance> {
167169
/// The transaction reduced storage consumption.
168170
///

frame/contracts/src/exec.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,17 @@ pub trait Ext: sealing::Sealed {
346346
}
347347

348348
/// Describes the different functions that can be exported by an [`Executable`].
349-
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
349+
#[derive(
350+
Copy,
351+
Clone,
352+
PartialEq,
353+
Eq,
354+
sp_core::RuntimeDebug,
355+
codec::Decode,
356+
codec::Encode,
357+
codec::MaxEncodedLen,
358+
scale_info::TypeInfo,
359+
)]
350360
pub enum ExportedFunction {
351361
/// The constructor function which is executed on deployment of a contract.
352362
Constructor,

frame/contracts/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use crate::{
108108
storage::{meter::Meter as StorageMeter, ContractInfo, DeletionQueueManager},
109109
wasm::{CodeInfo, WasmBlob},
110110
};
111-
use codec::{Codec, Decode, Encode, HasCompact};
111+
use codec::{Codec, Decode, Encode, HasCompact, MaxEncodedLen};
112112
use environmental::*;
113113
use frame_support::{
114114
dispatch::{
@@ -122,7 +122,7 @@ use frame_support::{
122122
ConstU32, Contains, Get, Randomness, Time,
123123
},
124124
weights::Weight,
125-
BoundedVec, RuntimeDebugNoBound,
125+
BoundedVec, RuntimeDebug, RuntimeDebugNoBound,
126126
};
127127
use frame_system::{ensure_signed, pallet_prelude::OriginFor, EventRecord, Pallet as System};
128128
use pallet_contracts_primitives::{
@@ -1119,7 +1119,9 @@ struct InstantiateInput<T: Config> {
11191119
}
11201120

11211121
/// Determines whether events should be collected during execution.
1122-
#[derive(PartialEq)]
1122+
#[derive(
1123+
Copy, Clone, PartialEq, Eq, RuntimeDebug, Decode, Encode, MaxEncodedLen, scale_info::TypeInfo,
1124+
)]
11231125
pub enum CollectEvents {
11241126
/// Collect events.
11251127
///
@@ -1135,7 +1137,9 @@ pub enum CollectEvents {
11351137
}
11361138

11371139
/// Determines whether debug messages will be collected.
1138-
#[derive(PartialEq)]
1140+
#[derive(
1141+
Copy, Clone, PartialEq, Eq, RuntimeDebug, Decode, Encode, MaxEncodedLen, scale_info::TypeInfo,
1142+
)]
11391143
pub enum DebugInfo {
11401144
/// Collect debug messages.
11411145
/// # Note

0 commit comments

Comments
 (0)