Skip to content

Commit

Permalink
Merge pull request #33 from uqbar-dao/hf/fix-get_capability-equality
Browse files Browse the repository at this point in the history
fix `get_capability()` params check
  • Loading branch information
dr-frmr authored Jan 21, 2024
2 parents ca63613 + 437093e commit 5104a50
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//!
pub use crate::kinode::process::standard::*;
use serde::{Deserialize, Serialize};
use serde_json::Value;

wit_bindgen::generate!({
path: "kinode-wit",
Expand Down Expand Up @@ -204,10 +205,13 @@ pub fn can_message(address: &Address) -> bool {
}

/// Get a capability in our store
/// NOTE unfortunatly this is O(n), not sure if wit let's us do any better
pub fn get_capability(our: &Address, params: &str) -> Option<Capability> {
let params = serde_json::from_str::<Value>(params).unwrap_or_default();
crate::our_capabilities()
.iter()
.find(|cap| cap.issuer == *our && cap.params == params)
.find(|cap| {
let cap_params = serde_json::from_str::<Value>(&cap.params).unwrap_or_default();
cap.issuer == *our && params == cap_params
})
.cloned()
}

0 comments on commit 5104a50

Please sign in to comment.