add specific network/coin/balance types (#619)

* add specific network/coin/balance types

* misc fixes

* fix clippy

* misc fixes

* fix pr comments

* Make halting for external networks

* fix encode/decode
This commit is contained in:
akildemir
2024-10-07 05:16:11 +03:00
committed by GitHub
parent d7ecab605e
commit 435f1d9ae1
91 changed files with 1536 additions and 1055 deletions

View File

@@ -53,8 +53,9 @@ use sp_runtime::{
#[allow(unused_imports)]
use primitives::{
NetworkId, PublicKey, AccountLookup, SubstrateAmount, Coin, NETWORKS, MEDIAN_PRICE_WINDOW_LENGTH,
HOURS, DAYS, MINUTES, TARGET_BLOCK_TIME, BLOCK_SIZE, FAST_EPOCH_DURATION,
NetworkId, PublicKey, AccountLookup, SubstrateAmount, Coin, EXTERNAL_NETWORKS,
MEDIAN_PRICE_WINDOW_LENGTH, HOURS, DAYS, MINUTES, TARGET_BLOCK_TIME, BLOCK_SIZE,
FAST_EPOCH_DURATION,
};
use support::{
@@ -570,10 +571,7 @@ sp_api::impl_runtime_apis! {
.map(|(id, _)| id.into_inner().0)
.collect::<hashbrown::HashSet<_>>();
let mut all = serai_validators;
for network in NETWORKS {
if network == NetworkId::Serai {
continue;
}
for network in EXTERNAL_NETWORKS {
// Returning the latest-decided, not latest and active, means the active set
// may fail to peer find if there isn't sufficient overlap. If a large amount reboot,
// forcing some validators to successfully peer find in order for the threshold to become
@@ -581,7 +579,7 @@ sp_api::impl_runtime_apis! {
//
// This is assumed not to matter in real life, yet an interesting note.
let participants =
ValidatorSets::participants_for_latest_decided_set(network)
ValidatorSets::participants_for_latest_decided_set(NetworkId::from(network))
.map_or(vec![], BoundedVec::into_inner);
for (participant, _) in participants {
all.insert(participant.0);
@@ -610,25 +608,25 @@ sp_api::impl_runtime_apis! {
impl dex::DexApi<Block> for Runtime {
fn quote_price_exact_tokens_for_tokens(
asset1: Coin,
asset2: Coin,
coin1: Coin,
coin2: Coin,
amount: SubstrateAmount,
include_fee: bool
) -> Option<SubstrateAmount> {
Dex::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee)
Dex::quote_price_exact_tokens_for_tokens(coin1, coin2, amount, include_fee)
}
fn quote_price_tokens_for_exact_tokens(
asset1: Coin,
asset2: Coin,
coin1: Coin,
coin2: Coin,
amount: SubstrateAmount,
include_fee: bool
) -> Option<SubstrateAmount> {
Dex::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee)
Dex::quote_price_tokens_for_exact_tokens(coin1, coin2, amount, include_fee)
}
fn get_reserves(asset1: Coin, asset2: Coin) -> Option<(SubstrateAmount, SubstrateAmount)> {
Dex::get_reserves(&asset1, &asset2).ok()
fn get_reserves(coin1: Coin, coin2: Coin) -> Option<(SubstrateAmount, SubstrateAmount)> {
Dex::get_reserves(&coin1, &coin2).ok()
}
}
}