griffin_solochain_runtime/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
4
5#[cfg(feature = "std")]
6include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
7
8extern crate alloc;
9
10pub mod genesis;
11
12use alloc::{string::ToString, vec, vec::Vec};
13use codec::{Decode, Encode};
14use griffin_core::genesis::config_builder::GenesisConfig;
15use griffin_core::MILLI_SECS_PER_SLOT;
16use scale_info::TypeInfo;
17use sp_api::impl_runtime_apis;
18use sp_consensus_aura::sr25519::AuthorityId as AuraId;
19use sp_consensus_grandpa::AuthorityId as GrandpaId;
20use sp_core::OpaqueMetadata;
21use sp_inherents::InherentData;
22use sp_runtime::{
23 create_runtime_str, impl_opaque_keys,
24 traits::Block as BlockT,
25 transaction_validity::{TransactionSource, TransactionValidity},
26 ApplyExtrinsicResult, BoundToRuntimeAppPublic,
27};
28
29#[cfg(feature = "std")]
30use sp_version::NativeVersion;
31use sp_version::RuntimeVersion;
32
33pub mod opaque {
38 use super::*;
39
40 impl_opaque_keys! {
42 pub struct SessionKeys {
43 pub aura: AuraAppPublic,
44 pub grandpa: GrandpaAppPublic,
45 }
46 }
47
48 pub struct AuraAppPublic;
52 impl BoundToRuntimeAppPublic for AuraAppPublic {
53 type Public = AuraId;
54 }
55
56 pub struct GrandpaAppPublic;
57 impl BoundToRuntimeAppPublic for GrandpaAppPublic {
58 type Public = sp_consensus_grandpa::AuthorityId;
59 }
60}
61
62#[sp_version::runtime_version]
64pub const VERSION: RuntimeVersion = RuntimeVersion {
65 spec_name: create_runtime_str!("griffin-solochain-runtime"),
66 impl_name: create_runtime_str!("griffin-solochain-runtime"),
67 authoring_version: 1,
68 spec_version: 100,
69 impl_version: 1,
70 apis: RUNTIME_API_VERSIONS,
71 transaction_version: 1,
72 state_version: 1,
73};
74
75#[cfg(feature = "std")]
77pub fn native_version() -> NativeVersion {
78 NativeVersion {
79 runtime_version: VERSION,
80 can_author_with: Default::default(),
81 }
82}
83
84pub type Transaction = griffin_core::types::Transaction;
85pub type Block = griffin_core::types::Block;
86pub type Executive = griffin_core::Executive;
87pub type Output = griffin_core::types::Output;
88
89#[derive(Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
91pub struct Runtime;
92
93impl Runtime {
98 fn aura_authorities() -> Vec<AuraId> {
100 use hex_literal::hex;
101 use sp_application_crypto::ByteArray;
102
103 [
104 hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"),
106 ]
117 .iter()
118 .map(|hex| AuraId::from_slice(hex.as_ref()).expect("Valid Aura authority hex was provided"))
119 .collect()
120 }
121
122 fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList {
124 use hex_literal::hex;
125 use sp_application_crypto::ByteArray;
126
127 [
128 hex!("88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee"),
130 ]
141 .iter()
142 .map(|hex| {
143 (
144 GrandpaId::from_slice(hex.as_ref())
145 .expect("Valid Grandpa authority hex was provided"),
146 1,
147 )
148 })
149 .collect()
150 }
151}
152
153impl_runtime_apis! {
154 impl sp_api::Core<Block> for Runtime {
156 fn version() -> RuntimeVersion {
157 VERSION
158 }
159
160 fn execute_block(block: Block) {
161 Executive::execute_block(block)
162 }
163
164 fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
165 Executive::open_block(header)
166 }
167 }
168
169 impl sp_block_builder::BlockBuilder<Block> for Runtime {
171 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
172 Executive::apply_extrinsic(extrinsic)
173 }
174
175 fn finalize_block() -> <Block as BlockT>::Header {
176 Executive::close_block()
177 }
178
179 fn inherent_extrinsics(_data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
180 Vec::new()
181 }
182
183 fn check_inherents(
184 _block: Block,
185 _data: InherentData
186 ) -> sp_inherents::CheckInherentsResult {
187 sp_inherents::CheckInherentsResult::new()
188 }
189 }
190
191 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
192 fn validate_transaction(
193 source: TransactionSource,
194 tx: <Block as BlockT>::Extrinsic,
195 block_hash: <Block as BlockT>::Hash,
196 ) -> TransactionValidity {
197 Executive::validate_transaction(source, tx, block_hash)
198 }
199 }
200
201 impl sp_api::Metadata<Block> for Runtime {
202 fn metadata() -> OpaqueMetadata {
203 OpaqueMetadata::new(Vec::new())
204 }
205
206 fn metadata_at_version(_version: u32) -> Option<OpaqueMetadata> {
207 None
208 }
209
210 fn metadata_versions() -> alloc::vec::Vec<u32> {
211 Default::default()
212 }
213 }
214
215 impl sp_session::SessionKeys<Block> for Runtime {
216 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
217 opaque::SessionKeys::generate(seed)
218 }
219
220 fn decode_session_keys(
221 encoded: Vec<u8>,
222 ) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
223 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
224 }
225 }
226
227 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
228 fn slot_duration() -> sp_consensus_aura::SlotDuration {
229 sp_consensus_aura::SlotDuration::from_millis(MILLI_SECS_PER_SLOT.into())
230 }
231
232 fn authorities() -> Vec<AuraId> {
233 Self::aura_authorities()
234 }
235 }
236
237 impl sp_consensus_grandpa::GrandpaApi<Block> for Runtime {
238 fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList {
239 Self::grandpa_authorities()
240 }
241
242 fn current_set_id() -> sp_consensus_grandpa::SetId {
243 0u64
244 }
245
246 fn submit_report_equivocation_unsigned_extrinsic(
247 _equivocation_proof: sp_consensus_grandpa::EquivocationProof<
248 <Block as BlockT>::Hash,
249 sp_runtime::traits::NumberFor<Block>,
250 >,
251 _key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof,
252 ) -> Option<()> {
253 None
254 }
255
256 fn generate_key_ownership_proof(
257 _set_id: sp_consensus_grandpa::SetId,
258 _authority_id: sp_consensus_grandpa::AuthorityId,
259 ) -> Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof> {
260 None
261 }
262 }
263
264 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
265 fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
266 let genesis_config = serde_json::from_slice::<GenesisConfig>(config.as_slice())
267 .map_err(|_| "The input JSON is not a valid genesis configuration.")?;
268
269 griffin_core::genesis::GriffinGenesisConfigBuilder::build(genesis_config)
270 }
271
272 fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
273 let genesis_config : &GenesisConfig = &genesis::get_genesis_config("".to_string());
274 Some(serde_json::to_vec(genesis_config)
275 .expect("Genesis configuration is valid."))
276 }
277
278 fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
279 vec![]
280 }
281 }
282}