-
Notifications
You must be signed in to change notification settings - Fork 49
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 #113 from hammeWang/develop
complete ethereum-chainrelay ingredient
- Loading branch information
Showing
13 changed files
with
1,526 additions
and
453 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,10 @@ | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct Header(Vec<u8>); | ||
impl Header { | ||
/// Create a new owning header view. | ||
/// Expects the data to be an RLP-encoded header -- any other case will likely lead to | ||
/// panics further down the line. | ||
pub fn new(encoded: Vec<u8>) -> Self { | ||
Header(encoded) | ||
} | ||
} |
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,38 @@ | ||
/// Define errors when verifying eth blocks | ||
use super::*; | ||
#[cfg(feature = "std")] | ||
use std::error::Error; | ||
#[derive(PartialEq, Eq, Clone, Copy, Debug)] | ||
/// Error indicating value found is outside of a valid range. | ||
pub struct OutOfBounds<T> { | ||
/// Minimum allowed value. | ||
pub min: Option<T>, | ||
/// Maximum allowed value. | ||
pub max: Option<T>, | ||
/// Value found. | ||
pub found: T, | ||
} | ||
|
||
#[derive(PartialEq, Eq, Clone, Copy, Debug)] | ||
/// Error indicating an expected value was not found. | ||
pub struct Mismatch<T> { | ||
/// Value expected. | ||
pub expected: T, | ||
/// Value found. | ||
pub found: T, | ||
} | ||
|
||
#[derive(PartialEq, Eq, Clone, Copy, Debug)] | ||
pub enum BlockError { | ||
InvalidProofOfWork(OutOfBounds<U256>), | ||
DifficultyOutOfBounds(OutOfBounds<U256>), | ||
InvalidSealArity(Mismatch<usize>), | ||
Rlp(&'static str), | ||
} | ||
|
||
//#[cfg(feature = "std")] | ||
//impl Error for BlockError { | ||
// fn description(&self) -> &str { | ||
// "Block error" | ||
// } | ||
//} |
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,56 @@ | ||
// Copyright 2015-2019 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity Ethereum. | ||
|
||
// Parity Ethereum is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity Ethereum 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 General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
extern crate keccak_hash as hash; | ||
|
||
pub type H256 = [u8; 32]; | ||
|
||
pub mod keccak_512 { | ||
use super::hash; | ||
|
||
pub use self::hash::keccak_512_unchecked as unchecked; | ||
|
||
pub fn write(input: &[u8], output: &mut [u8]) { | ||
hash::keccak_512(input, output); | ||
} | ||
|
||
pub fn inplace(input: &mut [u8]) { | ||
// This is safe since `keccak_*` uses an internal buffer and copies the result to the output. This | ||
// means that we can reuse the input buffer for both input and output. | ||
unsafe { | ||
hash::keccak_512_unchecked(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len()); | ||
} | ||
} | ||
} | ||
|
||
pub mod keccak_256 { | ||
use super::hash; | ||
|
||
pub use self::hash::keccak_256_unchecked as unchecked; | ||
|
||
#[allow(dead_code)] | ||
pub fn write(input: &[u8], output: &mut [u8]) { | ||
hash::keccak_256(input, output); | ||
} | ||
|
||
pub fn inplace(input: &mut [u8]) { | ||
// This is safe since `keccak_*` uses an internal buffer and copies the result to the output. This | ||
// means that we can reuse the input buffer for both input and output. | ||
unsafe { | ||
hash::keccak_256_unchecked(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len()); | ||
} | ||
} | ||
} |
Oops, something went wrong.