Update substrate

This commit is contained in:
Luke Parker 2023-07-18 22:30:55 -04:00
parent a7c9c1ef55
commit 64402914ba
No known key found for this signature in database
23 changed files with 881 additions and 798 deletions

1261
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -36,9 +36,7 @@ pub mod pallet {
use super::*; use super::*;
#[pallet::config] #[pallet::config]
pub trait Config: pub trait Config: frame_system::Config + ValidatorSetsConfig + TokensConfig {
frame_system::Config<BlockNumber = u64> + ValidatorSetsConfig + TokensConfig
{
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
} }

View file

@ -13,11 +13,11 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies] [dependencies]
zeroize = { version = "^1.5", features = ["derive"], optional = true } zeroize = { version = "^1.5", features = ["derive"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] } scale-info = { version = "2", default-features = false, features = ["derive"] }
serde = { version = "1", features = ["derive"], optional = true }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
@ -29,11 +29,11 @@ tokens-primitives = { package = "serai-tokens-primitives", path = "../../tokens/
std = [ std = [
"zeroize", "zeroize",
"serde/std",
"scale/std", "scale/std",
"scale-info/std", "scale-info/std",
"serde",
"sp-std/std", "sp-std/std",
"sp-runtime/std", "sp-runtime/std",

View file

@ -5,12 +5,11 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_application_crypto::sr25519::Signature; use sp_application_crypto::sr25519::Signature;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
@ -22,42 +21,51 @@ use serai_primitives::{BlockHash, Balance, NetworkId, SeraiAddress, ExternalAddr
mod shorthand; mod shorthand;
pub use shorthand::*; pub use shorthand::*;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[rustfmt::skip]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] #[derive(
Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum Application { pub enum Application {
DEX, DEX,
} }
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct ApplicationCall { pub struct ApplicationCall {
pub application: Application, pub application: Application,
pub data: Data, pub data: Data,
} }
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum InInstruction { pub enum InInstruction {
Transfer(SeraiAddress), Transfer(SeraiAddress),
Call(ApplicationCall), Call(ApplicationCall),
} }
#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug)] #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] #[cfg_attr(feature = "std", derive(Zeroize))]
pub struct RefundableInInstruction { pub struct RefundableInInstruction {
pub origin: Option<ExternalAddress>, pub origin: Option<ExternalAddress>,
pub instruction: InInstruction, pub instruction: InInstruction,
} }
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct InInstructionWithBalance { pub struct InInstructionWithBalance {
pub instruction: InInstruction, pub instruction: InInstruction,
pub balance: Balance, pub balance: Balance,
} }
#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug)] #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] #[cfg_attr(feature = "std", derive(Zeroize))]
pub struct Batch { pub struct Batch {
pub network: NetworkId, pub network: NetworkId,
pub id: u32, pub id: u32,
@ -65,8 +73,7 @@ pub struct Batch {
pub instructions: Vec<InInstructionWithBalance>, pub instructions: Vec<InInstructionWithBalance>,
} }
#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug)] #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct SignedBatch { pub struct SignedBatch {
pub batch: Batch, pub batch: Batch,
pub signature: Signature, pub signature: Signature,

View file

@ -1,12 +1,11 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress, Data}; use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress, Data};
use tokens_primitives::OutInstruction; use tokens_primitives::OutInstruction;
@ -15,8 +14,10 @@ use crate::RefundableInInstruction;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use crate::InInstruction; use crate::InInstruction;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum Shorthand { pub enum Shorthand {
Raw(Data), Raw(Data),
Swap { Swap {

View file

@ -33,6 +33,7 @@ frame-benchmarking-cli = { git = "https://github.com/serai-dex/substrate" }
serai-runtime = { path = "../runtime", features = ["std"] } serai-runtime = { path = "../runtime", features = ["std"] }
sc-offchain = { git = "https://github.com/serai-dex/substrate" }
sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" } sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
sc-transaction-pool-api = { git = "https://github.com/serai-dex/substrate" } sc-transaction-pool-api = { git = "https://github.com/serai-dex/substrate" }
sc-basic-authorship = { git = "https://github.com/serai-dex/substrate" } sc-basic-authorship = { git = "https://github.com/serai-dex/substrate" }

View file

@ -1,14 +1,16 @@
use core::marker::PhantomData;
use sp_core::Pair as PairTrait; use sp_core::Pair as PairTrait;
use sc_service::ChainType; use sc_service::ChainType;
use serai_runtime::{ use serai_runtime::{
primitives::*, tokens::primitives::ADDRESS as TOKENS_ADDRESS, WASM_BINARY, opaque::SessionKeys, primitives::*, tokens::primitives::ADDRESS as TOKENS_ADDRESS, WASM_BINARY, opaque::SessionKeys,
BABE_GENESIS_EPOCH_CONFIG, GenesisConfig, SystemConfig, BalancesConfig, AssetsConfig, BABE_GENESIS_EPOCH_CONFIG, RuntimeGenesisConfig, SystemConfig, BalancesConfig, AssetsConfig,
ValidatorSetsConfig, SessionConfig, BabeConfig, GrandpaConfig, AuthorityDiscoveryConfig, ValidatorSetsConfig, SessionConfig, BabeConfig, GrandpaConfig, AuthorityDiscoveryConfig,
}; };
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>; pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;
fn account_from_name(name: &'static str) -> PublicKey { fn account_from_name(name: &'static str) -> PublicKey {
insecure_pair_from_name(name).public() insecure_pair_from_name(name).public()
@ -18,7 +20,7 @@ fn testnet_genesis(
wasm_binary: &[u8], wasm_binary: &[u8],
validators: &[&'static str], validators: &[&'static str],
endowed_accounts: Vec<PublicKey>, endowed_accounts: Vec<PublicKey>,
) -> GenesisConfig { ) -> RuntimeGenesisConfig {
let session_key = |name| { let session_key = |name| {
let key = account_from_name(name); let key = account_from_name(name);
( (
@ -28,8 +30,8 @@ fn testnet_genesis(
) )
}; };
GenesisConfig { RuntimeGenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec() }, system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData },
balances: BalancesConfig { balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
@ -61,10 +63,14 @@ fn testnet_genesis(
participants: validators.iter().map(|name| account_from_name(name)).collect(), participants: validators.iter().map(|name| account_from_name(name)).collect(),
}, },
session: SessionConfig { keys: validators.iter().map(|name| session_key(*name)).collect() }, session: SessionConfig { keys: validators.iter().map(|name| session_key(*name)).collect() },
babe: BabeConfig { authorities: vec![], epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG) }, babe: BabeConfig {
grandpa: GrandpaConfig { authorities: vec![] }, authorities: vec![],
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
_config: PhantomData,
},
grandpa: GrandpaConfig { authorities: vec![], _config: PhantomData },
authority_discovery: AuthorityDiscoveryConfig { keys: vec![] }, authority_discovery: AuthorityDiscoveryConfig { keys: vec![], _config: PhantomData },
} }
} }

View file

@ -4,7 +4,7 @@ use serai_runtime::Block;
use sc_service::{PruningMode, PartialComponents}; use sc_service::{PruningMode, PartialComponents};
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; use sc_cli::SubstrateCli;
use frame_benchmarking_cli::{ExtrinsicFactory, BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; use frame_benchmarking_cli::{ExtrinsicFactory, BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use crate::{ use crate::{
@ -46,10 +46,6 @@ impl SubstrateCli for Cli {
_ => panic!("Unknown network ID"), _ => panic!("Unknown network ID"),
} }
} }
fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
&serai_runtime::VERSION
}
} }
pub fn run() -> sc_cli::Result<()> { pub fn run() -> sc_cli::Result<()> {
@ -99,29 +95,7 @@ pub fn run() -> sc_cli::Result<()> {
}), }),
Some(Subcommand::Benchmark(cmd)) => cli.create_runner(cmd)?.sync_run(|config| match cmd { Some(Subcommand::Benchmark(cmd)) => cli.create_runner(cmd)?.sync_run(|config| match cmd {
BenchmarkCmd::Pallet(cmd) => { BenchmarkCmd::Pallet(cmd) => cmd.run::<Block, ()>(config),
use sc_executor::{NativeVersion, NativeExecutionDispatch};
use serai_runtime as runtime;
struct ExecutorDispatch;
impl NativeExecutionDispatch for ExecutorDispatch {
#[cfg(feature = "runtime-benchmarks")]
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
#[cfg(not(feature = "runtime-benchmarks"))]
type ExtendHostFunctions = ();
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
runtime::api::dispatch(method, data)
}
fn native_version() -> NativeVersion {
runtime::native_version()
}
}
cmd.run::<Block, ExecutorDispatch>(config)
}
BenchmarkCmd::Block(cmd) => cmd.run(service::new_partial(&config)?.client), BenchmarkCmd::Block(cmd) => cmd.run(service::new_partial(&config)?.client),

View file

@ -12,7 +12,8 @@ use sc_network_common::sync::warp::WarpSyncParams;
use sc_network::{Event, NetworkEventStream}; use sc_network::{Event, NetworkEventStream};
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, TFullClient}; use sc_service::{error::Error as ServiceError, Configuration, TaskManager, TFullClient};
use sc_client_api::BlockBackend; use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sc_client_api::{BlockBackend, Backend};
use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_telemetry::{Telemetry, TelemetryWorker};
@ -116,17 +117,21 @@ pub fn new_partial(config: &Configuration) -> Result<PartialComponents, ServiceE
)?; )?;
let slot_duration = babe_link.config().slot_duration(); let slot_duration = babe_link.config().slot_duration();
let (import_queue, babe_handle) = sc_consensus_babe::import_queue( let (import_queue, babe_handle) =
babe_link.clone(), sc_consensus_babe::import_queue(sc_consensus_babe::ImportQueueParams {
block_import.clone(), link: babe_link.clone(),
Some(Box::new(justification_import)), block_import: block_import.clone(),
client.clone(), justification_import: Some(Box::new(justification_import)),
select_chain.clone(), client: client.clone(),
move |_, _| async move { Ok(create_inherent_data_providers(slot_duration)) }, select_chain: select_chain.clone(),
&task_manager.spawn_essential_handle(), create_inherent_data_providers: move |_, _| async move {
config.prometheus_registry(), Ok(create_inherent_data_providers(slot_duration))
telemetry.as_ref().map(Telemetry::handle), },
)?; spawner: &task_manager.spawn_essential_handle(),
registry: config.prometheus_registry(),
telemetry: telemetry.as_ref().map(Telemetry::handle),
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool.clone()),
})?;
// This can't be dropped, or BABE breaks // This can't be dropped, or BABE breaks
// We don't have anything to do with it though // We don't have anything to do with it though
// This won't grow in size, so forgetting this isn't a disastrous memleak // This won't grow in size, so forgetting this isn't a disastrous memleak
@ -184,11 +189,20 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
})?; })?;
if config.offchain_worker.enabled { if config.offchain_worker.enabled {
sc_service::build_offchain_workers( task_manager.spawn_handle().spawn(
&config, "offchain-workers-runner",
task_manager.spawn_handle(), "offchain-worker",
client.clone(), sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
network.clone(), runtime_api_provider: client.clone(),
is_validator: config.role.is_authority(),
keystore: Some(keystore_container.keystore()),
offchain_db: backend.offchain_storage(),
transaction_pool: Some(OffchainTransactionPoolFactory::new(transaction_pool.clone())),
network_provider: network.clone(),
enable_http_requests: true,
custom_extensions: |_| vec![],
})
.run(client.clone(), task_manager.spawn_handle()),
); );
} }
@ -238,7 +252,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
env: sc_basic_authorship::ProposerFactory::new( env: sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(), task_manager.spawn_handle(),
client.clone(), client.clone(),
transaction_pool, transaction_pool.clone(),
prometheus_registry.as_ref(), prometheus_registry.as_ref(),
telemetry.as_ref().map(Telemetry::handle), telemetry.as_ref().map(Telemetry::handle),
), ),
@ -312,6 +326,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
voting_rule: grandpa::VotingRulesBuilder::default().build(), voting_rule: grandpa::VotingRulesBuilder::default().build(),
prometheus_registry, prometheus_registry,
shared_voter_state, shared_voter_state,
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool),
})?, })?,
); );
} }

