@@ -28,6 +28,7 @@ use frame_system::{
2828use loans:: { OnSlashHook , PostDeposit , PostTransfer , PreDeposit , PreTransfer } ;
2929use orml_asset_registry:: SequentialId ;
3030use orml_traits:: { currency:: MutationHooks , parameter_type_with_key} ;
31+ use pallet_contracts_primitives:: ContractResult ;
3132use pallet_transaction_payment:: { Multiplier , TargetedFeeAdjustment } ;
3233use sp_api:: impl_runtime_apis;
3334use sp_core:: { OpaqueMetadata , H256 } ;
@@ -2156,6 +2157,133 @@ impl_runtime_apis! {
21562157 )
21572158 }
21582159 }
2160+
2161+ impl pallet_contracts:: ContractsApi <Block , AccountId , Balance , BlockNumber , Hash > for Runtime {
2162+ fn call(
2163+ origin: AccountId ,
2164+ dest: AccountId ,
2165+ value: Balance ,
2166+ gas_limit: Option <Weight >,
2167+ storage_deposit_limit: Option <Balance >,
2168+ input_data: Vec <u8 >,
2169+ ) -> pallet_contracts_primitives:: ContractExecResult <Balance > {
2170+ if !contracts:: EnableContracts :: get( ) {
2171+ return ContractResult {
2172+ gas_consumed: Default :: default ( ) ,
2173+ gas_required: Default :: default ( ) ,
2174+ storage_deposit: Default :: default ( ) ,
2175+ debug_message: Default :: default ( ) ,
2176+ result: Err ( sp_runtime:: DispatchError :: Other ( "pallet_contracts is disabled" ) ) ,
2177+ } ;
2178+ }
2179+
2180+ let gas_limit = gas_limit. unwrap_or( RuntimeBlockWeights :: get( ) . max_block) ;
2181+ Contracts :: bare_call(
2182+ origin,
2183+ dest,
2184+ value,
2185+ gas_limit,
2186+ storage_deposit_limit,
2187+ input_data,
2188+ true ,
2189+ pallet_contracts:: Determinism :: Enforced ,
2190+ )
2191+ }
2192+
2193+ fn instantiate(
2194+ origin: AccountId ,
2195+ value: Balance ,
2196+ gas_limit: Option <Weight >,
2197+ storage_deposit_limit: Option <Balance >,
2198+ code: pallet_contracts_primitives:: Code <Hash >,
2199+ data: Vec <u8 >,
2200+ salt: Vec <u8 >,
2201+ ) -> pallet_contracts_primitives:: ContractInstantiateResult <AccountId , Balance > {
2202+ if !contracts:: EnableContracts :: get( ) {
2203+ return ContractResult {
2204+ gas_consumed: Default :: default ( ) ,
2205+ gas_required: Default :: default ( ) ,
2206+ storage_deposit: Default :: default ( ) ,
2207+ debug_message: Default :: default ( ) ,
2208+ result: Err ( sp_runtime:: DispatchError :: Other ( "pallet_contracts is disabled" ) ) ,
2209+ } ;
2210+ }
2211+
2212+ let gas_limit = gas_limit. unwrap_or( RuntimeBlockWeights :: get( ) . max_block) ;
2213+ Contracts :: bare_instantiate(
2214+ origin,
2215+ value,
2216+ gas_limit,
2217+ storage_deposit_limit,
2218+ code,
2219+ data,
2220+ salt,
2221+ true ,
2222+ )
2223+ }
2224+
2225+ fn upload_code(
2226+ origin: AccountId ,
2227+ code: Vec <u8 >,
2228+ storage_deposit_limit: Option <Balance >,
2229+ determinism: pallet_contracts:: Determinism ,
2230+ ) -> pallet_contracts_primitives:: CodeUploadResult <Hash , Balance >
2231+ {
2232+ if !contracts:: EnableContracts :: get( ) {
2233+ return Err ( sp_runtime:: DispatchError :: Other ( "pallet_contracts is disabled" ) ) ;
2234+ }
2235+ Contracts :: bare_upload_code( origin, code, storage_deposit_limit, determinism)
2236+ }
2237+
2238+ fn get_storage(
2239+ address: AccountId ,
2240+ key: Vec <u8 >,
2241+ ) -> pallet_contracts_primitives:: GetStorageResult {
2242+ Contracts :: get_storage( address, key)
2243+ }
2244+ }
2245+
2246+ // todo: enable this once we add contracts benchmarking
2247+ // #[cfg(feature = "runtime-benchmarks")]
2248+ // impl frame_benchmarking::Benchmark<Block> for Runtime {
2249+ // fn benchmark_metadata(extra: bool) -> (
2250+ // Vec<frame_benchmarking::BenchmarkList>,
2251+ // Vec<frame_support::traits::StorageInfo>,
2252+ // ) {
2253+ // use frame_benchmarking::{baseline, Benchmarking, BenchmarkList};
2254+ // use frame_support::traits::StorageInfoTrait;
2255+ // use frame_system_benchmarking::Pallet as SystemBench;
2256+ // use baseline::Pallet as BaselineBench;
2257+ //
2258+ // let mut list = Vec::<BenchmarkList>::new();
2259+ // list_benchmarks!(list, extra);
2260+ //
2261+ // let storage_info = AllPalletsWithSystem::storage_info();
2262+ //
2263+ // (list, storage_info)
2264+ // }
2265+ //
2266+ // fn dispatch_benchmark(
2267+ // config: frame_benchmarking::BenchmarkConfig
2268+ // ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
2269+ // use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey};
2270+ // use frame_system_benchmarking::Pallet as SystemBench;
2271+ // use baseline::Pallet as BaselineBench;
2272+ //
2273+ // impl frame_system_benchmarking::Config for Runtime {}
2274+ // impl baseline::Config for Runtime {}
2275+ //
2276+ // use frame_support::traits::WhitelistedStorageKeys;
2277+ // let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
2278+ //
2279+ // let mut batches = Vec::<BenchmarkBatch>::new();
2280+ // let params = (&config, &whitelist);
2281+ // add_benchmarks!(params, batches);
2282+ //
2283+ // if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
2284+ // Ok(batches)
2285+ // }
2286+ // }
21592287}
21602288
21612289struct CheckInherents ;
0 commit comments