Skip to content

Commit

Permalink
use account_not_found convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
madninja committed Jun 13, 2024
1 parent 3cb4715 commit a28511d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion helium-lib/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl AssetProof {
let canopy_heights = get_canopy_heights().await?;
let height = canopy_heights
.get(tree)
.ok_or_else(|| anchor_client::ClientError::AccountNotFound)?;
.ok_or_else(Error::account_not_found)?;
self.proof(Some(*height))
}
}
Expand Down
17 changes: 4 additions & 13 deletions helium-lib/src/kta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ pub fn init(settings: &Settings) -> Result<()> {
}

pub async fn get(kta_key: &Pubkey) -> Result<KeyToAssetV0> {
let cache = CACHE
.get()
.ok_or_else(|| anchor_client::ClientError::AccountNotFound)?;
let cache = CACHE.get().ok_or_else(Error::account_not_found)?;
cache.get(kta_key).await
}

pub async fn get_many(kta_keys: &[Pubkey]) -> Result<Vec<KeyToAssetV0>> {
let cache = CACHE
.get()
.ok_or_else(|| anchor_client::ClientError::AccountNotFound)?;
let cache = CACHE.get().ok_or_else(Error::account_not_found)?;
cache.get_many(kta_keys).await
}

Expand Down Expand Up @@ -101,7 +97,7 @@ impl KtaCache {
.zip(missing_accounts.iter_mut())
.map(|(key, maybe_account)| {
let Some(account) = maybe_account.as_mut() else {
return Err(Error::from(anchor_client::ClientError::AccountNotFound));
return Err(Error::account_not_found());
};
helium_entity_manager::KeyToAssetV0::try_deserialize(&mut account.data.as_ref())
.map_err(Error::from)
Expand All @@ -116,12 +112,7 @@ impl KtaCache {
let cache = self.cache_read();
kta_keys
.iter()
.map(|key| {
cache
.get(key)
.cloned()
.ok_or(anchor_client::ClientError::AccountNotFound.into())
})
.map(|key| cache.get(key).cloned().ok_or(Error::account_not_found()))
.try_collect()
}
}
Expand Down
6 changes: 6 additions & 0 deletions helium-lib/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ pub enum Error {
Encode(#[from] EncodeError),
}

impl Error {
pub fn account_not_found() -> Self {
anchor_client::ClientError::AccountNotFound.into()
}
}

#[derive(Debug, Error)]
pub enum EncodeError {
#[error("proto: {0}")]
Expand Down
3 changes: 1 addition & 2 deletions helium-lib/src/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ pub async fn pending(
let kta = kta::for_entity_key(&entity_key).await?;
recipient::for_kta(&client, subdao, &kta)
.and_then(|maybe_recipient| async move {
maybe_recipient
.ok_or_else(|| anchor_client::ClientError::AccountNotFound.into())
maybe_recipient.ok_or_else(Error::account_not_found)
})
.map_ok(|recipient| {
for_entity_key(&bulk_rewards, entity_key_string).map(|mut oracle_reward| {
Expand Down

0 comments on commit a28511d

Please sign in to comment.