-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.rs
More file actions
124 lines (109 loc) · 3.86 KB
/
main.rs
File metadata and controls
124 lines (109 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! rem = reth + malachite proof of concept
//!
//!
//! bootstrapping and scaffolding are partly inspired from `custom-dev-node` example from reth.
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
mod chain;
mod launcher;
mod mac;
use crate::launcher::MalachiteNodeLauncher;
use crate::mac::MalachiteConsensusBuilder;
use futures_util::StreamExt;
use reth::primitives::{b256, hex};
use reth::{
builder::{NodeBuilder, NodeHandle},
providers::CanonStateSubscriptions,
rpc::api::eth::helpers::EthTransactions,
tasks::TaskManager,
};
use reth_chainspec::ChainSpec;
use reth_node_core::args::DevArgs;
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
use reth_node_ethereum::node::EthereumAddOns;
use reth_node_ethereum::EthereumNode;
use reth_primitives::Genesis;
use std::sync::Arc;
#[tokio::main]
async fn main() -> eyre::Result<()> {
let tasks = TaskManager::current();
// create node config
let node_config = NodeConfig::test()
.dev()
.with_dev(DevArgs {
dev: true,
block_max_transactions: None,
block_time: Some(std::time::Duration::from_secs(1)),
})
.with_rpc(RpcServerArgs::default().with_http())
.with_chain(custom_chain());
println!("created the node config");
let NodeHandle {
node,
node_exit_future: _,
} = NodeBuilder::new(node_config)
.testing_node(tasks.executor())
.with_types::<EthereumNode>()
.with_components(EthereumNode::components().consensus(MalachiteConsensusBuilder::default()))
.with_add_ons::<EthereumAddOns>()
.launch_with_fn(|builder| {
let launcher = MalachiteNodeLauncher::new(tasks.executor(), builder.config().datadir());
builder.launch_with(launcher)
})
.await?;
let mut notifications = node.provider.canonical_state_stream();
// submit tx through rpc
let raw_tx = hex!("02f876820a28808477359400847735940082520894ab0840c0e43688012c1adb0f5e3fc665188f83d28a029d394a5d630544000080c080a0a044076b7e67b5deecc63f61a8d7913fab86ca365b344b5759d1fe3563b4c39ea019eab979dd000da04dfc72bb0377c092d30fd9e1cab5ae487de49586cc8b0090");
let eth_api = node.rpc_registry.eth_api();
let hash = eth_api.send_raw_transaction(raw_tx.into()).await?;
let expected = b256!("b1c6512f4fc202c04355fbda66755e0e344b152e633010e8fd75ecec09b63398");
assert_eq!(hash, expected);
println!("main: submitted transaction with hash {hash}");
loop {
let head = notifications.next().await.unwrap();
println!(
"main: block finalized & executed: height={:?}, tx count={}",
head.tip().number,
head.tip().block.body.len()
);
}
}
fn custom_chain() -> Arc<ChainSpec> {
let custom_genesis = r#"
{
"nonce": "0x42",
"timestamp": "0x0",
"extraData": "0x5343",
"gasLimit": "0xa388",
"difficulty": "0x400000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b": {
"balance": "0x4a47e3c12448f4ad000000"
}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"config": {
"ethash": {},
"chainId": 2600,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"terminalTotalDifficulty": 0,
"terminalTotalDifficultyPassed": true,
"shanghaiTime": 0
}
}
"#;
let genesis: Genesis = serde_json::from_str(custom_genesis).unwrap();
Arc::new(genesis.into())
}