From b2483bcc80e87361efb7348ab827ba7c239cb0e7 Mon Sep 17 00:00:00 2001 From: Jesse Schulman Date: Wed, 7 Aug 2024 16:55:05 -0700 Subject: [PATCH] Cleanup --- Cargo.lock | 1 - bin/reth/Cargo.toml | 5 -- bin/reth/src/telos.rs | 1 - crates/telos/node/src/args.rs | 2 - crates/telos/node/src/lib.rs | 152 +-------------------------------- crates/telos/node/src/node.rs | 1 - crates/telos/rpc/src/client.rs | 2 +- 7 files changed, 2 insertions(+), 162 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b138e69849e3..14995d2696a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6467,7 +6467,6 @@ name = "reth" version = "1.0.5" dependencies = [ "alloy-rlp", - "antelope-client", "aquamarine", "backon", "clap", diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 90ae56a47860..a9cac2ae2d33 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -113,7 +113,6 @@ discv5.workspace = true # telos reth-node-telos = { workspace = true, optional = true } reth-telos-rpc = { workspace = true, optional = true } -antelope-client = { workspace = true, optional = true } [target.'cfg(unix)'.dependencies] tikv-jemallocator = { version = "0.5.0", optional = true } @@ -154,12 +153,8 @@ optimism = [ ethereum = [] telos = [ - "dep:antelope-client", "dep:reth-node-telos", "dep:reth-telos-rpc", -# "reth-rpc/telos", -# "reth-network/telos", -# "reth-node-core/telos", ] [[bin]] diff --git a/bin/reth/src/telos.rs b/bin/reth/src/telos.rs index 6e8e89b0ee15..198d1c72b510 100644 --- a/bin/reth/src/telos.rs +++ b/bin/reth/src/telos.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use clap::Parser; -use reth::cli::Cli; use reth_node_telos::TelosArgs; use reth_node_telos::TelosNode; use reth_telos_rpc::TelosClient; diff --git a/crates/telos/node/src/args.rs b/crates/telos/node/src/args.rs index 514effae1d11..9835b44c918b 100644 --- a/crates/telos/node/src/args.rs +++ b/crates/telos/node/src/args.rs @@ -1,7 +1,5 @@ //! clap [Args](clap::Args) for telos configuration -use serde::{Deserialize, Serialize}; - #[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)] #[clap(next_help_heading = "Telos")] pub struct TelosArgs { diff --git a/crates/telos/node/src/lib.rs b/crates/telos/node/src/lib.rs index 00b08bc9ed0b..cd7613e16701 100644 --- a/crates/telos/node/src/lib.rs +++ b/crates/telos/node/src/lib.rs @@ -9,158 +9,8 @@ #![cfg(feature = "telos")] -use std::fmt::{Debug, Formatter}; -use antelope::api::client::{APIClient, DefaultProvider}; -use antelope::api::v1::structs::GetTableRowsParams; -use antelope::chain::action::{Action, PermissionLevel}; -use antelope::chain::checksum::{Checksum160, Checksum256}; -use antelope::chain::name::Name; -use antelope::chain::private_key::PrivateKey; -use antelope::chain::transaction::{SignedTransaction, Transaction}; -use antelope::serializer::{Decoder, Encoder, Packer}; -use antelope::{name, StructPacker}; -use reth_primitives::{TransactionSigned, U256}; -use std::time::{Duration, Instant}; - pub mod args; pub mod node; pub use crate::args::TelosArgs; -pub use crate::node::TelosNode; - - -/// Telos Network Config -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone, Default)] -pub struct TelosNetworkConfig { - pub api_client: APIClient, - pub signer_account: Name, - pub signer_permission: Name, - pub signer_key: PrivateKey, - pub gas_cache: GasPriceCache, -} - -#[derive(StructPacker)] -pub struct RawActionData { - pub ram_payer: Name, - pub tx: Vec, - pub estimate_gas: bool, - pub sender: Option, -} - -#[derive(Clone)] -pub struct GasPriceCache { - api_client: Box>, - gas_cache_duration: Duration, - value: Option<(U256, Instant)>, -} - -impl Debug for GasPriceCache { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "GasPriceCache duration: ") - } -} - -impl Default for GasPriceCache { - fn default() -> Self { - GasPriceCache { - api_client: Box::new(APIClient::::default_provider("https://example.com".into()).unwrap()), - gas_cache_duration: Duration::default(), - value: None - } - } -} - -#[derive(StructPacker, Default)] -struct TelosEVMConfig { - trx_index: u32, - last_block: u32, - gas_used_block: Checksum256, - gas_price: Checksum256, - revision: Option, -} - -impl GasPriceCache { - pub fn new(api_client: Box>, gas_cache_duration: Duration) -> Self { - GasPriceCache { api_client, gas_cache_duration, value: None } - } - - async fn load_value(&self) -> U256 { - let table_rows_params = GetTableRowsParams { - code: name!("eosio.evm"), - table: name!("config"), - scope: Some(name!("eosio.evm")), - lower_bound: None, - upper_bound: None, - limit: Some(1), - reverse: None, - index_position: None, - show_payer: None, - }; - let config_result = - self.api_client.v1_chain.get_table_rows::(table_rows_params).await.unwrap(); - - return U256::from_be_slice(&config_result.rows[0].gas_price.data); - } - - pub async fn get(&mut self) -> &U256 { - let now = Instant::now(); - if self.value.as_ref().map_or(true, |&(_, ref expiry)| *expiry <= now) { - let new_val = self.load_value(); // Call the hardcoded loader function - self.value = Some((new_val.await, now + self.gas_cache_duration)); - } - &self.value.as_ref().unwrap().0 - } -} - -pub async fn send_to_telos( - network_config: &TelosNetworkConfig, - trxs: &Vec, -) -> Result { - let get_info = network_config.api_client.v1_chain.get_info().await.unwrap(); - let trx_header = get_info.get_transaction_header(90); - let _trxs_results = trxs.iter().map(|trx| { - let trx_header = trx_header.clone(); - async move { - let mut trx_bytes = Vec::new(); - trx.encode_enveloped(&mut trx_bytes); - - let raw_action_data = RawActionData { - ram_payer: name!("eosio.evm"), - tx: trx_bytes, - estimate_gas: false, - sender: None, - }; - - let action = Action::new_ex( - name!("eosio.evm"), - name!("raw"), - vec![PermissionLevel::new( - network_config.signer_account, - network_config.signer_permission, - )], - raw_action_data, - ); - - let transaction = Transaction { - header: trx_header, - context_free_actions: vec![], - actions: vec![action], - extension: vec![], - }; - - let signed_telos_transaction = SignedTransaction { - transaction: transaction.clone(), - signatures: vec![network_config - .signer_key - .sign_message(&transaction.signing_data(&get_info.chain_id.data.to_vec()))], - context_free_data: vec![], - }; - - let result = network_config.api_client.v1_chain.send_transaction(signed_telos_transaction); - - result.await.unwrap().transaction_id - } - }); - Ok("Good".into()) -} \ No newline at end of file +pub use crate::node::TelosNode; \ No newline at end of file diff --git a/crates/telos/node/src/node.rs b/crates/telos/node/src/node.rs index a3b7a6cfe1c8..688cf1c5c219 100644 --- a/crates/telos/node/src/node.rs +++ b/crates/telos/node/src/node.rs @@ -3,7 +3,6 @@ use reth_evm_ethereum::EthEvmConfig; use reth_node_api::{FullNodeTypes, NodeTypes}; use reth_node_builder::components::ComponentsBuilder; use reth_node_builder::{Node, PayloadTypes}; -use reth_node_ethereum::EthereumNode; use reth_node_ethereum::node::{EthereumAddOns, EthereumConsensusBuilder, EthereumExecutorBuilder, EthereumNetworkBuilder, EthereumPayloadBuilder, EthereumPoolBuilder}; use crate::args::TelosArgs; diff --git a/crates/telos/rpc/src/client.rs b/crates/telos/rpc/src/client.rs index 522458b75041..fefbe70dbde5 100644 --- a/crates/telos/rpc/src/client.rs +++ b/crates/telos/rpc/src/client.rs @@ -25,7 +25,7 @@ struct TelosClientInner { } #[derive(StructPacker)] -pub struct RawActionData { +struct RawActionData { pub ram_payer: Name, pub tx: Vec, pub estimate_gas: bool,