Skip to content

Commit 1c09b63

Browse files
authored
Merge pull request #6 from gskapka/update-license-and-rust-version
feat(repo): update license and rust version
2 parents 6e1bc31 + 1c0f786 commit 1c09b63

34 files changed

Lines changed: 2911 additions & 4428 deletions

Cargo.lock

Lines changed: 683 additions & 683 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rusty-receipt-proof-maker"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Greg Kapka <greg@oraclize.it>"]
55
edition = "2018"
66

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Greg Kapka
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ A Maker of Merkle-Proofs for Transaction Receipts in Ethereum using Rust.
1212

1313
### :point_right: Usage:
1414

15-
__>__ To generate a proof for a given transaction hash:
15+
__>__ To generate a proof for a given transaction hash, first you'll need RPC access to an ETH node on the network your transaction exists on. Once you have that, set it as an environment variable and run the tool thusly::
1616

17-
__`❍ rusty-receipt-proof-maker <your-tx-hash-here>`__
17+
__`ENDPOINT=<ETH-mainnet-rpc-endpoint> rusty-receipt-proof-maker <your-tx-hash-here>`__
1818

1919

2020
```
2121
22-
rusty-receipt-proof-maker 0x5d761b001c4d69bf14c94b8e8a604d97e008a8a7dfb74a6459823b2178ffc033 -v`
22+
ENDPOINT=<redacted> rusty-receipt-proof-maker 0x5d761b001c4d69bf14c94b8e8a604d97e008a8a7dfb74a6459823b2178ffc033 -v`
2323
12:02:21 [ INFO] ✔ CLI Args parsed successfully!
2424
12:02:21 [ INFO] ✔ Verbose mode: true
2525
12:02:21 [ INFO] ✔ Transaction hash: 0x5d76…c033
@@ -39,7 +39,6 @@ rusty-receipt-proof-maker 0x5d761b001c4d69bf14c94b8e8a604d97e008a8a7dfb74a645982
3939
4040
f90264f8b1a0dc1a1b7bc9f38fc6710af9abdf1da874fa708573431381908b8b6a25bd1f2b55a0701833ef4ede796d9c96b1ae7c66830b0126f106ea0bfe99864e679e8b0dfeafa00db067f1c8ee75d8a563038903eb5129ee1d73beeea9380ca58d1920c15fe84ba0a55d0852ba77dbcc2824337150c123ccde62699b0c6eaddf735c1b2638bb85ba80808080a04937e058ea19511f92f803c23f4e9a4eceaaf2246c86da0f1b2241316be8a34d8080808080808080f901ae30b901aaf901a701837ab31ab9010000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000002000000080000000000000000200000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000020000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000004000000000000010200000000000000000000000000000000000000000000000000000000000f89df89b94c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2f863a08c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a0000000000000000000000000539efb706852838c51905d3d31966c296e034000a0000000000000000000000000a2881a90bf33f03e7a3f803765cd2ed5c8928dfba0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
4141
42-
4342
```
4443

