Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
poplexity committed Aug 17, 2024
1 parent e0e3e4e commit 0120131
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 162 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -174,12 +173,8 @@ telos = [
]

telos = [
"dep:antelope-client",
"dep:reth-node-telos",
"dep:reth-telos-rpc",
# "reth-rpc/telos",
# "reth-network/telos",
# "reth-node-core/telos",
]

[[bin]]
Expand Down
1 change: 0 additions & 1 deletion bin/reth/src/telos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions crates/telos/node/src/args.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
152 changes: 1 addition & 151 deletions crates/telos/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultProvider>,
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<u8>,
pub estimate_gas: bool,
pub sender: Option<Checksum160>,
}

#[derive(Clone)]
pub struct GasPriceCache {
api_client: Box<APIClient<DefaultProvider>>,
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::<DefaultProvider>::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<u32>,
}

impl GasPriceCache {
pub fn new(api_client: Box<APIClient<DefaultProvider>>, 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::<TelosEVMConfig>(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<TransactionSigned>,
) -> Result<String, String> {
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())
}
pub use crate::node::TelosNode;
1 change: 0 additions & 1 deletion crates/telos/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion crates/telos/rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct TelosClientInner {
}

#[derive(StructPacker)]
pub struct RawActionData {
struct RawActionData {
pub ram_payer: Name,
pub tx: Vec<u8>,
pub estimate_gas: bool,
Expand Down

0 comments on commit 0120131

Please sign in to comment.