diff --git a/rust-libs/duniter-dbs/src/cm_v1.rs b/rust-libs/duniter-dbs/src/cm_v1.rs new file mode 100644 index 0000000000000000000000000000000000000000..0f3b2b61fd2f7ed8fc2c300d27f9ee07b85abad4 --- /dev/null +++ b/rust-libs/duniter-dbs/src/cm_v1.rs @@ -0,0 +1,24 @@ +// 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,], + ] +); diff --git a/rust-libs/duniter-dbs/src/lib.rs b/rust-libs/duniter-dbs/src/lib.rs index 7eaaf508750fb24ff219d2f67e0381373beba049..ebbe6c13c85c65685a13ce8fb5e65815a8e336fd 100644 --- a/rust-libs/duniter-dbs/src/lib.rs +++ b/rust-libs/duniter-dbs/src/lib.rs @@ -24,6 +24,7 @@ mod bc_v1; pub mod bc_v2; +pub mod cm_v1; mod errors; pub mod gva_v1; mod keys; @@ -81,6 +82,7 @@ pub use values::idty_db::IdtyDbV2; pub use values::iindex_db::IIndexDbV1; pub use values::kick_db::KickDbV1; pub use values::mindex_db::MIndexDbV1; +pub use values::peer_card::PeerCardDbV1; pub use values::pubkey_db::{PubKeyValV2, PublicKeyArrayDbV1, PublicKeySingletonDbV1}; pub use values::sindex_db::{SIndexDBV1, SourceKeyArrayDbV1}; pub use values::source_amount::SourceAmountValV2; @@ -119,14 +121,13 @@ pub trait ToDumpString { #[cfg(feature = "mem")] pub type DbsBackend = kv_typed::backend::memory::Mem; -#[cfg(all(not(feature = "mem"), target_arch = "x86_64"))] -pub type DbsBackend = Sled; // TODO ESZ -#[cfg(all(not(feature = "mem"), not(target_arch = "x86_64")))] +#[cfg(not(feature = "mem"))] pub type DbsBackend = Sled; #[derive(Clone, Debug)] pub struct DuniterDbs { pub bc_db: bc_v2::BcV2Db<DbsBackend>, + pub cm_db: cm_v1::CmV1Db<MemSingleton>, pub gva_db: GvaV1Db<DbsBackend>, pub txs_mp_db: TxsMpV2Db<DbsBackend>, } diff --git a/rust-libs/duniter-dbs/src/open_dbs.rs b/rust-libs/duniter-dbs/src/open_dbs.rs index 6bdbed583b69a89fb35ab081df423190de0a619e..0f99368b5237bc3266fdb63f66ff90be3146a4db 100644 --- a/rust-libs/duniter-dbs/src/open_dbs.rs +++ b/rust-libs/duniter-dbs/src/open_dbs.rs @@ -14,6 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::bc_v2::BcV2DbWritable as _; +use crate::cm_v1::CmV1DbWritable as _; use crate::*; 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, )) .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)) .expect("fail to open Gva DB"), txs_mp_db: TxsMpV2Db::<DbsBackend>::open(DbsBackend::gen_backend_conf( diff --git a/rust-libs/duniter-dbs/src/values.rs b/rust-libs/duniter-dbs/src/values.rs index 7c6823de95323b4f9856a8857e3d7a687bbb7101..3c8cb10b24e187a98bcd6ac1a345a0423012537a 100644 --- a/rust-libs/duniter-dbs/src/values.rs +++ b/rust-libs/duniter-dbs/src/values.rs @@ -23,6 +23,7 @@ pub mod idty_db; pub mod iindex_db; pub mod kick_db; pub mod mindex_db; +pub mod peer_card; pub mod pubkey_db; pub mod sindex_db; pub mod source_amount; diff --git a/rust-libs/duniter-dbs/src/values/peer_card.rs b/rust-libs/duniter-dbs/src/values/peer_card.rs new file mode 100644 index 0000000000000000000000000000000000000000..c51c1c44d76b88d2dec94388ec2d181ae5bf449c --- /dev/null +++ b/rust-libs/duniter-dbs/src/values/peer_card.rs @@ -0,0 +1,58 @@ +// 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))) + } +}