mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
signals-primitives, plus various minor tweaks
This commit is contained in:
parent
6e15bb2434
commit
7768ea90ad
11 changed files with 114 additions and 38 deletions
|
@ -47,6 +47,7 @@ members = [
|
|||
"substrate/validator-sets/primitives",
|
||||
"substrate/validator-sets/pallet",
|
||||
|
||||
"substrate/signals/primitives",
|
||||
"substrate/signals/pallet",
|
||||
|
||||
"substrate/runtime",
|
||||
|
|
|
@ -236,6 +236,7 @@ pub mod pallet {
|
|||
/// The amount of lp tokens that were burned of that id.
|
||||
lp_token_burned: SubstrateAmount,
|
||||
},
|
||||
|
||||
/// Coins have been converted from one to another. Both `SwapExactTokenForToken`
|
||||
/// and `SwapTokenForExactToken` will generate this event.
|
||||
SwapExecuted {
|
||||
|
|
|
@ -8,8 +8,7 @@ use sp_api::ProvideRuntimeApi;
|
|||
|
||||
use serai_runtime::{
|
||||
primitives::{SubstrateAmount, PublicKey},
|
||||
opaque::Block,
|
||||
Nonce,
|
||||
Nonce, Block,
|
||||
};
|
||||
|
||||
pub use sc_rpc_api::DenyUnsafe;
|
||||
|
|
|
@ -17,7 +17,7 @@ use sc_client_api::{BlockBackend, Backend};
|
|||
|
||||
use sc_telemetry::{Telemetry, TelemetryWorker};
|
||||
|
||||
use serai_runtime::{opaque::Block, RuntimeApi};
|
||||
use serai_runtime::{Block, RuntimeApi};
|
||||
|
||||
use sc_consensus_babe::{self, SlotProportion};
|
||||
use sc_consensus_grandpa as grandpa;
|
||||
|
|
|
@ -139,3 +139,6 @@ impl AsRef<[u8]> for Data {
|
|||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub type BlockNumber = u64;
|
||||
pub type Header = sp_runtime::generic::Header<BlockNumber, sp_runtime::traits::BlakeTwo256>;
|
||||
|
|
|
@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
|||
|
||||
// Re-export all components
|
||||
pub use serai_primitives as primitives;
|
||||
pub use primitives::{BlockNumber, Header};
|
||||
|
||||
pub use frame_system as system;
|
||||
pub use frame_support as support;
|
||||
|
@ -40,7 +41,7 @@ use sp_runtime::{
|
|||
create_runtime_str, generic, impl_opaque_keys, KeyTypeId,
|
||||
traits::{Convert, BlakeTwo256, Block as BlockT},
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
ApplyExtrinsicResult, Perbill,
|
||||
Perbill, ApplyExtrinsicResult,
|
||||
};
|
||||
|
||||
use primitives::{PublicKey, SeraiAddress, AccountLookup, Signature, SubstrateAmount};
|
||||
|
@ -58,24 +59,31 @@ use babe::AuthorityId as BabeId;
|
|||
use grandpa::AuthorityId as GrandpaId;
|
||||
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
|
||||
|
||||
/// An index to a block.
|
||||
pub type BlockNumber = u64;
|
||||
|
||||
/// Nonce of a transaction in the chain, for a given account.
|
||||
pub type Nonce = u32;
|
||||
|
||||
/// A hash of some data used by the chain.
|
||||
pub type Hash = sp_core::H256;
|
||||
|
||||
pub mod opaque {
|
||||
use super::*;
|
||||
pub type SignedExtra = (
|
||||
system::CheckNonZeroSender<Runtime>,
|
||||
system::CheckSpecVersion<Runtime>,
|
||||
system::CheckTxVersion<Runtime>,
|
||||
system::CheckGenesis<Runtime>,
|
||||
system::CheckEra<Runtime>,
|
||||
system::CheckNonce<Runtime>,
|
||||
system::CheckWeight<Runtime>,
|
||||
transaction_payment::ChargeTransactionPayment<Runtime>,
|
||||
);
|
||||
pub type UncheckedExtrinsic =
|
||||
generic::UncheckedExtrinsic<SeraiAddress, RuntimeCall, Signature, SignedExtra>;
|
||||
|
||||
use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
|
||||
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
pub type BlockId = generic::BlockId<Block>;
|
||||
|
||||
pub mod opaque {
|
||||
use super::*;
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
pub babe: Babe,
|
||||
|
@ -296,21 +304,6 @@ impl grandpa::Config for Runtime {
|
|||
type EquivocationReportSystem = ();
|
||||
}
|
||||
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
pub type SignedExtra = (
|
||||
system::CheckNonZeroSender<Runtime>,
|
||||
system::CheckSpecVersion<Runtime>,
|
||||
system::CheckTxVersion<Runtime>,
|
||||
system::CheckGenesis<Runtime>,
|
||||
system::CheckEra<Runtime>,
|
||||
system::CheckNonce<Runtime>,
|
||||
system::CheckWeight<Runtime>,
|
||||
transaction_payment::ChargeTransactionPayment<Runtime>,
|
||||
);
|
||||
pub type UncheckedExtrinsic =
|
||||
generic::UncheckedExtrinsic<SeraiAddress, RuntimeCall, Signature, SignedExtra>;
|
||||
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
|
||||
pub type Executive = frame_executive::Executive<
|
||||
Runtime,
|
||||
Block,
|
||||
|
@ -372,7 +365,7 @@ sp_api::impl_runtime_apis! {
|
|||
Executive::execute_block(block);
|
||||
}
|
||||
|
||||
fn initialize_block(header: &<Block as BlockT>::Header) {
|
||||
fn initialize_block(header: &Header) {
|
||||
Executive::initialize_block(header)
|
||||
}
|
||||
}
|
||||
|
@ -396,7 +389,7 @@ sp_api::impl_runtime_apis! {
|
|||
Executive::apply_extrinsic(extrinsic)
|
||||
}
|
||||
|
||||
fn finalize_block() -> <Block as BlockT>::Header {
|
||||
fn finalize_block() -> Header {
|
||||
Executive::finalize_block()
|
||||
}
|
||||
|
||||
|
@ -423,7 +416,7 @@ sp_api::impl_runtime_apis! {
|
|||
}
|
||||
|
||||
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
|
||||
fn offchain_worker(header: &<Block as BlockT>::Header) {
|
||||
fn offchain_worker(header: &Header) {
|
||||
Executive::offchain_worker(header)
|
||||
}
|
||||
}
|
||||
|
@ -475,7 +468,7 @@ sp_api::impl_runtime_apis! {
|
|||
}
|
||||
|
||||
fn submit_report_equivocation_unsigned_extrinsic(
|
||||
_: sp_consensus_babe::EquivocationProof<<Block as BlockT>::Header>,
|
||||
_: sp_consensus_babe::EquivocationProof<Header>,
|
||||
_: sp_consensus_babe::OpaqueKeyOwnershipProof,
|
||||
) -> Option<()> {
|
||||
None
|
||||
|
|
|
@ -23,6 +23,8 @@ frame-system = { git = "https://github.com/serai-dex/substrate", default-feature
|
|||
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
|
||||
serai-primitives = { path = "../../primitives", default-features = false }
|
||||
serai-signals-primitives = { path = "../primitives", default-features = false }
|
||||
|
||||
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../../validator-sets/pallet", default-features = false }
|
||||
in-instructions-pallet = { package = "serai-in-instructions-pallet", path = "../../in-instructions/pallet", default-features = false }
|
||||
|
||||
|
@ -38,6 +40,8 @@ std = [
|
|||
"frame-support/std",
|
||||
|
||||
"serai-primitives/std",
|
||||
"serai-signals-primitives/std",
|
||||
|
||||
"validator-sets-pallet/std",
|
||||
"in-instructions-pallet/std",
|
||||
]
|
||||
|
|
|
@ -12,6 +12,7 @@ pub mod pallet {
|
|||
use frame_support::{pallet_prelude::*, sp_runtime};
|
||||
|
||||
use serai_primitives::*;
|
||||
use serai_signals_primitives::SignalId;
|
||||
use validator_sets_pallet::{primitives::ValidatorSet, Config as VsConfig, Pallet as VsPallet};
|
||||
use in_instructions_pallet::{Config as IiConfig, Pallet as InInstructions};
|
||||
|
||||
|
@ -47,12 +48,6 @@ pub mod pallet {
|
|||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
|
||||
pub enum SignalId {
|
||||
Retirement([u8; 32]),
|
||||
Halt(NetworkId),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
|
||||
pub struct RegisteredRetirementSignal<T: Config> {
|
||||
in_favor_of: [u8; 32],
|
||||
|
|
42
substrate/signals/primitives/Cargo.toml
Normal file
42
substrate/signals/primitives/Cargo.toml
Normal file
|
@ -0,0 +1,42 @@
|
|||
[package]
|
||||
name = "serai-signals-primitives"
|
||||
version = "0.1.0"
|
||||
description = "Signals primitives"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/serai-dex/serai/tree/develop/substrate/signals/primitives"
|
||||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||
edition = "2021"
|
||||
rust-version = "1.74"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[dependencies]
|
||||
zeroize = { version = "^1.5", features = ["derive"], optional = true }
|
||||
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "2", default-features = false, features = ["derive"] }
|
||||
|
||||
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"], optional = true }
|
||||
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }
|
||||
|
||||
serai-primitives = { path = "../../primitives", version = "0.1", default-features = false }
|
||||
|
||||
[features]
|
||||
std = [
|
||||
"zeroize",
|
||||
|
||||
"scale/std",
|
||||
"scale-info/std",
|
||||
|
||||
"borsh?/std",
|
||||
"serde?/std",
|
||||
|
||||
"serai-primitives/std",
|
||||
]
|
||||
|
||||
borsh = ["dep:borsh"]
|
||||
serde = ["dep:serde"]
|
||||
|
||||
default = ["std"]
|
21
substrate/signals/primitives/LICENSE
Normal file
21
substrate/signals/primitives/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2023 Luke Parker
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
17
substrate/signals/primitives/src/lib.rs
Normal file
17
substrate/signals/primitives/src/lib.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use scale::{Encode, Decode, MaxEncodedLen};
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
use serai_primitives::NetworkId;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
||||
#[cfg_attr(feature = "std", derive(zeroize::Zeroize))]
|
||||
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum SignalId {
|
||||
Retirement([u8; 32]),
|
||||
Halt(NetworkId),
|
||||
}
|
Loading…
Reference in a new issue