#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
pub mod genesis;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
use sp_inherents::InherentData;
use sp_runtime::{
create_runtime_str, impl_opaque_keys,
traits::Block as BlockT,
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, BoundToRuntimeAppPublic,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use tuxedo_core::{
genesis::TuxedoGenesisConfigBuilder,
tuxedo_constraint_checker, tuxedo_verifier,
types::Transaction as TuxedoTransaction,
verifier::{Sr25519Signature, ThresholdMultiSignature, UpForGrabs},
InherentAdapter, TuxedoMetadata,
};
pub use amoeba;
pub use kitties;
pub use money;
pub use poe;
pub use runtime_upgrade;
pub use timestamp;
pub mod opaque {
use super::*;
impl_opaque_keys! {
pub struct SessionKeys {
pub aura: AuraAppPublic,
pub grandpa: GrandpaAppPublic,
}
}
pub struct AuraAppPublic;
impl BoundToRuntimeAppPublic for AuraAppPublic {
type Public = AuraId;
}
pub struct GrandpaAppPublic;
impl BoundToRuntimeAppPublic for GrandpaAppPublic {
type Public = sp_consensus_grandpa::AuthorityId;
}
}
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("tuxedo-template-runtime"),
impl_name: create_runtime_str!("tuxedo-template-runtime"),
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
};
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
NativeVersion {
runtime_version: VERSION,
can_author_with: Default::default(),
}
}
pub type Transaction = TuxedoTransaction<OuterVerifier, OuterConstraintChecker>;
pub type Block = tuxedo_core::types::Block<OuterVerifier, OuterConstraintChecker>;
pub type Executive = tuxedo_core::Executive<OuterVerifier, OuterConstraintChecker>;
pub type Output = tuxedo_core::types::Output<OuterVerifier>;
const BLOCK_TIME: u64 = 3000;
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[tuxedo_verifier]
pub enum OuterVerifier {
Sr25519Signature(Sr25519Signature),
UpForGrabs(UpForGrabs),
ThresholdMultiSignature(ThresholdMultiSignature),
}
impl poe::PoeConfig for Runtime {
fn block_height() -> u32 {
Executive::block_height()
}
}
impl timestamp::TimestampConfig for Runtime {
fn block_height() -> u32 {
Executive::block_height()
}
}
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[tuxedo_constraint_checker]
pub enum OuterConstraintChecker {
Money(money::MoneyConstraintChecker<0>),
FreeKittyConstraintChecker(kitties::FreeKittyConstraintChecker),
AmoebaMitosis(amoeba::AmoebaMitosis),
AmoebaDeath(amoeba::AmoebaDeath),
AmoebaCreation(amoeba::AmoebaCreation),
PoeClaim(poe::PoeClaim<Runtime>),
PoeRevoke(poe::PoeRevoke),
PoeDispute(poe::PoeDispute),
SetTimestamp(InherentAdapter<timestamp::SetTimestamp<Runtime>>),
RuntimeUpgrade(runtime_upgrade::RuntimeUpgrade),
}
#[derive(Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
pub struct Runtime;
impl Runtime {
fn aura_authorities() -> Vec<AuraId> {
use hex_literal::hex;
use sp_application_crypto::ByteArray;
[
hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"),
]
.iter()
.map(|hex| AuraId::from_slice(hex.as_ref()).expect("Valid Aura authority hex was provided"))
.collect()
}
fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList {
use hex_literal::hex;
use sp_application_crypto::ByteArray;
[
hex!("88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee"),
]
.iter()
.map(|hex| {
(
GrandpaId::from_slice(hex.as_ref())
.expect("Valid Grandpa authority hex was provided"),
1,
)
})
.collect()
}
}
impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block)
}
fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
Executive::open_block(header)
}
}
impl sp_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
}
fn finalize_block() -> <Block as BlockT>::Header {
Executive::close_block()
}
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
Executive::inherent_extrinsics(data)
}
fn check_inherents(
block: Block,
data: InherentData
) -> sp_inherents::CheckInherentsResult {
Executive::check_inherents(block, data)
}
}
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
}
}
impl sp_api::Metadata<Block> for Runtime {
fn metadata() -> OpaqueMetadata {
OpaqueMetadata::new(TuxedoMetadata::default().encode())
}
fn metadata_at_version(_version: u32) -> Option<OpaqueMetadata> {
None
}
fn metadata_versions() -> sp_std::vec::Vec<u32> {
Default::default()
}
}
impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
opaque::SessionKeys::generate(seed)
}
fn decode_session_keys(
encoded: Vec<u8>,
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
}
}
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(BLOCK_TIME)
}
fn authorities() -> Vec<AuraId> {
Self::aura_authorities()
}
}
impl sp_consensus_grandpa::GrandpaApi<Block> for Runtime {
fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList {
Self::grandpa_authorities()
}
fn current_set_id() -> sp_consensus_grandpa::SetId {
0u64
}
fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: sp_consensus_grandpa::EquivocationProof<
<Block as BlockT>::Hash,
sp_runtime::traits::NumberFor<Block>,
>,
_key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
}
fn generate_key_ownership_proof(
_set_id: sp_consensus_grandpa::SetId,
_authority_id: sp_consensus_grandpa::AuthorityId,
) -> Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof> {
None
}
}
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn create_default_config() -> Vec<u8> {
serde_json::to_vec(&genesis::development_genesis_transactions())
.expect("Development genesis transactions are valid.")
}
fn build_config(config: Vec<u8>) -> sp_genesis_builder::Result {
let genesis_transactions = serde_json::from_slice::<Vec<Transaction>>(config.as_slice())
.map_err(|_| "The input JSON is not a valid list of Transactions.")?;
TuxedoGenesisConfigBuilder::build(genesis_transactions)
}
}
}