make decimals part of network data

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2026-09-10 21:40:06 +03:00
parent 84195a64ef
commit 59b5356613
Signed by: st1nky
GPG Key ID: 016064BD97603B40
6 changed files with 54 additions and 3 deletions

4
Cargo.lock generated
View File

@ -3757,7 +3757,7 @@ dependencies = [
[[package]] [[package]]
name = "ghost-helpers" name = "ghost-helpers"
version = "0.0.8" version = "0.0.10"
dependencies = [ dependencies = [
"frame-support", "frame-support",
"ghost-traits", "ghost-traits",
@ -4109,7 +4109,7 @@ dependencies = [
[[package]] [[package]]
name = "ghost-weaver" name = "ghost-weaver"
version = "0.0.6" version = "0.0.7"
dependencies = [ dependencies = [
"frame-benchmarking", "frame-benchmarking",
"frame-support", "frame-support",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "ghost-helpers" 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." description = "Cryptographic utility suite for custom runtimes: optimized Bitmaps, UTXO parsing, Merkle Tree proofs, and Hash Chain components."
license.workspace = true license.workspace = true
authors.workspace = true authors.workspace = true

View File

@ -218,6 +218,7 @@ pub struct NetworkData {
pub r#type: NetworkType, pub r#type: NetworkType,
pub curve: NetworkCurve, pub curve: NetworkCurve,
pub decimals: u8,
pub finality_delay: u64, pub finality_delay: u64,
pub rate_limit_delay: u64, pub rate_limit_delay: u64,
@ -235,6 +236,7 @@ pub struct NetworkDataBuilder {
pub r#type: NetworkType, pub r#type: NetworkType,
pub curve: NetworkCurve, pub curve: NetworkCurve,
pub decimals: u8,
pub finality_delay: u64, pub finality_delay: u64,
pub rate_limit_delay: u64, pub rate_limit_delay: u64,
@ -265,6 +267,11 @@ impl NetworkDataBuilder {
self 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 { pub fn with_finality_delay(mut self, finality_delay: u64) -> Self {
self.finality_delay = finality_delay; self.finality_delay = finality_delay;
self self
@ -323,6 +330,7 @@ impl NetworkDataBuilder {
r#type: self.r#type, r#type: self.r#type,
curve: self.curve, curve: self.curve,
decimals: self.decimals,
finality_delay: self.finality_delay, finality_delay: self.finality_delay,
rate_limit_delay: self.rate_limit_delay, rate_limit_delay: self.rate_limit_delay,

View File

@ -186,6 +186,18 @@ benchmarks! {
assert_ne!(GhostNetworks::<T>::networks(chain_id), prev_network); 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 { update_network_gatekeeper {
let mut raw_gatekeeper = b"0x".to_vec(); let mut raw_gatekeeper = b"0x".to_vec();
for i in 0..40 { raw_gatekeeper.push(i + 1); } for i in 0..40 { raw_gatekeeper.push(i + 1); }

View File

@ -175,6 +175,7 @@ pub mod module {
NetworkBlockDeviationUpdated { chain_id: T::NetworkId, block_deviation: u64 }, NetworkBlockDeviationUpdated { chain_id: T::NetworkId, block_deviation: u64 },
NetworkTypeUpdated { chain_id: T::NetworkId, network_type: NetworkType }, NetworkTypeUpdated { chain_id: T::NetworkId, network_type: NetworkType },
NetworkCurveUpdated { chain_id: T::NetworkId, network_curve: NetworkCurve }, NetworkCurveUpdated { chain_id: T::NetworkId, network_curve: NetworkCurve },
NetworkDecimalsUpdated { chain_id: T::NetworkId, decimals: u8 },
NetworkGatekeeperUpdated { chain_id: T::NetworkId }, NetworkGatekeeperUpdated { chain_id: T::NetworkId },
NetworkIncomingShareUpdated { chain_id: T::NetworkId, incoming_share: u32 }, NetworkIncomingShareUpdated { chain_id: T::NetworkId, incoming_share: u32 },
NetworkOutgoingShareUpdated { chain_id: T::NetworkId, outgoing_share: u32 }, NetworkOutgoingShareUpdated { chain_id: T::NetworkId, outgoing_share: u32 },
@ -396,6 +397,17 @@ pub mod module {
T::RemoveOrigin::ensure_origin_or_root(origin)?; T::RemoveOrigin::ensure_origin_or_root(origin)?;
Self::do_remove_network(chain_id) 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(()) 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. /// Update existent network type.
pub fn do_update_network_type( pub fn do_update_network_type(
chain_id: T::NetworkId, chain_id: T::NetworkId,

View File

@ -57,6 +57,7 @@ pub trait WeightInfo {
fn update_network_block_deviation() -> Weight; fn update_network_block_deviation() -> Weight;
fn update_network_type() -> Weight; fn update_network_type() -> Weight;
fn update_network_curve() -> Weight; fn update_network_curve() -> Weight;
fn update_network_decimals() -> Weight;
fn update_network_gatekeeper() -> Weight; fn update_network_gatekeeper() -> Weight;
fn update_incoming_network_share() -> Weight; fn update_incoming_network_share() -> Weight;
fn update_outgoing_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().reads(4))
.saturating_add(RocksDbWeight::get().writes(4)) .saturating_add(RocksDbWeight::get().writes(4))
} }
fn update_network_decimals() -> Weight { Default::default() }
/// Storage: `GhostNetworks::Networks` (r:1 w:1) /// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_gatekeeper() -> Weight { fn update_network_gatekeeper() -> Weight {