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

[ref] gva: move gva db definition in new crate duniter-gva-db

parent 781131b0
No related branches found
No related tags found
No related merge requests found
Showing
with 63 additions and 71 deletions
......@@ -14,6 +14,7 @@ path = "src/lib.rs"
[dependencies]
anyhow = "1.0.34"
duniter-dbs = { path = "../../../duniter-dbs" }
duniter-gva-db = { path = "../db" }
dubp = { version = "0.34.0" }
resiter = "0.4.0"
......
......@@ -139,17 +139,17 @@ impl DbsReader {
mod tests {
use super::*;
use duniter_dbs::{
databases::{bc_v2::BcV2DbWritable, gva_v1::GvaV1DbWritable, txs_mp_v2::TxsMpV2DbWritable},
BlockMetaV2, GvaUtxoIdDbV1, SourceAmountValV2, UdIdV2, UtxoIdDbV2, UtxoValV2,
WalletConditionsV2,
databases::{bc_v2::BcV2DbWritable, txs_mp_v2::TxsMpV2DbWritable},
BlockMetaV2, SourceAmountValV2, UdIdV2, UtxoIdDbV2, UtxoValV2, WalletConditionsV2,
};
use duniter_gva_db::{GvaUtxoIdDbV1, GvaV1DbWritable};
const UD0: i64 = 100;
#[test]
fn test_find_inputs() -> anyhow::Result<()> {
let bc_db = duniter_dbs::databases::bc_v2::BcV2Db::<Mem>::open(MemConf::default())?;
let gva_db = duniter_dbs::databases::gva_v1::GvaV1Db::<Mem>::open(MemConf::default())?;
let gva_db = duniter_gva_db::GvaV1Db::<Mem>::open(MemConf::default())?;
let db_reader = create_dbs_reader(unsafe { std::mem::transmute(&gva_db.get_ro_handler()) });
let txs_mp_db =
duniter_dbs::databases::txs_mp_v2::TxsMpV2Db::<Mem>::open(MemConf::default())?;
......
......@@ -41,14 +41,12 @@ use duniter_dbs::{
databases::{
bc_v2::{BcV2DbReadable, BcV2DbRo},
cm_v1::CmV1DbReadable,
gva_v1::{GvaV1DbReadable, GvaV1DbRo},
txs_mp_v2::TxsMpV2DbReadable,
},
BlockMetaV2,
};
use duniter_dbs::{
kv_typed::prelude::*, HashKeyV2, PubKeyKeyV2, SourceAmountValV2, TxDbV2, UtxoIdDbV2,
};
use duniter_dbs::{kv_typed::prelude::*, HashKeyV2, PubKeyKeyV2, SourceAmountValV2, UtxoIdDbV2};
use duniter_gva_db::{GvaIdtyDbV1, GvaTxDbV1, GvaUtxoIdDbV1, GvaV1DbReadable, GvaV1DbRo};
use resiter::filter::Filter;
use resiter::filter_map::FilterMap;
use resiter::flatten::Flatten;
......@@ -119,8 +117,8 @@ impl DbsReader {
#[cfg(test)]
impl DbsReader {
pub(crate) fn mem() -> Self {
use duniter_dbs::databases::gva_v1::GvaV1DbWritable;
let gva_db = duniter_dbs::databases::gva_v1::GvaV1Db::<Mem>::open(MemConf::default())
use duniter_gva_db::GvaV1DbWritable;
let gva_db = duniter_gva_db::GvaV1Db::<Mem>::open(MemConf::default())
.expect("fail to create memory gva db");
create_dbs_reader(unsafe { std::mem::transmute(&gva_db.get_ro_handler()) })
}
......
......@@ -14,7 +14,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use duniter_dbs::{smallvec::SmallVec, WalletHashWithBnV1Db};
use duniter_dbs::smallvec::SmallVec;
use duniter_gva_db::WalletHashWithBnV1Db;
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
pub struct TxBcCursor {
......@@ -50,7 +51,7 @@ impl DbsReader {
&self,
page_info: PageInfo<TxBcCursor>,
script_hash: Hash,
) -> KvResult<PagedData<VecDeque<TxDbV2>>> {
) -> KvResult<PagedData<VecDeque<GvaTxDbV1>>> {
let mut start_k = WalletHashWithBnV1Db::new(script_hash, BlockNumber(0));
let mut end_k = WalletHashWithBnV1Db::new(script_hash, BlockNumber(u32::MAX));
let first_cursor_opt = if page_info.not_all() {
......@@ -124,7 +125,7 @@ impl DbsReader {
.0
.txs_by_recipient()
.iter_ref_slice(start_k..=end_k, |_k, hashs| {
let mut sent = SmallVec::<[TxDbV2; 8]>::new();
let mut sent = SmallVec::<[GvaTxDbV1; 8]>::new();
for hash in hashs {
if let Some(tx_db) = self.0.txs().get(HashKeyV2::from_ref(hash))? {
sent.push(tx_db);
......@@ -146,7 +147,7 @@ impl DbsReader {
.0
.txs_by_recipient()
.iter_ref_slice_rev(start_k..=end_k, |_k, hashs| {
let mut sent = SmallVec::<[TxDbV2; 8]>::new();
let mut sent = SmallVec::<[GvaTxDbV1; 8]>::new();
for hash in hashs {
if let Some(tx_db) = self.0.txs().get(HashKeyV2::from_ref(hash))? {
sent.push(tx_db);
......@@ -169,7 +170,7 @@ impl DbsReader {
&self,
page_info: PageInfo<TxBcCursor>,
script_hash: Hash,
) -> KvResult<PagedData<VecDeque<TxDbV2>>> {
) -> KvResult<PagedData<VecDeque<GvaTxDbV1>>> {
let mut start_k = WalletHashWithBnV1Db::new(script_hash, BlockNumber(0));
let mut end_k = WalletHashWithBnV1Db::new(script_hash, BlockNumber(u32::MAX));
let first_cursor_opt = if page_info.not_all() {
......@@ -247,7 +248,7 @@ impl DbsReader {
.0
.txs_by_issuer()
.iter_ref_slice(start_k..=end_k, |_k, hashs| {
let mut sent = SmallVec::<[TxDbV2; 8]>::new();
let mut sent = SmallVec::<[GvaTxDbV1; 8]>::new();
for hash in hashs {
if let Some(tx_db) = self.0.txs().get(HashKeyV2::from_ref(hash))? {
sent.push(tx_db);
......@@ -269,7 +270,7 @@ impl DbsReader {
.0
.txs_by_issuer()
.iter_ref_slice_rev(start_k..=end_k, |_k, hashs| {
let mut sent = SmallVec::<[TxDbV2; 8]>::new();
let mut sent = SmallVec::<[GvaTxDbV1; 8]>::new();
for hash in hashs.iter().rev() {
if let Some(tx_db) = self.0.txs().get(HashKeyV2::from_ref(hash))? {
sent.push(tx_db);
......@@ -321,14 +322,14 @@ impl DbsReader {
}
}
fn txs_history_bc_collect<I: Iterator<Item = KvResult<TxDbV2>>>(
fn txs_history_bc_collect<I: Iterator<Item = KvResult<GvaTxDbV1>>>(
dbs_reader: DbsReader,
first_cursor_opt: Option<TxBcCursor>,
first_hashs_opt: Option<SmallVec<[Hash; 8]>>,
last_cursor_opt: Option<TxBcCursor>,
page_info: PageInfo<TxBcCursor>,
txs_iter: I,
) -> KvResult<PagedData<VecDeque<TxDbV2>>> {
) -> KvResult<PagedData<VecDeque<GvaTxDbV1>>> {
let mut txs = if let Some(limit) = page_info.limit_opt {
txs_iter.take(limit).collect::<KvResult<VecDeque<_>>>()?
} else {
......@@ -384,8 +385,8 @@ fn txs_history_bc_collect<I: Iterator<Item = KvResult<TxDbV2>>>(
// Needed for BMA only
pub struct TxsHistory {
pub sent: Vec<TxDbV2>,
pub received: Vec<TxDbV2>,
pub sent: Vec<GvaTxDbV1>,
pub received: Vec<GvaTxDbV1>,
pub sending: Vec<TransactionDocumentV10>,
pub pending: Vec<TransactionDocumentV10>,
}
......@@ -403,7 +404,7 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
let sent = gva_db_ro
.txs_by_issuer()
.iter_ref_slice(start_k..end_k, |_k, hashs| {
let mut sent = SmallVec::<[TxDbV2; 2]>::new();
let mut sent = SmallVec::<[GvaTxDbV1; 2]>::new();
for hash in hashs {
if let Some(tx_db) = gva_db_ro.txs().get(HashKeyV2::from_ref(hash))? {
sent.push(tx_db);
......@@ -417,7 +418,7 @@ pub fn get_transactions_history_for_bma<GvaDb: GvaV1DbReadable, TxsMpDb: TxsMpV2
let received = gva_db_ro
.txs_by_recipient()
.iter_ref_slice(start_k..end_k, |_k, hashs| {
let mut sent = SmallVec::<[TxDbV2; 2]>::new();
let mut sent = SmallVec::<[GvaTxDbV1; 2]>::new();
for hash in hashs {
if let Some(tx_db) = gva_db_ro.txs().get(HashKeyV2::from_ref(hash))? {
sent.push(tx_db);
......@@ -468,12 +469,12 @@ mod tests {
documents::transaction::{TransactionDocumentV10, TransactionDocumentV10Stringified},
documents_parser::prelude::FromStringObject,
};
use duniter_dbs::databases::gva_v1::GvaV1DbWritable;
use duniter_gva_db::GvaV1DbWritable;
use maplit::btreeset;
use unwrap::unwrap;
fn gen_tx(hash: Hash, written_block_number: BlockNumber) -> TxDbV2 {
TxDbV2 {
fn gen_tx(hash: Hash, written_block_number: BlockNumber) -> GvaTxDbV1 {
GvaTxDbV1 {
tx: unwrap!(TransactionDocumentV10::from_string_object(
&TransactionDocumentV10Stringified {
currency: "test".to_owned(),
......@@ -500,7 +501,7 @@ mod tests {
#[test]
fn test_get_txs_history_bc_sent() -> KvResult<()> {
let gva_db = duniter_dbs::databases::gva_v1::GvaV1Db::<Mem>::open(MemConf::default())?;
let gva_db = duniter_gva_db::GvaV1Db::<Mem>::open(MemConf::default())?;
let db_reader = create_dbs_reader(unsafe { std::mem::transmute(&gva_db.get_ro_handler()) });
let s1 = WalletScriptV10::single_sig(PublicKey::default());
......
......@@ -17,7 +17,7 @@ use crate::*;
use duniter_dbs::smallvec::SmallVec;
use duniter_dbs::{
databases::bc_v2::{UdsEvent, UdsRevalEvent},
GvaIdtyDbV1, UdIdV2,
UdIdV2,
};
#[derive(Debug, Default)]
......@@ -472,10 +472,8 @@ mod tests {
use super::*;
use duniter_dbs::smallvec::smallvec as svec;
use duniter_dbs::{
databases::{bc_v2::BcV2DbWritable, gva_v1::GvaV1DbWritable},
SourceAmountValV2, UdIdV2,
};
use duniter_dbs::{databases::bc_v2::BcV2DbWritable, SourceAmountValV2, UdIdV2};
use duniter_gva_db::GvaV1DbWritable;
use std::iter::FromIterator;
#[test]
......@@ -538,7 +536,7 @@ mod tests {
let bc_db = duniter_dbs::databases::bc_v2::BcV2Db::<Mem>::open(MemConf::default())?;
let bc_db_ro = bc_db.get_ro_handler();
let gva_db = duniter_dbs::databases::gva_v1::GvaV1Db::<Mem>::open(MemConf::default())?;
let gva_db = duniter_gva_db::GvaV1Db::<Mem>::open(MemConf::default())?;
let db_reader = create_dbs_reader(unsafe { std::mem::transmute(&gva_db.get_ro_handler()) });
bc_db
.uds_reval_write()
......
......@@ -14,7 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use dubp::documents::dubp_wallet::prelude::*;
use duniter_dbs::{GvaUtxoIdDbV1, SourceAmountValV2};
use duniter_dbs::SourceAmountValV2;
use crate::*;
......@@ -251,14 +251,14 @@ where
mod tests {
use super::*;
use duniter_dbs::databases::gva_v1::GvaV1DbWritable;
use duniter_dbs::databases::txs_mp_v2::TxsMpV2DbWritable;
use duniter_gva_db::GvaV1DbWritable;
#[test]
fn test_find_script_utxos() -> anyhow::Result<()> {
let script = WalletScriptV10::single_sig(PublicKey::default());
let gva_db = duniter_dbs::databases::gva_v1::GvaV1Db::<Mem>::open(MemConf::default())?;
let gva_db = duniter_gva_db::GvaV1Db::<Mem>::open(MemConf::default())?;
let db_reader = create_dbs_reader(unsafe { std::mem::transmute(&gva_db.get_ro_handler()) });
let txs_mp_db =
duniter_dbs::databases::txs_mp_v2::TxsMpV2Db::<Mem>::open(MemConf::default())?;
......
......@@ -14,6 +14,7 @@ dubp = { version = "0.34.0" }
duniter-conf = { path = "../../../duniter-conf" }
duniter-dbs = { path = "../../../duniter-dbs" }
duniter-bc-reader = { path = "../../../duniter-bc-reader" }
duniter-gva-db = { path = "../db" }
duniter-gva-dbs-reader = { path = "../dbs-reader" }
duniter-mempools = { path = "../../../duniter-mempools" }
duniter-module = { path = "../../../duniter-module" }
......
......@@ -13,9 +13,9 @@
// 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 dubp::documents::transaction::TransactionDocumentV10Stringified;
use crate::*;
use dubp::documents::transaction::TransactionDocumentV10Stringified;
use duniter_gva_db::GvaTxDbV1;
#[derive(async_graphql::SimpleObject)]
pub(crate) struct TxGva {
......@@ -47,8 +47,8 @@ pub(crate) struct TxGva {
pub written_time: Option<i64>,
}
impl From<TxDbV2> for TxGva {
fn from(db_tx: TxDbV2) -> Self {
impl From<GvaTxDbV1> for TxGva {
fn from(db_tx: GvaTxDbV1) -> Self {
let mut self_: TxGva = (&db_tx.tx).into();
self_.written_block = Some(db_tx.written_block.to_string());
self_.written_time = Some(db_tx.written_time);
......
......@@ -56,7 +56,7 @@ use dubp::documents_parser::prelude::*;
use dubp::wallet::prelude::*;
use duniter_dbs::databases::txs_mp_v2::TxsMpV2DbReadable;
use duniter_dbs::prelude::*;
use duniter_dbs::{kv_typed::prelude::*, FileBackend, TxDbV2};
use duniter_dbs::{kv_typed::prelude::*, FileBackend};
use duniter_gva_dbs_reader::pagination::PageInfo;
#[cfg(not(test))]
use duniter_gva_dbs_reader::DbsReader;
......@@ -136,12 +136,12 @@ mod tests {
&self,
page_info: PageInfo<duniter_gva_dbs_reader::txs_history::TxBcCursor>,
script_hash: Hash,
) -> KvResult<PagedData<VecDeque<TxDbV2>>>;
) -> KvResult<PagedData<VecDeque<duniter_gva_db::GvaTxDbV1>>>;
fn get_txs_history_bc_sent(
&self,
page_info: PageInfo<duniter_gva_dbs_reader::txs_history::TxBcCursor>,
script_hash: Hash,
) -> KvResult<PagedData<VecDeque<TxDbV2>>>;
) -> KvResult<PagedData<VecDeque<duniter_gva_db::GvaTxDbV1>>>;
fn get_txs_history_mempool<TxsMpDb: 'static + TxsMpV2DbReadable>(
&self,
txs_mp_db_ro: &TxsMpDb,
......
......@@ -15,6 +15,7 @@
use crate::*;
use dubp::documents_parser::wallet_script_from_str;
use duniter_gva_db::GvaTxDbV1;
use duniter_gva_dbs_reader::txs_history::TxBcCursor;
use futures::future::join;
......@@ -84,7 +85,7 @@ impl TxsHistoryBlockchainQueryInner {
.into_iter()
.map(|db_tx| (TxDirection::Received, db_tx)),
)
.collect::<Vec<(TxDirection, TxDbV2)>>();
.collect::<Vec<(TxDirection, GvaTxDbV1)>>();
/*if let Some(TxBcCursor { tx_hash, .. }) = pagination.pos() {
while both.txs
}*/
......@@ -229,7 +230,7 @@ mod tests {
use dubp::documents::transaction::TransactionDocumentV10;
use dubp::documents::transaction::TransactionDocumentV10Stringified;
use dubp::documents_parser::prelude::FromStringObject;
use duniter_dbs::TxDbV2;
use duniter_gva_db::GvaTxDbV1;
use duniter_gva_dbs_reader::pagination::PagedData;
#[tokio::test]
......@@ -264,7 +265,7 @@ mod tests {
)
.expect("wrong tx");
let mut expected_data = VecDeque::new();
expected_data.push_back(TxDbV2 {
expected_data.push_back(GvaTxDbV1 {
tx,
..Default::default()
});
......
......@@ -14,6 +14,7 @@ path = "src/lib.rs"
[dependencies]
anyhow = "1.0.34"
duniter-dbs = { path = "../../../duniter-dbs" }
duniter-gva-db = { path = "../db" }
dubp = { version = "0.34.0" }
once_cell = "1.5.2"
resiter = "0.4.0"
......
......@@ -14,7 +14,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use duniter_dbs::databases::gva_v1::GvaIdentitiesEvent;
pub(crate) fn update_identities<B: Backend>(
block: &DubpBlockV10,
......
......@@ -33,13 +33,11 @@ use dubp::documents::{
prelude::*, transaction::TransactionDocumentTrait, transaction::TransactionDocumentV10,
};
use dubp::wallet::prelude::*;
use duniter_dbs::databases::gva_v1::*;
use duniter_dbs::{
databases::gva_v1::{GvaV1Db, GvaV1DbReadable, GvaV1DbWritable},
kv_typed::prelude::*,
prelude::*,
FileBackend, HashKeyV2, PubKeyKeyV2, SourceAmountValV2, TxDbV2, WalletConditionsV2,
kv_typed::prelude::*, prelude::*, FileBackend, HashKeyV2, PubKeyKeyV2, SourceAmountValV2,
WalletConditionsV2,
};
use duniter_gva_db::*;
use resiter::filter::Filter;
use std::{
collections::{BTreeSet, HashMap},
......@@ -56,7 +54,7 @@ pub fn get_gva_db_ro(profile_path_opt: Option<&Path>) -> &'static GvaV1DbRo<File
}
pub fn get_gva_db_rw(profile_path_opt: Option<&Path>) -> &'static GvaV1Db<FileBackend> {
GVA_DB_RW.get_or_init(|| {
duniter_dbs::databases::gva_v1::GvaV1Db::<FileBackend>::open(FileBackend::gen_backend_conf(
duniter_gva_db::GvaV1Db::<FileBackend>::open(FileBackend::gen_backend_conf(
"gva_v1",
profile_path_opt,
))
......@@ -250,11 +248,9 @@ mod tests {
documents::transaction::TransactionDocumentV10Stringified,
documents_parser::prelude::FromStringObject,
};
use duniter_dbs::GvaUtxoIdDbV1;
#[test]
fn test_gva_apply_block() -> anyhow::Result<()> {
let gva_db = duniter_dbs::databases::gva_v1::GvaV1Db::<Mem>::open(MemConf::default())?;
let gva_db = GvaV1Db::<Mem>::open(MemConf::default())?;
let s1 = WalletScriptV10::single_sig(PublicKey::from_base58(
"D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx",
......
......@@ -14,7 +14,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use duniter_dbs::{databases::gva_v1::BalancesEvent, WalletHashWithBnV1Db};
pub(crate) type ScriptsHash = HashMap<WalletScriptV10, Hash>;
......@@ -140,7 +139,7 @@ pub(crate) fn apply_tx<B: Backend>(
// Insert tx itself
txs.upsert(
HashKeyV2(tx_hash),
TxDbV2 {
GvaTxDbV1 {
tx: tx.clone(),
written_block: current_blockstamp,
written_time: current_time,
......@@ -315,7 +314,7 @@ mod tests {
let o1_amount = ud0_amount - SourceAmount::with_base0(600);
let o2_amount = ud0_amount - SourceAmount::with_base0(400);
let gva_db = duniter_dbs::databases::gva_v1::GvaV1Db::<Mem>::open(MemConf::default())?;
let gva_db = GvaV1Db::<Mem>::open(MemConf::default())?;
let b0 = BlockMetaV2 {
dividend: Some(ud0_amount),
......
......@@ -14,11 +14,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use duniter_dbs::GvaUtxoIdDbV1;
pub(crate) fn write_utxo_v10<'s, B: Backend>(
scripts_by_pubkey: &mut TxColRw<B::Col, duniter_dbs::databases::gva_v1::ScriptsByPubkeyEvent>,
gva_utxos: &mut TxColRw<B::Col, duniter_dbs::databases::gva_v1::GvaUtxosEvent>,
scripts_by_pubkey: &mut TxColRw<B::Col, ScriptsByPubkeyEvent>,
gva_utxos: &mut TxColRw<B::Col, GvaUtxosEvent>,
utxo: UtxoV10<'s>,
utxo_script_hash: Hash,
) -> KvResult<()> {
......@@ -49,8 +48,8 @@ pub(crate) fn write_utxo_v10<'s, B: Backend>(
}
pub(crate) fn remove_utxo_v10<B: Backend>(
scripts_by_pubkey: &mut TxColRw<B::Col, duniter_dbs::databases::gva_v1::ScriptsByPubkeyEvent>,
gva_utxos: &mut TxColRw<B::Col, duniter_dbs::databases::gva_v1::GvaUtxosEvent>,
scripts_by_pubkey: &mut TxColRw<B::Col, ScriptsByPubkeyEvent>,
gva_utxos: &mut TxColRw<B::Col, GvaUtxosEvent>,
utxo_id: UtxoIdV10,
utxo_script: &WalletScriptV10,
utxo_script_hash: Hash,
......
......@@ -32,12 +32,10 @@ use dubp::common::crypto::keys::{ed25519::PublicKey, KeyPair as _};
use dubp::common::prelude::*;
use dubp::documents::transaction::TransactionDocumentV10;
use dubp::{block::DubpBlockV10, crypto::hashs::Hash};
use duniter_dbs::databases::{
gva_v1::{GvaV1DbReadable, GvaV1DbRo},
txs_mp_v2::TxsMpV2DbReadable,
};
use duniter_dbs::databases::txs_mp_v2::TxsMpV2DbReadable;
use duniter_dbs::prelude::*;
use duniter_dbs::{kv_typed::prelude::*, FileBackend, TxDbV2};
use duniter_dbs::{kv_typed::prelude::*, FileBackend};
use duniter_gva_db::*;
use duniter_gva_gql::GvaSchema;
use duniter_gva_indexer::{get_gva_db_ro, get_gva_db_rw};
use duniter_mempools::Mempools;
......@@ -177,7 +175,7 @@ impl duniter_module::DuniterModule for GvaModule {
sent: sent
.into_iter()
.map(
|TxDbV2 {
|GvaTxDbV1 {
tx,
written_block,
written_time,
......@@ -187,7 +185,7 @@ impl duniter_module::DuniterModule for GvaModule {
received: received
.into_iter()
.map(
|TxDbV2 {
|GvaTxDbV1 {
tx,
written_block,
written_time,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment