Skip to content

Commit

Permalink
make platform can be compiled
Browse files Browse the repository at this point in the history
  • Loading branch information
tommady committed Jul 24, 2024
1 parent 391583b commit 58f9655
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
8 changes: 3 additions & 5 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use {
chrono::Local,
config::abci::global_cfg::CFG,
enterprise_web3::{
Setter, ALLOWANCES, BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, RECEIPTS,
REDIS_CLIENT, STATE_UPDATE_LIST, TOTAL_ISSUANCE, TXS, WEB3_SERVICE_START_HEIGHT,
ALLOWANCES, BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, RECEIPTS,
PG_CLIENT, STATE_UPDATE_LIST, TOTAL_ISSUANCE, TXS, WEB3_SERVICE_START_HEIGHT,
},
fp_storage::hash::{Sha256, StorageHasher},
fp_storage::BorrowMut,
Expand Down Expand Up @@ -660,9 +660,7 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm

if CFG.enable_enterprise_web3 && td_height as u64 > *WEB3_SERVICE_START_HEIGHT {
let height = td_height as u32;
let redis_pool = REDIS_CLIENT.lock().expect("REDIS_CLIENT error");
let mut conn = redis_pool.get().expect("get redis connect");
let mut setter = Setter::new(&mut *conn, "evm".to_string());
let setter = PG_CLIENT.lock().expect("PG_CLIENT error");

let nonce_map = if let Ok(mut nonce_map) = NONCE_MAP.lock() {
take(&mut *nonce_map)
Expand Down
21 changes: 5 additions & 16 deletions src/components/contracts/baseapp/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::extensions::SignedExtra;
use abci::*;
use config::abci::global_cfg::CFG;
use enterprise_web3::{
Setter, PENDING_CODE_MAP, PENDING_STATE_UPDATE_LIST, REDIS_CLIENT,
REMOVE_PENDING_CODE_MAP, REMOVE_PENDING_STATE_UPDATE_LIST,
PENDING_CODE_MAP, PENDING_STATE_UPDATE_LIST, PG_CLIENT, REMOVE_PENDING_CODE_MAP,
REMOVE_PENDING_STATE_UPDATE_LIST,
};
use fp_core::context::RunTxMode;
use fp_evm::BlockId;
Expand Down Expand Up @@ -110,13 +110,8 @@ impl crate::BaseApp {
fp_types::actions::ethereum::Action::Transact(tx),
) = tx.function
{
let redis_pool =
REDIS_CLIENT.lock().expect("REDIS_CLIENT error");
let mut conn =
redis_pool.get().expect("get redis connect");
let mut setter =
Setter::new(&mut *conn, "evm".to_string());

let setter =
PG_CLIENT.lock().expect("PG_CLIENT error");
setter
.set_pending_tx(tx)
.map_err(|e| error!("{e:?}"))
Expand Down Expand Up @@ -239,13 +234,7 @@ impl crate::BaseApp {
fp_types::actions::ethereum::Action::Transact(tx),
) = tx.function
{
let redis_pool =
REDIS_CLIENT.lock().expect("REDIS_CLIENT error");
let mut conn =
redis_pool.get().expect("get redis connect");
let mut setter =
Setter::new(&mut *conn, "evm".to_string());

let setter = PG_CLIENT.lock().expect("PG_CLIENT error");
setter
.remove_pending_tx(tx)
.map_err(|e| error!("{:?}", e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
lazy_static = "1.4.0"
evm-exporter = { package = "evm-exporter", git = "https://github.com/FindoraNetwork/enterprise-web3.git", branch = "main"}
evm-exporter = { package = "evm-exporter", git = "https://github.com/FindoraNetwork/enterprise-web3.git", branch = "main", features = ["postgres"]}
ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] }
primitive-types = "0.11.1"
ruc = "1.0"
18 changes: 10 additions & 8 deletions src/components/contracts/primitives/enterprise-web3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use evm_exporter::{
Block as EnterpriseBlock, Getter, PgGetter, PgSetter, Receipt as EnterpriseReceipt,
Setter, State as EnterpriseState, TransactionStatus as EnterpriseTxState,
Block as EnterpriseBlock, ConnectionType, Getter, PgGetter, PgSetter,
Receipt as EnterpriseReceipt, Setter as EnterpriseSetter, State as EnterpriseState,
TransactionStatus as EnterpriseTxState,
};
use lazy_static::lazy_static;
use primitive_types::{H160, H256, U256};
use ruc::*;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};

pub type State = EnterpriseState;
pub type Block = EnterpriseBlock;
pub type Receipt = EnterpriseReceipt;
pub type TxState = EnterpriseTxState;
pub type Setter = dyn EnterpriseSetter;

pub struct AllowancesKey {
pub owner_address: H160,
Expand All @@ -30,8 +31,8 @@ lazy_static! {
pub static ref BLOCK: Arc<Mutex<Option<Block>>> = Arc::new(Mutex::new(None));
pub static ref RECEIPTS: Arc<Mutex<Vec<Receipt>>> = Arc::new(Mutex::new(vec![]));
pub static ref TXS: Arc<Mutex<Vec<TxState>>> = Arc::new(Mutex::new(vec![]));
pub static ref REDIS_CLIENT: Arc<Mutex<dyn Setter>> =
Arc::new(Mutex::new(gen_redis_client()));
pub static ref PG_CLIENT: Arc<Mutex<Box<dyn EnterpriseSetter + Send + Sync>>> =
Arc::new(Mutex::new(gen_postgres_client()));
pub static ref WEB3_SERVICE_START_HEIGHT: u64 = load_start_height();
pub static ref PENDING_CODE_MAP: Arc<Mutex<HashMap<H160, Vec<u8>>>> =
Arc::new(Mutex::new(HashMap::new()));
Expand All @@ -46,14 +47,15 @@ lazy_static! {
Arc::new(Mutex::new(Vec::new()));
}

fn gen_redis_client() -> dyn Setter {
fn gen_postgres_client() -> Box<dyn EnterpriseSetter + Send + Sync> {
let uri = std::env::var("POSTGRES_URI").expect("loading env POSTGRES_URI failed");
PgSetter::new(ConnectionType::Postgres(uri), String::new())
Box::new(PgSetter::new(ConnectionType::Postgres(uri), String::new()))
}

fn load_start_height() -> u64 {
let uri = std::env::var("POSTGRES_URI").expect("loading env POSTGRES_URI failed");
let getter: dyn Getter = PgGetter::new(ConnectionType::Postgres(uri), String::new());
let getter: Box<dyn Getter> =
Box::new(PgGetter::new(ConnectionType::Postgres(uri), String::new()));
let last_height = getter.latest_height().expect("redis latest_height error");
last_height as u64
}

0 comments on commit 58f9655

Please sign in to comment.