mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
babe: treat epoch_authorship RPC method as unsafe (#6069)
* service: pass DenyUnsafe to rpc extensions * node: add DenyUnsafe to rpc full node dependencies * client: fix whitespace in rpc policy file * babe: treat epochAuthorship rpc method as unsafe * babe: add test for unsafe rpc method * babe: rename babe rpc handler * service: traitify rpc extension builder * service: make the rpc extensions builder api non-breaking * service: revert changes from light node rpc extensions builder * node: remove unnecessary type in service creation * service: cleanup with_rpc_extensions implementation * service: add missing docs to RpcExtensionBuilder
This commit is contained in:
@@ -26,21 +26,21 @@ use jsonrpc_core as rpc;
|
||||
/// Signifies whether a potentially unsafe RPC should be denied.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum DenyUnsafe {
|
||||
/// Denies only potentially unsafe RPCs.
|
||||
Yes,
|
||||
/// Allows calling every RPCs.
|
||||
No
|
||||
/// Denies only potentially unsafe RPCs.
|
||||
Yes,
|
||||
/// Allows calling every RPCs.
|
||||
No,
|
||||
}
|
||||
|
||||
impl DenyUnsafe {
|
||||
/// Returns `Ok(())` if the RPCs considered unsafe are safe to call,
|
||||
/// otherwise returns `Err(UnsafeRpcError)`.
|
||||
pub fn check_if_safe(self) -> Result<(), UnsafeRpcError> {
|
||||
match self {
|
||||
DenyUnsafe::Yes => Err(UnsafeRpcError),
|
||||
DenyUnsafe::No => Ok(())
|
||||
}
|
||||
}
|
||||
/// Returns `Ok(())` if the RPCs considered unsafe are safe to call,
|
||||
/// otherwise returns `Err(UnsafeRpcError)`.
|
||||
pub fn check_if_safe(self) -> Result<(), UnsafeRpcError> {
|
||||
match self {
|
||||
DenyUnsafe::Yes => Err(UnsafeRpcError),
|
||||
DenyUnsafe::No => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Signifies whether an RPC considered unsafe is denied to be called externally.
|
||||
@@ -48,15 +48,15 @@ impl DenyUnsafe {
|
||||
pub struct UnsafeRpcError;
|
||||
|
||||
impl std::fmt::Display for UnsafeRpcError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "RPC call is unsafe to be called externally")
|
||||
}
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "RPC call is unsafe to be called externally")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for UnsafeRpcError {}
|
||||
|
||||
impl From<UnsafeRpcError> for rpc::Error {
|
||||
fn from(_: UnsafeRpcError) -> rpc::Error {
|
||||
rpc::Error::method_not_found()
|
||||
}
|
||||
fn from(_: UnsafeRpcError) -> rpc::Error {
|
||||
rpc::Error::method_not_found()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user