Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use super::prelude::*;

impl HttpDispatcher {
/// Handles the `getBlockhashForAccounts` RPC request.
///
/// On the validator, this is intentionally implemented as an alias for
/// `getLatestBlockhash`. The method exists purely for API compatibility
/// with the Magic Router SDK and does not implement full router routing
/// logic.
pub(crate) fn get_blockhash_for_accounts(
&self,
request: &JsonRequest,
) -> HandlerResult {
// We ignore any parameters and simply return the validator's latest
// blockhash, matching the behavior of `getLatestBlockhash`.
self.get_latest_blockhash(request)
}
}
39 changes: 39 additions & 0 deletions magicblock-aperture/src/requests/http/get_delegation_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use super::prelude::*;

impl HttpDispatcher {
/// Handles the `getDelegationStatus` RPC request.
///
/// Returns a minimal delegation status object of the form:
/// `{ "isDelegated": true | false }`
///
/// The status is derived solely from the `AccountSharedData::delegated()`
/// flag of the local `AccountsDb`. No delegation record resolution or
/// router-style logic is performed here by design.
pub(crate) async fn get_delegation_status(
&self,
request: &mut JsonRequest,
) -> HandlerResult {
// Parse single pubkey parameter from positional params without using
// the generic `parse_params!` helper to keep the logic simple and
// avoid tuple unpacking for this custom method.
let params = request.params()?;
// We expect the *first* positional parameter to be the account pubkey.
let value = params.first().cloned().ok_or_else(|| {
RpcError::invalid_params("missing pubkey parameter")
})?;
let pubkey_bytes: Serde32Bytes =
json::from_value(&value).map_err(RpcError::parse_error)?;
let pubkey: Pubkey = pubkey_bytes.into();

// Ensure the account is present in the local AccountsDb, cloning it
// from the reference cluster if necessary.
let account = self.read_account_with_ensure(&pubkey).await;

let is_delegated =
account.as_ref().map(|acc| acc.delegated()).unwrap_or(false);

let payload = json::json!({ "isDelegated": is_delegated });

Ok(ResponsePayload::encode_no_context(&request.id, payload))
}
}
15 changes: 15 additions & 0 deletions magicblock-aperture/src/requests/http/get_routes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::prelude::*;

impl HttpDispatcher {
/// Handles the `getRoutes` RPC request.
///
/// This is a validator-specific, mocked implementation used only to satisfy
/// the Magic Router / SDK API. A validator does not act as a router and
/// therefore always returns an empty list of routes.
pub(crate) fn get_routes(&self, request: &JsonRequest) -> HandlerResult {
Ok(ResponsePayload::encode_no_context(
&request.id,
json::json!([]),
))
}
}
5 changes: 5 additions & 0 deletions magicblock-aperture/src/requests/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,8 @@ pub(crate) mod mocked;
pub(crate) mod request_airdrop;
pub(crate) mod send_transaction;
pub(crate) mod simulate_transaction;

// Magic Router compatibility methods.
pub(crate) mod get_blockhash_for_accounts;
pub(crate) mod get_delegation_status;
pub(crate) mod get_routes;
9 changes: 9 additions & 0 deletions magicblock-aperture/src/requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ pub(crate) enum JsonRpcHttpMethod {
RequestAirdrop,
SendTransaction,
SimulateTransaction,
/// Custom Magic Router-compatible method: mocked on validator.
GetRoutes,
/// Custom Magic Router-compatible method: alias of `getLatestBlockhash` on validator.
GetBlockhashForAccounts,
/// Custom Magic Router-compatible method: exposes simple delegation flag.
GetDelegationStatus,
}

/// All supported JSON-RPC Websocket method names.
Expand Down Expand Up @@ -140,6 +146,9 @@ impl JsonRpcHttpMethod {
Self::RequestAirdrop => "requestAirdrop",
Self::SendTransaction => "sendTransaction",
Self::SimulateTransaction => "simulateTransaction",
Self::GetRoutes => "getRoutes",
Self::GetBlockhashForAccounts => "getBlockhashForAccounts",
Self::GetDelegationStatus => "getDelegationStatus",
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions magicblock-aperture/src/server/http/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ impl HttpDispatcher {
RequestAirdrop => self.request_airdrop(request).await,
SendTransaction => self.send_transaction(request).await,
SimulateTransaction => self.simulate_transaction(request).await,
GetRoutes => self.get_routes(request),
GetBlockhashForAccounts => self.get_blockhash_for_accounts(request),
GetDelegationStatus => self.get_delegation_status(request).await,
}
}

Expand Down