diff --git a/magicblock-aperture/src/requests/http/get_delegation_status.rs b/magicblock-aperture/src/requests/http/get_delegation_status.rs new file mode 100644 index 000000000..006056c1e --- /dev/null +++ b/magicblock-aperture/src/requests/http/get_delegation_status.rs @@ -0,0 +1,31 @@ +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 { + 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)) + } +} diff --git a/magicblock-aperture/src/requests/http/mocked.rs b/magicblock-aperture/src/requests/http/mocked.rs index 85a9c2725..134460f06 100644 --- a/magicblock-aperture/src/requests/http/mocked.rs +++ b/magicblock-aperture/src/requests/http/mocked.rs @@ -243,4 +243,13 @@ 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, [])) + } } diff --git a/magicblock-aperture/src/requests/http/mod.rs b/magicblock-aperture/src/requests/http/mod.rs index 4c68cfb6e..984b9e259 100644 --- a/magicblock-aperture/src/requests/http/mod.rs +++ b/magicblock-aperture/src/requests/http/mod.rs @@ -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; diff --git a/magicblock-aperture/src/requests/mod.rs b/magicblock-aperture/src/requests/mod.rs index 1b4c14e77..87c4f4f7d 100644 --- a/magicblock-aperture/src/requests/mod.rs +++ b/magicblock-aperture/src/requests/mod.rs @@ -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. @@ -140,6 +146,9 @@ impl JsonRpcHttpMethod { Self::RequestAirdrop => "requestAirdrop", Self::SendTransaction => "sendTransaction", Self::SimulateTransaction => "simulateTransaction", + Self::GetRoutes => "getRoutes", + Self::GetBlockhashForAccounts => "getBlockhashForAccounts", + Self::GetDelegationStatus => "getDelegationStatus", } } } diff --git a/magicblock-aperture/src/server/http/dispatch.rs b/magicblock-aperture/src/server/http/dispatch.rs index 32955d2e7..29569beca 100644 --- a/magicblock-aperture/src/server/http/dispatch.rs +++ b/magicblock-aperture/src/server/http/dispatch.rs @@ -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, } }