-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedicated enveloped transaction/receipt encoding and decoding (#44)
- Loading branch information
Showing
7 changed files
with
270 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
# ethereum-rs | ||
|
||
Apache-2 licensed common Ethereum structs shared by crates. Nightly version of etcommon-rs. | ||
|
||
## List of Crates | ||
|
||
Below are all crates provided by the ethereum-rs project. | ||
|
||
| Name | Description | Crates.io | Documentation | | ||
| ---- | ----------- | --------- | ------------- | | ||
| ethereum-rlp | Recursive-length prefix encoding, decoding, and compression | [crates.io](https://crates.io/crates/ethereum-rlp) | [Documentation](https://docs.rs/ethereum-rlp) | | ||
| ethereum-bigint | Big integer and hash implementation | [crates.io](https://crates.io/crates/ethereum-bigint) | [Documentation](https://docs.rs/ethereum-bigint) | | ||
| ethereum-hexutil | Small hex decoding helpers | [crates.io](https://crates.io/crates/ethereum-hexutil) | [Documentation](https://docs.rs/ethereum-hexutil) | | ||
| ethereum-bloom | Log bloom for Ethereum | [crates.io](https://crates.io/crates/ethereum-bloom) | [Documentation](https://docs.rs/ethereum-bloom) | | ||
| ethereum-trie | Merkle Trie specialized for Ethereum | [crates.io](https://crates.io/crates/ethereum-trie) | [Documentation](https://docs.rs/ethereum-trie) | | ||
| ethereum-block | Block, transaction and account structs for Ethereum | [crates.io](https://crates.io/crates/ethereum-block) | [Documentation](https://docs.rs/ethereum-block) | | ||
| ethereum-block-core | Core block, transaction and account structs for Ethereum | [crates.io](https://crates.io/crates/ethereum-block-core) | [Documentation](https://docs.rs/ethereum-block-core) | | ||
Apache-2 licensed common Ethereum structs shared by crates. |
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,46 @@ | ||
use bytes::BytesMut; | ||
|
||
/// DecoderError for typed transactions. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub enum EnvelopedDecoderError<T> { | ||
UnknownTypeId, | ||
Payload(T), | ||
} | ||
|
||
impl<T> From<T> for EnvelopedDecoderError<T> { | ||
fn from(e: T) -> Self { | ||
Self::Payload(e) | ||
} | ||
} | ||
|
||
/// Encodable typed transactions. | ||
pub trait EnvelopedEncodable { | ||
/// Convert self to an owned vector. | ||
fn encode(&self) -> BytesMut { | ||
let type_id = self.type_id(); | ||
|
||
let mut out = BytesMut::new(); | ||
if let Some(type_id) = type_id { | ||
assert!(type_id <= 0x7f); | ||
out.extend_from_slice(&[type_id]); | ||
} | ||
|
||
out.extend_from_slice(&self.encode_payload()[..]); | ||
out | ||
} | ||
|
||
/// Type Id of the transaction. | ||
fn type_id(&self) -> Option<u8>; | ||
|
||
/// Encode inner payload. | ||
fn encode_payload(&self) -> BytesMut; | ||
} | ||
|
||
/// Decodable typed transactions. | ||
pub trait EnvelopedDecodable: Sized { | ||
/// Inner payload decoder error. | ||
type PayloadDecoderError; | ||
|
||
/// Decode raw bytes to a Self type. | ||
fn decode(bytes: &[u8]) -> Result<Self, EnvelopedDecoderError<Self::PayloadDecoderError>>; | ||
} |
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
Oops, something went wrong.