Function convert_to_internal_rpc_request

Source
pub fn convert_to_internal_rpc_request(
    request: Value,
    network_type: &NetworkType,
) -> Result<JsonRpcRequest<NetworkRpcRequest>, ApiError>
Expand description

Converts a raw JSON-RPC request to the internal NetworkRpcRequest format.

This function parses a raw JSON-RPC request and converts it into the appropriate internal request type based on the specified network type. It handles the JSON-RPC 2.0 specification including proper ID handling (String, Number, or Null).

§Arguments

  • request - A raw JSON value containing the JSON-RPC request
  • network_type - The type of network (EVM, Solana, or Stellar) to parse the request for

§Returns

Returns a Result containing the parsed JsonRpcRequest on success, or an ApiError on failure.

§Examples

use serde_json::json;
use crate::models::{convert_to_internal_rpc_request, NetworkType};

let request = json!({
    "jsonrpc": "2.0",
    "method": "eth_getBalance",
    "params": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "latest"],
    "id": 1
});

let result = convert_to_internal_rpc_request(request, &NetworkType::Evm)?;