View file

@ -16,14 +16,14 @@ lazy_static = { version = "1", optional = true }
zeroize = { version = "^1.5", features = ["derive"], optional = true } zeroize = { version = "^1.5", features = ["derive"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] } scale-info = { version = "2", default-features = false, features = ["derive"] }
serde = { version = "1", features = ["derive"], optional = true }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
[features] [features]
std = ["lazy_static", "zeroize", "scale/std", "scale-info/std", "serde", "sp-core/std", "sp-runtime/std"] std = ["lazy_static", "zeroize", "scale/std", "scale-info/std", "serde/std", "sp-core/std", "sp-runtime/std"]
default = ["std"] default = ["std"]

View file

@ -1,12 +1,11 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_core::sr25519::Public; use sp_core::sr25519::Public;
pub use sp_core::sr25519::Signature; pub use sp_core::sr25519::Signature;
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -17,9 +16,21 @@ use sp_runtime::traits::{LookupError, Lookup, StaticLookup};
pub type PublicKey = Public; pub type PublicKey = Public;
#[derive( #[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Encode, Decode, MaxEncodedLen, TypeInfo, Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)] )]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] #[cfg_attr(feature = "std", derive(Zeroize))]
pub struct SeraiAddress(pub [u8; 32]); pub struct SeraiAddress(pub [u8; 32]);
impl SeraiAddress { impl SeraiAddress {
pub fn new(key: [u8; 32]) -> SeraiAddress { pub fn new(key: [u8; 32]) -> SeraiAddress {

View file

@ -6,10 +6,10 @@ use core::{
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
/// The type used for amounts within Substrate. /// The type used for amounts within Substrate.
// Distinct from Amount due to Substrate's requirements on this type. // Distinct from Amount due to Substrate's requirements on this type.
@ -19,9 +19,20 @@ use serde::{Serialize, Deserialize};
pub type SubstrateAmount = u64; pub type SubstrateAmount = u64;
/// The type used for amounts. /// The type used for amounts.
#[derive( #[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Debug, Encode, Decode, MaxEncodedLen, TypeInfo, Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)] )]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] #[cfg_attr(feature = "std", derive(Zeroize))]
pub struct Amount(pub SubstrateAmount); pub struct Amount(pub SubstrateAmount);
impl Add for Amount { impl Add for Amount {

View file

@ -3,16 +3,19 @@ use core::ops::{Add, Sub, Mul};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use crate::{Coin, Amount}; use crate::{Coin, Amount};
/// The type used for balances (a Coin and Balance). /// The type used for balances (a Coin and Balance).
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[rustfmt::skip]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] #[derive(
Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct Balance { pub struct Balance {
pub coin: Coin, pub coin: Coin,
pub amount: Amount, pub amount: Amount,

View file

@ -1,19 +1,30 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_core::H256; use sp_core::H256;
/// The type used to identify block numbers. /// The type used to identify block numbers.
#[derive( #[derive(
Clone, Copy, Default, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo, Clone,
Copy,
Default,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)] )]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] #[cfg_attr(feature = "std", derive(Zeroize))]
pub struct BlockNumber(pub u64); pub struct BlockNumber(pub u64);
impl From<u64> for BlockNumber { impl From<u64> for BlockNumber {
fn from(number: u64) -> BlockNumber { fn from(number: u64) -> BlockNumber {
@ -26,8 +37,21 @@ impl From<u64> for BlockNumber {
// If a block exists with a hash which isn't 32-bytes, it can be hashed into a value with 32-bytes // If a block exists with a hash which isn't 32-bytes, it can be hashed into a value with 32-bytes
// This would require the processor to maintain a mapping of 32-byte IDs to actual hashes, which // This would require the processor to maintain a mapping of 32-byte IDs to actual hashes, which
// would be fine // would be fine
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct BlockHash(pub [u8; 32]); pub struct BlockHash(pub [u8; 32]);
impl AsRef<[u8]> for BlockHash { impl AsRef<[u8]> for BlockHash {

View file

@ -4,17 +4,29 @@ use std::collections::HashMap;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
use sp_core::{ConstU32, bounded::BoundedVec}; use sp_core::{ConstU32, bounded::BoundedVec};
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
/// The type used to identify networks. /// The type used to identify networks.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum NetworkId { pub enum NetworkId {
Serai, Serai,
Bitcoin, Bitcoin,
@ -23,8 +35,21 @@ pub enum NetworkId {
} }
/// The type used to identify coins. /// The type used to identify coins.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum Coin { pub enum Coin {
Serai, Serai,
Bitcoin, Bitcoin,
@ -55,8 +80,9 @@ impl Coin {
pub const MAX_COINS_PER_NETWORK: u32 = 8; pub const MAX_COINS_PER_NETWORK: u32 = 8;
/// Network definition. /// Network definition.
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
pub struct Network { pub struct Network {
coins: BoundedVec<Coin, ConstU32<{ MAX_COINS_PER_NETWORK }>>, coins: BoundedVec<Coin, ConstU32<{ MAX_COINS_PER_NETWORK }>>,
} }

View file

@ -5,10 +5,10 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_core::{ConstU32, bounded::BoundedVec}; use sp_core::{ConstU32, bounded::BoundedVec};
@ -32,8 +32,9 @@ pub use account::*;
// When JAMTIS arrives, it'll become 114 bytes // When JAMTIS arrives, it'll become 114 bytes
pub const MAX_ADDRESS_LEN: u32 = 128; pub const MAX_ADDRESS_LEN: u32 = 128;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
pub struct ExternalAddress(BoundedVec<u8, ConstU32<{ MAX_ADDRESS_LEN }>>); pub struct ExternalAddress(BoundedVec<u8, ConstU32<{ MAX_ADDRESS_LEN }>>);
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -67,8 +68,9 @@ impl AsRef<[u8]> for ExternalAddress {
// Should be enough for a Uniswap v3 call // Should be enough for a Uniswap v3 call
pub const MAX_DATA_LEN: u32 = 512; pub const MAX_DATA_LEN: u32 = 512;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
pub struct Data(BoundedVec<u8, ConstU32<{ MAX_DATA_LEN }>>); pub struct Data(BoundedVec<u8, ConstU32<{ MAX_DATA_LEN }>>);
#[cfg(feature = "std")] #[cfg(feature = "std")]

View file

@ -94,7 +94,6 @@ use opaque::SessionKeys;
pub const VERSION: RuntimeVersion = RuntimeVersion { pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("serai"), spec_name: create_runtime_str!("serai"),
impl_name: create_runtime_str!("core"), impl_name: create_runtime_str!("core"),
authoring_version: 1,
// TODO: 1? Do we prefer some level of compatibility or our own path? // TODO: 1? Do we prefer some level of compatibility or our own path?
spec_version: 100, spec_version: 100,
impl_version: 1, impl_version: 1,
@ -188,11 +187,10 @@ impl system::Config for Runtime {
type AccountId = PublicKey; type AccountId = PublicKey;
type RuntimeCall = RuntimeCall; type RuntimeCall = RuntimeCall;
type Lookup = AccountLookup; type Lookup = AccountLookup;
type Index = Index;
type BlockNumber = BlockNumber;
type Hash = Hash; type Hash = Hash;
type Hashing = BlakeTwo256; type Hashing = BlakeTwo256;
type Header = Header; type Nonce = u32;
type Block = Block;
type RuntimeOrigin = RuntimeOrigin; type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount; type BlockHashCount = BlockHashCount;
@ -224,8 +222,8 @@ impl balances::Config for Runtime {
type Balance = SubstrateAmount; type Balance = SubstrateAmount;
type ReserveIdentifier = (); type ReserveIdentifier = ();
type HoldIdentifier = ();
type FreezeIdentifier = (); type FreezeIdentifier = ();
type RuntimeHoldReason = ();
type MaxLocks = (); type MaxLocks = ();
type MaxReserves = (); type MaxReserves = ();
@ -380,11 +378,7 @@ pub type Executive = frame_executive::Executive<
>; >;
construct_runtime!( construct_runtime!(
pub enum Runtime where pub enum Runtime {
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system, System: system,
Timestamp: timestamp, Timestamp: timestamp,

View file

@ -13,16 +13,16 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies] [dependencies]
zeroize = { version = "^1.5", features = ["derive"], optional = true } zeroize = { version = "^1.5", features = ["derive"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] } scale-info = { version = "2", default-features = false, features = ["derive"] }
serde = { version = "1", features = ["derive"], optional = true }
serai-primitives = { path = "../../primitives", default-features = false } serai-primitives = { path = "../../primitives", default-features = false }
[dev-dependencies] [dev-dependencies]
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
[features] [features]
std = ["zeroize", "scale/std", "scale-info/std", "serde", "sp-runtime/std", "serai-primitives/std"] std = ["zeroize", "serde/std", "scale/std", "scale-info/std", "sp-runtime/std", "serai-primitives/std"]
default = ["std"] default = ["std"]

View file

@ -5,32 +5,37 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use serai_primitives::{Balance, SeraiAddress, ExternalAddress, Data, pallet_address}; use serai_primitives::{Balance, SeraiAddress, ExternalAddress, Data, pallet_address};
pub const ADDRESS: SeraiAddress = pallet_address(b"Tokens"); pub const ADDRESS: SeraiAddress = pallet_address(b"Tokens");
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct OutInstruction { pub struct OutInstruction {
pub address: ExternalAddress, pub address: ExternalAddress,
pub data: Option<Data>, pub data: Option<Data>,
} }
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct OutInstructionWithBalance { pub struct OutInstructionWithBalance {
pub instruction: OutInstruction, pub instruction: OutInstruction,
pub balance: Balance, pub balance: Balance,
} }
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum Destination { pub enum Destination {
Native(SeraiAddress), Native(SeraiAddress),
External(OutInstruction), External(OutInstruction),

View file

@ -20,6 +20,7 @@ scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false } sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false } frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false } frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }

View file

@ -34,10 +34,13 @@ pub mod pallet {
pub participants: Vec<T::AccountId>, pub participants: Vec<T::AccountId>,
} }
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> { impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self { fn default() -> Self {
GenesisConfig { bond: Amount(1), networks: vec![], participants: vec![] } GenesisConfig {
bond: Amount(1),
networks: Default::default(),
participants: Default::default(),
}
} }
} }
@ -68,7 +71,7 @@ pub mod pallet {
} }
#[pallet::genesis_build] #[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> { impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) { fn build(&self) {
let hash_set = let hash_set =
self.participants.iter().map(|key| key.0).collect::<hashbrown::HashSet<[u8; 32]>>(); self.participants.iter().map(|key| key.0).collect::<hashbrown::HashSet<[u8; 32]>>();

View file

@ -14,11 +14,11 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies] [dependencies]
zeroize = { version = "^1.5", features = ["derive"], optional = true } zeroize = { version = "^1.5", features = ["derive"], optional = true }
serde = { version = "1", features = ["derive"], optional = true }
ciphersuite = { path = "../../../crypto/ciphersuite", version = "0.3", default-features = false, features = ["alloc", "ristretto"] } ciphersuite = { path = "../../../crypto/ciphersuite", version = "0.3", default-features = false, features = ["alloc", "ristretto"] }
dkg = { path = "../../../crypto/dkg", version = "0.4", default-features = false } dkg = { path = "../../../crypto/dkg", version = "0.4", default-features = false }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2", default-features = false, features = ["derive"] } scale-info = { version = "2", default-features = false, features = ["derive"] }
@ -28,5 +28,5 @@ sp-std = { git = "https://github.com/serai-dex/substrate", default-features = fa
serai-primitives = { path = "../../primitives", default-features = false } serai-primitives = { path = "../../primitives", default-features = false }
[features] [features]
std = ["zeroize", "serde", "ciphersuite/std", "dkg/std", "scale/std", "scale-info/std", "sp-core/std", "sp-std/std", "serai-primitives/std"] std = ["zeroize", "ciphersuite/std", "dkg/std", "serde/std", "scale/std", "scale-info/std", "sp-core/std", "sp-std/std", "serai-primitives/std"]
default = ["std"] default = ["std"]

View file

@ -3,13 +3,11 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
use zeroize::Zeroize; use zeroize::Zeroize;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto}; use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
use scale::{Encode, Decode, MaxEncodedLen}; use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
use serde::{Serialize, Deserialize};
use sp_core::{ConstU32, sr25519::Public, bounded::BoundedVec}; use sp_core::{ConstU32, sr25519::Public, bounded::BoundedVec};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
@ -21,13 +19,39 @@ use serai_primitives::{NetworkId, Network, Amount};
const MAX_KEY_LEN: u32 = 96; const MAX_KEY_LEN: u32 = 96;
/// The type used to identify a specific session of validators. /// The type used to identify a specific session of validators.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct Session(pub u32); pub struct Session(pub u32);
/// The type used to identify a specific validator set during a specific session. /// The type used to identify a specific validator set during a specific session.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)] #[derive(
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))] Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct ValidatorSet { pub struct ValidatorSet {
pub session: Session, pub session: Session,
pub network: NetworkId, pub network: NetworkId,