mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +00:00
restricted json-rpc error
This commit is contained in:
parent
3763dc9693
commit
ce6838bd6f
3 changed files with 17 additions and 22 deletions
|
@ -71,12 +71,13 @@ macro_rules! generate_endpoints_inner {
|
||||||
($variant:ident, $handler:ident, $request:expr_2021) => {
|
($variant:ident, $handler:ident, $request:expr_2021) => {
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
{
|
{
|
||||||
// INVARIANT:
|
// Check if restricted.
|
||||||
// The handler functions in `cuprated` depend on this line existing,
|
|
||||||
// the functions themselves do not check if they are being called
|
|
||||||
// from an (un)restricted context.
|
|
||||||
//
|
//
|
||||||
// This line must be here or all methods will be allowed to be called freely.
|
// INVARIANT:
|
||||||
|
// The RPC handler functions in `cuprated` depend on this line existing,
|
||||||
|
// the functions themselves do not check if they are being called
|
||||||
|
// from an (un)restricted context. This line must be here or all
|
||||||
|
// methods will be allowed to be called freely.
|
||||||
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
|
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
|
||||||
// TODO: mimic `monerod` behavior.
|
// TODO: mimic `monerod` behavior.
|
||||||
return Err(StatusCode::FORBIDDEN);
|
return Err(StatusCode::FORBIDDEN);
|
||||||
|
|
|
@ -39,21 +39,16 @@ pub(crate) async fn json_rpc<H: RpcHandler>(
|
||||||
// the requested method is only for non-restricted RPC.
|
// the requested method is only for non-restricted RPC.
|
||||||
//
|
//
|
||||||
// INVARIANT:
|
// INVARIANT:
|
||||||
// The handler functions in `cuprated` depend on this line existing,
|
// The RPC handler functions in `cuprated` depend on this line existing,
|
||||||
// the functions themselves do not check if they are being called
|
// the functions themselves do not check if they are being called
|
||||||
// from an (un)restricted context.
|
// from an (un)restricted context. This line must be here or all
|
||||||
//
|
// methods will be allowed to be called freely.
|
||||||
// This line must be here or all methods will be allowed to be called freely.
|
|
||||||
if request.body.is_restricted() && handler.is_restricted() {
|
if request.body.is_restricted() && handler.is_restricted() {
|
||||||
let error_object = ErrorObject {
|
// The error when a restricted JSON-RPC method is called as per:
|
||||||
code: ErrorCode::ServerError(-1 /* TODO */),
|
//
|
||||||
message: Cow::Borrowed("Restricted. TODO: mimic monerod message"),
|
// - <https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/contrib/epee/include/net/http_server_handlers_map2.h#L244-L252>
|
||||||
data: None,
|
// - <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.h#L188>
|
||||||
};
|
return Ok(Json(Response::method_not_found(id)));
|
||||||
|
|
||||||
let response = Response::err(id, error_object);
|
|
||||||
|
|
||||||
return Ok(Json(response));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send request.
|
// Send request.
|
||||||
|
|
|
@ -77,11 +77,10 @@ macro_rules! generate_endpoints_inner {
|
||||||
// Check if restricted.
|
// Check if restricted.
|
||||||
//
|
//
|
||||||
// INVARIANT:
|
// INVARIANT:
|
||||||
// The handler functions in `cuprated` depend on this line existing,
|
// The RPC handler functions in `cuprated` depend on this line existing,
|
||||||
// the functions themselves do not check if they are being called
|
// the functions themselves do not check if they are being called
|
||||||
// from an (un)restricted context.
|
// from an (un)restricted context. This line must be here or all
|
||||||
//
|
// methods will be allowed to be called freely.
|
||||||
// This line must be here or all methods will be allowed to be called freely.
|
|
||||||
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
|
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
|
||||||
// TODO: mimic `monerod` behavior.
|
// TODO: mimic `monerod` behavior.
|
||||||
return Err(StatusCode::FORBIDDEN);
|
return Err(StatusCode::FORBIDDEN);
|
||||||
|
|
Loading…
Reference in a new issue