Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
32 changes: 32 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,32 @@
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 the first positional parameter (account pubkey) using the
// standard helper macro, mirroring `get_account_info`.
let pubkey = parse_params!(request.params()?, Serde32Bytes);
let pubkey: Pubkey = some_or_err!(pubkey);

// 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))
}
}
12 changes: 12 additions & 0 deletions magicblock-aperture/src/requests/http/mocked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,16 @@ impl HttpDispatcher {
};
Ok(ResponsePayload::encode_no_context(&request.id, status))
}

/// 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,
Vec::<()>::new(),
))
}
}
3 changes: 3 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,6 @@ 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_delegation_status;
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
4 changes: 4 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,10 @@ 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),
// Alias for getLatestBlockhash; exists for Magic Router SDK compatibility.
GetBlockhashForAccounts => self.get_latest_blockhash(request),
GetDelegationStatus => self.get_delegation_status(request).await,
}
}

Expand Down