keyword_search_contract/
lib.rs

1mod error;
2pub mod v1;
3
4pub use crate::error::Error;
5use platform_value::{Identifier, IdentifierBytes32};
6use platform_version::version::PlatformVersion;
7use serde_json::Value;
8
9pub const ID_BYTES: [u8; 32] = [
10    161, 147, 167, 153, 40, 225, 219, 101, 50, 156, 28, 146, 150, 52, 114, 213, 56, 154, 106, 15,
11    79, 66, 18, 156, 94, 146, 216, 104, 140, 93, 170, 215,
12];
13
14pub const OWNER_ID_BYTES: [u8; 32] = [0; 32];
15
16pub const ID: Identifier = Identifier(IdentifierBytes32(ID_BYTES));
17pub const OWNER_ID: Identifier = Identifier(IdentifierBytes32(OWNER_ID_BYTES));
18pub fn load_definitions(platform_version: &PlatformVersion) -> Result<Option<Value>, Error> {
19    match platform_version.system_data_contracts.keyword_search {
20        1 => Ok(None),
21        version => Err(Error::UnknownVersionMismatch {
22            method: "keyword_search_contract::load_definitions".to_string(),
23            known_versions: vec![1],
24            received: version,
25        }),
26    }
27}
28pub fn load_documents_schemas(platform_version: &PlatformVersion) -> Result<Value, Error> {
29    match platform_version.system_data_contracts.keyword_search {
30        1 => v1::load_documents_schemas(),
31        version => Err(Error::UnknownVersionMismatch {
32            method: "keyword_search_contract::load_documents_schemas".to_string(),
33            known_versions: vec![1],
34            received: version,
35        }),
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use base58::FromBase58;
42
43    use super::*;
44
45    #[test]
46    /// Ensure that the ID constant matches the expected value
47    /// and that it can be encoded to base58 correctly.
48    fn test_id() {
49        assert_eq!(
50            ID,
51            Identifier(IdentifierBytes32(ID_BYTES)),
52            "ID should match the expected value"
53        );
54
55        let base58_decoded = "BsjE6tQxG47wffZCRQCovFx5rYrAYYC3rTVRWKro27LA"
56            .from_base58()
57            .unwrap();
58        assert_eq!(
59            base58_decoded, ID_BYTES,
60            "ID should match the base58 decoded value"
61        );
62    }
63}