forked from ghostchain/ghost-node
		
	rustfmt the ghost-networks pallet
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
		
							parent
							
								
									40a8152f69
								
							
						
					
					
						commit
						f7ba592d50
					
				@ -1,6 +1,6 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "ghost-networks"
 | 
			
		||||
version = "0.1.10"
 | 
			
		||||
version = "0.1.11"
 | 
			
		||||
license.workspace = true
 | 
			
		||||
authors.workspace = true
 | 
			
		||||
edition.workspace = true
 | 
			
		||||
 | 
			
		||||
@ -13,17 +13,19 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
 | 
			
		||||
    frame_system::Pallet::<T>::assert_last_event(generic_event.into());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn prepare_network<T: Config>(
 | 
			
		||||
    n: u32, m: u32,
 | 
			
		||||
) -> (<T as module::Config>::NetworkId, NetworkData) {
 | 
			
		||||
fn prepare_network<T: Config>(n: u32, m: u32) -> (<T as module::Config>::NetworkId, NetworkData) {
 | 
			
		||||
    let chain_id: <T as module::Config>::NetworkId = Default::default();
 | 
			
		||||
    let chain_id = chain_id.saturating_add((n + m).into());
 | 
			
		||||
 | 
			
		||||
    let mut gatekeeper = b"0x".to_vec();
 | 
			
		||||
    for i in 0..40 { gatekeeper.push(i); }
 | 
			
		||||
    for i in 0..40 {
 | 
			
		||||
        gatekeeper.push(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let mut topic_name = b"0x".to_vec();
 | 
			
		||||
    for i in 0..64 { topic_name.push(i); }
 | 
			
		||||
    for i in 0..64 {
 | 
			
		||||
        topic_name.push(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let network = NetworkData {
 | 
			
		||||
        chain_name: sp_std::vec![0x69; n as usize],
 | 
			
		||||
@ -51,8 +53,11 @@ fn create_network<T: Config>(
 | 
			
		||||
            let authority = T::RegisterOrigin::try_successful_origin()
 | 
			
		||||
                .map_err(|_| BenchmarkError::Weightless)?;
 | 
			
		||||
            GhostNetworks::<T>::register_network(
 | 
			
		||||
                authority.clone(), chain_id.clone(), network.clone()
 | 
			
		||||
            ).map_err(|_| BenchmarkError::Weightless)?;
 | 
			
		||||
                authority.clone(),
 | 
			
		||||
                chain_id.clone(),
 | 
			
		||||
                network.clone(),
 | 
			
		||||
            )
 | 
			
		||||
            .map_err(|_| BenchmarkError::Weightless)?;
 | 
			
		||||
            network
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@ -4,27 +4,27 @@
 | 
			
		||||
 | 
			
		||||
use frame_support::{
 | 
			
		||||
    pallet_prelude::*,
 | 
			
		||||
    storage::PrefixIterator, traits::{tokens::fungible::Inspect, EnsureOrigin},
 | 
			
		||||
    storage::PrefixIterator,
 | 
			
		||||
    traits::{tokens::fungible::Inspect, EnsureOrigin},
 | 
			
		||||
};
 | 
			
		||||
use frame_system::pallet_prelude::*;
 | 
			
		||||
use scale_info::TypeInfo;
 | 
			
		||||
 | 
			
		||||
use sp_runtime::{
 | 
			
		||||
    traits::{CheckedSub, CheckedAdd, AtLeast32BitUnsigned, Member},
 | 
			
		||||
    curve::PiecewiseLinear,
 | 
			
		||||
    traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Member},
 | 
			
		||||
    DispatchResult,
 | 
			
		||||
};
 | 
			
		||||
use sp_std::{prelude::*, convert::TryInto};
 | 
			
		||||
use sp_std::{convert::TryInto, prelude::*};
 | 
			
		||||
 | 
			
		||||
pub use ghost_traits::networks::{
 | 
			
		||||
    NetworkDataBasicHandler, NetworkDataInspectHandler, 
 | 
			
		||||
    NetworkDataMutateHandler,
 | 
			
		||||
    NetworkDataBasicHandler, NetworkDataInspectHandler, NetworkDataMutateHandler,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
mod weights;
 | 
			
		||||
 | 
			
		||||
pub use module::*;
 | 
			
		||||
pub use crate::weights::WeightInfo;
 | 
			
		||||
pub use module::*;
 | 
			
		||||
 | 
			
		||||
#[cfg(any(feature = "runtime-benchmarks", test))]
 | 
			
		||||
mod benchmarking;
 | 
			
		||||
@ -33,9 +33,8 @@ mod mock;
 | 
			
		||||
#[cfg(all(feature = "std", test))]
 | 
			
		||||
mod tests;
 | 
			
		||||
 | 
			
		||||
pub type BalanceOf<T> = <<T as Config>::Currency as Inspect<
 | 
			
		||||
    <T as frame_system::Config>::AccountId,
 | 
			
		||||
>>::Balance;
 | 
			
		||||
pub type BalanceOf<T> =
 | 
			
		||||
    <<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance;
 | 
			
		||||
 | 
			
		||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
 | 
			
		||||
pub enum NetworkType {
 | 
			
		||||
@ -45,7 +44,9 @@ pub enum NetworkType {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Default for NetworkType {
 | 
			
		||||
    fn default() -> Self { NetworkType::Evm }
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
        NetworkType::Evm
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
 | 
			
		||||
@ -69,7 +70,8 @@ pub struct BridgeAdjustment<Balance> {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct BridgedInflationCurve<RewardCurve, T>(core::marker::PhantomData<(RewardCurve, T)>);
 | 
			
		||||
impl<Balance, RewardCurve, T> pallet_staking::EraPayout<Balance> for BridgedInflationCurve<RewardCurve, T>
 | 
			
		||||
impl<Balance, RewardCurve, T> pallet_staking::EraPayout<Balance>
 | 
			
		||||
    for BridgedInflationCurve<RewardCurve, T>
 | 
			
		||||
where
 | 
			
		||||
    Balance: Default + AtLeast32BitUnsigned + Clone + Copy + From<u128>,
 | 
			
		||||
    RewardCurve: Get<&'static PiecewiseLinear<'static>>,
 | 
			
		||||
@ -99,10 +101,11 @@ where
 | 
			
		||||
        match piecewise_linear
 | 
			
		||||
            .calculate_for_fraction_times_denominator(total_staked, adjusted_issuance)
 | 
			
		||||
            .checked_mul(&accumulated_balance)
 | 
			
		||||
            .and_then(|product| product.checked_div(&adjusted_issuance)) {
 | 
			
		||||
                Some(payout) => (payout, accumulated_balance.saturating_sub(payout)),
 | 
			
		||||
                None => (Balance::default(), Balance::default()),
 | 
			
		||||
            }
 | 
			
		||||
            .and_then(|product| product.checked_div(&adjusted_issuance))
 | 
			
		||||
        {
 | 
			
		||||
            Some(payout) => (payout, accumulated_balance.saturating_sub(payout)),
 | 
			
		||||
            None => (Balance::default(), Balance::default()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -155,18 +158,53 @@ pub mod module {
 | 
			
		||||
    #[pallet::event]
 | 
			
		||||
    #[pallet::generate_deposit(pub(crate) fn deposit_event)]
 | 
			
		||||
    pub enum Event<T: Config> {
 | 
			
		||||
        NetworkRegistered { chain_id: T::NetworkId, network: NetworkData },
 | 
			
		||||
        NetworkNameUpdated { chain_id: T::NetworkId, chain_name: Vec<u8> },
 | 
			
		||||
        NetworkEndpointUpdated { chain_id: T::NetworkId, default_endpoint: Vec<u8> },
 | 
			
		||||
        NetworkFinalityDelayUpdated { chain_id: T::NetworkId, finality_delay: u64 },
 | 
			
		||||
        NetworkRateLimitDelayUpdated { chain_id: T::NetworkId, rate_limit_delay: u64 },
 | 
			
		||||
        NetworkBlockDistanceUpdated { chain_id: T::NetworkId, block_distance: u64 },
 | 
			
		||||
        NetworkTypeUpdated { chain_id: T::NetworkId, network_type: NetworkType },
 | 
			
		||||
        NetworkGatekeeperUpdated { chain_id: T::NetworkId, gatekeeper: Vec<u8> },
 | 
			
		||||
        NetworkTopicNameUpdated { chain_id: T::NetworkId, topic_name: Vec<u8> },
 | 
			
		||||
        NetworkIncomingFeeUpdated { chain_id: T::NetworkId, incoming_fee: u32 },
 | 
			
		||||
        NetworkOutgoingFeeUpdated { chain_id: T::NetworkId, outgoing_fee: u32 },
 | 
			
		||||
        NetworkRemoved { chain_id: T::NetworkId },
 | 
			
		||||
        NetworkRegistered {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            network: NetworkData,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkNameUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            chain_name: Vec<u8>,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkEndpointUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            default_endpoint: Vec<u8>,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkFinalityDelayUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            finality_delay: u64,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkRateLimitDelayUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            rate_limit_delay: u64,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkBlockDistanceUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            block_distance: u64,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkTypeUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            network_type: NetworkType,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkGatekeeperUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            gatekeeper: Vec<u8>,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkTopicNameUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            topic_name: Vec<u8>,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkIncomingFeeUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            incoming_fee: u32,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkOutgoingFeeUpdated {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
            outgoing_fee: u32,
 | 
			
		||||
        },
 | 
			
		||||
        NetworkRemoved {
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
        },
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[pallet::storage]
 | 
			
		||||
@ -180,8 +218,7 @@ pub mod module {
 | 
			
		||||
 | 
			
		||||
    #[pallet::storage]
 | 
			
		||||
    #[pallet::getter(fn accumulated_commission)]
 | 
			
		||||
    pub type AccumulatedCommission<T: Config> =
 | 
			
		||||
        StorageValue<_, BalanceOf<T>, ValueQuery>;
 | 
			
		||||
    pub type AccumulatedCommission<T: Config> = StorageValue<_, BalanceOf<T>, ValueQuery>;
 | 
			
		||||
 | 
			
		||||
    #[pallet::storage]
 | 
			
		||||
    #[pallet::getter(fn networks)]
 | 
			
		||||
@ -190,13 +227,8 @@ pub mod module {
 | 
			
		||||
 | 
			
		||||
    #[pallet::storage]
 | 
			
		||||
    #[pallet::getter(fn gatekeeper_amount)]
 | 
			
		||||
    pub type GatekeeperAmount<T: Config> = StorageMap<
 | 
			
		||||
        _,
 | 
			
		||||
        Twox64Concat,
 | 
			
		||||
        T::NetworkId,
 | 
			
		||||
        BalanceOf<T>,
 | 
			
		||||
        ValueQuery,
 | 
			
		||||
    >;
 | 
			
		||||
    pub type GatekeeperAmount<T: Config> =
 | 
			
		||||
        StorageMap<_, Twox64Concat, T::NetworkId, BalanceOf<T>, ValueQuery>;
 | 
			
		||||
 | 
			
		||||
    #[pallet::genesis_config]
 | 
			
		||||
    pub struct GenesisConfig<T: Config> {
 | 
			
		||||
@ -213,12 +245,13 @@ pub mod module {
 | 
			
		||||
    impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
 | 
			
		||||
        fn build(&self) {
 | 
			
		||||
            if !self.networks.is_empty() {
 | 
			
		||||
                self.networks.iter().for_each(|(chain_id, network_metadata)| {
 | 
			
		||||
                    let network =
 | 
			
		||||
                        NetworkData::decode(&mut &network_metadata[..])
 | 
			
		||||
                        .expect("Error decoding NetworkData");
 | 
			
		||||
                    Pallet::<T>::do_register_network(chain_id.clone(), network)
 | 
			
		||||
                        .expect("Error registering network");
 | 
			
		||||
                self.networks
 | 
			
		||||
                    .iter()
 | 
			
		||||
                    .for_each(|(chain_id, network_metadata)| {
 | 
			
		||||
                        let network = NetworkData::decode(&mut &network_metadata[..])
 | 
			
		||||
                            .expect("Error decoding NetworkData");
 | 
			
		||||
                        Pallet::<T>::do_register_network(chain_id.clone(), network)
 | 
			
		||||
                            .expect("Error registering network");
 | 
			
		||||
                    });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@ -268,10 +301,7 @@ pub mod module {
 | 
			
		||||
            chain_name: Vec<u8>,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_name(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                chain_name,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_network_name(chain_id, chain_name)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(2)]
 | 
			
		||||
@ -284,10 +314,7 @@ pub mod module {
 | 
			
		||||
            default_endpoint: Vec<u8>,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_endpoint(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                default_endpoint,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_network_endpoint(chain_id, default_endpoint)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(3)]
 | 
			
		||||
@ -298,10 +325,7 @@ pub mod module {
 | 
			
		||||
            finality_delay: u64,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_finality_delay(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                finality_delay,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_network_finality_delay(chain_id, finality_delay)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(4)]
 | 
			
		||||
@ -312,10 +336,7 @@ pub mod module {
 | 
			
		||||
            rate_limit_delay: u64,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_rate_limit_delay(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                rate_limit_delay,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_network_rate_limit_delay(chain_id, rate_limit_delay)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(5)]
 | 
			
		||||
@ -326,10 +347,7 @@ pub mod module {
 | 
			
		||||
            block_distance: u64,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_block_distance(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                block_distance,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_network_block_distance(chain_id, block_distance)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(6)]
 | 
			
		||||
@ -340,10 +358,7 @@ pub mod module {
 | 
			
		||||
            network_type: NetworkType,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_type(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                network_type,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_network_type(chain_id, network_type)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(7)]
 | 
			
		||||
@ -354,10 +369,7 @@ pub mod module {
 | 
			
		||||
            gatekeeper: Vec<u8>,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_gatekeeper(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                gatekeeper,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_network_gatekeeper(chain_id, gatekeeper)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(8)]
 | 
			
		||||
@ -368,10 +380,7 @@ pub mod module {
 | 
			
		||||
            topic_name: Vec<u8>,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_network_topic_name(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                topic_name,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_network_topic_name(chain_id, topic_name)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(9)]
 | 
			
		||||
@ -382,10 +391,7 @@ pub mod module {
 | 
			
		||||
            incoming_fee: u32,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_incoming_network_fee(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                incoming_fee,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_incoming_network_fee(chain_id, incoming_fee)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(10)]
 | 
			
		||||
@ -396,18 +402,12 @@ pub mod module {
 | 
			
		||||
            outgoing_fee: u32,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
            T::UpdateOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_update_outgoing_network_fee(
 | 
			
		||||
                chain_id,
 | 
			
		||||
                outgoing_fee,
 | 
			
		||||
            )
 | 
			
		||||
            Self::do_update_outgoing_network_fee(chain_id, outgoing_fee)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[pallet::call_index(11)]
 | 
			
		||||
        #[pallet::weight(T::WeightInfo::remove_network())]
 | 
			
		||||
        pub fn remove_network(
 | 
			
		||||
            origin: OriginFor<T>,
 | 
			
		||||
            chain_id: T::NetworkId,
 | 
			
		||||
        ) -> DispatchResult {
 | 
			
		||||
        pub fn remove_network(origin: OriginFor<T>, chain_id: T::NetworkId) -> DispatchResult {
 | 
			
		||||
            T::RemoveOrigin::ensure_origin_or_root(origin)?;
 | 
			
		||||
            Self::do_remove_network(chain_id)
 | 
			
		||||
        }
 | 
			
		||||
@ -416,12 +416,12 @@ pub mod module {
 | 
			
		||||
 | 
			
		||||
impl<T: Config> Pallet<T> {
 | 
			
		||||
    /// Register a new network.
 | 
			
		||||
    pub fn do_register_network(
 | 
			
		||||
        chain_id: T::NetworkId,
 | 
			
		||||
        network: NetworkData,
 | 
			
		||||
    ) -> DispatchResult {
 | 
			
		||||
    pub fn do_register_network(chain_id: T::NetworkId, network: NetworkData) -> DispatchResult {
 | 
			
		||||
        Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
 | 
			
		||||
            ensure!(maybe_network.is_none(), Error::<T>::NetworkAlreadyRegistered);
 | 
			
		||||
            ensure!(
 | 
			
		||||
                maybe_network.is_none(),
 | 
			
		||||
                Error::<T>::NetworkAlreadyRegistered
 | 
			
		||||
            );
 | 
			
		||||
            *maybe_network = Some(network.clone());
 | 
			
		||||
            Ok(())
 | 
			
		||||
        })?;
 | 
			
		||||
@ -443,10 +443,7 @@ impl<T: Config> Pallet<T> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Update existent network name.
 | 
			
		||||
    pub fn do_update_network_name(
 | 
			
		||||
        chain_id: T::NetworkId,
 | 
			
		||||
        chain_name: Vec<u8>,
 | 
			
		||||
    ) -> DispatchResult {
 | 
			
		||||
    pub fn do_update_network_name(chain_id: T::NetworkId, chain_name: Vec<u8>) -> DispatchResult {
 | 
			
		||||
        Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
 | 
			
		||||
            ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
 | 
			
		||||
            let net = maybe_network.as_mut().unwrap();
 | 
			
		||||
@ -562,8 +559,10 @@ impl<T: Config> Pallet<T> {
 | 
			
		||||
        chain_id: T::NetworkId,
 | 
			
		||||
        gatekeeper: Vec<u8>,
 | 
			
		||||
    ) -> DispatchResult {
 | 
			
		||||
        ensure!(gatekeeper.len() == 42 && gatekeeper[0] == 48 && gatekeeper[1] == 120, 
 | 
			
		||||
            Error::<T>::WrongGatekeeperAddress);
 | 
			
		||||
        ensure!(
 | 
			
		||||
            gatekeeper.len() == 42 && gatekeeper[0] == 48 && gatekeeper[1] == 120,
 | 
			
		||||
            Error::<T>::WrongGatekeeperAddress
 | 
			
		||||
        );
 | 
			
		||||
        Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
 | 
			
		||||
            ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
 | 
			
		||||
            let net = maybe_network.as_mut().unwrap();
 | 
			
		||||
@ -583,8 +582,10 @@ impl<T: Config> Pallet<T> {
 | 
			
		||||
        chain_id: T::NetworkId,
 | 
			
		||||
        topic_name: Vec<u8>,
 | 
			
		||||
    ) -> DispatchResult {
 | 
			
		||||
        ensure!(topic_name.len() == 66 && topic_name[0] == 48 && topic_name[1] == 120, 
 | 
			
		||||
            Error::<T>::WrongTopicName);
 | 
			
		||||
        ensure!(
 | 
			
		||||
            topic_name.len() == 66 && topic_name[0] == 48 && topic_name[1] == 120,
 | 
			
		||||
            Error::<T>::WrongTopicName
 | 
			
		||||
        );
 | 
			
		||||
        Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
 | 
			
		||||
            ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
 | 
			
		||||
            let net = maybe_network.as_mut().unwrap();
 | 
			
		||||
@ -667,15 +668,16 @@ impl<T: Config> NetworkDataMutateHandler<NetworkData, BalanceOf<T>> for Pallet<T
 | 
			
		||||
        network_id: &T::NetworkId,
 | 
			
		||||
        amount: &BalanceOf<T>,
 | 
			
		||||
    ) -> Result<BalanceOf<T>, ()> {
 | 
			
		||||
        let new_gatekeeper_amount = GatekeeperAmount::<T>::mutate(network_id, |gatekeeper_amount| {
 | 
			
		||||
            match gatekeeper_amount.checked_add(amount) {
 | 
			
		||||
        let new_gatekeeper_amount =
 | 
			
		||||
            GatekeeperAmount::<T>::mutate(network_id, |gatekeeper_amount| match gatekeeper_amount
 | 
			
		||||
                .checked_add(amount)
 | 
			
		||||
            {
 | 
			
		||||
                Some(value) => {
 | 
			
		||||
                    *gatekeeper_amount = value;
 | 
			
		||||
                    Ok(value)
 | 
			
		||||
                },
 | 
			
		||||
                None => Err(())
 | 
			
		||||
            }
 | 
			
		||||
        })?;
 | 
			
		||||
                }
 | 
			
		||||
                None => Err(()),
 | 
			
		||||
            })?;
 | 
			
		||||
 | 
			
		||||
        Ok(new_gatekeeper_amount)
 | 
			
		||||
    }
 | 
			
		||||
@ -684,28 +686,29 @@ impl<T: Config> NetworkDataMutateHandler<NetworkData, BalanceOf<T>> for Pallet<T
 | 
			
		||||
        network_id: &T::NetworkId,
 | 
			
		||||
        amount: &BalanceOf<T>,
 | 
			
		||||
    ) -> Result<BalanceOf<T>, ()> {
 | 
			
		||||
        let new_gatekeeper_amount = GatekeeperAmount::<T>::mutate(network_id, |gatekeeper_amount| {
 | 
			
		||||
            match gatekeeper_amount.checked_sub(amount) {
 | 
			
		||||
        let new_gatekeeper_amount =
 | 
			
		||||
            GatekeeperAmount::<T>::mutate(network_id, |gatekeeper_amount| match gatekeeper_amount
 | 
			
		||||
                .checked_sub(amount)
 | 
			
		||||
            {
 | 
			
		||||
                Some(value) => {
 | 
			
		||||
                    *gatekeeper_amount = value;
 | 
			
		||||
                    Ok(value)
 | 
			
		||||
                },
 | 
			
		||||
                None => Err(())
 | 
			
		||||
            }
 | 
			
		||||
        })?;
 | 
			
		||||
                }
 | 
			
		||||
                None => Err(()),
 | 
			
		||||
            })?;
 | 
			
		||||
 | 
			
		||||
        Ok(new_gatekeeper_amount)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn accumulate_outgoing_imbalance(amount: &BalanceOf<T>) -> Result<BalanceOf<T>, ()> {
 | 
			
		||||
        let new_bridged_out_amount = BridgedImbalance::<T>::mutate(|bridged_imbalance| {
 | 
			
		||||
             match bridged_imbalance.bridged_out.checked_add(amount) {
 | 
			
		||||
                 Some(value) => {
 | 
			
		||||
                     (*bridged_imbalance).bridged_out = value;
 | 
			
		||||
                     Ok(value)
 | 
			
		||||
                 },
 | 
			
		||||
                 None => Err(())
 | 
			
		||||
             }
 | 
			
		||||
            match bridged_imbalance.bridged_out.checked_add(amount) {
 | 
			
		||||
                Some(value) => {
 | 
			
		||||
                    (*bridged_imbalance).bridged_out = value;
 | 
			
		||||
                    Ok(value)
 | 
			
		||||
                }
 | 
			
		||||
                None => Err(()),
 | 
			
		||||
            }
 | 
			
		||||
        })?;
 | 
			
		||||
 | 
			
		||||
        Ok(new_bridged_out_amount)
 | 
			
		||||
@ -717,8 +720,8 @@ impl<T: Config> NetworkDataMutateHandler<NetworkData, BalanceOf<T>> for Pallet<T
 | 
			
		||||
                Some(value) => {
 | 
			
		||||
                    (*bridged_imbalance).bridged_in = value;
 | 
			
		||||
                    Ok(value)
 | 
			
		||||
                },
 | 
			
		||||
                None => Err(())
 | 
			
		||||
                }
 | 
			
		||||
                None => Err(()),
 | 
			
		||||
            }
 | 
			
		||||
        })?;
 | 
			
		||||
 | 
			
		||||
@ -731,7 +734,7 @@ impl<T: Config> NetworkDataMutateHandler<NetworkData, BalanceOf<T>> for Pallet<T
 | 
			
		||||
                Some(value) => {
 | 
			
		||||
                    *accumulated = value;
 | 
			
		||||
                    Ok(value)
 | 
			
		||||
                },
 | 
			
		||||
                }
 | 
			
		||||
                None => Err(()),
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
@ -1,17 +1,16 @@
 | 
			
		||||
use crate::{self as ghost_networks};
 | 
			
		||||
use frame_system::EnsureSignedBy;
 | 
			
		||||
use frame_support::{
 | 
			
		||||
    construct_runtime, ord_parameter_types, parameter_types,
 | 
			
		||||
    traits::{ConstU128, ConstU32, Everything},
 | 
			
		||||
};
 | 
			
		||||
use frame_system::EnsureSignedBy;
 | 
			
		||||
pub use primitives::{
 | 
			
		||||
    AccountId, Balance, Nonce, BlockNumber, Hash,
 | 
			
		||||
    ReserveIdentifier, FreezeIdentifier,
 | 
			
		||||
    AccountId, Balance, BlockNumber, FreezeIdentifier, Hash, Nonce, ReserveIdentifier,
 | 
			
		||||
};
 | 
			
		||||
use sp_runtime::{
 | 
			
		||||
    curve::PiecewiseLinear,
 | 
			
		||||
    traits::{AccountIdLookup, BlakeTwo256},
 | 
			
		||||
    BuildStorage
 | 
			
		||||
    BuildStorage,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
parameter_types! {
 | 
			
		||||
@ -96,9 +95,9 @@ impl ghost_networks::Config for Test {
 | 
			
		||||
    type RuntimeEvent = RuntimeEvent;
 | 
			
		||||
    type Currency = Balances;
 | 
			
		||||
    type NetworkId = u32;
 | 
			
		||||
    type RegisterOrigin = EnsureSignedBy::<RegistererAccount, AccountId>;
 | 
			
		||||
    type UpdateOrigin = EnsureSignedBy::<UpdaterAccount, AccountId>;
 | 
			
		||||
    type RemoveOrigin = EnsureSignedBy::<RemoverAccount, AccountId>;
 | 
			
		||||
    type RegisterOrigin = EnsureSignedBy<RegistererAccount, AccountId>;
 | 
			
		||||
    type UpdateOrigin = EnsureSignedBy<UpdaterAccount, AccountId>;
 | 
			
		||||
    type RemoveOrigin = EnsureSignedBy<RemoverAccount, AccountId>;
 | 
			
		||||
    type WeightInfo = crate::weights::SubstrateWeight<Test>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user