Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
reorder_imports = true
imports_granularity = "Crate"
use_small_heuristics = "Max"
comment_width = 100
wrap_comments = true
binop_separator = "Back"
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
format_code_in_doc_comments = true
doc_comment_code_block_width = 100
11 changes: 5 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use reth::builder::NodeHandle;
use reth_bsc::{
chainspec::parser::BscChainSpecParser,
consensus::ParliaConsensus,
node::network::block_import::service::ImportService as BlockImportService,
node::{cli::Cli, BscNode},
node::{
cli::Cli, network::block_import::service::ImportService as BlockImportService, BscNode,
},
};
use std::sync::Arc;
use tracing::error;
Expand All @@ -28,10 +29,8 @@ fn main() -> eyre::Result<()> {
}

Cli::<BscChainSpecParser, NoArgs>::parse().run(|builder, _| async move {
let NodeHandle {
node,
node_exit_future: exit_future,
} = builder.node(BscNode::default()).launch().await?;
let NodeHandle { node, node_exit_future: exit_future } =
builder.node(BscNode::default()).launch().await?;
let provider = node.provider.clone();
let consensus = Arc::new(ParliaConsensus { provider });
let (service, _) = BlockImportService::new(consensus, node.beacon_engine_handle.clone());
Expand Down
80 changes: 16 additions & 64 deletions src/system_contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,13 @@ impl<Spec: EthChainSpec> SystemContract<Spec> {
pub(crate) fn new(chain_spec: Spec) -> Self {
let validator_abi = serde_json::from_str(*VALIDATOR_SET_ABI).unwrap();
let stake_hub_abi = serde_json::from_str(*STAKE_HUB_ABI).unwrap();
Self {
validator_abi,
stake_hub_abi,
chain_spec,
}
Self { validator_abi, stake_hub_abi, chain_spec }
}

/// Creates a deposit tx to pay block reward to a validator.
pub fn pay_validator_tx(&self, address: Address, block_reward: u128) -> TransactionSigned {
let function = self
.validator_abi
.function("deposit")
.unwrap()
.first()
.unwrap();
let input = function
.abi_encode_input(&[DynSolValue::Address(address)])
.unwrap();
let function = self.validator_abi.function("deposit").unwrap().first().unwrap();
let input = function.abi_encode_input(&[DynSolValue::Address(address)]).unwrap();

let signature = Signature::new(Default::default(), Default::default(), false);

Expand Down Expand Up @@ -87,12 +76,7 @@ impl<Spec: EthChainSpec> SystemContract<Spec> {
}

pub(crate) fn genesis_contracts_txs(&self) -> Vec<TransactionSigned> {
let function = self
.validator_abi
.function("init")
.unwrap()
.first()
.unwrap();
let function = self.validator_abi.function("init").unwrap().first().unwrap();
let input = function.abi_encode_input(&[]).unwrap();

let contracts = vec![
Expand Down Expand Up @@ -127,12 +111,7 @@ impl<Spec: EthChainSpec> SystemContract<Spec> {

pub(crate) fn feynman_contracts_txs(&self) -> Vec<TransactionSigned> {
println!("feynman_contracts_txs");
let function = self
.stake_hub_abi
.function("initialize")
.unwrap()
.first()
.unwrap();
let function = self.stake_hub_abi.function("initialize").unwrap().first().unwrap();
let input = function.abi_encode_input(&[]).unwrap();

let signature = Signature::new(Default::default(), Default::default(), false);
Expand Down Expand Up @@ -226,10 +205,7 @@ impl SystemContractName {

fn get_all_system_contracts() -> Vec<SystemContractName> {
let res = vec![
SystemContractName::new(
"ValidatorContract".to_string(),
VALIDATOR_CONTRACT.to_string(),
),
SystemContractName::new("ValidatorContract".to_string(), VALIDATOR_CONTRACT.to_string()),
SystemContractName::new("SlashContract".to_string(), SLASH_CONTRACT.to_string()),
SystemContractName::new(
"SystemRewardContract".to_string(),
Expand All @@ -239,52 +215,28 @@ fn get_all_system_contracts() -> Vec<SystemContractName> {
"LightClientContract".to_string(),
LIGHT_CLIENT_CONTRACT.to_string(),
),
SystemContractName::new(
"TokenHubContract".to_string(),
TOKEN_HUB_CONTRACT.to_string(),
),
SystemContractName::new("TokenHubContract".to_string(), TOKEN_HUB_CONTRACT.to_string()),
SystemContractName::new(
"RelayerIncentivizeContract".to_string(),
RELAYER_INCENTIVIZE_CONTRACT.to_string(),
),
SystemContractName::new(
"RelayerHubContract".to_string(),
RELAYER_HUB_CONTRACT.to_string(),
),
SystemContractName::new("RelayerHubContract".to_string(), RELAYER_HUB_CONTRACT.to_string()),
SystemContractName::new("GovHubContract".to_string(), GOV_HUB_CONTRACT.to_string()),
SystemContractName::new(
"TokenHubContract".to_string(),
TOKEN_HUB_CONTRACT.to_string(),
),
SystemContractName::new("TokenHubContract".to_string(), TOKEN_HUB_CONTRACT.to_string()),
SystemContractName::new(
"TokenManagerContract".to_string(),
TOKEN_MANAGER_CONTRACT.to_string(),
),
SystemContractName::new(
"CrossChainContract".to_string(),
CROSS_CHAIN_CONTRACT.to_string(),
),
SystemContractName::new("CrossChainContract".to_string(), CROSS_CHAIN_CONTRACT.to_string()),
SystemContractName::new("StakingContract".to_string(), STAKING_CONTRACT.to_string()),
SystemContractName::new(
"StakeHubContract".to_string(),
STAKE_HUB_CONTRACT.to_string(),
),
SystemContractName::new("StakeHubContract".to_string(), STAKE_HUB_CONTRACT.to_string()),
SystemContractName::new(
"StakeCreditContract".to_string(),
STAKE_CREDIT_CONTRACT.to_string(),
),
SystemContractName::new(
"GovTokenContract".to_string(),
GOV_TOKEN_CONTRACT.to_string(),
),
SystemContractName::new(
"GovernorContract".to_string(),
GOVERNOR_CONTRACT.to_string(),
),
SystemContractName::new(
"TimelockContract".to_string(),
TIMELOCK_CONTRACT.to_string(),
),
SystemContractName::new("GovTokenContract".to_string(), GOV_TOKEN_CONTRACT.to_string()),
SystemContractName::new("GovernorContract".to_string(), GOVERNOR_CONTRACT.to_string()),
SystemContractName::new("TimelockContract".to_string(), TIMELOCK_CONTRACT.to_string()),
SystemContractName::new(
"TokenRecoverPortalContract".to_string(),
TOKEN_RECOVER_PORTAL_CONTRACT.to_string(),
Expand Down Expand Up @@ -429,8 +381,8 @@ where
{
let mut m = HashMap::new();
for (fork, condition) in spec.forks_iter() {
if condition.transitions_at_block(block_number)
|| condition.transitions_at_timestamp(block_time, parent_block_time)
if condition.transitions_at_block(block_number) ||
condition.transitions_at_timestamp(block_time, parent_block_time)
{
if let Ok(contracts) = get_system_contract_codes(spec, fork.name()) {
for (k, v) in &contracts {
Expand Down