make decimals part of network data
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
84195a64ef
commit
59b5356613
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -3757,7 +3757,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ghost-helpers"
|
||||
version = "0.0.8"
|
||||
version = "0.0.10"
|
||||
dependencies = [
|
||||
"frame-support",
|
||||
"ghost-traits",
|
||||
@ -4109,7 +4109,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ghost-weaver"
|
||||
version = "0.0.6"
|
||||
version = "0.0.7"
|
||||
dependencies = [
|
||||
"frame-benchmarking",
|
||||
"frame-support",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-helpers"
|
||||
version = "0.0.9"
|
||||
version = "0.0.10"
|
||||
description = "Cryptographic utility suite for custom runtimes: optimized Bitmaps, UTXO parsing, Merkle Tree proofs, and Hash Chain components."
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@ -218,6 +218,7 @@ pub struct NetworkData {
|
||||
|
||||
pub r#type: NetworkType,
|
||||
pub curve: NetworkCurve,
|
||||
pub decimals: u8,
|
||||
|
||||
pub finality_delay: u64,
|
||||
pub rate_limit_delay: u64,
|
||||
@ -235,6 +236,7 @@ pub struct NetworkDataBuilder {
|
||||
|
||||
pub r#type: NetworkType,
|
||||
pub curve: NetworkCurve,
|
||||
pub decimals: u8,
|
||||
|
||||
pub finality_delay: u64,
|
||||
pub rate_limit_delay: u64,
|
||||
@ -265,6 +267,11 @@ impl NetworkDataBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_decimals(mut self, decimals: u8) -> Self {
|
||||
self.decimals = decimals;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_finality_delay(mut self, finality_delay: u64) -> Self {
|
||||
self.finality_delay = finality_delay;
|
||||
self
|
||||
@ -323,6 +330,7 @@ impl NetworkDataBuilder {
|
||||
|
||||
r#type: self.r#type,
|
||||
curve: self.curve,
|
||||
decimals: self.decimals,
|
||||
|
||||
finality_delay: self.finality_delay,
|
||||
rate_limit_delay: self.rate_limit_delay,
|
||||
|
||||
@ -186,6 +186,18 @@ benchmarks! {
|
||||
assert_ne!(GhostNetworks::<T>::networks(chain_id), prev_network);
|
||||
}
|
||||
|
||||
update_network_decimals {
|
||||
let decimals = 18;
|
||||
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
|
||||
let authority = T::UpdateOrigin::try_successful_origin()
|
||||
.map_err(|_| BenchmarkError::Weightless)?;
|
||||
let prev_network = create_network::<T>(chain_id, network)?;
|
||||
}: _<T::RuntimeOrigin>(authority, chain_id, decimals)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::NetworkDecimalsUpdated { chain_id, decimals }.into());
|
||||
assert_ne!(GhostNetworks::<T>::networks(chain_id), prev_network);
|
||||
}
|
||||
|
||||
update_network_gatekeeper {
|
||||
let mut raw_gatekeeper = b"0x".to_vec();
|
||||
for i in 0..40 { raw_gatekeeper.push(i + 1); }
|
||||
|
||||
@ -175,6 +175,7 @@ pub mod module {
|
||||
NetworkBlockDeviationUpdated { chain_id: T::NetworkId, block_deviation: u64 },
|
||||
NetworkTypeUpdated { chain_id: T::NetworkId, network_type: NetworkType },
|
||||
NetworkCurveUpdated { chain_id: T::NetworkId, network_curve: NetworkCurve },
|
||||
NetworkDecimalsUpdated { chain_id: T::NetworkId, decimals: u8 },
|
||||
NetworkGatekeeperUpdated { chain_id: T::NetworkId },
|
||||
NetworkIncomingShareUpdated { chain_id: T::NetworkId, incoming_share: u32 },
|
||||
NetworkOutgoingShareUpdated { chain_id: T::NetworkId, outgoing_share: u32 },
|
||||
@ -396,6 +397,17 @@ pub mod module {
|
||||
T::RemoveOrigin::ensure_origin_or_root(origin)?;
|
||||
Self::do_remove_network(chain_id)
|
||||
}
|
||||
|
||||
#[pallet::call_index(12)]
|
||||
#[pallet::weight(T::WeightInfo::update_network_decimals())]
|
||||
pub fn update_network_decimals(
|
||||
origin: OriginFor<T>,
|
||||
chain_id: T::NetworkId,
|
||||
decimals: u8,
|
||||
) -> DispatchResult {
|
||||
T::UpdateOrigin::ensure_origin_or_root(origin)?;
|
||||
Self::do_update_network_decimals(chain_id, decimals)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -591,6 +603,23 @@ impl<T: Config> Pallet<T> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update existent network decimals.
|
||||
pub fn do_update_network_decimals(
|
||||
chain_id: T::NetworkId,
|
||||
decimals: u8,
|
||||
) -> DispatchResult {
|
||||
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
|
||||
let network = maybe_network.as_mut().ok_or(Error::<T>::NetworkDoesNotExist)?;
|
||||
network.decimals = decimals;
|
||||
Ok(())
|
||||
})?;
|
||||
Self::deposit_event(Event::<T>::NetworkDecimalsUpdated {
|
||||
chain_id,
|
||||
decimals,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update existent network type.
|
||||
pub fn do_update_network_type(
|
||||
chain_id: T::NetworkId,
|
||||
|
||||
@ -57,6 +57,7 @@ pub trait WeightInfo {
|
||||
fn update_network_block_deviation() -> Weight;
|
||||
fn update_network_type() -> Weight;
|
||||
fn update_network_curve() -> Weight;
|
||||
fn update_network_decimals() -> Weight;
|
||||
fn update_network_gatekeeper() -> Weight;
|
||||
fn update_incoming_network_share() -> Weight;
|
||||
fn update_outgoing_network_share() -> Weight;
|
||||
@ -182,6 +183,7 @@ impl WeightInfo for () {
|
||||
.saturating_add(RocksDbWeight::get().reads(4))
|
||||
.saturating_add(RocksDbWeight::get().writes(4))
|
||||
}
|
||||
fn update_network_decimals() -> Weight { Default::default() }
|
||||
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
|
||||
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
|
||||
fn update_network_gatekeeper() -> Weight {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user