Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocean: api rpc controller #3090

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
lint
canonbrother committed Oct 10, 2024
commit 035002e548290f8f3f4bf4e595ea68670892d487
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ mod pool_pair;
pub mod prices;
mod query;
mod rawtx;
mod rpc;
mod response;
mod rpc;
mod stats;
mod tokens;
mod transactions;
59 changes: 28 additions & 31 deletions lib/ain-ocean/src/api/rpc.rs
Original file line number Diff line number Diff line change
@@ -5,10 +5,7 @@ use axum::{routing::post, Extension, Json, Router};
use defichain_rpc::RpcApi;
use serde::{Deserialize, Serialize};

use super::{
response::Response,
AppContext,
};
use super::{response::Response, AppContext};
use crate::{
error::{ApiError, Error},
Result,
@@ -23,32 +20,34 @@ struct RpcDto {

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"
];
"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() })
}
if !methods.contains(&method) {
log::debug!("forbidden");
return Err(Error::Forbidden {
method: method.to_owned(),
});
}

Ok(())
Ok(())
}

#[ocean_endpoint]
@@ -64,7 +63,5 @@ async fn rpc(
}

pub fn router(ctx: Arc<AppContext>) -> Router {
Router::new()
.route("/", post(rpc))
.layer(Extension(ctx))
Router::new().route("/", post(rpc)).layer(Extension(ctx))
}