From 40960f3f1eae00ad95b3f12c8f4cab5d30cb46b7 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 5 Aug 2024 10:32:56 +1200 Subject: [PATCH] feat: Remove unnecessary null check --- coordinator/src/registry.rs | 39 ++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/coordinator/src/registry.rs b/coordinator/src/registry.rs index 9f0824d3..eb9c0ad6 100644 --- a/coordinator/src/registry.rs +++ b/coordinator/src/registry.rs @@ -233,30 +233,25 @@ impl RegistryImpl { .context("Failed to fetch indexer")?; if let QueryResponseKind::CallResult(call_result) = response.kind { - // Handle case where call returns successfully but returns null due to not matching - let raw_json: Value = serde_json::from_slice(&call_result.result) - .context("Failed to deserialize config from JSON provided by RPC call")?; - if raw_json.is_null() { - return Ok(None); - } - - // Handle case where we now expect returned JSON to actually parse into config - let config: registry_types::IndexerConfig = - serde_json::from_slice::(&call_result.result) + let config: Option = + serde_json::from_slice(&call_result.result) .context("Failed to deserialize config from JSON provided by RPC call")?; - let indexer = IndexerConfig { - account_id: account_id.clone(), - function_name: function_name.to_string(), - code: config.code, - schema: config.schema, - rule: config.rule, - start_block: config.start_block, - updated_at_block_height: config.updated_at_block_height, - created_at_block_height: config.created_at_block_height, - deleted_at_block_height: config.deleted_at_block_height, - }; - return Ok(Some(indexer)); + return if let Some(config) = config { + Ok(Some(IndexerConfig { + account_id: account_id.clone(), + function_name: function_name.to_string(), + code: config.code, + schema: config.schema, + rule: config.rule, + start_block: config.start_block, + updated_at_block_height: config.updated_at_block_height, + created_at_block_height: config.created_at_block_height, + deleted_at_block_height: config.deleted_at_block_height, + })) + } else { + Ok(None) + }; } anyhow::bail!("Invalid registry response")