4544
By default, the tool's full tracing logs for each run are output to a file in __`./logs/<utc-timestamp>.log`__
@@ -76,33 +75,6 @@ Options:
7675
<txhash> ❍ A transaction hash of an Ethereum transaction
7776
➔ Format: A 32-byte long, prefixed hex string.
7877
79-
❍ Rusty Receipt Proof Maker ❍
80-
81-
Copyright Provable 2019
82-
Questions: greg@oraclize.it
83-
84-
❍ Info ❍
85-
86-
This tool generates a merkle receipt proof of the receipt pertaining to the given transaction hash.
87-
88-
***
89-
90-
Usage: rusty-receipt-proof-maker [-h | --help]
91-
rusty-receipt-proof-maker <txhash> [-t | --trace]
92-
rusty-receipt-proof-maker <txhash> [-v | --verbose]
93-
94-
Options:
95-
96-
-h, --help ❍ Show this message.
97-
98-
-v, --verbose ❍ Enable verbose mode for additional output.
99-
100-
-t, --trace ❍ Enable tracing for debugging/bug reporting.
101-
102-
<txhash> ❍ A transaction hash of an Ethereum transaction
103-
➔ Format: A 32-byte long, prefixed hex string.
104-
105-
10678
```
10779

10880
&nbsp;
@@ -151,7 +123,7 @@ rusty-receipt-proof-maker -v 0x5d761b001c4d69bf14c94b8e8a604d97e008a8a7dfb74a645
151123

152124
To run the tests:
153125

154-
__`❍ cargo +nightly test`__
126+
__`❍ cargo test`__
155127

156128
__Note:__ Some expensive tests are ignored by default. To run all test, including those ignored, add the __`--ignored`__ flag.
157129

src/connect_to_node.rs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
1+
use crate::get_block::get_block_by_number;
12
use crate::state::State;
23
use crate::types::Result;
3-
use crate::get_block::get_block_by_number;
44

55
pub fn connect_to_node(state: State) -> Result<State> {
66
info!("✔ Connecting to node...");
7-
get_block_by_number(State::get_endpoint_from_state(&state)?, "latest")
8-
.and_then(|block| {
9-
info!(
10-
"✔ Connection successful! Latest block number: {:?}",
11-
block.number
12-
);
13-
Ok(state)
14-
})
7+
get_block_by_number(State::get_endpoint_from_state(&state)?, "latest").map(|block| {
8+
info!(
9+
"✔ Connection successful! Latest block number: {:?}",
10+
block.number
11+
);
12+
state
13+
})
1514
}
1615

1716
#[cfg(test)]
1817
mod tests {
1918
use super::*;
20-
use crate::test_utils::{
21-
WORKING_ENDPOINT,
22-
get_valid_tx_hash_h256,
23-
get_valid_initial_state,
24-
};
19+
use crate::test_utils::{get_valid_initial_state, get_valid_tx_hash_h256, WORKING_ENDPOINT};
2520

2621
#[test]
2722
fn should_connect_to_node_and_return_state_when_endpoint_works() {
2823
let state = State::set_endpoint_in_state(
2924
get_valid_initial_state().unwrap(),
30-
WORKING_ENDPOINT.to_string()
31-
).unwrap();
32-
let expected_tx_hash = get_valid_tx_hash_h256()
33-
.unwrap();
25+
WORKING_ENDPOINT.to_string(),
26+
)
27+
.unwrap();
28+
let expected_tx_hash = get_valid_tx_hash_h256().unwrap();
3429
match connect_to_node(state) {
35-
Ok(returned_state) =>
36-
assert!(returned_state.tx_hash == expected_tx_hash),
37-
Err(e) => panic!("Error connecting to node: {}", e)
30+
Ok(returned_state) => assert!(returned_state.tx_hash == expected_tx_hash),
31+
Err(e) => panic!("Error connecting to node: {}", e),
3832
}
3933
}
4034

4135
#[test]
4236
fn should_fail_to_connect_to_node_to_non_working_endpoint() {
4337
let non_working_endpoint = "non-working-endpoint".to_string();
44-
let state = State::set_endpoint_in_state(
45-
get_valid_initial_state().unwrap(),
46-
non_working_endpoint
47-
).unwrap();
38+
let state =
39+
State::set_endpoint_in_state(get_valid_initial_state().unwrap(), non_working_endpoint)
40+
.unwrap();
4841
match connect_to_node(state) {
4942
Ok(_) => panic!("Should not connect to non-working endpoint!"),
50-
Err(_) => assert!(true)
43+
Err(_) => assert!(true),
5144
}
5245
}
5346
}

src/constants.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
use crate::nibble_utils::Nibbles;
12
use crate::types::Byte;
23
use ethereum_types::H256;
3-
use crate::nibble_utils::Nibbles;
44

55
pub const ZERO_BYTE: u8 = 0u8;
6-
pub const HASH_LENGTH: usize = 32;
7-
pub const HASH_HEX_CHARS: usize = 64;
6+
pub const HASH_LENGTH: usize = 32;
7+
pub const HASH_HEX_CHARS: usize = 64;
88
pub const HEX_PREFIX_LENGTH: usize = 2;
99
pub const NUM_BITS_IN_NIBBLE: usize = 4;
1010
pub const REQWEST_TIMEOUT_TIME: u64 = 5;
1111
pub const NUM_NIBBLES_IN_BYTE: usize = 2;
1212
pub const HIGH_NIBBLE_MASK: Byte = 15u8; // NOTE: 15u8 == [0,0,0,0,1,1,1,1]
13-
pub static DOT_ENV_PATH: &'static str = "./.env";
14-
pub static LOG_FILE_PATH: &'static str = "logs/";
15-
pub static LEAF_NODE_STRING: &'static str = "leaf";
16-
pub static BRANCH_NODE_STRING: &'static str = "branch";
17-
pub static EXTENSION_NODE_STRING: &'static str = "extension";
13+
pub static DOT_ENV_PATH: &str = "./.env";
14+
pub static LEAF_NODE_STRING: &str = "leaf";
15+
pub static BRANCH_NODE_STRING: &str = "branch";
16+
pub static EXTENSION_NODE_STRING: &str = "extension";
1817
pub const HASHED_NULL_NODE: H256 = H256(HASHED_NULL_NODE_BYTES);
19-
pub static DEFAULT_ENDPOINT: &'static str = "http://localhost:8545/";
20-
pub const EMPTY_NIBBLES: Nibbles = Nibbles { data: Vec::new(), offset: 0 };
18+
pub static DEFAULT_ENDPOINT: &str = "http://localhost:8545/";
19+
pub const EMPTY_NIBBLES: Nibbles = Nibbles {
20+
data: Vec::new(),
21+
offset: 0,
22+
};
2123

22-
const HASHED_NULL_NODE_BYTES: [u8; 32] = [ // NOTE: keccak hash of the RLP of null
23-
0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6,
24-
0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e,
25-
0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0,
26-
0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21
24+
const HASHED_NULL_NODE_BYTES: [u8; 32] = [
25+
// NOTE: keccak hash of the RLP of null
26+
0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e,
27+
0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21,
2728
];

src/errors.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
1-
use hex;
2-
use log;
3-
use reqwest;
4-
use std::fmt;
5-
use serde_json;
6-
use std::error::Error;
1+
use std::{error::Error, fmt};
72

83
#[derive(Debug)]
94
pub enum AppError {
105
Custom(String),
6+
NoneError(String),
117
IOError(std::io::Error),
128
HexError(hex::FromHexError),
139
ReqwestError(reqwest::Error),
1410
SerdeJsonError(serde_json::Error),
15-
NoneError(std::option::NoneError),
1611
SetLoggerError(log::SetLoggerError),
12+
TermLogError(simplelog::TermLogError),
1713
}
1814

1915
impl fmt::Display for AppError {
2016
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2117
let msg = match *self {
22-
AppError::Custom(ref msg) =>
23-
format!("{}", msg),
24-
AppError::HexError(ref e) =>
25-
format!("✘ Hex Error!\n✘ {}", e),
26-
AppError::IOError(ref e) =>
27-
format!("✘ I/O Error!\n✘ {}", e),
28-
AppError::SerdeJsonError(ref e) =>
29-
format!("✘ Serde-Json Error!\n✘ {}", e),
30-
AppError::NoneError(ref e) =>
31-
format!("✘ Nothing to unwrap!\n✘ {:?}", e),
32-
AppError::SetLoggerError(ref e) =>
33-
format!("✘ Error setting up logger!\n✘ {}", e),
34-
AppError::ReqwestError(ref e) =>
35-
format!(
36-
"\n✘ HTTP Reqwest Error!\n✘ {}\n{}",
37-
e,
38-
"✘ Please check your node & port settings and retry.\n"
39-
),
18+
AppError::Custom(ref msg) => msg.to_string(),
19+
AppError::HexError(ref e) => format!("✘ Hex Error!\n✘ {}", e),
20+
AppError::IOError(ref e) => format!("✘ I/O Error!\n✘ {}", e),
21+
AppError::NoneError(ref e) => format!("✘ Nothing to unwrap!\n✘ {:?}", e),
22+
AppError::SerdeJsonError(ref e) => format!("✘ Serde-Json Error!\n✘ {}", e),
23+
AppError::TermLogError(ref e) => format!("✘ Terminal logger error: {}", e),
24+
AppError::SetLoggerError(ref e) => format!("✘ Error setting up logger!\n✘ {}", e),
25+
AppError::ReqwestError(ref e) => format!(
26+
"\n✘ HTTP Reqwest Error!\n✘ {}\n{}",
27+
e, "✘ Please check your node & port settings and retry.\n"
28+
),
4029
};
4130
f.write_fmt(format_args!("{}", msg))
4231
}
@@ -60,12 +49,6 @@ impl From<std::io::Error> for AppError {
6049
}
6150
}
6251

63-
impl From<std::option::NoneError> for AppError {
64-
fn from(e: std::option::NoneError) -> AppError {
65-
AppError::NoneError(e)
66-
}
67-
}
68-
6952
impl From<reqwest::Error> for AppError {
7053
fn from(e: reqwest::Error) -> AppError {
7154
AppError::ReqwestError(e)
@@ -83,3 +66,9 @@ impl From<log::SetLoggerError> for AppError {
8366
AppError::SetLoggerError(e)
8467
}
8568
}
69+
70+
impl From<simplelog::TermLogError> for AppError {
71+
fn from(e: simplelog::TermLogError) -> AppError {
72+
AppError::TermLogError(e)
73+
}
74+
}

0 commit comments

Comments
 (0)