diff --git a/dbs/src/databases/bc_v2.rs b/dbs/src/databases/bc_v2.rs index c5256029671a892a8e1a676e32ccb85d7f44556a..cd70820a3561793d0c6628c7dad04d2ab25d17ad 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 863221c4167376e342274d6c93b12175940f4b6c..952523cf33e09660c5a1118bc1094ed77b34a1fd 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 a77cb7fd247c3dd9d085da764bc323ca733eb8f2..b9ef8e7bc22df46ec9f8b87c7a319c9f99dd9b69 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 0000000000000000000000000000000000000000..28fb7a5df625c6bda9d105a16673435e9cdbd1b7 --- /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())) + } +}