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

[ref] duniter-dbs: move dbs def in module databases

parent b5d308a6
No related branches found
No related tags found
1 merge request!1338Peers heads
Showing
with 84 additions and 47 deletions
...@@ -31,15 +31,18 @@ use self::cli::{Database, Opt, OutputFormat, SubCommand}; ...@@ -31,15 +31,18 @@ use self::cli::{Database, Opt, OutputFormat, SubCommand};
use self::stringify_json_value::stringify_json_value; use self::stringify_json_value::stringify_json_value;
use anyhow::anyhow; use anyhow::anyhow;
use comfy_table::Table; use comfy_table::Table;
use duniter_dbs::bc_v2::{BcV2Db, BcV2DbWritable}; use duniter_dbs::databases::bc_v2::{BcV2Db, BcV2DbWritable};
use duniter_dbs::databases::{
bc_v1::{BcV1Db, BcV1DbWritable},
gva_v1::{GvaV1Db, GvaV1DbWritable},
txs_mp_v2::{TxsMpV2Db, TxsMpV2DbWritable},
};
use duniter_dbs::kv_typed::backend::sled; use duniter_dbs::kv_typed::backend::sled;
use duniter_dbs::kv_typed::prelude::*; use duniter_dbs::kv_typed::prelude::*;
use duniter_dbs::prelude::*; use duniter_dbs::prelude::*;
use duniter_dbs::regex::Regex; use duniter_dbs::regex::Regex;
use duniter_dbs::serde_json::{Map, Value}; use duniter_dbs::serde_json::{Map, Value};
use duniter_dbs::smallvec::{smallvec, SmallVec}; use duniter_dbs::smallvec::{smallvec, SmallVec};
use duniter_dbs::{BcV1Db, GvaV1Db, TxsMpV2Db};
use duniter_dbs::{BcV1DbWritable, GvaV1DbWritable, TxsMpV2DbWritable};
use rayon::prelude::*; use rayon::prelude::*;
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
......
...@@ -18,7 +18,7 @@ use dubp::{ ...@@ -18,7 +18,7 @@ use dubp::{
block::parser::parse_json_block_from_serde_value, block::parser::ParseJsonBlockError, block::parser::parse_json_block_from_serde_value, block::parser::ParseJsonBlockError,
block::prelude::DubpBlockTrait, block::DubpBlock, common::prelude::BlockNumber, block::prelude::DubpBlockTrait, block::DubpBlock, common::prelude::BlockNumber,
}; };
use duniter_dbs::{BcV1DbReadable, FileBackend}; use duniter_dbs::{databases::bc_v1::BcV1DbReadable, FileBackend};
use fast_threadpool::{ThreadPool, ThreadPoolConfig}; use fast_threadpool::{ThreadPool, ThreadPoolConfig};
use std::{ops::Deref, path::PathBuf}; use std::{ops::Deref, path::PathBuf};
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
)] )]
use dubp::crypto::hashs::Hash; use dubp::crypto::hashs::Hash;
use duniter_dbs::{bc_v2::BcV2DbReadable, HashKeyV2}; use duniter_dbs::{databases::bc_v2::BcV2DbReadable, HashKeyV2};
use duniter_dbs::{kv_typed::prelude::*, BlockMetaV2}; use duniter_dbs::{kv_typed::prelude::*, BlockMetaV2};
pub fn get_current_block_meta<BcDb: BcV2DbReadable>(bc_db: &BcDb) -> KvResult<Option<BlockMetaV2>> { pub fn get_current_block_meta<BcDb: BcV2DbReadable>(bc_db: &BcDb) -> KvResult<Option<BlockMetaV2>> {
......
...@@ -18,10 +18,10 @@ mod txs; ...@@ -18,10 +18,10 @@ mod txs;
mod uds; mod uds;
use crate::*; use crate::*;
use duniter_dbs::bc_v2::BcV2DbWritable; use duniter_dbs::databases::bc_v2::BcV2DbWritable;
pub fn apply_block<B: Backend>( pub fn apply_block<B: Backend>(
bc_db: &duniter_dbs::bc_v2::BcV2Db<B>, bc_db: &duniter_dbs::databases::bc_v2::BcV2Db<B>,
block: &DubpBlockV10, block: &DubpBlockV10,
) -> KvResult<BlockMetaV2> { ) -> KvResult<BlockMetaV2> {
//log::info!("apply_block #{}", block.number().0); //log::info!("apply_block #{}", block.number().0);
...@@ -84,7 +84,7 @@ pub fn apply_block<B: Backend>( ...@@ -84,7 +84,7 @@ pub fn apply_block<B: Backend>(
} }
pub fn revert_block<B: Backend>( pub fn revert_block<B: Backend>(
bc_db: &duniter_dbs::bc_v2::BcV2Db<B>, bc_db: &duniter_dbs::databases::bc_v2::BcV2Db<B>,
block: &DubpBlockV10, block: &DubpBlockV10,
) -> KvResult<Option<BlockMetaV2>> { ) -> KvResult<Option<BlockMetaV2>> {
( (
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +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::*; use crate::*;
use duniter_dbs::bc_v2::IdentitiesEvent; use duniter_dbs::databases::bc_v2::IdentitiesEvent;
use duniter_dbs::IdtyDbV2; use duniter_dbs::IdtyDbV2;
pub(crate) fn update_identities<B: Backend>( pub(crate) fn update_identities<B: Backend>(
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
use crate::*; use crate::*;
use duniter_dbs::{ use duniter_dbs::{
bc_v2::{TxsHashsEvent, UdsEvent}, databases::bc_v2::{TxsHashsEvent, UdsEvent},
UdIdV2, UdIdV2,
}; };
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
use crate::*; use crate::*;
use duniter_dbs::{ use duniter_dbs::{
bc_v2::{IdentitiesEvent, UdsEvent, UdsRevalEvent}, databases::bc_v2::{IdentitiesEvent, UdsEvent, UdsRevalEvent},
UdIdV2, UdIdV2,
}; };
......
...@@ -37,9 +37,13 @@ use dubp::documents::{ ...@@ -37,9 +37,13 @@ use dubp::documents::{
}; };
use dubp::wallet::prelude::*; use dubp::wallet::prelude::*;
use duniter_dbs::{ use duniter_dbs::{
bc_v2::BcV2Db, kv_typed::prelude::*, BlockMetaV2, DuniterDbs, FileBackend, HashKeyV2, databases::{
PendingTxDbV2, PubKeyKeyV2, PubKeyValV2, SourceAmountValV2, TxsMpV2Db, TxsMpV2DbReadable, bc_v2::BcV2Db,
TxsMpV2DbWritable, UtxoValV2, WalletConditionsV2, txs_mp_v2::{TxsMpV2Db, TxsMpV2DbReadable, TxsMpV2DbWritable},
},
kv_typed::prelude::*,
BlockMetaV2, DuniterDbs, FileBackend, HashKeyV2, PendingTxDbV2, PubKeyKeyV2, PubKeyValV2,
SourceAmountValV2, UtxoValV2, WalletConditionsV2,
}; };
use resiter::filter_map::FilterMap; use resiter::filter_map::FilterMap;
use resiter::flatten::Flatten; use resiter::flatten::Flatten;
......
...@@ -41,7 +41,7 @@ pub fn add_pending_tx< ...@@ -41,7 +41,7 @@ pub fn add_pending_tx<
B: Backend, B: Backend,
F: FnOnce( F: FnOnce(
&TransactionDocumentV10, &TransactionDocumentV10,
&TxColRw<B::Col, duniter_dbs::txs_mp_v2::TxsEvent>, &TxColRw<B::Col, duniter_dbs::databases::txs_mp_v2::TxsEvent>,
) -> KvResult<()>, ) -> KvResult<()>,
>( >(
control: F, control: F,
......
// 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/>.
pub mod bc_v1;
pub mod bc_v2;
pub mod cm_v1;
pub mod gva_v1;
pub mod txs_mp_v2;
...@@ -22,13 +22,9 @@ ...@@ -22,13 +22,9 @@
unused_import_braces unused_import_braces
)] )]
mod bc_v1; pub mod databases;
pub mod bc_v2;
pub mod cm_v1;
pub mod gva_v1;
mod keys; mod keys;
mod open_dbs; mod open_dbs;
pub mod txs_mp_v2;
mod values; mod values;
// Re-export dependencies // Re-export dependencies
...@@ -56,8 +52,6 @@ pub use crate::open_dbs::open_dbs; ...@@ -56,8 +52,6 @@ pub use crate::open_dbs::open_dbs;
// Export profession types // Export profession types
pub use crate::keys::utxo_id::UtxoIdDbV2; pub use crate::keys::utxo_id::UtxoIdDbV2;
pub use bc_v1::{BcV1Db, BcV1DbReadable, BcV1DbRo, BcV1DbWritable, MainBlocksEvent, UidsEvent};
pub use gva_v1::{GvaV1Db, GvaV1DbReadable, GvaV1DbRo, GvaV1DbWritable};
pub use keys::all::AllKeyV1; pub use keys::all::AllKeyV1;
pub use keys::block_number::BlockNumberKeyV1; pub use keys::block_number::BlockNumberKeyV1;
pub use keys::blockstamp::BlockstampKeyV1; pub use keys::blockstamp::BlockstampKeyV1;
...@@ -70,7 +64,6 @@ pub use keys::ud_id::UdIdV2; ...@@ -70,7 +64,6 @@ pub use keys::ud_id::UdIdV2;
pub use keys::uid::UidKeyV1; pub use keys::uid::UidKeyV1;
pub use keys::utxo_id::GvaUtxoIdDbV1; pub use keys::utxo_id::GvaUtxoIdDbV1;
pub use keys::wallet_conditions::{WalletConditionsV1, WalletConditionsV2}; pub use keys::wallet_conditions::{WalletConditionsV1, WalletConditionsV2};
pub use txs_mp_v2::{TxsMpV2Db, TxsMpV2DbReadable, TxsMpV2DbRo, TxsMpV2DbWritable};
pub use values::block_db::{BlockDbEnum, BlockDbV1, TransactionInBlockDbV1}; pub use values::block_db::{BlockDbEnum, BlockDbV1, TransactionInBlockDbV1};
pub use values::block_head_db::BlockHeadDbV1; pub use values::block_head_db::BlockHeadDbV1;
pub use values::block_meta::BlockMetaV2; pub use values::block_meta::BlockMetaV2;
...@@ -121,21 +114,23 @@ pub type FileBackend = kv_typed::backend::memory::Mem; ...@@ -121,21 +114,23 @@ pub type FileBackend = kv_typed::backend::memory::Mem;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct DuniterDbs<B: Backend> { pub struct DuniterDbs<B: Backend> {
pub bc_db_ro: bc_v2::BcV2DbRo<B>, pub bc_db_ro: databases::bc_v2::BcV2DbRo<B>,
pub cm_db: cm_v1::CmV1Db<MemSingleton>, pub cm_db: databases::cm_v1::CmV1Db<MemSingleton>,
pub gva_db: GvaV1Db<B>, pub gva_db: databases::gva_v1::GvaV1Db<B>,
pub txs_mp_db: TxsMpV2Db<B>, pub txs_mp_db: databases::txs_mp_v2::TxsMpV2Db<B>,
} }
impl DuniterDbs<Mem> { impl DuniterDbs<Mem> {
pub fn mem() -> KvResult<Self> { pub fn mem() -> KvResult<Self> {
use bc_v2::BcV2DbWritable as _; use databases::bc_v2::BcV2DbWritable as _;
use cm_v1::CmV1DbWritable as _; use databases::cm_v1::CmV1DbWritable as _;
use databases::gva_v1::GvaV1DbWritable as _;
use databases::txs_mp_v2::TxsMpV2DbWritable as _;
Ok(DuniterDbs { Ok(DuniterDbs {
bc_db_ro: bc_v2::BcV2Db::<Mem>::open(MemConf::default())?.get_ro_handler(), bc_db_ro: databases::bc_v2::BcV2Db::<Mem>::open(MemConf::default())?.get_ro_handler(),
cm_db: cm_v1::CmV1Db::<MemSingleton>::open(MemSingletonConf::default())?, cm_db: databases::cm_v1::CmV1Db::<MemSingleton>::open(MemSingletonConf::default())?,
gva_db: GvaV1Db::<Mem>::open(MemConf::default())?, gva_db: databases::gva_v1::GvaV1Db::<Mem>::open(MemConf::default())?,
txs_mp_db: TxsMpV2Db::<Mem>::open(MemConf::default())?, txs_mp_db: databases::txs_mp_v2::TxsMpV2Db::<Mem>::open(MemConf::default())?,
}) })
} }
} }
...@@ -13,22 +13,31 @@ ...@@ -13,22 +13,31 @@
// You should have received a copy of the GNU Affero General Public License // 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/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::bc_v2::BcV2DbWritable as _; use crate::databases::bc_v2::BcV2DbWritable as _;
use crate::cm_v1::CmV1DbWritable as _; use crate::databases::cm_v1::CmV1DbWritable as _;
use crate::databases::gva_v1::GvaV1DbWritable as _;
use crate::databases::txs_mp_v2::TxsMpV2DbWritable as _;
use crate::*; use crate::*;
pub fn open_dbs<B: BackendConf>( pub fn open_dbs<B: BackendConf>(
home_path_opt: Option<&Path>, home_path_opt: Option<&Path>,
) -> (crate::bc_v2::BcV2Db<B>, DuniterDbs<B>) { ) -> (crate::databases::bc_v2::BcV2Db<B>, DuniterDbs<B>) {
let bc_db = crate::bc_v2::BcV2Db::<B>::open(B::gen_backend_conf("bc_v2", home_path_opt)) let bc_db =
crate::databases::bc_v2::BcV2Db::<B>::open(B::gen_backend_conf("bc_v2", home_path_opt))
.expect("fail to open BcV2 DB"); .expect("fail to open BcV2 DB");
let dbs = DuniterDbs { let dbs = DuniterDbs {
bc_db_ro: bc_db.get_ro_handler(), bc_db_ro: bc_db.get_ro_handler(),
cm_db: crate::cm_v1::CmV1Db::<MemSingleton>::open(MemSingletonConf::default()) cm_db: crate::databases::cm_v1::CmV1Db::<MemSingleton>::open(MemSingletonConf::default())
.expect("fail to open CmV1 DB"), .expect("fail to open CmV1 DB"),
gva_db: GvaV1Db::<B>::open(B::gen_backend_conf("gva_v1", home_path_opt)) gva_db: crate::databases::gva_v1::GvaV1Db::<B>::open(B::gen_backend_conf(
"gva_v1",
home_path_opt,
))
.expect("fail to open Gva DB"), .expect("fail to open Gva DB"),
txs_mp_db: TxsMpV2Db::<B>::open(B::gen_backend_conf("txs_mp_v2", home_path_opt)) txs_mp_db: crate::databases::txs_mp_v2::TxsMpV2Db::<B>::open(B::gen_backend_conf(
"txs_mp_v2",
home_path_opt,
))
.expect("fail to open TxsMp DB"), .expect("fail to open TxsMp DB"),
}; };
(bc_db, dbs) (bc_db, dbs)
......
...@@ -22,7 +22,10 @@ mod explorer { ...@@ -22,7 +22,10 @@ mod explorer {
use duniter_dbs::kv_typed::regex; use duniter_dbs::kv_typed::regex;
use duniter_dbs::prelude::*; use duniter_dbs::prelude::*;
use duniter_dbs::smallvec::smallvec; use duniter_dbs::smallvec::smallvec;
use duniter_dbs::{BcV1Db, BcV1DbWritable, PublicKeySingletonDbV1, UidKeyV1}; use duniter_dbs::{
databases::bc_v1::{BcV1Db, BcV1DbWritable},
PublicKeySingletonDbV1, UidKeyV1,
};
use std::{num::NonZeroUsize, str::FromStr}; use std::{num::NonZeroUsize, str::FromStr};
use tempdir::TempDir; use tempdir::TempDir;
use unwrap::unwrap; use unwrap::unwrap;
......
...@@ -18,8 +18,8 @@ use dubp::common::crypto::keys::PublicKey as _; ...@@ -18,8 +18,8 @@ use dubp::common::crypto::keys::PublicKey as _;
use dubp::common::prelude::*; use dubp::common::prelude::*;
use duniter_dbs::kv_typed::prelude::*; use duniter_dbs::kv_typed::prelude::*;
use duniter_dbs::{ use duniter_dbs::{
BcV1Db, BcV1DbReadable, BcV1DbWritable, BlockDbV1, BlockNumberKeyV1, MainBlocksEvent, databases::bc_v1::{BcV1Db, BcV1DbReadable, BcV1DbWritable, MainBlocksEvent},
PublicKeySingletonDbV1, UidKeyV1, BlockDbV1, BlockNumberKeyV1, PublicKeySingletonDbV1, UidKeyV1,
}; };
use kv_typed::channel::TryRecvError; use kv_typed::channel::TryRecvError;
use std::str::FromStr; use std::str::FromStr;
......
...@@ -28,7 +28,10 @@ use dubp::common::crypto::keys::ed25519::PublicKey; ...@@ -28,7 +28,10 @@ use dubp::common::crypto::keys::ed25519::PublicKey;
use dubp::documents::prelude::*; use dubp::documents::prelude::*;
use dubp::documents::transaction::TransactionDocumentV10; use dubp::documents::transaction::TransactionDocumentV10;
use duniter_dbs::kv_typed::prelude::*; use duniter_dbs::kv_typed::prelude::*;
use duniter_dbs::{bc_v2::BcV2DbReadable, TxsMpV2Db, TxsMpV2DbReadable}; use duniter_dbs::{
databases::bc_v2::BcV2DbReadable,
databases::txs_mp_v2::{TxsMpV2Db, TxsMpV2DbReadable},
};
use thiserror::Error; use thiserror::Error;
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment