-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [feature] add FindAllTransactions query Signed-off-by: Artemii Gerasimovich <gerasimovich@soramitsu.co.jp> * [feature] add FindAllBlocks query Signed-off-by: Artemii Gerasimovich <gerasimovich@soramitsu.co.jp> * split valid and rejected txns in BlockValue Signed-off-by: Artemii Gerasimovich <gerasimovich@soramitsu.co.jp> * fix suggestions Signed-off-by: Artemii Gerasimovich <gerasimovich@soramitsu.co.jp>
- Loading branch information
Showing
17 changed files
with
449 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! This module contains trait implementations related to block queries | ||
use eyre::Result; | ||
use iroha_data_model::block_value::BlockValue; | ||
use iroha_telemetry::metrics; | ||
|
||
use super::*; | ||
|
||
impl<W: WorldTrait> ValidQuery<W> for FindAllBlocks { | ||
#[metrics(+"find_all_blocks")] | ||
fn execute(&self, wsv: &WorldStateView<W>) -> Result<Self::Output, query::Error> { | ||
let mut blocks: Vec<BlockValue> = wsv | ||
.blocks() | ||
.map(|blk| blk.clone()) | ||
.map(VersionedCommittedBlock::into_value) | ||
.collect(); | ||
blocks.reverse(); | ||
Ok(blocks) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//! This module contains [`BlockValue`] and [`BlockHeaderValue`] structures, their implementation and related traits and | ||
//! instructions implementations. | ||
#[cfg(not(feature = "std"))] | ||
use alloc::{format, string::String, vec::Vec}; | ||
use core::cmp::Ordering; | ||
|
||
use iroha_crypto::{Hash, HashOf, MerkleTree}; | ||
use iroha_schema::IntoSchema; | ||
use parity_scale_codec::{Decode, Encode}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{ | ||
events::Event, | ||
transaction::{VersionedRejectedTransaction, VersionedTransaction, VersionedValidTransaction}, | ||
}; | ||
|
||
/// Block header | ||
#[derive(Debug, Clone, PartialEq, Eq, Decode, Encode, Deserialize, Serialize, IntoSchema)] | ||
pub struct BlockHeaderValue { | ||
/// Unix time (in milliseconds) of block forming by a peer. | ||
pub timestamp: u128, | ||
/// a number of blocks in the chain up to the block. | ||
pub height: u64, | ||
/// Hash of a previous block in the chain. | ||
/// Is an array of zeros for the first block. | ||
pub previous_block_hash: Hash, | ||
/// Hash of merkle tree root of the tree of valid transactions' hashes. | ||
pub transactions_hash: HashOf<MerkleTree<VersionedTransaction>>, | ||
/// Hash of merkle tree root of the tree of rejected transactions' hashes. | ||
pub rejected_transactions_hash: HashOf<MerkleTree<VersionedTransaction>>, | ||
/// Hashes of the blocks that were rejected by consensus. | ||
pub invalidated_blocks_hashes: Vec<Hash>, | ||
} | ||
|
||
impl PartialOrd for BlockHeaderValue { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(self.timestamp.cmp(&other.timestamp)) | ||
} | ||
} | ||
|
||
impl Ord for BlockHeaderValue { | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
self.timestamp.cmp(&other.timestamp) | ||
} | ||
} | ||
|
||
/// Representation of block on blockchain | ||
#[derive(Debug, Clone, PartialEq, Eq, Decode, Encode, Serialize, Deserialize, IntoSchema)] | ||
pub struct BlockValue { | ||
/// Header | ||
pub header: BlockHeaderValue, | ||
/// Array of transactions | ||
pub transactions: Vec<VersionedValidTransaction>, | ||
/// Array of rejected transactions. | ||
pub rejected_transactions: Vec<VersionedRejectedTransaction>, | ||
/// Event recommendations | ||
pub event_recommendations: Vec<Event>, | ||
} | ||
|
||
impl BlockValue { | ||
/// ... | ||
pub fn nested_len(&self) -> usize { | ||
self.event_recommendations.len() | ||
+ self.transactions.len() | ||
+ self.rejected_transactions.len() | ||
+ self.header.invalidated_blocks_hashes.len() | ||
} | ||
} | ||
|
||
impl PartialOrd for BlockValue { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(self.header.cmp(&other.header)) | ||
} | ||
} | ||
|
||
impl Ord for BlockValue { | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
self.header.cmp(&other.header) | ||
} | ||
} | ||
|
||
/// The prelude re-exports most commonly used traits, structs and macros from this crate. | ||
pub mod prelude { | ||
pub use super::{BlockHeaderValue, BlockValue}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.