From d1471fa1fc8018f9867780ce77fcd62fb1dd8a03 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Thu, 19 Dec 2024 13:32:02 +0100 Subject: [PATCH] stake-contract: add config management functions --- contracts/stake/src/lib.rs | 13 +++++++++++++ contracts/stake/src/state.rs | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/contracts/stake/src/lib.rs b/contracts/stake/src/lib.rs index dd38a86d1..9da757d3e 100644 --- a/contracts/stake/src/lib.rs +++ b/contracts/stake/src/lib.rs @@ -94,6 +94,11 @@ unsafe fn get_version(arg_len: u32) -> u32 { rusk_abi::wrap_call(arg_len, |_: ()| STATE.get_version()) } +#[no_mangle] +unsafe fn get_config(arg_len: u32) -> u32 { + rusk_abi::wrap_call(arg_len, |_: ()| STATE.config().clone()) +} + // "Feeder" queries #[no_mangle] @@ -116,6 +121,14 @@ unsafe fn before_state_transition(arg_len: u32) -> u32 { }) } +#[no_mangle] +unsafe fn set_config(arg_len: u32) -> u32 { + rusk_abi::wrap_call(arg_len, |config| { + assert_external_caller(); + STATE.configure(config) + }) +} + #[no_mangle] unsafe fn insert_stake(arg_len: u32) -> u32 { rusk_abi::wrap_call(arg_len, |(pk, stake_data)| { diff --git a/contracts/stake/src/state.rs b/contracts/stake/src/state.rs index 56f01d245..262b65ba0 100644 --- a/contracts/stake/src/state.rs +++ b/contracts/stake/src/state.rs @@ -53,6 +53,14 @@ impl StakeState { } } + pub fn config(&self) -> &StakeConfig { + &self.conf + } + + pub fn configure(&mut self, conf: StakeConfig) { + self.conf = conf; + } + pub fn on_new_block(&mut self) { self.previous_block_state.clear() }