Skip to content

Commit 5104a50

Browse files
authored
Merge pull request #33 from uqbar-dao/hf/fix-get_capability-equality
fix `get_capability()` params check
2 parents ca63613 + 437093e commit 5104a50

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//!
1616
pub use crate::kinode::process::standard::*;
1717
use serde::{Deserialize, Serialize};
18+
use serde_json::Value;
1819

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

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

0 commit comments

Comments
 (0)