Skip to content

Commit

Permalink
feat: Remove unnecessary null check
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Aug 4, 2024
1 parent b177fba commit 40960f3
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions coordinator/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<registry_types::IndexerConfig>(&call_result.result)
let config: Option<registry_types::IndexerConfig> =
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")
Expand Down

0 comments on commit 40960f3

Please sign in to comment.