Skip to content
Merged
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
17 changes: 15 additions & 2 deletions evm_loader/Cargo.lock

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

26 changes: 0 additions & 26 deletions evm_loader/api/src/api_context.rs

This file was deleted.

19 changes: 6 additions & 13 deletions evm_loader/api/src/api_server/handlers/emulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use actix_web::{http::StatusCode, post, web::Json, Responder};
use std::convert::Into;

use crate::api_server::handlers::process_error;
use crate::{
api_context, commands::emulate as EmulateCommand, types::EmulateApiRequest, NeonApiState,
};
use crate::{commands::emulate as EmulateCommand, types::EmulateApiRequest, NeonApiState};

use super::process_result;

Expand All @@ -19,19 +17,14 @@ pub async fn emulate(
let slot = emulate_request.slot;
let index = emulate_request.tx_index_in_block;

let rpc_client = match api_context::build_rpc_client(&state, slot, index).await {
Ok(rpc_client) => rpc_client,
let rpc = match state.build_rpc(slot, index).await {
Ok(rpc) => rpc,
Err(e) => return process_error(StatusCode::BAD_REQUEST, &e),
};

process_result(
&EmulateCommand::execute(
rpc_client.as_ref(),
state.config.evm_loader,
emulate_request.body,
None,
)
.await
.map_err(Into::into),
&EmulateCommand::execute(&rpc, state.config.evm_loader, emulate_request.body, None)
.await
.map_err(Into::into),
)
}
16 changes: 6 additions & 10 deletions evm_loader/api/src/api_server/handlers/get_balance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::api_server::handlers::process_error;
use crate::commands::get_balance as GetBalanceCommand;
use crate::{api_context, types::GetBalanceRequest, NeonApiState};
use crate::{types::GetBalanceRequest, NeonApiState};
use actix_request_identifier::RequestId;
use actix_web::web::Json;
use actix_web::{http::StatusCode, post, Responder};
Expand All @@ -15,18 +15,14 @@ pub async fn get_balance(
request_id: RequestId,
Json(req_params): Json<GetBalanceRequest>,
) -> impl Responder {
let rpc_client = match api_context::build_rpc_client(&state, req_params.slot, None).await {
Ok(rpc_client) => rpc_client,
let rpc = match state.build_rpc(req_params.slot, None).await {
Ok(rpc) => rpc,
Err(e) => return process_error(StatusCode::BAD_REQUEST, &e),
};

process_result(
&GetBalanceCommand::execute(
rpc_client.as_ref(),
&state.config.evm_loader,
&req_params.account,
)
.await
.map_err(Into::into),
&GetBalanceCommand::execute(&rpc, &state.config.evm_loader, &req_params.account)
.await
.map_err(Into::into),
)
}
8 changes: 4 additions & 4 deletions evm_loader/api/src/api_server/handlers/get_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::api_server::handlers::process_error;
use crate::{api_context, NeonApiState};
use crate::NeonApiState;
use actix_request_identifier::RequestId;
use actix_web::routes;
use actix_web::{http::StatusCode, Responder};
Expand All @@ -14,13 +14,13 @@ use super::process_result;
#[post("/config")]
#[get("/config")]
pub async fn get_config(state: NeonApiState, request_id: RequestId) -> impl Responder {
let rpc_client = match api_context::build_rpc_client(&state, None, None).await {
Ok(rpc_client) => rpc_client,
let rpc = match state.build_rpc(None, None).await {
Ok(rpc) => rpc,
Err(e) => return process_error(StatusCode::BAD_REQUEST, &e),
};

process_result(
&GetConfigCommand::execute(rpc_client.as_ref(), state.config.evm_loader)
&GetConfigCommand::execute(&rpc, state.config.evm_loader)
.await
.map_err(Into::into),
)
Expand Down
16 changes: 6 additions & 10 deletions evm_loader/api/src/api_server/handlers/get_contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::api_server::handlers::process_error;
use crate::commands::get_contract as GetContractCommand;
use crate::{api_context, types::GetContractRequest, NeonApiState};
use crate::{types::GetContractRequest, NeonApiState};
use actix_request_identifier::RequestId;
use actix_web::post;
use actix_web::web::Json;
Expand All @@ -16,18 +16,14 @@ pub async fn get_contract(
request_id: RequestId,
Json(req_params): Json<GetContractRequest>,
) -> impl Responder {
let rpc_client = match api_context::build_rpc_client(&state, req_params.slot, None).await {
Ok(rpc_client) => rpc_client,
let rpc = match state.build_rpc(req_params.slot, None).await {
Ok(rpc) => rpc,
Err(e) => return process_error(StatusCode::BAD_REQUEST, &e),
};

process_result(
&GetContractCommand::execute(
rpc_client.as_ref(),
&state.config.evm_loader,
&req_params.contract,
)
.await
.map_err(Into::into),
&GetContractCommand::execute(&rpc, &state.config.evm_loader, &req_params.contract)
.await
.map_err(Into::into),
)
}
16 changes: 6 additions & 10 deletions evm_loader/api/src/api_server/handlers/get_holder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::api_server::handlers::process_error;
use crate::commands::get_holder as GetHolderCommand;
use crate::{api_context, types::GetHolderRequest, NeonApiState};
use crate::{types::GetHolderRequest, NeonApiState};
use actix_request_identifier::RequestId;
use actix_web::post;
use actix_web::web::Json;
Expand All @@ -16,18 +16,14 @@ pub async fn get_holder_account_data(
request_id: RequestId,
Json(req_params): Json<GetHolderRequest>,
) -> impl Responder {
let rpc_client = match api_context::build_rpc_client(&state, req_params.slot, None).await {
Ok(rpc_client) => rpc_client,
let rpc = match state.build_rpc(req_params.slot, None).await {
Ok(rpc) => rpc,
Err(e) => return process_error(StatusCode::BAD_REQUEST, &e),
};

process_result(
&GetHolderCommand::execute(
rpc_client.as_ref(),
&state.config.evm_loader,
req_params.pubkey,
)
.await
.map_err(Into::into),
&GetHolderCommand::execute(&rpc, &state.config.evm_loader, req_params.pubkey)
.await
.map_err(Into::into),
)
}
8 changes: 4 additions & 4 deletions evm_loader/api/src/api_server/handlers/get_storage_at.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::api_server::handlers::process_error;
use crate::{api_context, types::GetStorageAtRequest, NeonApiState};
use crate::{types::GetStorageAtRequest, NeonApiState};
use actix_request_identifier::RequestId;
use actix_web::post;
use actix_web::web::Json;
Expand All @@ -17,14 +17,14 @@ pub async fn get_storage_at(
request_id: RequestId,
Json(req_params): Json<GetStorageAtRequest>,
) -> impl Responder {
let rpc_client = match api_context::build_rpc_client(&state, req_params.slot, None).await {
Ok(rpc_client) => rpc_client,
let rpc = match state.build_rpc(req_params.slot, None).await {
Ok(rpc) => rpc,
Err(e) => return process_error(StatusCode::BAD_REQUEST, &e),
};

process_result(
&GetStorageAtCommand::execute(
rpc_client.as_ref(),
&rpc,
&state.config.evm_loader,
req_params.contract,
req_params.index,
Expand Down
16 changes: 6 additions & 10 deletions evm_loader/api/src/api_server/handlers/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::convert::Into;

use crate::api_server::handlers::process_error;
use crate::commands::trace::trace_transaction;
use crate::{api_context, types::EmulateApiRequest, NeonApiState};
use crate::{types::EmulateApiRequest, NeonApiState};

use super::process_result;

Expand All @@ -18,18 +18,14 @@ pub async fn trace(
let slot = trace_request.slot;
let index = trace_request.tx_index_in_block;

let rpc_client = match api_context::build_rpc_client(&state, slot, index).await {
Ok(rpc_client) => rpc_client,
let rpc = match state.build_rpc(slot, index).await {
Ok(rpc) => rpc,
Err(e) => return process_error(StatusCode::BAD_REQUEST, &e),
};

process_result(
&trace_transaction(
rpc_client.as_ref(),
state.config.evm_loader,
trace_request.body,
)
.await
.map_err(Into::into),
&trace_transaction(&rpc, state.config.evm_loader, trace_request.body)
.await
.map_err(Into::into),
)
}
28 changes: 19 additions & 9 deletions evm_loader/api/src/api_server/state.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
use crate::Config;
use neon_lib::rpc::{CallDbClient, CloneRpcClient, RpcEnum};
use neon_lib::types::TracerDb;
use solana_client::nonblocking::rpc_client::RpcClient;
use std::sync::Arc;
use neon_lib::NeonError;

pub struct State {
pub tracer_db: TracerDb,
pub rpc_client: Arc<RpcClient>,
pub rpc_client: CloneRpcClient,
pub config: Config,
}

impl State {
pub fn new(config: Config) -> Self {
let db_config = config.db_config.as_ref().expect("db-config not found");
Self {
tracer_db: TracerDb::new(db_config),
rpc_client: Arc::new(RpcClient::new_with_commitment(
config.json_rpc_url.clone(),
config.commitment,
)),
tracer_db: TracerDb::new(&config),
rpc_client: config.build_clone_solana_rpc_client(),
config,
}
}

pub async fn build_rpc(
&self,
slot: Option<u64>,
tx_index_in_block: Option<u64>,
) -> Result<RpcEnum, NeonError> {
Ok(if let Some(slot) = slot {
RpcEnum::CallDbClient(
CallDbClient::new(self.tracer_db.clone(), slot, tx_index_in_block).await?,
)
} else {
RpcEnum::CloneRpcClient(self.rpc_client.clone())
})
}
}
3 changes: 0 additions & 3 deletions evm_loader/api/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![deny(warnings)]
#![deny(clippy::all, clippy::pedantic)]
mod api_context;
mod api_options;
mod api_server;
#[allow(clippy::module_name_repetitions)]
Expand All @@ -12,7 +11,6 @@ use actix_web::HttpServer;
use api_server::handlers::NeonApiError;
pub use neon_lib::commands;
pub use neon_lib::config;
pub use neon_lib::context;
pub use neon_lib::errors;
pub use neon_lib::types;
use tracing_appender::non_blocking::NonBlockingBuilder;
Expand All @@ -31,7 +29,6 @@ use crate::api_server::handlers::get_storage_at::get_storage_at;
use crate::api_server::handlers::trace::trace;
use crate::build_info::get_build_info;
pub use config::Config;
pub use context::Context;
use tracing::info;

type NeonApiResult<T> = Result<T, NeonApiError>;
Expand Down
Loading