feat(db): add cols blocks_chunk_hash & compressed_blocks_chunk
This commit is contained in:
parent
7fe98256d2
commit
1b65c83c6a
3 changed files with 102 additions and 0 deletions
|
@ -27,9 +27,11 @@ mod values;
|
|||
|
||||
pub use keys::gva_utxo_id::GvaUtxoIdDbV1;
|
||||
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_tx::GvaTxDbV1;
|
||||
pub use values::wallet_script_array::WalletScriptArrayV2;
|
||||
pub use values::HashDb;
|
||||
|
||||
pub(crate) use dubp::common::prelude::*;
|
||||
pub(crate) use dubp::crypto::hashs::Hash;
|
||||
|
@ -50,6 +52,9 @@ db_schema!(
|
|||
["blocks_by_common_time", BlocksByCommonTime, U64BE, u32],
|
||||
["blocks_with_ud", BlocksWithUd, U32BE, ()],
|
||||
["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_by_block", TxsByBlock, U32BE, Vec<Hash>],
|
||||
["txs_by_issuer", TxsByIssuer, WalletHashWithBnV1Db, BTreeSet<Hash>],
|
||||
|
|
|
@ -13,6 +13,46 @@
|
|||
// 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::*;
|
||||
|
||||
pub mod gva_block_db;
|
||||
pub mod gva_idty_db;
|
||||
pub mod gva_tx;
|
||||
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()))
|
||||
}
|
||||
}
|
||||
|
|
57
db/src/values/gva_block_db.rs
Normal file
57
db/src/values/gva_block_db.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
// 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()))
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue