/// Starts the HTTP-RPC server.
Starts the HTTP-RPC server.
Starts the HTTP - RPC server .
pub fn run_server(addr: SocketAddr, api: RpcApi) -> Result<(HttpServerHandle, SocketAddr), Error> {
    let server = HttpServerBuilder::default().build(addr)?;
    let local_addr = server.local_addr()?;
    let mut module = RpcModuleWrapper(RpcModule::new(api));
    module.register_async_method("starknet_getBlockByHash", |params, context| async move {
        #[derive(Debug, Deserialize)]
        pub struct NamedArgs {
            pub block_hash: BlockHashOrTag,
            #[serde(default)]
            pub requested_scope: Option<BlockResponseScope>,
        }
        let params = params.parse::<NamedArgs>()?;
        context
            .get_block_by_hash(params.block_hash, params.requested_scope)
            .await
    })?;
    module.register_async_method("starknet_getBlockByNumber", |params, context| async move {
        #[derive(Debug, Deserialize)]
        pub struct NamedArgs {
            pub block_number: BlockNumberOrTag,
            #[serde(default)]
            pub requested_scope: Option<BlockResponseScope>,
        }
        let params = params.parse::<NamedArgs>()?;
        context
            .get_block_by_number(params.block_number, params.requested_scope)
            .await
    })?;
    // module.register_async_method(
    //     "starknet_getStateUpdateByHash",
    //     |params, context| async move {
    //         let hash = if params.is_object() {
    //             #[derive(Debug, Deserialize)]
    //             pub struct NamedArgs {
    //                 pub block_hash: BlockHashOrTag,
    //             }
    //             params.parse::<NamedArgs>()?.block_hash
    //         } else {
    //             params.one::<BlockHashOrTag>()?
    //         };
    //         context.get_state_update_by_hash(hash).await
    //     },
    // )?;
    module.register_async_method("starknet_getStorageAt", |params, context| async move {
        #[derive(Debug, Deserialize)]
        pub struct NamedArgs {
            pub contract_address: ContractAddress,
            // Accept overflowing type here to report INVALID_STORAGE_KEY properly
            pub key: OverflowingStorageAddress,
            pub block_hash: BlockHashOrTag,
        }
        let params = params.parse::<NamedArgs>()?;
        context
            .get_storage_at(params.contract_address, params.key, params.block_hash)
            .await
    })?;
    module.register_async_method(
        "starknet_getTransactionByHash",
        |params, context| async move {
            #[derive(Debug, Deserialize)]
            pub struct NamedArgs {
                pub transaction_hash: StarknetTransactionHash,
            }
            context
                .get_transaction_by_hash(params.parse::<NamedArgs>()?.transaction_hash)
                .await
        },
    )?;
    module.register_async_method(
        "starknet_getTransactionByBlockHashAndIndex",
        |params, context| async move {
            #[derive(Debug, Deserialize)]
            pub struct NamedArgs {
                pub block_hash: BlockHashOrTag,
                pub index: StarknetTransactionIndex,
            }
            let params = params.parse::<NamedArgs>()?;
            context
                .get_transaction_by_block_hash_and_index(params.block_hash, params.index)
                .await
        },
    )?;
    module.register_async_method(
        "starknet_getTransactionByBlockNumberAndIndex",
        |params, context| async move {
            #[derive(Debug, Deserialize)]
            pub struct NamedArgs {
                pub block_number: BlockNumberOrTag,
                pub index: StarknetTransactionIndex,
            }
            let params = params.parse::<NamedArgs>()?;
            context
                .get_transaction_by_block_number_and_index(params.block_number, params.index)
                .await
        },
    )?;
    module.register_async_method(
        "starknet_getTransactionReceipt",
        |params, context| async move {
            #[derive(Debug, Deserialize)]
            pub struct NamedArgs {
                pub transaction_hash: StarknetTransactionHash,
            }
            context
                .get_transaction_receipt(params.parse::<NamedArgs>()?.transaction_hash)
                .await
        },
    )?;
    module.register_async_method("starknet_getCode", |params, context| async move {
        #[derive(Debug, Deserialize)]
        pub struct NamedArgs {
            pub contract_address: ContractAddress,
        }
        context
            .get_code(params.parse::<NamedArgs>()?.contract_address)
            .await
    })?;
    module.register_async_method(
        "starknet_getBlockTransactionCountByHash",
        |params, context| async move {
            #[derive(Debug, Deserialize)]
            pub struct NamedArgs {
                pub block_hash: BlockHashOrTag,
            }
            context
                .get_block_transaction_count_by_hash(params.parse::<NamedArgs>()?.block_hash)
                .await
        },
    )?;
    module.register_async_method(
        "starknet_getBlockTransactionCountByNumber",
        |params, context| async move {
            #[derive(Debug, Deserialize)]
            pub struct NamedArgs {
                pub block_number: BlockNumberOrTag,
            }
            context
                .get_block_transaction_count_by_number(params.parse::<NamedArgs>()?.block_number)
                .await
        },
    )?;
    module.register_async_method("starknet_call", |params, context| async move {
        #[derive(Debug, Deserialize)]
        pub struct NamedArgs {
            pub request: Call,
            pub block_hash: BlockHashOrTag,
        }
        let params = params.parse::<NamedArgs>()?;
        context.call(params.request, params.block_hash).await
    })?;
    module.register_async_method("starknet_blockNumber", |_, context| async move {
        context.block_number().await
    })?;
    module.register_async_method("starknet_chainId", |_, context| async move {
        context.chain_id().await
    })?;
    // module.register_async_method("starknet_pendingTransactions", |_, context| async move {
    //     context.pending_transactions().await
    // })?;
    // module.register_async_method("starknet_protocolVersion", |_, context| async move {
    //     context.protocol_version().await
    // })?;
    module.register_async_method("starknet_syncing", |_, context| async move {
        context.syncing().await
    })?;
    let module = module.into_inner();
    server.start(module).map(|handle| (handle, local_addr))
}
pub fn run_server ( addr : SocketAddr , api : RpcApi ) -> Result < ( HttpServerHandle , SocketAddr ) , Error > { let server = HttpServerBuilder :: default ( ) . build ( addr ) ? ; let local_addr = server . local_addr ( ) ? ; let mut module = RpcModuleWrapper ( RpcModule :: new ( api ) ) ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub block_hash : BlockHashOrTag , # [ serde ( default ) ] pub requested_scope : Option < BlockResponseScope > , } let params = params . parse :: < NamedArgs > ( ) ? ; context . get_block_by_hash ( params . block_hash , params . requested_scope ) . await } ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub block_number : BlockNumberOrTag , # [ serde ( default ) ] pub requested_scope : Option < BlockResponseScope > , } let params = params . parse :: < NamedArgs > ( ) ? ; context . get_block_by_number ( params . block_number , params . requested_scope ) . await } ) ? ; // module.register_async_method( //     "starknet_getStateUpdateByHash", //     |params, context| async move { //         let hash = if params.is_object() { //             #[derive(Debug, Deserialize)] //             pub struct NamedArgs { //                 pub block_hash: BlockHashOrTag, //             } //             params.parse::<NamedArgs>()?.block_hash //         } else { //             params.one::<BlockHashOrTag>()? //         }; //         context.get_state_update_by_hash(hash).await //     }, // )?; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub contract_address : ContractAddress , // Accept overflowing type here to report INVALID_STORAGE_KEY properly pub key : OverflowingStorageAddress , pub block_hash : BlockHashOrTag , } let params = params . parse :: < NamedArgs > ( ) ? ; context . get_storage_at ( params . contract_address , params . key , params . block_hash ) . await } ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub transaction_hash : StarknetTransactionHash , } context . get_transaction_by_hash ( params . parse :: < NamedArgs > ( ) ? . transaction_hash ) . await } , ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub block_hash : BlockHashOrTag , pub index : StarknetTransactionIndex , } let params = params . parse :: < NamedArgs > ( ) ? ; context . get_transaction_by_block_hash_and_index ( params . block_hash , params . index ) . await } , ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub block_number : BlockNumberOrTag , pub index : StarknetTransactionIndex , } let params = params . parse :: < NamedArgs > ( ) ? ; context . get_transaction_by_block_number_and_index ( params . block_number , params . index ) . await } , ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub transaction_hash : StarknetTransactionHash , } context . get_transaction_receipt ( params . parse :: < NamedArgs > ( ) ? . transaction_hash ) . await } , ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub contract_address : ContractAddress , } context . get_code ( params . parse :: < NamedArgs > ( ) ? . contract_address ) . await } ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub block_hash : BlockHashOrTag , } context . get_block_transaction_count_by_hash ( params . parse :: < NamedArgs > ( ) ? . block_hash ) . await } , ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub block_number : BlockNumberOrTag , } context . get_block_transaction_count_by_number ( params . parse :: < NamedArgs > ( ) ? . block_number ) . await } , ) ? ; module . register_async_method ( " " , | params , context | async move { # [ derive ( Debug Deserialize ) ] pub struct NamedArgs { pub request : Call , pub block_hash : BlockHashOrTag , } let params = params . parse :: < NamedArgs > ( ) ? ; context . call ( params . request , params . block_hash ) . await } ) ? ; module . register_async_method ( " " , | _ , context | async move { context . block_number ( ) . await } ) ? ; module . register_async_method ( " " , | _ , context | async move { context . chain_id ( ) . await } ) ? ; // module.register_async_method("starknet_pendingTransactions", |_, context| async move { //     context.pending_transactions().await // })?; // module.register_async_method("starknet_protocolVersion", |_, context| async move { //     context.protocol_version().await // })?; module . register_async_method ( " " , | _ , context | async move { context . syncing ( ) . await } ) ? ; let module = module . into_inner ( ) ; server . start ( module ) . map ( | handle | ( handle , local_addr ) ) }
Starts the HTTP-RPC server.
Starts the HTTP - RPC server .
addr
SocketAddr
api
RpcApi