From ce0cb755acd91c2e91fe6fc89ea57ae7d7e3eaef Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Mon, 17 May 2021 15:00:11 +0200 Subject: [PATCH] feat(dbs): add col currency_params in db BcV2 --- dbs/src/databases/bc_v2.rs | 1 + dbs/src/lib.rs | 2 ++ dbs/src/values.rs | 1 + dbs/src/values/currency_params.rs | 51 +++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 dbs/src/values/currency_params.rs diff --git a/dbs/src/databases/bc_v2.rs b/dbs/src/databases/bc_v2.rs index c525602..cd70820 100644 --- a/dbs/src/databases/bc_v2.rs +++ b/dbs/src/databases/bc_v2.rs @@ -19,6 +19,7 @@ db_schema!( BcV2, [ ["blocks_meta", BlocksMeta, U32BE, BlockMetaV2], + ["currency_params", CurrencyParams, (), CurrencyParamsDbV2], ["identities", Identities, PubKeyKeyV2, IdtyDbV2], ["txs_hashs", TxsHashs, HashKeyV2, ()], ["uds", Uds, UdIdV2, ()], diff --git a/dbs/src/lib.rs b/dbs/src/lib.rs index 863221c..952523c 100644 --- a/dbs/src/lib.rs +++ b/dbs/src/lib.rs @@ -71,6 +71,7 @@ pub use values::block_head_db::BlockHeadDbV1; pub use values::block_meta::BlockMetaV2; pub use values::block_number_array_db::BlockNumberArrayV1; pub use values::cindex_db::CIndexDbV1; +pub use values::currency_params::CurrencyParamsDbV2; pub use values::dunp_head::DunpHeadDbV1; pub use values::idty_db::IdtyDbV2; pub use values::iindex_db::IIndexDbV1; @@ -97,6 +98,7 @@ pub(crate) use dubp::common::crypto::bases::BaseConversionError; pub(crate) use dubp::common::crypto::hashs::Hash; pub(crate) use dubp::common::crypto::keys::ed25519::{PublicKey, Signature}; pub(crate) use dubp::common::crypto::keys::{PublicKey as _, Signature as _}; +pub(crate) use dubp::common::currency_params::CurrencyParameters; pub(crate) use dubp::common::prelude::*; pub(crate) use dubp::documents::dubp_wallet::prelude::*; pub(crate) use kv_typed::db_schema; diff --git a/dbs/src/values.rs b/dbs/src/values.rs index a77cb7f..b9ef8e7 100644 --- a/dbs/src/values.rs +++ b/dbs/src/values.rs @@ -18,6 +18,7 @@ pub mod block_head_db; pub mod block_meta; pub mod block_number_array_db; pub mod cindex_db; +pub mod currency_params; pub mod dunp_head; pub mod idty_db; pub mod iindex_db; diff --git a/dbs/src/values/currency_params.rs b/dbs/src/values/currency_params.rs new file mode 100644 index 0000000..28fb7a5 --- /dev/null +++ b/dbs/src/values/currency_params.rs @@ -0,0 +1,51 @@ +// 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, Copy, Debug, Default, Deserialize, PartialEq, Serialize)] +pub struct CurrencyParamsDbV2(pub CurrencyParameters); + +impl AsBytes for CurrencyParamsDbV2 { + fn as_bytes<T, F: FnMut(&[u8]) -> T>(&self, mut f: F) -> T { + f(&bincode_db() + .serialize(&self) + .unwrap_or_else(|_| unreachable!())) + } +} + +impl kv_typed::prelude::FromBytes for CurrencyParamsDbV2 { + type Err = bincode::Error; + + fn from_bytes(bytes: &[u8]) -> std::result::Result<Self, Self::Err> { + bincode_db().deserialize(bytes) + } +} + +impl ToDumpString for CurrencyParamsDbV2 { + fn to_dump_string(&self) -> String { + todo!() + } +} + +#[cfg(feature = "explorer")] +impl ExplorableValue for CurrencyParamsDbV2 { + 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())) + } +} -- GitLab