-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add skip_serialize_none macro * Use skip_serializing_none * pp skip_serializing_none * lint * Plugin ocean_invalidate_block * Ocean: api rpc controller (#3090) * add rpc ctrl * update ocean ci * lint * Ocean logging middleware * Fix lint * fmt cpp --------- Co-authored-by: canonbrother <w.canonbrother@gmail.com>
- Loading branch information
1 parent
0a179f3
commit c9f4519
Showing
17 changed files
with
181 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
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,67 @@ | ||
use std::sync::Arc; | ||
|
||
use ain_macros::ocean_endpoint; | ||
use axum::{routing::post, Extension, Json, Router}; | ||
use defichain_rpc::RpcApi; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::{response::Response, AppContext}; | ||
use crate::{ | ||
error::{ApiError, Error}, | ||
Result, | ||
}; | ||
|
||
#[derive(Serialize, Deserialize, Default, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
struct RpcDto { | ||
method: String, | ||
params: Vec<serde_json::Value>, | ||
} | ||
|
||
fn method_whitelist(method: &str) -> Result<()> { | ||
let methods = [ | ||
"getblockchaininfo", | ||
"getblockhash", | ||
"getblockcount", | ||
"getblock", | ||
"getblockstats", | ||
"getgov", | ||
"validateaddress", | ||
"listcommunitybalances", | ||
"getaccounthistory", | ||
"getfutureswapblock", | ||
"getpendingfutureswaps", | ||
"sendrawtransaction", | ||
"getrawtransaction", | ||
"getgovproposal", | ||
"listgovproposals", | ||
"listgovproposalvotes", | ||
"vmmap", | ||
"gettxout", | ||
]; | ||
|
||
if !methods.contains(&method) { | ||
log::debug!("forbidden"); | ||
return Err(Error::Forbidden { | ||
method: method.to_owned(), | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[ocean_endpoint] | ||
async fn rpc( | ||
Extension(ctx): Extension<Arc<AppContext>>, | ||
Json(body): Json<RpcDto>, | ||
) -> Result<Response<serde_json::Value>> { | ||
method_whitelist(&body.method)?; | ||
|
||
let res: serde_json::Value = ctx.client.call(&body.method, &body.params).await?; | ||
|
||
Ok(Response::new(res)) | ||
} | ||
|
||
pub fn router(ctx: Arc<AppContext>) -> Router { | ||
Router::new().route("/", post(rpc)).layer(Extension(ctx)) | ||
} |
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
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
Oops, something went wrong.