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

feat(db): add cols blocks_chunk_hash & compressed_blocks_chunk

parent 7fe98256
No related branches found
No related tags found
No related merge requests found
...@@ -27,9 +27,11 @@ mod values; ...@@ -27,9 +27,11 @@ mod values;
pub use keys::gva_utxo_id::GvaUtxoIdDbV1; pub use keys::gva_utxo_id::GvaUtxoIdDbV1;
pub use keys::wallet_hash_with_bn::WalletHashWithBnV1Db; pub use keys::wallet_hash_with_bn::WalletHashWithBnV1Db;
pub use values::gva_block_db::GvaBlockDbV1;
pub use values::gva_idty_db::GvaIdtyDbV1; pub use values::gva_idty_db::GvaIdtyDbV1;
pub use values::gva_tx::GvaTxDbV1; pub use values::gva_tx::GvaTxDbV1;
pub use values::wallet_script_array::WalletScriptArrayV2; pub use values::wallet_script_array::WalletScriptArrayV2;
pub use values::HashDb;
pub(crate) use dubp::common::prelude::*; pub(crate) use dubp::common::prelude::*;
pub(crate) use dubp::crypto::hashs::Hash; pub(crate) use dubp::crypto::hashs::Hash;
...@@ -50,6 +52,9 @@ db_schema!( ...@@ -50,6 +52,9 @@ db_schema!(
["blocks_by_common_time", BlocksByCommonTime, U64BE, u32], ["blocks_by_common_time", BlocksByCommonTime, U64BE, u32],
["blocks_with_ud", BlocksWithUd, U32BE, ()], ["blocks_with_ud", BlocksWithUd, U32BE, ()],
["blockchain_time", BlockchainTime, U32BE, u64], ["blockchain_time", BlockchainTime, U32BE, u64],
["blocks_chunk_hash", BlocksChunkHash, U32BE, HashDb],
["compressed_blocks_chunk", CompressedBlocksChunk, U32BE, Vec<u8>],
["current_blocks_chunk", CurrentBlocksChunk, U32BE, GvaBlockDbV1],
["txs", Txs, HashKeyV2, GvaTxDbV1], ["txs", Txs, HashKeyV2, GvaTxDbV1],
["txs_by_block", TxsByBlock, U32BE, Vec<Hash>], ["txs_by_block", TxsByBlock, U32BE, Vec<Hash>],
["txs_by_issuer", TxsByIssuer, WalletHashWithBnV1Db, BTreeSet<Hash>], ["txs_by_issuer", TxsByIssuer, WalletHashWithBnV1Db, BTreeSet<Hash>],
......
...@@ -13,6 +13,46 @@ ...@@ -13,6 +13,46 @@
// 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::*;
pub mod gva_block_db;
pub mod gva_idty_db; pub mod gva_idty_db;
pub mod gva_tx; pub mod gva_tx;
pub mod wallet_script_array; pub mod wallet_script_array;
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct HashDb(pub Hash);
impl AsBytes for HashDb {
fn as_bytes<T, F: FnMut(&[u8]) -> T>(&self, mut f: F) -> T {
f(self.0.as_ref())
}
}
impl kv_typed::prelude::FromBytes for HashDb {
type Err = bincode::Error;
fn from_bytes(bytes: &[u8]) -> std::result::Result<Self, Self::Err> {
let mut hash_bytes = [0; 32];
hash_bytes.copy_from_slice(bytes);
Ok(Self(Hash(hash_bytes)))
}
}
impl ToDumpString for HashDb {
fn to_dump_string(&self) -> String {
todo!()
}
}
#[cfg(feature = "explorer")]
impl ExplorableValue for HashDb {
fn from_explorer_str(source: &str) -> Result<Self, FromExplorerValueErr> {
Ok(Self(
Hash::from_hex(source).map_err(|e| FromExplorerValueErr(e.into()))?,
))
}
fn to_explorer_json(&self) -> KvResult<serde_json::Value> {
Ok(serde_json::Value::String(self.0.to_hex()))
}
}
// 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::*;
use dubp::block::{DubpBlock, DubpBlockV10};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[repr(transparent)]
pub struct GvaBlockDbV1(pub DubpBlock);
impl Default for GvaBlockDbV1 {
fn default() -> Self {
Self(DubpBlock::V10(DubpBlockV10::default()))
}
}
impl AsBytes for GvaBlockDbV1 {
fn as_bytes<T, F: FnMut(&[u8]) -> T>(&self, mut f: F) -> T {
f(&bincode::serialize(&self).unwrap_or_else(|_| unreachable!()))
}
}
impl kv_typed::prelude::FromBytes for GvaBlockDbV1 {
type Err = bincode::Error;
fn from_bytes(bytes: &[u8]) -> std::result::Result<Self, Self::Err> {
bincode::deserialize(bytes)
}
}
impl ToDumpString for GvaBlockDbV1 {
fn to_dump_string(&self) -> String {
todo!()
}
}
#[cfg(feature = "explorer")]
impl ExplorableValue for GvaBlockDbV1 {
fn from_explorer_str(source: &str) -> Result<Self, FromExplorerValueErr> {
serde_json::from_str(source).map_err(|e| FromExplorerValueErr(e.into()))
}
fn to_explorer_json(&self) -> KvResult<serde_json::Value> {
serde_json::to_value(&self).map_err(|e| KvError::DeserError(e.into()))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment