From f36598077e88ac1e468901a8db943025152ad332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Mon, 6 Mar 2023 06:14:57 +0000 Subject: [PATCH] gov/parameters: init via storage_api write log --- apps/src/lib/node/ledger/shell/init_chain.rs | 3 +- core/src/ledger/governance/parameters.rs | 40 +++++--------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/apps/src/lib/node/ledger/shell/init_chain.rs b/apps/src/lib/node/ledger/shell/init_chain.rs index 3ebfd50962c..2e6843a0030 100644 --- a/apps/src/lib/node/ledger/shell/init_chain.rs +++ b/apps/src/lib/node/ledger/shell/init_chain.rs @@ -147,7 +147,8 @@ where // Initialize governance parameters genesis .gov_params - .init_storage(&mut self.wl_storage.storage); + .init_storage(&mut self.wl_storage) + .expect("Initializing governance parameters must not fail"); // Depends on parameters being initialized self.wl_storage diff --git a/core/src/ledger/governance/parameters.rs b/core/src/ledger/governance/parameters.rs index 71dca8c91b4..9ae820d96c3 100644 --- a/core/src/ledger/governance/parameters.rs +++ b/core/src/ledger/governance/parameters.rs @@ -3,8 +3,7 @@ use std::fmt::Display; use borsh::{BorshDeserialize, BorshSerialize}; use super::storage as gov_storage; -use crate::ledger::storage::types::encode; -use crate::ledger::storage::{self, Storage}; +use crate::ledger::storage_api::{self, StorageRead, StorageWrite}; use crate::types::token::Amount; #[derive( @@ -66,10 +65,9 @@ impl Default for GovParams { impl GovParams { /// Initialize governance parameters into storage - pub fn init_storage(&self, storage: &mut Storage) + pub fn init_storage(&self, storage: &mut S) -> storage_api::Result<()> where - DB: storage::DB + for<'iter> storage::DBIter<'iter>, - H: storage::StorageHasher, + S: StorageRead + StorageWrite, { let Self { min_proposal_fund, @@ -82,49 +80,31 @@ impl GovParams { let min_proposal_fund_key = gov_storage::get_min_proposal_fund_key(); let amount = Amount::whole(*min_proposal_fund); - storage - .write(&min_proposal_fund_key, encode(&amount)) - .unwrap(); + storage.write(&min_proposal_fund_key, amount)?; let max_proposal_code_size_key = gov_storage::get_max_proposal_code_size_key(); - storage - .write(&max_proposal_code_size_key, encode(max_proposal_code_size)) - .unwrap(); + storage.write(&max_proposal_code_size_key, max_proposal_code_size)?; let min_proposal_period_key = gov_storage::get_min_proposal_period_key(); - storage - .write(&min_proposal_period_key, encode(min_proposal_period)) - .unwrap(); + storage.write(&min_proposal_period_key, min_proposal_period)?; let max_proposal_period_key = gov_storage::get_max_proposal_period_key(); - storage - .write(&max_proposal_period_key, encode(max_proposal_period)) - .unwrap(); + storage.write(&max_proposal_period_key, max_proposal_period)?; let max_proposal_content_size_key = gov_storage::get_max_proposal_content_key(); storage - .write( - &max_proposal_content_size_key, - encode(max_proposal_content_size), - ) - .expect("Should be able to write to storage"); + .write(&max_proposal_content_size_key, max_proposal_content_size)?; let min_proposal_grace_epoch_key = gov_storage::get_min_proposal_grace_epoch_key(); storage - .write( - &min_proposal_grace_epoch_key, - encode(min_proposal_grace_epochs), - ) - .expect("Should be able to write to storage"); + .write(&min_proposal_grace_epoch_key, min_proposal_grace_epochs)?; let counter_key = gov_storage::get_counter_key(); - storage - .write(&counter_key, encode(&u64::MIN)) - .expect("Should be able to write to storage"); + storage.write(&counter_key, u64::MIN) } }