From fd53556f812663c6fa7ab239281ef5acec12cbe0 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Sun, 14 Apr 2019 22:55:56 +0200 Subject: [PATCH] [ref] documents: rename BlockId -> BlockNumber --- lib/core/message/requests.rs | 4 +- lib/core/message/responses.rs | 4 +- .../blockchain-dal/src/entities/block.rs | 10 ++-- .../blockchain-dal/src/entities/fork_tree.rs | 50 ++++++++++--------- .../blockchain-dal/src/entities/identity.rs | 4 +- .../blockchain-dal/src/entities/sources.rs | 4 +- .../blockchain-dal/src/filters/mod.rs | 10 ++-- .../blockchain/blockchain-dal/src/lib.rs | 10 ++-- .../blockchain-dal/src/readers/block.rs | 12 ++--- .../blockchain-dal/src/readers/certs.rs | 6 +-- .../src/readers/currency_params.rs | 2 +- .../blockchain-dal/src/readers/identity.rs | 34 ++++++------- .../src/writers/certification.rs | 8 +-- .../blockchain-dal/src/writers/dividend.rs | 4 +- .../blockchain-dal/src/writers/fork_tree.rs | 8 +-- .../blockchain-dal/src/writers/identity.rs | 6 +-- .../blockchain-dal/src/writers/requests.rs | 16 +++--- .../blockchain-dal/src/writers/transaction.rs | 6 +-- lib/modules/blockchain/blockchain/src/dbex.rs | 4 +- .../blockchain/src/dubp/apply/mod.rs | 4 +- .../blockchain/src/dubp/check/mod.rs | 2 +- .../blockchain/blockchain/src/dunp/queries.rs | 2 +- .../blockchain/src/fork/fork_algo.rs | 6 +-- lib/modules/blockchain/blockchain/src/lib.rs | 2 +- .../blockchain/src/requests/sent.rs | 2 +- .../blockchain/blockchain/src/sync/mod.rs | 6 +-- lib/modules/ws2p-v1-legacy/parsers/blocks.rs | 8 +-- lib/modules/ws2p/ws2p-messages/v2/requests.rs | 6 +-- .../src/mocks/identity.rs | 2 +- .../documents-tests-tools/src/mocks/mod.rs | 4 +- lib/tools/documents/src/blockstamp.rs | 20 ++++---- lib/tools/documents/src/documents/block.rs | 10 ++-- .../documents/src/documents/certification.rs | 4 +- lib/tools/documents/src/documents/identity.rs | 2 +- .../documents/src/documents/membership.rs | 2 +- .../documents/src/documents/revocation.rs | 2 +- .../documents/src/documents/transaction.rs | 10 ++-- lib/tools/documents/src/lib.rs | 4 +- lib/tools/documents/src/parsers/blocks.rs | 6 +-- .../documents/src/parsers/certifications.rs | 4 +- .../network-documents/src/network_head_v3.rs | 4 +- .../network-documents/src/network_peer.rs | 4 +- 42 files changed, 160 insertions(+), 158 deletions(-) diff --git a/lib/core/message/requests.rs b/lib/core/message/requests.rs index a4bd538f..013bc021 100644 --- a/lib/core/message/requests.rs +++ b/lib/core/message/requests.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; -use dubp_documents::BlockId; +use dubp_documents::BlockNumber; use duniter_network::requests::OldNetworkRequest; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; @@ -32,7 +32,7 @@ pub enum DursReqContent { /// Mem pool datas request MemPoolRequest(MemPoolRequest), /// Request to the pow module - ProverRequest(BlockId, Hash), + ProverRequest(BlockNumber, Hash), /// Arbitrary datas ArbitraryDatas(ArbitraryDatas), } diff --git a/lib/core/message/responses.rs b/lib/core/message/responses.rs index 0e957257..e4631241 100644 --- a/lib/core/message/responses.rs +++ b/lib/core/message/responses.rs @@ -18,7 +18,7 @@ use dubp_documents::documents::certification::CertificationDocument; use dubp_documents::documents::identity::IdentityDocument; use dubp_documents::documents::membership::MembershipDocument; use dubp_documents::documents::revocation::RevocationDocument; -use dubp_documents::BlockId; +use dubp_documents::BlockNumber; use dubp_documents::Blockstamp; use duniter_module::ModuleReqId; use duniter_network::requests::NetworkResponse; @@ -36,7 +36,7 @@ pub enum DursResContent { /// Response of OldNetworkRequest NetworkResponse(NetworkResponse), /// Pow module response - ProverResponse(BlockId, Sig, u64), + ProverResponse(BlockNumber, Sig, u64), } #[derive(Debug, Clone)] diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/block.rs b/lib/modules/blockchain/blockchain-dal/src/entities/block.rs index 46c4fa5e..2ea74206 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/block.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/block.rs @@ -16,7 +16,7 @@ use crate::*; use dubp_documents::documents::block::BlockDocument; use dubp_documents::Document; -use dubp_documents::{BlockId, Blockstamp}; +use dubp_documents::{BlockNumber, Blockstamp}; use durs_wot::NodeId; use std::collections::HashMap; @@ -26,9 +26,9 @@ pub struct DALBlock { /// Block document pub block: BlockDocument, /// List of certifications that expire in this block. - /// Warning : BlockId contain the emission block, not the written block ! - /// HashMap<(Source, Target), CreatedBlockId> - pub expire_certs: Option<HashMap<(NodeId, NodeId), BlockId>>, + /// Warning : BlockNumber contain the emission block, not the written block ! + /// HashMap<(Source, Target), BlockNumber> + pub expire_certs: Option<HashMap<(NodeId, NodeId), BlockNumber>>, } impl DALBlock { @@ -39,7 +39,7 @@ impl DALBlock { /// Get previous blockstamp pub fn previous_blockstamp(&self) -> PreviousBlockstamp { Blockstamp { - id: BlockId(self.block.number.0 - 1), + id: BlockNumber(self.block.number.0 - 1), hash: BlockHash(self.block.previous_hash), } } diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs index 670f23bc..3859f511 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs @@ -15,7 +15,7 @@ //! Describe fork tree -use dubp_documents::{BlockHash, BlockId, Blockstamp}; +use dubp_documents::{BlockHash, BlockNumber, Blockstamp}; use serde::de::{self, Deserialize, Deserializer, Visitor}; use serde::{Serialize, Serializer}; use std::collections::{HashMap, HashSet}; @@ -114,7 +114,7 @@ impl TreeNode { pub struct ForkTree { root: Option<TreeNodeId>, nodes: Vec<Option<TreeNode>>, - main_branch: HashMap<BlockId, TreeNodeId>, + main_branch: HashMap<BlockNumber, TreeNodeId>, sheets: HashSet<TreeNodeId>, removed_blockstamps: Vec<Blockstamp>, } @@ -198,7 +198,7 @@ impl ForkTree { } /// Get main branch node #[inline] - pub fn get_main_branch_node_id(&self, block_id: BlockId) -> Option<TreeNodeId> { + pub fn get_main_branch_node_id(&self, block_id: BlockNumber) -> Option<TreeNodeId> { if let Some(node_id) = self.main_branch.get(&block_id) { Some(*node_id) } else { @@ -207,7 +207,7 @@ impl ForkTree { } /// Get main branch block hash #[inline] - pub fn get_main_branch_block_hash(&self, block_id: BlockId) -> Option<BlockHash> { + pub fn get_main_branch_block_hash(&self, block_id: BlockNumber) -> Option<BlockHash> { if let Some(node_id) = self.main_branch.get(&block_id) { Some(self.get_ref_node(*node_id).data.hash) } else { @@ -299,13 +299,13 @@ impl ForkTree { .data .id; for block_id in first_fork_block_id.0..=new_current_blockstamp.id.0 { - self.main_branch.remove(&BlockId(block_id)); + self.main_branch.remove(&BlockNumber(block_id)); } } // Delete the part of the old branch that exceeds the new branch if old_current_blockstamp.id > new_current_blockstamp.id { for block_id in (new_current_blockstamp.id.0 + 1)..=old_current_blockstamp.id.0 { - self.main_branch.remove(&BlockId(block_id)); + self.main_branch.remove(&BlockNumber(block_id)); } } @@ -379,14 +379,14 @@ impl ForkTree { // get root node infos let root_node_id = self.root.expect("safe unwrap"); let root_node = self.get_node(root_node_id); - let root_node_block_id: BlockId = root_node.data.id; + let root_node_block_id: BlockNumber = root_node.data.id; // Shift the tree one step : remove root node and all his children except main child self.main_branch.remove(&root_node_block_id); self.removed_blockstamps.push(root_node.data); let root_node_main_child_id = self .main_branch - .get(&BlockId(root_node_block_id.0 + 1)) + .get(&BlockNumber(root_node_block_id.0 + 1)) .cloned() .expect("safe unwrap"); let mut children_to_remove = Vec::new(); @@ -447,7 +447,7 @@ mod tests { assert_eq!(0, tree.size()); let root_blockstamp = Blockstamp { - id: BlockId(0), + id: BlockNumber(0), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')), }; tree.insert_new_node(root_blockstamp, None, true); @@ -460,11 +460,11 @@ mod tests { assert_eq!(None, tree.get_free_node_id()); assert_eq!( Some(TreeNodeId(0)), - tree.get_main_branch_node_id(BlockId(0)) + tree.get_main_branch_node_id(BlockNumber(0)) ); assert_eq!( Some(root_blockstamp.hash), - tree.get_main_branch_block_hash(BlockId(0)) + tree.get_main_branch_block_hash(BlockNumber(0)) ); assert_eq!( Some(TreeNodeId(0)), @@ -477,15 +477,15 @@ mod tests { let mut tree = ForkTree::default(); let blockstamps = vec![ Blockstamp { - id: BlockId(0), + id: BlockNumber(0), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')), }, Blockstamp { - id: BlockId(1), + id: BlockNumber(1), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('B')), }, Blockstamp { - id: BlockId(2), + id: BlockNumber(2), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('C')), }, ]; @@ -503,11 +503,11 @@ mod tests { for i in 0..=2 { assert_eq!( Some(TreeNodeId(i)), - tree.get_main_branch_node_id(BlockId(i as u32)) + tree.get_main_branch_node_id(BlockNumber(i as u32)) ); assert_eq!( Some(blockstamps[i].hash), - tree.get_main_branch_block_hash(BlockId(i as u32)) + tree.get_main_branch_block_hash(BlockNumber(i as u32)) ); assert_eq!( Some(TreeNodeId(i)), @@ -530,12 +530,12 @@ mod tests { // Insert fork block after block 5 let fork_blockstamp = Blockstamp { - id: BlockId(6), + id: BlockNumber(6), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('B')), }; tree.insert_new_node( fork_blockstamp, - tree.get_main_branch_node_id(BlockId(5)), + tree.get_main_branch_node_id(BlockNumber(5)), false, ); @@ -548,7 +548,7 @@ mod tests { ( TreeNodeId(9), Blockstamp { - id: BlockId(9), + id: BlockNumber(9), hash: BlockHash(dup_crypto_tests_tools::mocks::hash_from_byte(9u8)), }, ), @@ -568,7 +568,7 @@ mod tests { // Insert child to fork block let child_fork_blockstamp = Blockstamp { - id: BlockId(7), + id: BlockNumber(7), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('C')), }; tree.insert_new_node(child_fork_blockstamp, Some(TreeNodeId(10)), false); @@ -582,7 +582,7 @@ mod tests { ( TreeNodeId(9), Blockstamp { - id: BlockId(9), + id: BlockNumber(9), hash: BlockHash(dup_crypto_tests_tools::mocks::hash_from_byte(9u8)), }, ), @@ -657,16 +657,18 @@ mod tests { // Insert 2 forks blocks after block (FORK_WINDOW_SIZE - 2) let fork_blockstamp = Blockstamp { - id: BlockId(*crate::constants::FORK_WINDOW_SIZE as u32 - 1), + id: BlockNumber(*crate::constants::FORK_WINDOW_SIZE as u32 - 1), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')), }; tree.insert_new_node( fork_blockstamp, - tree.get_main_branch_node_id(BlockId(*crate::constants::FORK_WINDOW_SIZE as u32 - 2)), + tree.get_main_branch_node_id(BlockNumber( + *crate::constants::FORK_WINDOW_SIZE as u32 - 2, + )), false, ); let fork_blockstamp_2 = Blockstamp { - id: BlockId(*crate::constants::FORK_WINDOW_SIZE as u32), + id: BlockNumber(*crate::constants::FORK_WINDOW_SIZE as u32), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('B')), }; tree.insert_new_node( diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs b/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs index 5d4b3829..0868b914 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use dubp_documents::documents::identity::IdentityDocument; -use dubp_documents::{BlockId, Blockstamp}; +use dubp_documents::{BlockNumber, Blockstamp}; use durs_wot::NodeId; #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] @@ -50,7 +50,7 @@ pub struct DALIdentity { /// Identity wot id pub wot_id: NodeId, /// Membership created block number - pub ms_created_block_id: BlockId, + pub ms_created_block_id: BlockNumber, /// Timestamp from which membership can be renewed pub ms_chainable_on: Vec<u64>, /// Timestamp from which the identity can write a new certification diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/sources.rs b/lib/modules/blockchain/blockchain-dal/src/entities/sources.rs index 64e5bc68..25821a57 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/sources.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/sources.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use dubp_documents::documents::transaction::*; -use dubp_documents::BlockId; +use dubp_documents::BlockNumber; use dup_crypto::hashs::Hash; use dup_crypto::keys::PubKey; use std::cmp::Ordering; @@ -116,5 +116,5 @@ pub enum SourceIndexV10 { /// unused Transaction Output UTXO(UTXOIndexV10), /// universal Dividend - UD(PubKey, BlockId), + UD(PubKey, BlockNumber), } diff --git a/lib/modules/blockchain/blockchain-dal/src/filters/mod.rs b/lib/modules/blockchain/blockchain-dal/src/filters/mod.rs index b4db0e0c..b04d5402 100644 --- a/lib/modules/blockchain/blockchain-dal/src/filters/mod.rs +++ b/lib/modules/blockchain/blockchain-dal/src/filters/mod.rs @@ -15,15 +15,15 @@ pub mod identities; -use dubp_documents::BlockId; +use dubp_documents::BlockNumber; #[derive(Debug, Copy, Clone, PartialEq, Eq)] /// Pagination parameters pub struct PagingFilter { /// Retrieve only the elements created after this block - pub from: BlockId, + pub from: BlockNumber, /// Retrieve only the elements created before this block - pub to: Option<BlockId>, + pub to: Option<BlockNumber>, /// Number of elements per page pub page_size: usize, /// Number of the page requested @@ -33,7 +33,7 @@ pub struct PagingFilter { impl Default for PagingFilter { fn default() -> Self { PagingFilter { - from: BlockId(0), + from: BlockNumber(0), to: None, page_size: *crate::constants::DEFAULT_PAGE_SIZE, page_number: 0, @@ -44,7 +44,7 @@ impl Default for PagingFilter { impl PagingFilter { #[inline] /// Checks if a given element has been created in the requested period - pub fn check_created_on(&self, created_on: BlockId, current_block_id: BlockId) -> bool { + pub fn check_created_on(&self, created_on: BlockNumber, current_block_id: BlockNumber) -> bool { created_on >= self.from && created_on <= self.to.unwrap_or(current_block_id) } #[inline] diff --git a/lib/modules/blockchain/blockchain-dal/src/lib.rs b/lib/modules/blockchain/blockchain-dal/src/lib.rs index 14fe46f3..c38106e8 100644 --- a/lib/modules/blockchain/blockchain-dal/src/lib.rs +++ b/lib/modules/blockchain/blockchain-dal/src/lib.rs @@ -54,7 +54,7 @@ pub mod writers; use dubp_documents::documents::block::BlockV10Parameters; use dubp_documents::documents::transaction::*; use dubp_documents::CurrencyName; -use dubp_documents::{BlockHash, BlockId, Blockstamp, PreviousBlockstamp}; +use dubp_documents::{BlockHash, BlockNumber, Blockstamp, PreviousBlockstamp}; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_wot::data::{rusty::RustyWebOfTrust, NodeId}; @@ -79,7 +79,7 @@ use crate::writers::transaction::DALTxV10; /// Currency parameters (Protocol V10) pub type CurrencyParamsV10Datas = (CurrencyName, BlockV10Parameters); /// All blocks of local blockchain indexed by block number -pub type LocalBlockchainV10Datas = FnvHashMap<BlockId, DALBlock>; +pub type LocalBlockchainV10Datas = FnvHashMap<BlockNumber, DALBlock>; /// Forks tree meta datas (block number and hash only) pub type ForksTreeV10Datas = entities::fork_tree::ForkTree; /// Forks blocks referenced in tree indexed by their blockstamp @@ -91,15 +91,15 @@ pub type WotDB = RustyWebOfTrust; /// V10 Identities indexed by public key pub type IdentitiesV10Datas = HashMap<PubKey, DALIdentity>; /// Memberships sorted by created block -pub type MsExpirV10Datas = FnvHashMap<BlockId, HashSet<NodeId>>; +pub type MsExpirV10Datas = FnvHashMap<BlockNumber, HashSet<NodeId>>; /// Certifications sorted by created block -pub type CertsExpirV10Datas = FnvHashMap<BlockId, HashSet<(NodeId, NodeId)>>; +pub type CertsExpirV10Datas = FnvHashMap<BlockNumber, HashSet<(NodeId, NodeId)>>; /// V10 Transactions indexed by their hashs pub type TxV10Datas = HashMap<Hash, DALTxV10>; /// V10 Unused Transaction Output (=sources) pub type UTXOsV10Datas = HashMap<UTXOIndexV10, UTXOContentV10>; /// V10 UDs sources -pub type UDsV10Datas = HashMap<PubKey, HashSet<BlockId>>; +pub type UDsV10Datas = HashMap<PubKey, HashSet<BlockNumber>>; /// V10 Balances accounts pub type BalancesV10Datas = HashMap<UTXOConditionsGroup, (SourceAmount, HashSet<UTXOIndexV10>)>; diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/block.rs b/lib/modules/blockchain/blockchain-dal/src/readers/block.rs index 608767ec..8904dda1 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/block.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/block.rs @@ -16,7 +16,7 @@ use crate::*; use dubp_documents::documents::block::BlockDocument; use dubp_documents::Document; -use dubp_documents::{BlockHash, BlockId, Blockstamp}; +use dubp_documents::{BlockHash, BlockNumber, Blockstamp}; use dup_crypto::keys::*; use std::collections::HashMap; @@ -26,7 +26,7 @@ pub fn get_current_blockstamp(blocks_db: &BlocksV10DBs) -> Result<Option<Blockst let blockchain_len = db.len() as u32; if blockchain_len == 0 { None - } else if let Some(dal_block) = db.get(&BlockId(blockchain_len - 1)) { + } else if let Some(dal_block) = db.get(&BlockNumber(blockchain_len - 1)) { Some(dal_block.blockstamp()) } else { None @@ -37,7 +37,7 @@ pub fn get_current_blockstamp(blocks_db: &BlocksV10DBs) -> Result<Option<Blockst /// Get block hash pub fn get_block_hash( db: &BinDB<LocalBlockchainV10Datas>, - block_number: BlockId, + block_number: BlockNumber, ) -> Result<Option<BlockHash>, DALError> { Ok(db.read(|db| { if let Some(dal_block) = db.get(&block_number) { @@ -55,7 +55,7 @@ pub fn already_have_block( previous_hash: Hash, ) -> Result<bool, DALError> { let previous_blockstamp = Blockstamp { - id: BlockId(blockstamp.id.0 - 1), + id: BlockNumber(blockstamp.id.0 - 1), hash: BlockHash(previous_hash), }; @@ -110,7 +110,7 @@ pub fn get_block( /// Get block in local blockchain pub fn get_block_in_local_blockchain( db: &BinDB<LocalBlockchainV10Datas>, - block_id: BlockId, + block_id: BlockNumber, ) -> Result<Option<BlockDocument>, DALError> { Ok(db.read(|db| { if let Some(dal_block) = db.get(&block_id) { @@ -131,7 +131,7 @@ pub fn get_current_frame( let mut current_frame: HashMap<PubKey, usize> = HashMap::new(); for block_number in frame_begin..current_block.block.number.0 { let issuer = db - .get(&BlockId(block_number)) + .get(&BlockNumber(block_number)) .unwrap_or_else(|| panic!("Fail to get block #{} !", block_number)) .block .issuers()[0]; diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs b/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs index 3515f9f3..33ebdcfd 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs @@ -14,15 +14,15 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::{BinDB, CertsExpirV10Datas, DALError}; -use dubp_documents::BlockId; +use dubp_documents::BlockNumber; use durs_wot::NodeId; use std::collections::HashMap; /// Find certifications that emitted in indicated blocks expiring pub fn find_expire_certs( certs_db: &BinDB<CertsExpirV10Datas>, - blocks_expiring: Vec<BlockId>, -) -> Result<HashMap<(NodeId, NodeId), BlockId>, DALError> { + blocks_expiring: Vec<BlockNumber>, +) -> Result<HashMap<(NodeId, NodeId), BlockNumber>, DALError> { Ok(certs_db.read(|db| { let mut all_expire_certs = HashMap::new(); for expire_block_id in blocks_expiring { diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/currency_params.rs b/lib/modules/blockchain/blockchain-dal/src/readers/currency_params.rs index d53287f4..be269d0d 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/currency_params.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/currency_params.rs @@ -21,7 +21,7 @@ pub fn get_currency_params( blockchain_db: &BinDB<LocalBlockchainV10Datas>, ) -> Result<Option<CurrencyParameters>, DALError> { Ok(blockchain_db.read(|db| { - if let Some(genesis_block) = db.get(&BlockId(0)) { + if let Some(genesis_block) = db.get(&BlockNumber(0)) { if genesis_block.block.parameters.is_some() { Some(CurrencyParameters::from(( genesis_block.block.currency.clone(), diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs index d637384b..4cbbe766 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs @@ -16,7 +16,7 @@ use crate::entities::identity::DALIdentity; use crate::filters::identities::IdentitiesFilter; use crate::{BinDB, DALError, IdentitiesV10Datas}; -use dubp_documents::{BlockId, Document}; +use dubp_documents::{BlockNumber, Document}; use dup_crypto::keys::*; use durs_wot::NodeId; use std::collections::HashMap; @@ -25,7 +25,7 @@ use std::collections::HashMap; pub fn get_identities( db: &BinDB<IdentitiesV10Datas>, filters: IdentitiesFilter, - current_block_id: BlockId, + current_block_id: BlockNumber, ) -> Result<Vec<DALIdentity>, DALError> { if let Some(pubkey) = filters.by_pubkey { if let Some(idty) = db.read(|db| db.get(&pubkey).cloned())? { @@ -124,7 +124,7 @@ mod test { use dup_crypto_tests_tools::mocks::pubkey; use rust_tests_tools::collections::slice_same_elems; - fn gen_mock_dal_idty(pubkey: PubKey, created_block_id: BlockId) -> DALIdentity { + fn gen_mock_dal_idty(pubkey: PubKey, created_block_id: BlockNumber) -> DALIdentity { DALIdentity { hash: "".to_owned(), state: DALIdentityState::Member(vec![]), @@ -136,7 +136,7 @@ mod test { created_block_id, ), wot_id: NodeId(0), - ms_created_block_id: BlockId(0), + ms_created_block_id: BlockNumber(0), ms_chainable_on: vec![], cert_chainable_on: vec![], } @@ -146,11 +146,11 @@ mod test { fn test_get_identities() -> Result<(), DALError> { // Create mock identities let mock_identities = vec![ - gen_mock_dal_idty(pubkey('A'), BlockId(0)), - gen_mock_dal_idty(pubkey('B'), BlockId(1)), - gen_mock_dal_idty(pubkey('C'), BlockId(3)), - gen_mock_dal_idty(pubkey('D'), BlockId(4)), - gen_mock_dal_idty(pubkey('E'), BlockId(5)), + gen_mock_dal_idty(pubkey('A'), BlockNumber(0)), + gen_mock_dal_idty(pubkey('B'), BlockNumber(1)), + gen_mock_dal_idty(pubkey('C'), BlockNumber(3)), + gen_mock_dal_idty(pubkey('D'), BlockNumber(4)), + gen_mock_dal_idty(pubkey('E'), BlockNumber(5)), ]; // Write mock identities in DB @@ -166,25 +166,25 @@ mod test { let mut filters = IdentitiesFilter::default(); assert!(slice_same_elems( &mock_identities, - &get_identities(&identities_db, filters, BlockId(5))? + &get_identities(&identities_db, filters, BlockNumber(5))? )); // Test by pubkey filter filters = IdentitiesFilter::by_pubkey(pubkey('A')); assert_eq!( vec![mock_identities[0].clone()], - get_identities(&identities_db, filters, BlockId(5))? + get_identities(&identities_db, filters, BlockNumber(5))? ); filters = IdentitiesFilter::by_pubkey(pubkey('C')); assert_eq!( vec![mock_identities[2].clone()], - get_identities(&identities_db, filters, BlockId(5))? + get_identities(&identities_db, filters, BlockNumber(5))? ); // Test paging filter with little page size filters = IdentitiesFilter { paging: PagingFilter { - from: BlockId(0), + from: BlockNumber(0), to: None, page_size: 2, page_number: 1, @@ -193,14 +193,14 @@ mod test { }; assert!(slice_same_elems( &vec![mock_identities[2].clone(), mock_identities[3].clone()], - &get_identities(&identities_db, filters, BlockId(5))? + &get_identities(&identities_db, filters, BlockNumber(5))? )); // Test paging filter with limited interval filters = IdentitiesFilter { paging: PagingFilter { - from: BlockId(2), - to: Some(BlockId(3)), + from: BlockNumber(2), + to: Some(BlockNumber(3)), page_size: 50, page_number: 0, }, @@ -208,7 +208,7 @@ mod test { }; assert_eq!( vec![mock_identities[2].clone()], - get_identities(&identities_db, filters, BlockId(5))? + get_identities(&identities_db, filters, BlockNumber(5))? ); Ok(()) diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs b/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs index fb2b34c0..bf3c1947 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs @@ -16,7 +16,7 @@ use crate::entities::currency_params::CurrencyParameters; use crate::{BinDB, CertsExpirV10Datas, DALError, IdentitiesV10Datas}; use dubp_documents::documents::certification::CompactCertificationDocument; -use dubp_documents::BlockId; +use dubp_documents::BlockNumber; use dup_crypto::keys::*; use durs_wot::NodeId; @@ -28,7 +28,7 @@ pub fn write_certification( source_pubkey: PubKey, source: NodeId, target: NodeId, - created_block_id: BlockId, + created_block_id: BlockNumber, written_timestamp: u64, ) -> Result<(), DALError> { // Get cert_chainable_on @@ -86,7 +86,7 @@ pub fn revert_expire_cert( certs_db: &BinDB<CertsExpirV10Datas>, source: NodeId, target: NodeId, - created_block_id: BlockId, + created_block_id: BlockNumber, ) -> Result<(), DALError> { // Reinsert CertsExpirV10Datas entry certs_db.write(|db| { @@ -100,7 +100,7 @@ pub fn revert_expire_cert( /// Apply "certification expiry" event in databases pub fn expire_certs( certs_db: &BinDB<CertsExpirV10Datas>, - created_block_id: BlockId, + created_block_id: BlockNumber, ) -> Result<(), DALError> { // Remove CertsExpirV10Datas entries certs_db.write(|db| { diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs b/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs index 710259f3..0bf89428 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs @@ -16,7 +16,7 @@ use crate::entities::sources::SourceAmount; use crate::*; use dubp_documents::documents::transaction::*; -use dubp_documents::BlockId; +use dubp_documents::BlockNumber; use dup_crypto::keys::PubKey; use std::collections::{HashMap, HashSet}; @@ -25,7 +25,7 @@ pub fn create_du( du_db: &BinDB<UDsV10Datas>, balances_db: &BinDB<BalancesV10Datas>, du_amount: &SourceAmount, - du_block_id: BlockId, + du_block_id: BlockNumber, members: &[PubKey], revert: bool, ) -> Result<(), DALError> { diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs index de1a7c6c..8981bf20 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs @@ -24,7 +24,7 @@ pub fn insert_new_head_block( ) -> Result<Vec<Blockstamp>, DALError> { fork_tree_db.write(|fork_tree| { let parent_id_opt = if blockstamp.id.0 > 0 && fork_tree.size() > 0 { - Some(fork_tree.get_main_branch_node_id(BlockId(blockstamp.id.0 - 1)) + Some(fork_tree.get_main_branch_node_id(BlockNumber(blockstamp.id.0 - 1)) .expect("Fatal error: fail to insert new head block : previous block not exist in main branch")) } else { None @@ -43,7 +43,7 @@ pub fn insert_new_fork_block( previous_hash: Hash, ) -> Result<bool, DALError> { let previous_blockstamp = Blockstamp { - id: BlockId(blockstamp.id.0 - 1), + id: BlockNumber(blockstamp.id.0 - 1), hash: BlockHash(previous_hash), }; @@ -176,7 +176,7 @@ mod test { // Insert first fork block at child of block 2 let fork_blockstamp = Blockstamp { - id: BlockId(3), + id: BlockNumber(3), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')), }; assert_eq!( @@ -196,7 +196,7 @@ mod test { // Insert second fork block at child of first fork block let fork_blockstamp_2 = Blockstamp { - id: BlockId(4), + id: BlockNumber(4), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('B')), }; assert_eq!( diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs index b0a24e8c..713a779e 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs @@ -18,7 +18,7 @@ use crate::entities::identity::{DALIdentity, DALIdentityState}; use crate::{BinDB, DALError, IdentitiesV10Datas, MsExpirV10Datas}; use dubp_documents::documents::identity::IdentityDocument; use dubp_documents::Document; -use dubp_documents::{BlockId, Blockstamp}; +use dubp_documents::{BlockNumber, Blockstamp}; use dup_crypto::keys::PubKey; use durs_wot::NodeId; @@ -55,7 +55,7 @@ pub fn create_identity( identities_db: &BinDB<IdentitiesV10Datas>, ms_db: &BinDB<MsExpirV10Datas>, idty_doc: &IdentityDocument, - ms_created_block_id: BlockId, + ms_created_block_id: BlockNumber, wot_id: NodeId, current_blockstamp: Blockstamp, current_bc_time: u64, @@ -182,7 +182,7 @@ pub fn renewal_identity( pubkey: &PubKey, idty_wot_id: NodeId, renewal_timestamp: u64, - ms_created_block_id: BlockId, + ms_created_block_id: BlockNumber, revert: bool, ) -> Result<(), DALError> { // Get idty_datas diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs index 514e9166..c6c67ea4 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs @@ -94,13 +94,13 @@ impl BlocksDBsWriteQuery { /// Contain a pending write request for wots databases pub enum WotsDBsWriteQuery { /// Newcomer (wot_id, blockstamp, current_bc_time, idty_doc, ms_created_block_id) - CreateIdentity(NodeId, Blockstamp, u64, Box<IdentityDocument>, BlockId), + CreateIdentity(NodeId, Blockstamp, u64, Box<IdentityDocument>, BlockNumber), /// Revert newcomer event (wot_id, blockstamp, current_bc_time, idty_doc, ms_created_block_id) RevertCreateIdentity(PubKey), /// Active (pubKey, idty_wot_id, current_bc_time, ms_created_block_id) - RenewalIdentity(PubKey, NodeId, u64, BlockId), + RenewalIdentity(PubKey, NodeId, u64, BlockNumber), /// Revert active (pubKey, idty_wot_id, current_bc_time, ms_created_block_id) - RevertRenewalIdentity(PubKey, NodeId, u64, BlockId), + RevertRenewalIdentity(PubKey, NodeId, u64, BlockNumber), /// Excluded ExcludeIdentity(PubKey, Blockstamp), /// Revert exclusion @@ -110,13 +110,13 @@ pub enum WotsDBsWriteQuery { /// Revert revocation RevertRevokeIdentity(PubKey, Blockstamp, bool), /// Certification (source_pubkey, source, target, created_block_id, median_time) - CreateCert(PubKey, NodeId, NodeId, BlockId, u64), + CreateCert(PubKey, NodeId, NodeId, BlockNumber, u64), /// Revert certification (source_pubkey, source, target, created_block_id, median_time) RevertCert(CompactCertificationDocument, NodeId, NodeId), /// Certification expiry (source, target, created_block_id) - ExpireCerts(BlockId), + ExpireCerts(BlockNumber), /// Revert certification expiry event (source, target, created_block_id) - RevertExpireCert(NodeId, NodeId, BlockId), + RevertExpireCert(NodeId, NodeId, BlockNumber), } impl WotsDBsWriteQuery { @@ -277,9 +277,9 @@ pub enum CurrencyDBsWriteQuery { /// Revert transaction RevertTx(Box<DALTxV10>), /// Create dividend - CreateUD(SourceAmount, BlockId, Vec<PubKey>), + CreateUD(SourceAmount, BlockNumber, Vec<PubKey>), /// Revert dividend - RevertUD(SourceAmount, BlockId, Vec<PubKey>), + RevertUD(SourceAmount, BlockNumber, Vec<PubKey>), } impl CurrencyDBsWriteQuery { diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs b/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs index dfe76768..9991188c 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs @@ -223,7 +223,7 @@ pub fn revert_tx(dbs: &CurrencyV10DBs, dal_tx: &DALTxV10) -> Result<(), DALError db.insert(*utxo_index, utxo_content); })?; } else if let SourceIndexV10::UD(pubkey, block_id) = s_index { - let mut pubkey_dus: HashSet<BlockId> = dbs + let mut pubkey_dus: HashSet<BlockNumber> = dbs .du_db .read(|db| db.get(&pubkey).cloned().unwrap_or_default())?; pubkey_dus.insert(*block_id); @@ -330,7 +330,7 @@ pub fn apply_and_write_tx( db.remove(utxo_index); })?; } else if let SourceIndexV10::UD(pubkey, block_id) = source_index { - let mut pubkey_dus: HashSet<BlockId> = dbs + let mut pubkey_dus: HashSet<BlockNumber> = dbs .du_db .read(|db| db.get(&pubkey).cloned().unwrap_or_default())?; pubkey_dus.remove(block_id); @@ -473,7 +473,7 @@ mod tests { ¤cy_dbs.du_db, ¤cy_dbs.balances_db, &SourceAmount(TxAmount(1000), TxBase(0)), - BlockId(1), + BlockNumber(1), &vec![tx_doc.issuers()[0], tortue_pubkey], false, ) diff --git a/lib/modules/blockchain/blockchain/src/dbex.rs b/lib/modules/blockchain/blockchain/src/dbex.rs index 2c081f62..31020219 100644 --- a/lib/modules/blockchain/blockchain/src/dbex.rs +++ b/lib/modules/blockchain/blockchain/src/dbex.rs @@ -233,10 +233,10 @@ pub fn dbex_wot<DC: DuniterConf>(profile: &str, conf: &DC, csv: bool, query: &DB let blockchain_db = open_file_db::<LocalBlockchainV10Datas>(&db_path, "blockchain.db") .expect("Fail to open blockchain db"); // Get blocks_times - let (current_bc_time, blocks_times): (u64, HashMap<BlockId, u64>) = blockchain_db + let (current_bc_time, blocks_times): (u64, HashMap<BlockNumber, u64>) = blockchain_db .read(|db| { ( - db[&BlockId(db.len() as u32 - 1)].block.median_time, + db[&BlockNumber(db.len() as u32 - 1)].block.median_time, db.iter() .map(|(block_id, dal_block)| (*block_id, dal_block.block.median_time)) .collect(), diff --git a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs index 337e176f..350f445b 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs @@ -17,7 +17,7 @@ use dubp_documents::documents::block::BlockDocument; use dubp_documents::documents::transaction::{TxAmount, TxBase}; -use dubp_documents::{BlockId, Document}; +use dubp_documents::{BlockNumber, Document}; use dup_crypto::keys::*; use durs_blockchain_dal::entities::block::DALBlock; use durs_blockchain_dal::entities::sources::SourceAmount; @@ -46,7 +46,7 @@ pub fn apply_valid_block<W: WebOfTrust>( mut block: BlockDocument, wot_index: &mut HashMap<PubKey, NodeId>, wot_db: &BinDB<W>, - expire_certs: &HashMap<(NodeId, NodeId), BlockId>, + expire_certs: &HashMap<(NodeId, NodeId), BlockNumber>, ) -> Result<ValidBlockApplyReqs, ApplyValidBlockError> { debug!( "BlockchainModule : apply_valid_block({})", diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs index f22878e4..0c9959ba 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs @@ -43,7 +43,7 @@ pub fn verify_block_validity<W: WebOfTrust>( // Get previous block let previous_block_opt = readers::block::get_block_in_local_blockchain( blockchain_db, - BlockId(block.number.0 - 1), + BlockNumber(block.number.0 - 1), )?; // Previous block must exist diff --git a/lib/modules/blockchain/blockchain/src/dunp/queries.rs b/lib/modules/blockchain/blockchain/src/dunp/queries.rs index 2357dd0e..ca58b32d 100644 --- a/lib/modules/blockchain/blockchain/src/dunp/queries.rs +++ b/lib/modules/blockchain/blockchain/src/dunp/queries.rs @@ -54,7 +54,7 @@ pub fn request_chunk( /// Requests blocks from current to `to` pub fn request_blocks_to( bc: &BlockchainModule, - to: BlockId, + to: BlockNumber, ) -> HashMap<ModuleReqId, OldNetworkRequest> { let mut from = if bc.current_blockstamp == Blockstamp::default() { 0 diff --git a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs index 44255b0c..66d9795b 100644 --- a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs +++ b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs @@ -139,7 +139,7 @@ mod tests { .map(|i| { dubp_documents_tests_tools::mocks::gen_empty_timed_block( Blockstamp { - id: BlockId(fork_point.number.0 + i + 1), + id: BlockNumber(fork_point.number.0 + i + 1), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')), }, ADVANCE_TIME - 1, @@ -169,7 +169,7 @@ mod tests { // Add the determining fork block let determining_blockstamp = Blockstamp { - id: BlockId(fork_point.number.0 + 4), + id: BlockNumber(fork_point.number.0 + 4), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')), }; assert_eq!( @@ -204,7 +204,7 @@ mod tests { .map(|i| { dubp_documents_tests_tools::mocks::gen_empty_timed_block( Blockstamp { - id: BlockId(fork_point.number.0 + i + 1), + id: BlockNumber(fork_point.number.0 + i + 1), hash: BlockHash(dup_crypto_tests_tools::mocks::hash('B')), }, ADVANCE_TIME * 2, diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs index d20c9a7b..6e7e24c9 100644 --- a/lib/modules/blockchain/blockchain/src/lib.rs +++ b/lib/modules/blockchain/blockchain/src/lib.rs @@ -173,7 +173,7 @@ pub enum VerifyBlockHashsError { /// Invalid block inner hash InvalidInnerHash(), /// Invalid block hash - InvalidHash(BlockId, Option<BlockHash>), + InvalidHash(BlockNumber, Option<BlockHash>), /// Invalid block version InvalidVersion(), } diff --git a/lib/modules/blockchain/blockchain/src/requests/sent.rs b/lib/modules/blockchain/blockchain/src/requests/sent.rs index db0490f0..edfaf77f 100644 --- a/lib/modules/blockchain/blockchain/src/requests/sent.rs +++ b/lib/modules/blockchain/blockchain/src/requests/sent.rs @@ -36,7 +36,7 @@ pub fn request_next_main_blocks(bc: &mut BlockchainModule) { 0 => (bc.current_blockstamp.id.0 + *MAX_BLOCKS_REQUEST), _ => bc.consensus.id.0, }; - let new_pending_network_requests = dunp::queries::request_blocks_to(bc, BlockId(to)); + let new_pending_network_requests = dunp::queries::request_blocks_to(bc, BlockNumber(to)); for (new_req_id, new_req) in new_pending_network_requests { bc.pending_network_requests.insert(new_req_id, new_req); } diff --git a/lib/modules/blockchain/blockchain/src/sync/mod.rs b/lib/modules/blockchain/blockchain/src/sync/mod.rs index fd201d8f..757f851c 100644 --- a/lib/modules/blockchain/blockchain/src/sync/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/mod.rs @@ -18,7 +18,7 @@ mod download; use crate::dubp::apply::apply_valid_block; use crate::*; -use dubp_documents::{BlockHash, BlockId}; +use dubp_documents::{BlockHash, BlockNumber}; use dup_crypto::keys::*; use durs_blockchain_dal::entities::currency_params::CurrencyParameters; use durs_blockchain_dal::writers::requests::*; @@ -38,7 +38,7 @@ pub static NB_SYNC_JOBS: &'static usize = &4; #[derive(Debug, Clone, PartialEq, Eq)] /// Block header pub struct BlockHeader { - pub number: BlockId, + pub number: BlockNumber, pub hash: BlockHash, pub issuer: PubKey, } @@ -299,7 +299,7 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt) < Some(block_doc.median_time - currency_params.sig_validity) { last_block_expiring += 1; - blocks_expiring.push(BlockId(last_block_expiring as u32)); + blocks_expiring.push(BlockNumber(last_block_expiring as u32)); blocks_not_expiring.pop_front(); } // Find expire_certs diff --git a/lib/modules/ws2p-v1-legacy/parsers/blocks.rs b/lib/modules/ws2p-v1-legacy/parsers/blocks.rs index 76eea776..0baf44a6 100644 --- a/lib/modules/ws2p-v1-legacy/parsers/blocks.rs +++ b/lib/modules/ws2p-v1-legacy/parsers/blocks.rs @@ -7,12 +7,12 @@ use dubp_documents::documents::membership::*; use dubp_documents::parsers::certifications::*; use dubp_documents::parsers::revoked::*; use dubp_documents::CurrencyName; -use dubp_documents::{BlockHash, BlockId}; +use dubp_documents::{BlockHash, BlockNumber}; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use std::str::FromStr; -fn parse_previous_hash(block_number: BlockId, source: &serde_json::Value) -> Option<Hash> { +fn parse_previous_hash(block_number: BlockNumber, source: &serde_json::Value) -> Option<Hash> { match source.get("previousHash")?.as_str() { Some(hash_str) => match Hash::from_hex(hash_str) { Ok(hash) => Some(hash), @@ -59,7 +59,7 @@ fn parse_memberships( } pub fn parse_json_block(source: &serde_json::Value) -> Option<BlockDocument> { - let number = BlockId(source.get("number")?.as_u64()? as u32); + let number = BlockNumber(source.get("number")?.as_u64()? as u32); let currency = source.get("currency")?.as_str()?.to_string(); let issuer = match ed25519::PublicKey::from_base58(source.get("issuer")?.as_str()?) { Ok(pubkey) => PubKey::Ed25519(pubkey), @@ -120,7 +120,7 @@ pub fn parse_json_block(source: &serde_json::Value) -> Option<BlockDocument> { Some(BlockDocument { nonce: source.get("nonce")?.as_i64()? as u64, version: source.get("version")?.as_u64()? as u32, - number: BlockId(source.get("number")?.as_u64()? as u32), + number: BlockNumber(source.get("number")?.as_u64()? as u32), pow_min: source.get("powMin")?.as_u64()? as usize, time: source.get("time")?.as_u64()?, median_time: source.get("medianTime")?.as_u64()?, diff --git a/lib/modules/ws2p/ws2p-messages/v2/requests.rs b/lib/modules/ws2p/ws2p-messages/v2/requests.rs index 8a10db1a..f8d36676 100644 --- a/lib/modules/ws2p/ws2p-messages/v2/requests.rs +++ b/lib/modules/ws2p/ws2p-messages/v2/requests.rs @@ -13,7 +13,7 @@ // 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::{BlockId, Blockstamp}; +use dubp_documents::{BlockNumber, Blockstamp}; /// WS2Pv2Request #[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)] @@ -42,11 +42,11 @@ pub enum WS2Pv2RequestBody { /// It would be counterproductive to ask directly for the entire blocks, when you will only need them if you actually decide to stack the corresponding branch. /// param1: begin_block_id (u32) /// param2: blocks_count (u16) - BlocksHashs(BlockId, u16), + BlocksHashs(BlockNumber, u16), /// CHUNK: Request chunk of blocks. /// param1: begin_block_id (u32) /// param2: blocks_count (u16) - Chunk(BlockId, u16), + Chunk(BlockNumber, u16), /// CHUNK_BY_HASH : During synchronization, chunk is requested by Chunkstamp (= Blockstamp of the last block of the chunk). ChunkByHash(Blockstamp), /// WOT_POOL : For network performance reasons, a Durs* node never shares its entire wot pool at once. diff --git a/lib/tests-tools/documents-tests-tools/src/mocks/identity.rs b/lib/tests-tools/documents-tests-tools/src/mocks/identity.rs index b26e13a1..0037a258 100644 --- a/lib/tests-tools/documents-tests-tools/src/mocks/identity.rs +++ b/lib/tests-tools/documents-tests-tools/src/mocks/identity.rs @@ -21,7 +21,7 @@ use dup_crypto::hashs::Hash; use dup_crypto::keys::PubKey; /// Generate mock identity document -pub fn gen_mock_idty(pubkey: PubKey, created_on: BlockId) -> IdentityDocument { +pub fn gen_mock_idty(pubkey: PubKey, created_on: BlockNumber) -> IdentityDocument { let idty_builder = IdentityDocumentBuilder { currency: "", username: "", diff --git a/lib/tests-tools/documents-tests-tools/src/mocks/mod.rs b/lib/tests-tools/documents-tests-tools/src/mocks/mod.rs index 53fc9640..6f832f1d 100644 --- a/lib/tests-tools/documents-tests-tools/src/mocks/mod.rs +++ b/lib/tests-tools/documents-tests-tools/src/mocks/mod.rs @@ -25,7 +25,7 @@ use dup_crypto::hashs::Hash; pub fn generate_blockstamps(n: usize) -> Vec<Blockstamp> { (0..n) .map(|i| Blockstamp { - id: BlockId(i as u32), + id: BlockNumber(i as u32), hash: BlockHash(dup_crypto_tests_tools::mocks::hash_from_byte( (i % 255) as u8, )), @@ -39,7 +39,7 @@ pub fn gen_empty_timed_blocks(n: usize, time_step: u64) -> Vec<BlockDocument> { .map(|i| { gen_empty_timed_block( Blockstamp { - id: BlockId(i as u32), + id: BlockNumber(i as u32), hash: BlockHash(dup_crypto_tests_tools::mocks::hash_from_byte( (i % 255) as u8, )), diff --git a/lib/tools/documents/src/blockstamp.rs b/lib/tools/documents/src/blockstamp.rs index a042bac9..0a8d7629 100644 --- a/lib/tools/documents/src/blockstamp.rs +++ b/lib/tools/documents/src/blockstamp.rs @@ -25,9 +25,9 @@ pub enum BlockstampParseError { /// Given string have invalid format #[fail(display = "Given string have invalid format")] InvalidFormat(), - /// [`BlockId`](struct.BlockHash.html) part is not a valid number. - #[fail(display = "BlockId part is not a valid number.")] - InvalidBlockId(), + /// [`BlockNumber`](struct.BlockHash.html) part is not a valid number. + #[fail(display = "BlockNumber part is not a valid number.")] + InvalidBlockNumber(), /// [`BlockHash`](struct.BlockHash.html) part is not a valid hex number. #[fail(display = "BlockHash part is not a valid hex number.")] InvalidBlockHash(), @@ -35,24 +35,24 @@ pub enum BlockstampParseError { /// A blockstamp (Unique ID). /// -/// It's composed of the [`BlockId`] and +/// It's composed of the [`BlockNumber`] and /// the [`BlockHash`] of the block. /// /// Thanks to blockchain immutability and frequent block production, it can /// be used to date information. /// -/// [`BlockId`]: struct.BlockId.html +/// [`BlockNumber`]: struct.BlockNumber.html /// [`BlockHash`]: struct.BlockHash.html #[derive(Copy, Clone, Deserialize, PartialEq, Eq, Hash, Serialize)] pub struct Blockstamp { /// Block Id. - pub id: BlockId, + pub id: BlockNumber, /// Block hash. pub hash: BlockHash, } -/// Previous blockstamp (BlockId-1, previous_hash) +/// Previous blockstamp (BlockNumber-1, previous_hash) pub type PreviousBlockstamp = Blockstamp; impl Blockstamp { @@ -75,7 +75,7 @@ impl Debug for Blockstamp { impl Default for Blockstamp { fn default() -> Blockstamp { Blockstamp { - id: BlockId(0), + id: BlockNumber(0), hash: BlockHash(Hash::default()), } } @@ -126,12 +126,12 @@ impl Blockstamp { let hash = Hash::from_hex(split.next().unwrap()); if id.is_err() { - Err(BlockstampParseError::InvalidBlockId()) + Err(BlockstampParseError::InvalidBlockNumber()) } else if hash.is_err() { Err(BlockstampParseError::InvalidBlockHash()) } else { Ok(Blockstamp { - id: BlockId(id.unwrap()), + id: BlockNumber(id.unwrap()), hash: BlockHash( hash.expect("Try to get hash of an uncompleted or reduce block !"), ), diff --git a/lib/tools/documents/src/documents/block.rs b/lib/tools/documents/src/documents/block.rs index 0bef7e10..7199c420 100644 --- a/lib/tools/documents/src/documents/block.rs +++ b/lib/tools/documents/src/documents/block.rs @@ -229,7 +229,7 @@ pub struct BlockDocument { /// Nonce pub nonce: u64, /// number - pub number: BlockId, + pub number: BlockNumber, /// Minimal proof of work difficulty pub pow_min: usize, /// Local time of the block issuer @@ -292,7 +292,7 @@ impl BlockDocument { pub fn previous_blockstamp(&self) -> Blockstamp { if self.number.0 > 0 { Blockstamp { - id: BlockId(self.number.0 - 1), + id: BlockNumber(self.number.0 - 1), hash: BlockHash(self.previous_hash), } } else { @@ -584,7 +584,7 @@ mod tests { let mut block = BlockDocument { nonce: 100_010_200_000_006_940, version: 10, - number: BlockId(174_260), + number: BlockNumber(174_260), pow_min: 68, time: 1_525_296_873, median_time: 1_525_292_577, @@ -686,7 +686,7 @@ a9PHPuSfw7jW8FRQHXFsGi/bnLjbtDnTYvEVgUC9u0WlR7GVofa+Xb+l5iy6NwuEXiwvueAkf08wPVY8 let mut block = BlockDocument { nonce: 0, version: 10, - number: BlockId(107_984), + number: BlockNumber(107_984), pow_min: 88, time: 1_522_685_861, median_time: 1522683184, @@ -867,7 +867,7 @@ nxr4exGrt16jteN9ZX3XZPP9l+X0OUbZ1o/QjE1hbWQNtVU3HhH9SJoEvNj2iVl3gCRr9u2OA9uj9vCy let mut block = BlockDocument { nonce: 0, version: 10, - number: BlockId(165_647), + number: BlockNumber(165_647), pow_min: 90, time: 1_540_633_175, median_time: 1_540_627_811, diff --git a/lib/tools/documents/src/documents/certification.rs b/lib/tools/documents/src/documents/certification.rs index a21db71c..73318a1b 100644 --- a/lib/tools/documents/src/documents/certification.rs +++ b/lib/tools/documents/src/documents/certification.rs @@ -30,7 +30,7 @@ pub struct CompactCertificationDocument { /// Target pub target: PubKey, /// Blockstamp - pub block_number: BlockId, + pub block_number: BlockNumber, /// Signature pub signature: Sig, } @@ -301,7 +301,7 @@ impl TextDocumentParser<Rule> for CertificationDocumentParser { let block_id: &str = inner_rules.next().unwrap().as_str(); let block_hash: &str = inner_rules.next().unwrap().as_str(); blockstamps.push(Blockstamp { - id: BlockId(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. + id: BlockNumber(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. hash: BlockHash(Hash::from_hex(block_hash).unwrap()), // Grammar ensures that we have an hexadecimal string. }); } diff --git a/lib/tools/documents/src/documents/identity.rs b/lib/tools/documents/src/documents/identity.rs index 3b01663f..cbb6b89d 100644 --- a/lib/tools/documents/src/documents/identity.rs +++ b/lib/tools/documents/src/documents/identity.rs @@ -266,7 +266,7 @@ impl TextDocumentParser<Rule> for IdentityDocumentParser { let block_id: &str = inner_rules.next().unwrap().as_str(); let block_hash: &str = inner_rules.next().unwrap().as_str(); blockstamp = Blockstamp { - id: BlockId(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. + id: BlockNumber(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. hash: BlockHash(Hash::from_hex(block_hash).unwrap()), // Grammar ensures that we have an hexadecimal string. }; } diff --git a/lib/tools/documents/src/documents/membership.rs b/lib/tools/documents/src/documents/membership.rs index e7b9ada1..1e97cc32 100644 --- a/lib/tools/documents/src/documents/membership.rs +++ b/lib/tools/documents/src/documents/membership.rs @@ -329,7 +329,7 @@ impl TextDocumentParser<Rule> for MembershipDocumentParser { let block_id: &str = inner_rules.next().unwrap().as_str(); let block_hash: &str = inner_rules.next().unwrap().as_str(); blockstamps.push(Blockstamp { - id: BlockId(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. + id: BlockNumber(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. hash: BlockHash(Hash::from_hex(block_hash).unwrap()), // Grammar ensures that we have an hexadecimal string. }); } diff --git a/lib/tools/documents/src/documents/revocation.rs b/lib/tools/documents/src/documents/revocation.rs index 0f3cbca7..21eec597 100644 --- a/lib/tools/documents/src/documents/revocation.rs +++ b/lib/tools/documents/src/documents/revocation.rs @@ -263,7 +263,7 @@ impl TextDocumentParser<Rule> for RevocationDocumentParser { let block_id: &str = inner_rules.next().unwrap().as_str(); let block_hash: &str = inner_rules.next().unwrap().as_str(); blockstamps.push(Blockstamp { - id: BlockId(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. + id: BlockNumber(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. hash: BlockHash(Hash::from_hex(block_hash).unwrap()), // Grammar ensures that we have an hexadecimal string. }); } diff --git a/lib/tools/documents/src/documents/transaction.rs b/lib/tools/documents/src/documents/transaction.rs index 610524b4..17d916cc 100644 --- a/lib/tools/documents/src/documents/transaction.rs +++ b/lib/tools/documents/src/documents/transaction.rs @@ -56,7 +56,7 @@ pub struct TxIndex(pub usize); #[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum TransactionInput { /// Universal Dividend Input - D(TxAmount, TxBase, PubKey, BlockId), + D(TxAmount, TxBase, PubKey, BlockNumber), /// Previous Transaction Input T(TxAmount, TxBase, Hash, TxIndex), } @@ -88,7 +88,7 @@ impl TransactionInput { ed25519::PublicKey::from_base58(inner_rules.next().unwrap().as_str()) .unwrap(), ), - BlockId(inner_rules.next().unwrap().as_str().parse().unwrap()), + BlockNumber(inner_rules.next().unwrap().as_str().parse().unwrap()), ) } Rule::tx_input_tx => { @@ -135,7 +135,7 @@ impl FromStr for TransactionInput { PubKey::Ed25519( ed25519::PublicKey::from_base58(pubkey).expect("fail to parse input pubkey !"), ), - BlockId( + BlockNumber( block_number .parse() .expect("fail to parse input block_number !"), @@ -859,7 +859,7 @@ impl TextDocumentParser<Rule> for TransactionDocumentParser { let block_id: &str = inner_rules.next().unwrap().as_str(); let block_hash: &str = inner_rules.next().unwrap().as_str(); blockstamp = Blockstamp { - id: BlockId(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. + id: BlockNumber(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. hash: BlockHash(Hash::from_hex(block_hash).unwrap()), // Grammar ensures that we have an hexadecimal string. }; } @@ -941,7 +941,7 @@ mod tests { ed25519::PublicKey::from_base58("DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV") .unwrap(), ), - BlockId(0), + BlockNumber(0), )], unlocks: &vec![TransactionInputUnlocks { index: 0, diff --git a/lib/tools/documents/src/lib.rs b/lib/tools/documents/src/lib.rs index 62dd758c..4894b3e6 100644 --- a/lib/tools/documents/src/lib.rs +++ b/lib/tools/documents/src/lib.rs @@ -154,9 +154,9 @@ impl CurrencyName { /// A block Id. #[derive(Copy, Clone, Debug, Deserialize, Ord, PartialEq, PartialOrd, Eq, Hash, Serialize)] -pub struct BlockId(pub u32); +pub struct BlockNumber(pub u32); -impl Display for BlockId { +impl Display for BlockNumber { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { write!(f, "{}", self.0) } diff --git a/lib/tools/documents/src/parsers/blocks.rs b/lib/tools/documents/src/parsers/blocks.rs index 7df8747d..2153e2bb 100644 --- a/lib/tools/documents/src/parsers/blocks.rs +++ b/lib/tools/documents/src/parsers/blocks.rs @@ -41,7 +41,7 @@ pub fn parse_json_block(json_block: &JSONValue<DefaultHasher>) -> Result<BlockDo Ok(BlockDocument { version: get_number(json_block, "version")?.trunc() as u32, nonce: get_number(json_block, "nonce")?.trunc() as u64, - number: BlockId(block_number), + number: BlockNumber(block_number), pow_min: get_number(json_block, "powMin")?.trunc() as usize, time: get_number(json_block, "time")?.trunc() as u64, median_time: get_number(json_block, "medianTime")?.trunc() as u64, @@ -175,7 +175,7 @@ mod tests { BlockDocument { version: 10, nonce: 10200000037108, - number: BlockId(7), + number: BlockNumber(7), pow_min: 70, time: 1488987677, median_time: 1488987394, @@ -297,7 +297,7 @@ mod tests { let expected_block = BlockDocument { version: 10, nonce: 10100000033688, - number: BlockId(52), + number: BlockNumber(52), pow_min: 74, time: 1488990898, median_time: 1488990117, diff --git a/lib/tools/documents/src/parsers/certifications.rs b/lib/tools/documents/src/parsers/certifications.rs index c8653ec3..61a7abde 100644 --- a/lib/tools/documents/src/parsers/certifications.rs +++ b/lib/tools/documents/src/parsers/certifications.rs @@ -15,7 +15,7 @@ use crate::documents::certification::{CertificationDocument, CompactCertificationDocument}; use crate::text_document_traits::TextDocumentFormat; -use crate::BlockId; +use crate::BlockNumber; use dup_crypto::keys::*; /// Parse array of certification json documents into vector of `CompactCertificationDocument` @@ -35,7 +35,7 @@ pub fn parse_certifications_into_compact( ed25519::PublicKey::from_base58(certifications_datas[1]) .expect("Receive block in wrong format : fail to parse target !"), ), - block_number: BlockId( + block_number: BlockNumber( certifications_datas[2] .parse() .expect("Receive block in wrong format : fail to parse block number !"), diff --git a/lib/tools/network-documents/src/network_head_v3.rs b/lib/tools/network-documents/src/network_head_v3.rs index 53b2e2b0..05ac3395 100644 --- a/lib/tools/network-documents/src/network_head_v3.rs +++ b/lib/tools/network-documents/src/network_head_v3.rs @@ -18,7 +18,7 @@ use crate::*; use base58::ToBase58; use dubp_documents::blockstamp::Blockstamp; -use dubp_documents::{BlockHash, BlockId, CurrencyName, ToStringObject}; +use dubp_documents::{BlockHash, BlockNumber, CurrencyName, ToStringObject}; use dup_crypto::keys::text_signable::TextSignable; use dup_crypto::keys::*; use pest::iterators::Pair; @@ -150,7 +150,7 @@ impl TextDocumentParser<Rule> for NetworkHeadV3 { let block_id: &str = inner_rules.next().unwrap().as_str(); let block_hash: &str = inner_rules.next().unwrap().as_str(); blockstamp = Some(Blockstamp { - id: BlockId(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. + id: BlockNumber(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. hash: BlockHash(Hash::from_hex(block_hash).unwrap()), // Grammar ensures that we have an hexadecimal string. }); } diff --git a/lib/tools/network-documents/src/network_peer.rs b/lib/tools/network-documents/src/network_peer.rs index 91bacc53..e53d983a 100644 --- a/lib/tools/network-documents/src/network_peer.rs +++ b/lib/tools/network-documents/src/network_peer.rs @@ -20,7 +20,7 @@ use crate::*; use base58::ToBase58; use dubp_documents::ToStringObject; use dubp_documents::{blockstamp::Blockstamp, CurrencyName}; -use dubp_documents::{BlockHash, BlockId}; +use dubp_documents::{BlockHash, BlockNumber}; use dup_crypto::keys::text_signable::TextSignable; use dup_crypto::keys::*; use pest::iterators::Pair; @@ -162,7 +162,7 @@ impl TextDocumentParser<Rule> for PeerCardV11 { let block_id: &str = inner_rules.next().unwrap().as_str(); let block_hash: &str = inner_rules.next().unwrap().as_str(); blockstamp = Some(Blockstamp { - id: BlockId(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. + id: BlockNumber(block_id.parse().unwrap()), // Grammar ensures that we have a digits string. hash: BlockHash(Hash::from_hex(block_hash).unwrap()), // Grammar ensures that we have an hexadecimal string. }); } -- GitLab