From 70360196f03a2b6d54942cef14482ecae9c19e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 11 Jun 2024 17:38:24 +0100 Subject: [PATCH] bugfix: make sure nym-api can handle non-cw2 (or without detailed build info) compliant contracts --- .../validator-client/src/nyxd/mod.rs | 18 ++++++++++-------- .../src/nym_contract_cache/cache/refresher.rs | 8 +++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/common/client-libs/validator-client/src/nyxd/mod.rs b/common/client-libs/validator-client/src/nyxd/mod.rs index ec77c2ecad..e396af4053 100644 --- a/common/client-libs/validator-client/src/nyxd/mod.rs +++ b/common/client-libs/validator-client/src/nyxd/mod.rs @@ -331,29 +331,31 @@ where .map(|block| block.block_id.hash) } - pub async fn get_cw2_contract_version( + pub async fn try_get_cw2_contract_version( &self, contract_address: &AccountId, - ) -> Result, NyxdError> { + ) -> Option { let raw_info = self .query_contract_raw(contract_address, b"contract_info".to_vec()) - .await?; + .await + .ok()?; - Ok(serde_json::from_slice(&raw_info).ok()) + serde_json::from_slice(&raw_info).ok() } - pub async fn get_contract_build_information( + pub async fn try_get_contract_build_information( &self, contract_address: &AccountId, - ) -> Result, NyxdError> { + ) -> Option { let raw_info = self .query_contract_raw( contract_address, CONTRACT_BUILD_INFO_STORAGE_KEY.as_bytes().to_vec(), ) - .await?; + .await + .ok()?; - Ok(serde_json::from_slice(&raw_info).ok()) + serde_json::from_slice(&raw_info).ok() } } diff --git a/nym-api/src/nym_contract_cache/cache/refresher.rs b/nym-api/src/nym_contract_cache/cache/refresher.rs index 5a9970008e..c1ea22e825 100644 --- a/nym-api/src/nym_contract_cache/cache/refresher.rs +++ b/nym-api/src/nym_contract_cache/cache/refresher.rs @@ -66,9 +66,11 @@ impl NymContractCacheRefresher { (multisig, "nym-cw3-multisig-contract"), ] { let (cw2, build_info) = if let Some(address) = address { - let cw2 = query_guard!(client_guard, get_cw2_contract_version(address).await)?; - let mut build_info = - query_guard!(client_guard, get_contract_build_information(address).await)?; + let cw2 = query_guard!(client_guard, try_get_cw2_contract_version(address).await); + let mut build_info = query_guard!( + client_guard, + try_get_contract_build_information(address).await + ); // for backwards compatibility until we migrate the contracts if build_info.is_none() {