referrerpolicy=no-referrer-when-downgrade

polkadot_service/
fake_runtime_api.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Provides "fake" runtime API implementations
18//!
19//! These are used to provide a type that implements these runtime APIs without requiring to import
20//! the native runtimes.
21
22use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
23use polkadot_primitives::{
24	runtime_api, slashing, AccountId, AuthorityDiscoveryId, Balance, Block, BlockNumber,
25	CandidateCommitments, CandidateEvent, CandidateHash,
26	CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreState, DisputeState,
27	ExecutorParams, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage,
28	InboundHrmpMessage, Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement,
29	ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash,
30	ValidatorId, ValidatorIndex, ValidatorSignature,
31};
32use sp_consensus_beefy::ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature};
33use sp_consensus_grandpa::AuthorityId as GrandpaId;
34
35use sp_core::OpaqueMetadata;
36use sp_runtime::{
37	traits::Block as BlockT,
38	transaction_validity::{TransactionSource, TransactionValidity},
39	ApplyExtrinsicResult,
40};
41use sp_version::RuntimeVersion;
42use sp_weights::Weight;
43use std::collections::BTreeMap;
44use xcm::{
45	Version as XcmVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
46};
47sp_api::decl_runtime_apis! {
48	/// This runtime API is only implemented for the test runtime!
49	pub trait GetLastTimestamp {
50		/// Returns the last timestamp of a runtime.
51		fn get_last_timestamp() -> u64;
52	}
53}
54
55#[allow(dead_code)]
56struct Runtime;
57
58sp_api::impl_runtime_apis! {
59	impl sp_api::Core<Block> for Runtime {
60		fn version() -> RuntimeVersion {
61			unimplemented!()
62		}
63
64		fn execute_block(_: Block) {
65			unimplemented!()
66		}
67
68		fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
69			unimplemented!()
70		}
71	}
72
73	impl sp_api::Metadata<Block> for Runtime {
74		fn metadata() -> OpaqueMetadata {
75			unimplemented!()
76		}
77
78		fn metadata_at_version(_: u32) -> Option<OpaqueMetadata> {
79			unimplemented!()
80		}
81
82		fn metadata_versions() -> Vec<u32> {
83			unimplemented!()
84		}
85	}
86
87	impl sp_block_builder::BlockBuilder<Block> for Runtime {
88		fn apply_extrinsic(_: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
89			unimplemented!()
90		}
91
92		fn finalize_block() -> <Block as BlockT>::Header {
93			unimplemented!()
94		}
95
96		fn inherent_extrinsics(_: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
97			unimplemented!()
98		}
99
100		fn check_inherents(
101			_: Block,
102			_: sp_inherents::InherentData,
103		) -> sp_inherents::CheckInherentsResult {
104			unimplemented!()
105		}
106	}
107
108	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
109		fn validate_transaction(
110			_: TransactionSource,
111			_: <Block as BlockT>::Extrinsic,
112			_: <Block as BlockT>::Hash,
113		) -> TransactionValidity {
114			unimplemented!()
115		}
116	}
117
118	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
119		fn offchain_worker(_: &<Block as BlockT>::Header) {
120			unimplemented!()
121		}
122	}
123
124	impl runtime_api::ParachainHost<Block> for Runtime {
125		fn validators() -> Vec<ValidatorId> {
126			unimplemented!()
127		}
128
129		fn validator_groups() -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<BlockNumber>) {
130			unimplemented!()
131		}
132
133		fn availability_cores() -> Vec<CoreState<Hash, BlockNumber>> {
134			unimplemented!()
135		}
136
137		fn persisted_validation_data(_: ParaId, _: OccupiedCoreAssumption)
138			-> Option<PersistedValidationData<Hash, BlockNumber>> {
139			unimplemented!()
140		}
141
142		fn assumed_validation_data(
143			_: ParaId,
144			_: Hash,
145		) -> Option<(PersistedValidationData<Hash, BlockNumber>, ValidationCodeHash)> {
146			unimplemented!()
147		}
148
149		fn check_validation_outputs(
150			_: ParaId,
151			_: CandidateCommitments,
152		) -> bool {
153			unimplemented!()
154		}
155
156		fn session_index_for_child() -> SessionIndex {
157			unimplemented!()
158		}
159
160		fn validation_code(_: ParaId, _: OccupiedCoreAssumption)
161			-> Option<ValidationCode> {
162			unimplemented!()
163		}
164
165		fn candidate_pending_availability(_: ParaId) -> Option<CommittedCandidateReceipt<Hash>> {
166			unimplemented!()
167		}
168
169		fn candidate_events() -> Vec<CandidateEvent<Hash>> {
170			unimplemented!()
171		}
172
173		fn session_info(_: SessionIndex) -> Option<SessionInfo> {
174			unimplemented!()
175		}
176
177		fn session_executor_params(_: SessionIndex) -> Option<ExecutorParams> {
178			unimplemented!()
179		}
180
181		fn dmq_contents(_: ParaId) -> Vec<InboundDownwardMessage<BlockNumber>> {
182			unimplemented!()
183		}
184
185		fn inbound_hrmp_channels_contents(
186			_: ParaId
187		) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>> {
188			unimplemented!()
189		}
190
191		fn validation_code_by_hash(_: ValidationCodeHash) -> Option<ValidationCode> {
192			unimplemented!()
193		}
194
195		fn on_chain_votes() -> Option<ScrapedOnChainVotes<Hash>> {
196			unimplemented!()
197		}
198
199		fn submit_pvf_check_statement(
200			_: PvfCheckStatement,
201			_: ValidatorSignature,
202		) {
203			unimplemented!()
204		}
205
206		fn pvfs_require_precheck() -> Vec<ValidationCodeHash> {
207			unimplemented!()
208		}
209
210		fn validation_code_hash(_: ParaId, _: OccupiedCoreAssumption)
211			-> Option<ValidationCodeHash>
212		{
213			unimplemented!()
214		}
215
216		fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)> {
217			unimplemented!()
218		}
219
220		fn unapplied_slashes(
221		) -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)> {
222			unimplemented!()
223		}
224
225		fn key_ownership_proof(
226			_: ValidatorId,
227		) -> Option<slashing::OpaqueKeyOwnershipProof> {
228			unimplemented!()
229		}
230
231		fn submit_report_dispute_lost(
232			_: slashing::DisputeProof,
233			_: slashing::OpaqueKeyOwnershipProof,
234		) -> Option<()> {
235			unimplemented!()
236		}
237	}
238
239	impl sp_consensus_beefy::BeefyApi<Block, BeefyId> for Runtime {
240		fn beefy_genesis() -> Option<BlockNumber> {
241			unimplemented!()
242		}
243
244		fn validator_set() -> Option<sp_consensus_beefy::ValidatorSet<BeefyId>> {
245			unimplemented!()
246		}
247
248		fn submit_report_double_voting_unsigned_extrinsic(
249			_: sp_consensus_beefy::DoubleVotingProof<
250				BlockNumber,
251				BeefyId,
252				BeefySignature,
253			>,
254			_: sp_consensus_beefy::OpaqueKeyOwnershipProof,
255		) -> Option<()> {
256			unimplemented!()
257		}
258
259		fn submit_report_fork_voting_unsigned_extrinsic(
260			_: sp_consensus_beefy::ForkVotingProof<
261				<Block as BlockT>::Header,
262				BeefyId,
263				sp_runtime::OpaqueValue
264			>,
265			_: sp_consensus_beefy::OpaqueKeyOwnershipProof,
266		) -> Option<()> {
267			unimplemented!()
268		}
269
270		fn submit_report_future_block_voting_unsigned_extrinsic(
271			_: sp_consensus_beefy::FutureBlockVotingProof<BlockNumber, BeefyId>,
272			_: sp_consensus_beefy::OpaqueKeyOwnershipProof,
273		) -> Option<()> {
274			unimplemented!()
275		}
276
277		fn generate_key_ownership_proof(
278			_: sp_consensus_beefy::ValidatorSetId,
279			_: BeefyId,
280		) -> Option<sp_consensus_beefy::OpaqueKeyOwnershipProof> {
281			unimplemented!()
282		}
283
284		fn generate_ancestry_proof(
285			_: BlockNumber,
286			_: Option<BlockNumber>,
287		) -> Option<sp_runtime::OpaqueValue> {
288			unimplemented!()
289		}
290	}
291
292	impl sp_mmr_primitives::MmrApi<Block, Hash, BlockNumber> for Runtime {
293		fn mmr_root() -> Result<Hash, sp_mmr_primitives::Error> {
294			unimplemented!()
295		}
296
297		fn mmr_leaf_count() -> Result<sp_mmr_primitives::LeafIndex, sp_mmr_primitives::Error> {
298			unimplemented!()
299		}
300
301		fn generate_proof(
302			_: Vec<BlockNumber>,
303			_: Option<BlockNumber>,
304		) -> Result<(Vec<sp_mmr_primitives::EncodableOpaqueLeaf>, sp_mmr_primitives::LeafProof<Hash>), sp_mmr_primitives::Error> {
305			unimplemented!()
306		}
307
308		fn verify_proof(_: Vec<sp_mmr_primitives::EncodableOpaqueLeaf>, _: sp_mmr_primitives::LeafProof<Hash>)
309			-> Result<(), sp_mmr_primitives::Error>
310		{
311			unimplemented!()
312		}
313
314		fn verify_proof_stateless(
315			_: Hash,
316			_: Vec<sp_mmr_primitives::EncodableOpaqueLeaf>,
317			_: sp_mmr_primitives::LeafProof<Hash>
318		) -> Result<(), sp_mmr_primitives::Error> {
319			unimplemented!()
320		}
321	}
322
323	impl sp_consensus_grandpa::GrandpaApi<Block> for Runtime {
324		fn grandpa_authorities() -> Vec<(GrandpaId, u64)> {
325			unimplemented!()
326		}
327
328		fn current_set_id() -> sp_consensus_grandpa::SetId {
329			unimplemented!()
330		}
331
332		fn submit_report_equivocation_unsigned_extrinsic(
333			_: sp_consensus_grandpa::EquivocationProof<
334				<Block as BlockT>::Hash,
335				sp_runtime::traits::NumberFor<Block>,
336			>,
337			_: sp_consensus_grandpa::OpaqueKeyOwnershipProof,
338		) -> Option<()> {
339			unimplemented!()
340		}
341
342		fn generate_key_ownership_proof(
343			_: sp_consensus_grandpa::SetId,
344			_: sp_consensus_grandpa::AuthorityId,
345		) -> Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof> {
346			unimplemented!()
347		}
348	}
349
350	impl sp_consensus_babe::BabeApi<Block> for Runtime {
351		fn configuration() -> sp_consensus_babe::BabeConfiguration {
352			unimplemented!()
353		}
354
355		fn current_epoch_start() -> sp_consensus_babe::Slot {
356			unimplemented!()
357		}
358
359		fn current_epoch() -> sp_consensus_babe::Epoch {
360			unimplemented!()
361		}
362
363		fn next_epoch() -> sp_consensus_babe::Epoch {
364			unimplemented!()
365		}
366
367		fn generate_key_ownership_proof(
368			_: sp_consensus_babe::Slot,
369			_: sp_consensus_babe::AuthorityId,
370		) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> {
371			unimplemented!()
372		}
373
374		fn submit_report_equivocation_unsigned_extrinsic(
375			_: sp_consensus_babe::EquivocationProof<<Block as BlockT>::Header>,
376			_: sp_consensus_babe::OpaqueKeyOwnershipProof,
377		) -> Option<()> {
378			unimplemented!()
379		}
380	}
381
382	impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
383		fn authorities() -> Vec<AuthorityDiscoveryId> {
384			unimplemented!()
385		}
386	}
387
388	impl sp_session::SessionKeys<Block> for Runtime {
389		fn generate_session_keys(_: Option<Vec<u8>>) -> Vec<u8> {
390			unimplemented!()
391		}
392
393		fn decode_session_keys(
394			_: Vec<u8>,
395		) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
396			unimplemented!()
397		}
398	}
399
400	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
401		fn account_nonce(_: AccountId) -> Nonce {
402			unimplemented!()
403		}
404	}
405
406	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
407		Block,
408		Balance,
409	> for Runtime {
410		fn query_info(_: <Block as BlockT>::Extrinsic, _: u32) -> RuntimeDispatchInfo<Balance> {
411			unimplemented!()
412		}
413		fn query_fee_details(_: <Block as BlockT>::Extrinsic, _: u32) -> FeeDetails<Balance> {
414			unimplemented!()
415		}
416		fn query_weight_to_fee(_: Weight) -> Balance {
417			unimplemented!()
418		}
419		fn query_length_to_fee(_: u32) -> Balance {
420			unimplemented!()
421		}
422	}
423
424	impl crate::fake_runtime_api::GetLastTimestamp<Block> for Runtime {
425		fn get_last_timestamp() -> u64 {
426			unimplemented!()
427		}
428	}
429
430	impl xcm_runtime_apis::fees::XcmPaymentApi<Block> for Runtime {
431		fn query_acceptable_payment_assets(_: xcm::Version) -> Result<Vec<VersionedAssetId>, xcm_runtime_apis::fees::Error> {
432			unimplemented!()
433		}
434
435		fn query_weight_to_asset_fee(_: Weight, _: VersionedAssetId) -> Result<u128, xcm_runtime_apis::fees::Error> {
436			unimplemented!()
437		}
438
439		fn query_xcm_weight(_: VersionedXcm<()>) -> Result<Weight, xcm_runtime_apis::fees::Error> {
440			unimplemented!()
441		}
442
443		fn query_delivery_fees(_: VersionedLocation, _: VersionedXcm<()>) -> Result<VersionedAssets, xcm_runtime_apis::fees::Error> {
444			unimplemented!()
445		}
446	}
447
448	impl xcm_runtime_apis::dry_run::DryRunApi<Block, (), (), ()> for Runtime {
449		fn dry_run_call(_: (), _: (), _: XcmVersion) -> Result<xcm_runtime_apis::dry_run::CallDryRunEffects<()>, xcm_runtime_apis::dry_run::Error> {
450			unimplemented!()
451		}
452
453		fn dry_run_xcm(_: VersionedLocation, _: VersionedXcm<()>) -> Result<xcm_runtime_apis::dry_run::XcmDryRunEffects<()>, xcm_runtime_apis::dry_run::Error> {
454			unimplemented!()
455		}
456	}
457}