subspace_fake_runtime_api/
lib.rs

1//! Provides "fake" runtime API implementation as a workaround for compile-time checks.
2
3use domain_runtime_primitives::opaque::Header as DomainHeader;
4use domain_runtime_primitives::{
5    BlockNumber as DomainNumber, EthereumAccountId, Hash as DomainHash,
6};
7use frame_support::weights::Weight;
8use sp_consensus_subspace::{ChainConstants, PotParameters, SignedVote, SolutionRanges};
9use sp_core::crypto::KeyTypeId;
10use sp_core::{OpaqueMetadata, H256};
11use sp_domains::bundle_producer_election::BundleProducerElectionParams;
12use sp_domains::{
13    DomainAllowlistUpdates, DomainId, DomainInstanceData, ExecutionReceiptFor, OperatorId,
14    OperatorPublicKey, PermissionedActionAllowedBy,
15};
16use sp_domains_fraud_proof::fraud_proof::FraudProof;
17use sp_domains_fraud_proof::storage_proof::FraudProofStorageKeyRequest;
18use sp_messenger::messages::{
19    BlockMessagesWithStorageKey, ChainId, ChannelId, CrossDomainMessage, MessageId, MessageKey,
20};
21use sp_messenger::{ChannelNonce, XdmId};
22use sp_runtime::traits::NumberFor;
23use sp_runtime::transaction_validity::{TransactionSource, TransactionValidity};
24use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode};
25use sp_subspace_mmr::ConsensusChainMmrLeafProof;
26use sp_version::RuntimeVersion;
27use std::collections::btree_map::BTreeMap;
28use std::collections::btree_set::BTreeSet;
29use subspace_core_primitives::objects::BlockObjectMapping;
30use subspace_core_primitives::segments::{
31    HistorySize, SegmentCommitment, SegmentHeader, SegmentIndex,
32};
33use subspace_core_primitives::{PublicKey, Randomness, U256};
34use subspace_runtime_primitives::opaque::Block;
35use subspace_runtime_primitives::{
36    AccountId, Balance, BlockHashFor, BlockNumber, ExtrinsicFor, HeaderFor, Moment, Nonce,
37};
38
39mod mmr {
40    pub use pallet_mmr::primitives::*;
41    use sp_core::H256;
42    // Full type for this is actually `<<Runtime as pallet_mmr::Config>::Hashing as sp_runtime::traits::Hash>::Output`
43    // but since we don't really want to impl pallet for the fake runtime, we just use the `Keccak256::Output = H256`
44    pub type Hash = H256;
45}
46
47struct Runtime;
48
49sp_api::impl_runtime_apis! {
50    impl sp_api::Core<Block> for Runtime {
51        fn version() -> RuntimeVersion {
52            unreachable!()
53        }
54
55        fn execute_block(_block: Block) {
56            unreachable!()
57        }
58
59        fn initialize_block(_header: &HeaderFor<Block>) -> ExtrinsicInclusionMode {
60            unreachable!()
61        }
62    }
63
64    impl sp_api::Metadata<Block> for Runtime {
65        fn metadata() -> OpaqueMetadata {
66            unreachable!()
67        }
68
69        fn metadata_at_version(_version: u32) -> Option<OpaqueMetadata> {
70            unreachable!()
71        }
72
73        fn metadata_versions() -> Vec<u32> {
74            unreachable!()
75        }
76    }
77
78    impl sp_block_builder::BlockBuilder<Block> for Runtime {
79        fn apply_extrinsic(_extrinsic: ExtrinsicFor<Block>) -> ApplyExtrinsicResult {
80            unreachable!()
81        }
82
83        fn finalize_block() -> HeaderFor<Block> {
84            unreachable!()
85        }
86
87        fn inherent_extrinsics(_data: sp_inherents::InherentData) -> Vec<ExtrinsicFor<Block>> {
88            unreachable!()
89        }
90
91        fn check_inherents(
92            _block: Block,
93            _data: sp_inherents::InherentData,
94        ) -> sp_inherents::CheckInherentsResult {
95            unreachable!()
96        }
97    }
98
99    impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
100        fn validate_transaction(
101            _source: TransactionSource,
102            _tx: ExtrinsicFor<Block>,
103            _block_hash: BlockHashFor<Block>,
104        ) -> TransactionValidity {
105            unreachable!()
106        }
107    }
108
109    impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
110        fn offchain_worker(_header: &HeaderFor<Block>) {
111            unreachable!()
112        }
113    }
114
115    impl sp_objects::ObjectsApi<Block> for Runtime {
116        fn extract_block_object_mapping(_block: Block) -> BlockObjectMapping {
117            unreachable!()
118        }
119    }
120
121    impl sp_consensus_subspace::SubspaceApi<Block, PublicKey> for Runtime {
122        fn pot_parameters() -> PotParameters {
123            unreachable!()
124        }
125
126        fn solution_ranges() -> SolutionRanges {
127            unreachable!()
128        }
129
130        fn submit_vote_extrinsic(
131            _signed_vote: SignedVote<NumberFor<Block>, BlockHashFor<Block>, PublicKey>,
132        ) {
133            unreachable!()
134        }
135
136        fn history_size() -> HistorySize {
137            unreachable!()
138        }
139
140        fn max_pieces_in_sector() -> u16 {
141            unreachable!()
142        }
143
144        fn segment_commitment(_segment_index: SegmentIndex) -> Option<SegmentCommitment> {
145            unreachable!()
146        }
147
148        fn extract_segment_headers(_ext: &ExtrinsicFor<Block>) -> Option<Vec<SegmentHeader >> {
149            unreachable!()
150        }
151
152        fn is_inherent(_ext: &ExtrinsicFor<Block>) -> bool {
153            unreachable!()
154        }
155
156        fn root_plot_public_key() -> Option<PublicKey> {
157            unreachable!()
158        }
159
160        fn should_adjust_solution_range() -> bool {
161            unreachable!()
162        }
163
164        fn chain_constants() -> ChainConstants {
165            unreachable!()
166        }
167    }
168
169    impl sp_domains::DomainsApi<Block, DomainHeader> for Runtime {
170        fn submit_bundle_unsigned(
171            _opaque_bundle: sp_domains::OpaqueBundle<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, Balance>,
172        ) {
173            unreachable!()
174        }
175
176        fn submit_receipt_unsigned(
177            _singleton_receipt: sp_domains::SealedSingletonReceipt<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, Balance>,
178        ) {
179            unreachable!()
180        }
181
182        fn extract_successful_bundles(
183            _domain_id: DomainId,
184            _extrinsics: Vec<ExtrinsicFor<Block>>,
185        ) -> sp_domains::OpaqueBundles<Block, DomainHeader, Balance> {
186            unreachable!()
187        }
188
189        fn extrinsics_shuffling_seed() -> Randomness {
190            unreachable!()
191        }
192
193        fn domain_runtime_code(_domain_id: DomainId) -> Option<Vec<u8>> {
194            unreachable!()
195        }
196
197        fn runtime_id(_domain_id: DomainId) -> Option<sp_domains::RuntimeId> {
198            unreachable!()
199        }
200
201        fn runtime_upgrades() -> Vec<sp_domains::RuntimeId> {
202            unreachable!()
203        }
204
205        fn domain_instance_data(_domain_id: DomainId) -> Option<(DomainInstanceData, NumberFor<Block>)> {
206            unreachable!()
207        }
208
209        fn domain_timestamp() -> Moment {
210            unreachable!()
211        }
212
213        fn timestamp() -> Moment {
214            unreachable!()
215        }
216
217        fn consensus_transaction_byte_fee() -> Balance {
218            unreachable!()
219        }
220
221        fn consensus_chain_byte_fee() -> Balance {
222            unreachable!()
223        }
224
225        fn domain_tx_range(_domain_id: DomainId) -> U256 {
226            unreachable!()
227        }
228
229        fn genesis_state_root(_domain_id: DomainId) -> Option<H256> {
230            unreachable!()
231        }
232
233        fn head_receipt_number(_domain_id: DomainId) -> DomainNumber {
234            unreachable!()
235        }
236
237        fn oldest_unconfirmed_receipt_number(_domain_id: DomainId) -> Option<DomainNumber> {
238            unreachable!()
239        }
240
241        fn domain_bundle_limit(_domain_id: DomainId) -> Option<sp_domains::DomainBundleLimit> {
242            unreachable!()
243        }
244
245        fn non_empty_er_exists(_domain_id: DomainId) -> bool {
246            unreachable!()
247        }
248
249        fn domain_best_number(_domain_id: DomainId) -> Option<DomainNumber> {
250            unreachable!()
251        }
252
253        fn execution_receipt(_receipt_hash: DomainHash) -> Option<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
254            unreachable!()
255        }
256
257        fn domain_operators(_domain_id: DomainId) -> Option<(BTreeMap<OperatorId, Balance>, Vec<OperatorId>)> {
258            unreachable!()
259        }
260
261        fn receipt_hash(_domain_id: DomainId, _domain_number: DomainNumber) -> Option<DomainHash> {
262            unreachable!()
263        }
264
265        fn latest_confirmed_domain_block(_domain_id: DomainId) -> Option<(DomainNumber, DomainHash)>{
266            unreachable!()
267        }
268
269        fn is_bad_er_pending_to_prune(_domain_id: DomainId, _receipt_hash: DomainHash) -> bool {
270            unreachable!()
271        }
272
273        fn storage_fund_account_balance(_operator_id: OperatorId) -> Balance {
274            unreachable!()
275        }
276
277        fn is_domain_runtime_upgraded_since(_domain_id: DomainId, _at: NumberFor<Block>) -> Option<bool> {
278            unreachable!()
279        }
280
281        fn domain_sudo_call(_domain_id: DomainId) -> Option<Vec<u8>> {
282            unreachable!()
283        }
284
285        fn evm_domain_contract_creation_allowed_by_call(_domain_id: DomainId) -> Option<PermissionedActionAllowedBy<EthereumAccountId>>{
286            unreachable!()
287        }
288
289        fn last_confirmed_domain_block_receipt(_domain_id: DomainId) -> Option<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
290            unreachable!()
291        }
292    }
293
294    impl sp_domains::BundleProducerElectionApi<Block, Balance> for Runtime {
295        fn bundle_producer_election_params(_domain_id: DomainId) -> Option<BundleProducerElectionParams<Balance>> {
296            unreachable!()
297        }
298
299        fn operator(_operator_id: OperatorId) -> Option<(OperatorPublicKey, Balance)> {
300            unreachable!()
301        }
302    }
303
304    impl sp_session::SessionKeys<Block> for Runtime {
305        fn generate_session_keys(_seed: Option<Vec<u8>>) -> Vec<u8> {
306            unreachable!()
307        }
308
309        fn decode_session_keys(
310            _encoded: Vec<u8>,
311        ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
312            unreachable!()
313        }
314    }
315
316    impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
317        fn account_nonce(_account: AccountId) -> Nonce {
318            unreachable!()
319        }
320    }
321
322    impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
323        fn query_info(
324            _uxt: ExtrinsicFor<Block>,
325            _len: u32,
326        ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {
327            unreachable!()
328        }
329        fn query_fee_details(
330            _uxt: ExtrinsicFor<Block>,
331            _len: u32,
332        ) -> pallet_transaction_payment::FeeDetails<Balance> {
333            unreachable!()
334        }
335        fn query_weight_to_fee(_weight: Weight) -> Balance {
336            unreachable!()
337        }
338        fn query_length_to_fee(_length: u32) -> Balance {
339            unreachable!()
340        }
341    }
342
343    impl sp_messenger::MessengerApi<Block, BlockNumber, BlockHashFor<Block>> for Runtime {
344        fn is_xdm_mmr_proof_valid(
345            _ext: &ExtrinsicFor<Block>
346        ) -> Option<bool> {
347            unreachable!()
348        }
349
350        fn extract_xdm_mmr_proof(_ext: &ExtrinsicFor<Block>) -> Option<ConsensusChainMmrLeafProof<BlockNumber, BlockHashFor<Block>, sp_core::H256>> {
351            unreachable!()
352        }
353
354        fn batch_extract_xdm_mmr_proof(_extrinsics: &Vec<ExtrinsicFor<Block>>) -> BTreeMap<u32, ConsensusChainMmrLeafProof<BlockNumber, BlockHashFor<Block>, sp_core::H256>> {
355            unreachable!()
356        }
357
358        fn confirmed_domain_block_storage_key(_domain_id: DomainId) -> Vec<u8> {
359            unreachable!()
360        }
361
362        fn outbox_storage_key(_message_key: MessageKey) -> Vec<u8> {
363            unreachable!()
364        }
365
366        fn inbox_response_storage_key(_message_key: MessageKey) -> Vec<u8> {
367            unreachable!()
368        }
369
370        fn domain_chains_allowlist_update(_domain_id: DomainId) -> Option<DomainAllowlistUpdates>{
371            unreachable!()
372        }
373
374        fn xdm_id(_ext: &ExtrinsicFor<Block>) -> Option<XdmId> {
375            unreachable!()
376        }
377
378        fn channel_nonce(_chain_id: ChainId, _channel_id: ChannelId) -> Option<ChannelNonce> {
379            unreachable!()
380        }
381    }
382
383    impl sp_messenger::RelayerApi<Block, BlockNumber, BlockNumber, BlockHashFor<Block>> for Runtime {
384        fn block_messages() -> BlockMessagesWithStorageKey {
385            unreachable!()
386        }
387
388        fn outbox_message_unsigned(_msg: CrossDomainMessage<NumberFor<Block>, BlockHashFor<Block>, BlockHashFor<Block>>) -> Option<ExtrinsicFor<Block>> {
389            unreachable!()
390        }
391
392        fn inbox_response_message_unsigned(_msg: CrossDomainMessage<NumberFor<Block>, BlockHashFor<Block>, BlockHashFor<Block>>) -> Option<ExtrinsicFor<Block>> {
393            unreachable!()
394        }
395
396        fn should_relay_outbox_message(_dst_chain_id: ChainId, _msg_id: MessageId) -> bool {
397            unreachable!()
398        }
399
400        fn should_relay_inbox_message_response(_dst_chain_id: ChainId, _msg_id: MessageId) -> bool {
401            unreachable!()
402        }
403
404        fn updated_channels() -> BTreeSet<(ChainId, ChannelId)> {
405            unreachable!()
406        }
407
408        fn channel_storage_key(_chain_id: ChainId, _channel_id: ChannelId) -> Vec<u8> {
409            unreachable!()
410        }
411
412        fn open_channels() -> BTreeSet<(ChainId, ChannelId)> {
413            unreachable!()
414        }
415    }
416
417    impl sp_domains_fraud_proof::FraudProofApi<Block, DomainHeader> for Runtime {
418        fn submit_fraud_proof_unsigned(_fraud_proof: FraudProof<NumberFor<Block>, BlockHashFor<Block>, DomainHeader, H256>) {
419            unreachable!()
420        }
421
422        fn fraud_proof_storage_key(_req: FraudProofStorageKeyRequest<NumberFor<Block>>) -> Vec<u8> {
423            unreachable!()
424        }
425    }
426
427    impl mmr::MmrApi<Block, mmr::Hash, BlockNumber> for Runtime {
428        fn mmr_root() -> Result<mmr::Hash, mmr::Error> {
429            unreachable!()
430        }
431
432        fn mmr_leaf_count() -> Result<mmr::LeafIndex, mmr::Error> {
433            unreachable!()
434        }
435
436        fn generate_proof(
437            _block_numbers: Vec<BlockNumber>,
438            _best_known_block_number: Option<BlockNumber>,
439        ) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::LeafProof<mmr::Hash>), mmr::Error> {
440            unreachable!()
441        }
442
443        fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::LeafProof<mmr::Hash>)
444            -> Result<(), mmr::Error>
445        {
446            unreachable!()
447        }
448
449        fn verify_proof_stateless(
450            _root: mmr::Hash,
451            _leaves: Vec<mmr::EncodableOpaqueLeaf>,
452            _proof: mmr::LeafProof<mmr::Hash>
453        ) -> Result<(), mmr::Error> {
454            unreachable!()
455        }
456    }
457
458    impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
459        fn build_state(_config: Vec<u8>) -> sp_genesis_builder::Result {
460            unreachable!()
461        }
462
463        fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
464            unreachable!()
465        }
466
467        fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
468            unreachable!()
469        }
470    }
471}