Skip to content
Snippets Groups Projects
Commit 08f610ac authored by Éloïs's avatar Éloïs
Browse files

[feat] dbs: create db current meta (cm_v1)

parent d8734bda
Branches
No related tags found
1 merge request!1335Gva proto 2
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
db_schema!(
CmV1,
[
//["self_pubkey", self_pubkey, EmptyKey, PubKeyValV2,],
["self_peer_card", self_peer_card, EmptyKey, PeerCardDbV1,],
]
);
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
mod bc_v1; mod bc_v1;
pub mod bc_v2; pub mod bc_v2;
pub mod cm_v1;
mod errors; mod errors;
pub mod gva_v1; pub mod gva_v1;
mod keys; mod keys;
...@@ -81,6 +82,7 @@ pub use values::idty_db::IdtyDbV2; ...@@ -81,6 +82,7 @@ pub use values::idty_db::IdtyDbV2;
pub use values::iindex_db::IIndexDbV1; pub use values::iindex_db::IIndexDbV1;
pub use values::kick_db::KickDbV1; pub use values::kick_db::KickDbV1;
pub use values::mindex_db::MIndexDbV1; pub use values::mindex_db::MIndexDbV1;
pub use values::peer_card::PeerCardDbV1;
pub use values::pubkey_db::{PubKeyValV2, PublicKeyArrayDbV1, PublicKeySingletonDbV1}; pub use values::pubkey_db::{PubKeyValV2, PublicKeyArrayDbV1, PublicKeySingletonDbV1};
pub use values::sindex_db::{SIndexDBV1, SourceKeyArrayDbV1}; pub use values::sindex_db::{SIndexDBV1, SourceKeyArrayDbV1};
pub use values::source_amount::SourceAmountValV2; pub use values::source_amount::SourceAmountValV2;
...@@ -119,14 +121,13 @@ pub trait ToDumpString { ...@@ -119,14 +121,13 @@ pub trait ToDumpString {
#[cfg(feature = "mem")] #[cfg(feature = "mem")]
pub type DbsBackend = kv_typed::backend::memory::Mem; pub type DbsBackend = kv_typed::backend::memory::Mem;
#[cfg(all(not(feature = "mem"), target_arch = "x86_64"))] #[cfg(not(feature = "mem"))]
pub type DbsBackend = Sled; // TODO ESZ
#[cfg(all(not(feature = "mem"), not(target_arch = "x86_64")))]
pub type DbsBackend = Sled; pub type DbsBackend = Sled;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct DuniterDbs { pub struct DuniterDbs {
pub bc_db: bc_v2::BcV2Db<DbsBackend>, pub bc_db: bc_v2::BcV2Db<DbsBackend>,
pub cm_db: cm_v1::CmV1Db<MemSingleton>,
pub gva_db: GvaV1Db<DbsBackend>, pub gva_db: GvaV1Db<DbsBackend>,
pub txs_mp_db: TxsMpV2Db<DbsBackend>, pub txs_mp_db: TxsMpV2Db<DbsBackend>,
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::bc_v2::BcV2DbWritable as _; use crate::bc_v2::BcV2DbWritable as _;
use crate::cm_v1::CmV1DbWritable as _;
use crate::*; use crate::*;
pub fn open_dbs(home_path_opt: Option<&Path>) -> DuniterDbs { pub fn open_dbs(home_path_opt: Option<&Path>) -> DuniterDbs {
...@@ -23,6 +24,8 @@ pub fn open_dbs(home_path_opt: Option<&Path>) -> DuniterDbs { ...@@ -23,6 +24,8 @@ pub fn open_dbs(home_path_opt: Option<&Path>) -> DuniterDbs {
home_path_opt, home_path_opt,
)) ))
.expect("fail to open BcV2 DB"), .expect("fail to open BcV2 DB"),
cm_db: crate::cm_v1::CmV1Db::<MemSingleton>::open(MemSingletonConf::default())
.expect("fail to open CmV1 DB"),
gva_db: GvaV1Db::<DbsBackend>::open(DbsBackend::gen_backend_conf("gva_v1", home_path_opt)) gva_db: GvaV1Db::<DbsBackend>::open(DbsBackend::gen_backend_conf("gva_v1", home_path_opt))
.expect("fail to open Gva DB"), .expect("fail to open Gva DB"),
txs_mp_db: TxsMpV2Db::<DbsBackend>::open(DbsBackend::gen_backend_conf( txs_mp_db: TxsMpV2Db::<DbsBackend>::open(DbsBackend::gen_backend_conf(
......
...@@ -23,6 +23,7 @@ pub mod idty_db; ...@@ -23,6 +23,7 @@ pub mod idty_db;
pub mod iindex_db; pub mod iindex_db;
pub mod kick_db; pub mod kick_db;
pub mod mindex_db; pub mod mindex_db;
pub mod peer_card;
pub mod pubkey_db; pub mod pubkey_db;
pub mod sindex_db; pub mod sindex_db;
pub mod source_amount; pub mod source_amount;
......
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct PeerCardDbV1 {
pub version: u32,
pub currency: String,
pub pubkey: String,
pub blockstamp: String,
pub endpoints: Vec<String>,
pub status: String,
pub signature: String,
}
impl ValueAsBytes for PeerCardDbV1 {
fn as_bytes<T, F: FnMut(&[u8]) -> KvResult<T>>(&self, mut f: F) -> KvResult<T> {
let bytes = bincode::serialize(self).map_err(|e| KvError::DeserError(format!("{}", e)))?;
f(bytes.as_ref())
}
}
impl kv_typed::prelude::FromBytes for PeerCardDbV1 {
type Err = StringErr;
fn from_bytes(bytes: &[u8]) -> std::result::Result<Self, Self::Err> {
Ok(bincode::deserialize(&bytes).map_err(|e| StringErr(format!("{}: '{:?}'", e, bytes)))?)
}
}
impl ToDumpString for PeerCardDbV1 {
fn to_dump_string(&self) -> String {
todo!()
}
}
#[cfg(feature = "explorer")]
impl ExplorableValue for PeerCardDbV1 {
fn from_explorer_str(_source: &str) -> std::result::Result<Self, StringErr> {
unimplemented!()
}
fn to_explorer_json(&self) -> KvResult<serde_json::Value> {
serde_json::to_value(self).map_err(|e| KvError::DeserError(format!("{}", e)))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment