-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compare the genesis in storage and code when server start, then sugge…
…st users clean the storage (#682) * compare the genesis in storage and code when server start * fixed genesis match and and suggest user * revert coin doc changes * remove redundent clone call * remove docs in geneis crate
- Loading branch information
Showing
9 changed files
with
152 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,63 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::CONFIG_PREFIX_NAME; | ||
use crate::{CONFIG_GENESIS_PREFIX_NAME, CONFIG_STARTUP_INFO_PREFIX_NAME}; | ||
use anyhow::Result; | ||
use moveos_types::h256::H256; | ||
use moveos_types::startup_info::StartupInfo; | ||
use raw_store::{derive_store, CodecKVStore}; | ||
use raw_store::{derive_store, CodecKVStore, StoreInstance}; | ||
use std::string::ToString; | ||
|
||
pub const STARTUP_INFO_KEY: &str = "startup_info"; | ||
pub const GENESIS_KEY: &str = "genesis"; | ||
|
||
derive_store!(StartupInfoDBStore, String, StartupInfo, CONFIG_PREFIX_NAME); | ||
derive_store!( | ||
StartupInfoStore, | ||
String, | ||
StartupInfo, | ||
CONFIG_STARTUP_INFO_PREFIX_NAME | ||
); | ||
derive_store!(GenesisStore, String, H256, CONFIG_GENESIS_PREFIX_NAME); | ||
|
||
pub trait ConfigStore { | ||
fn get_startup_info(&self) -> Result<Option<StartupInfo>>; | ||
|
||
fn save_startup_info(&self, startup_info: StartupInfo) -> Result<()>; | ||
|
||
fn get_genesis(&self) -> Result<Option<H256>>; | ||
|
||
fn save_genesis(&self, genesis_hash: H256) -> Result<()>; | ||
} | ||
|
||
impl ConfigStore for StartupInfoDBStore { | ||
fn get_startup_info(&self) -> Result<Option<StartupInfo>> { | ||
self.kv_get(STARTUP_INFO_KEY.to_string()) | ||
#[derive(Clone)] | ||
pub struct ConfigDBStore { | ||
startup_store: StartupInfoStore, | ||
genesis_store: GenesisStore, | ||
} | ||
|
||
impl ConfigDBStore { | ||
pub fn new(instance: StoreInstance) -> Self { | ||
ConfigDBStore { | ||
startup_store: StartupInfoStore::new(instance.clone()), | ||
genesis_store: GenesisStore::new(instance), | ||
} | ||
} | ||
|
||
pub fn get_startup_info(&self) -> Result<Option<StartupInfo>> { | ||
self.startup_store.kv_get(STARTUP_INFO_KEY.to_string()) | ||
} | ||
|
||
pub fn save_startup_info(&self, startup_info: StartupInfo) -> Result<()> { | ||
self.startup_store | ||
.put_sync(STARTUP_INFO_KEY.to_string(), startup_info) | ||
} | ||
|
||
pub fn get_genesis(&self) -> Result<Option<H256>> { | ||
self.genesis_store.kv_get(GENESIS_KEY.to_string()) | ||
} | ||
|
||
fn save_startup_info(&self, startup_info: StartupInfo) -> Result<()> { | ||
self.put_sync(STARTUP_INFO_KEY.to_string(), startup_info) | ||
pub fn save_genesis(&self, genesis_hash: H256) -> Result<()> { | ||
self.genesis_store | ||
.put_sync(GENESIS_KEY.to_string(), genesis_hash) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters