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

contracts: Expose environment types for offchain tooling #14750

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ impl pallet_contracts::Config for Runtime {
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
#[cfg(feature = "unsafe-debug")]
type Debug = ();
type Environment = ();
}

impl pallet_sudo::Config for Runtime {
Expand Down
20 changes: 18 additions & 2 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub mod weights;
#[cfg(test)]
mod tests;
use crate::{
exec::{AccountIdOf, ErrorOrigin, ExecError, Executable, Key, Stack as ExecStack},
exec::{AccountIdOf, ErrorOrigin, ExecError, Executable, Key, Stack as ExecStack, MomentOf},
gas::GasMeter,
storage::{meter::Meter as StorageMeter, ContractInfo, DeletionQueueManager},
wasm::{CodeInfo, WasmBlob},
Expand All @@ -124,7 +124,7 @@ use frame_support::{
weights::Weight,
BoundedVec, RuntimeDebugNoBound,
};
use frame_system::{ensure_signed, pallet_prelude::OriginFor, EventRecord, Pallet as System};
use frame_system::{ensure_signed, pallet_prelude::{OriginFor, BlockNumberFor}, EventRecord, Pallet as System};
use pallet_contracts_primitives::{
Code, CodeUploadResult, CodeUploadReturnValue, ContractAccessError, ContractExecResult,
ContractInstantiateResult, ContractResult, ExecReturnValue, GetStorageResult,
Expand Down Expand Up @@ -179,6 +179,19 @@ const SENTINEL: u32 = u32::MAX;
/// Example: `RUST_LOG=runtime::contracts=debug my_code --dev`
const LOG_TARGET: &str = "runtime::contracts";


#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(Encode, Decode, Default, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct Environment<T: Config> {
account_id: PhantomData<AccountIdOf<T>>,
balance: PhantomData<BalanceOf<T>>,
hash: PhantomData<<T as frame_system::Config>::Hash>,
hasher: PhantomData<<T as frame_system::Config>::Hashing>,
timestamp: PhantomData<MomentOf<T>>,
block_number: PhantomData<BlockNumberFor<T>>,
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -360,6 +373,9 @@ pub mod pallet {
/// Do **not** use it in a production environment or for benchmarking purposes.
#[cfg(feature = "unsafe-debug")]
type Debug: unsafe_debug::UnsafeDebug<Self>;

#[pallet::constant]
type Environment: Get<Environment<Self>>;
}

#[pallet::hooks]
Expand Down
Loading