-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2832aaa
commit 986c3db
Showing
9 changed files
with
880 additions
and
815 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
pub mod configuration; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
pub mod diagnostics; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
pub mod server; | ||
pub mod types; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
mod v1; | ||
pub mod v2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use super::transactions; | ||
use crate::{ | ||
api::{ | ||
configuration::SharedConfig, | ||
types::{Error, Payload, Request, Response, Status, Version, WsResponse}, | ||
}, | ||
data::{Database, RpcNodeKey}, | ||
}; | ||
use std::sync::Arc; | ||
|
||
pub async fn handle_request( | ||
request: Request, | ||
version: &str, | ||
config: &SharedConfig, | ||
submitter: Option<Arc<impl transactions::Submit>>, | ||
db: impl Database, | ||
) -> Result<WsResponse, Error> { | ||
let request_id = request.request_id; | ||
match request.payload { | ||
Payload::Version => { | ||
let version = Version { | ||
version: version.to_string(), | ||
network_version: db.get(RpcNodeKey).unwrap_or_default().system_version, | ||
}; | ||
Ok(Response::new(request_id, version).into()) | ||
}, | ||
Payload::Status => { | ||
let status = Status::new(config, db); | ||
Ok(Response::new(request_id, status).into()) | ||
}, | ||
Payload::Submit(transaction) => { | ||
let Some(submitter) = submitter else { | ||
return Err(Error::bad_request(request_id, "Submit is not configured.")); | ||
}; | ||
if transaction.is_empty() { | ||
return Err(Error::bad_request(request_id, "Transaction is empty.")); | ||
} | ||
|
||
submitter | ||
.submit(transaction) | ||
.await | ||
.map(|response| Response::new(request_id, response).into()) | ||
.map_err(Error::internal_server_error) | ||
}, | ||
} | ||
} |
Oops, something went wrong.