forked from nervosnetwork/ckb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nervosnetwork#4494 from eval-exec/exec/block_numbe…
…r_and_hash Move `BlockNumberAndHash` from`ckb-sync` to `ckb-types`
- Loading branch information
Showing
6 changed files
with
63 additions
and
51 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
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,54 @@ | ||
//! Block Number and Hash struct | ||
use crate::core::BlockNumber; | ||
use ckb_gen_types::packed::Byte32; | ||
|
||
/// Block Number And Hash struct | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct BlockNumberAndHash { | ||
/// Block Number | ||
pub number: BlockNumber, | ||
/// Block Hash | ||
pub hash: Byte32, | ||
} | ||
|
||
impl BlockNumberAndHash { | ||
/// Create new BlockNumberAndHash | ||
pub fn new(number: BlockNumber, hash: Byte32) -> Self { | ||
Self { number, hash } | ||
} | ||
/// Return BlockNumber | ||
pub fn number(&self) -> BlockNumber { | ||
self.number | ||
} | ||
/// Return Hash | ||
pub fn hash(&self) -> Byte32 { | ||
self.hash.clone() | ||
} | ||
} | ||
|
||
impl From<(BlockNumber, Byte32)> for BlockNumberAndHash { | ||
fn from(inner: (BlockNumber, Byte32)) -> Self { | ||
Self { | ||
number: inner.0, | ||
hash: inner.1, | ||
} | ||
} | ||
} | ||
|
||
impl From<&crate::core::HeaderView> for BlockNumberAndHash { | ||
fn from(header: &crate::core::HeaderView) -> Self { | ||
Self { | ||
number: header.number(), | ||
hash: header.hash(), | ||
} | ||
} | ||
} | ||
|
||
impl From<crate::core::HeaderView> for BlockNumberAndHash { | ||
fn from(header: crate::core::HeaderView) -> Self { | ||
Self { | ||
number: header.number(), | ||
hash: header.hash(), | ||
} | ||
} | ||
} |
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