diff --git a/state-chain/custom-rpc/src/lib.rs b/state-chain/custom-rpc/src/lib.rs index 17b5ffc6c4..b3c33561a4 100644 --- a/state-chain/custom-rpc/src/lib.rs +++ b/state-chain/custom-rpc/src/lib.rs @@ -212,7 +212,7 @@ pub trait CustomApi { pair_asset: Asset, tick_range: Range, at: Option, - ) -> RpcResult, DispatchError>>>; + ) -> RpcResult>>; #[method(name = "pool_info")] fn cf_pool_info( &self, @@ -227,7 +227,7 @@ pub trait CustomApi { pair_asset: Asset, tick_range: Range, at: Option, - ) -> RpcResult, DispatchError>>>; + ) -> RpcResult>>; #[method(name = "pool_liquidity")] fn cf_pool_liquidity( &self, @@ -251,7 +251,7 @@ pub trait CustomApi { tick_range: Range, liquidity: Liquidity, at: Option, - ) -> RpcResult, DispatchError>>>; + ) -> RpcResult>>; #[method(name = "environment")] fn cf_environment(&self, at: Option) -> RpcResult; #[method(name = "current_compatibility_version")] @@ -289,6 +289,10 @@ fn to_rpc_error(e: E) -> jsonrpsee CallError::from_std_error(e).into() } +fn map_dispatch_error(e: DispatchError) -> jsonrpsee::core::Error { + jsonrpsee::core::Error::from(anyhow::anyhow!("Dispatch error: {}", <&'static str>::from(e))) +} + impl CustomApiServer for CustomRpc where B: BlockT, @@ -586,11 +590,13 @@ where pair_asset: Asset, tick_range: Range, at: Option, - ) -> RpcResult, DispatchError>>> { + ) -> RpcResult>> { self.client .runtime_api() .cf_pool_depth(self.unwrap_or_best(at), base_asset, pair_asset, tick_range) - .map_err(to_rpc_error) + .map_err(to_rpc_error)? + .transpose() + .map_err(map_dispatch_error) } fn cf_pool_liquidity( @@ -611,7 +617,7 @@ where pair_asset: Asset, tick_range: Range, at: Option, - ) -> RpcResult, DispatchError>>> { + ) -> RpcResult>> { self.client .runtime_api() .cf_required_asset_ratio_for_range_order( @@ -620,7 +626,9 @@ where pair_asset, tick_range, ) - .map_err(to_rpc_error) + .map_err(to_rpc_error)? + .transpose() + .map_err(map_dispatch_error) } fn cf_pool_orders( @@ -643,7 +651,7 @@ where tick_range: Range, liquidity: Liquidity, at: Option, - ) -> RpcResult, DispatchError>>> { + ) -> RpcResult>> { self.client .runtime_api() .cf_pool_range_order_liquidity_value( @@ -653,7 +661,9 @@ where tick_range, liquidity, ) - .map_err(to_rpc_error) + .map_err(to_rpc_error)? + .transpose() + .map_err(map_dispatch_error) } fn cf_environment(&self, at: Option) -> RpcResult {