diff --git a/contracts/okp4-law-stone/examples/multiple-sources/README.md b/contracts/okp4-law-stone/examples/multiple-sources/README.md index 02682e51..dbbe92ea 100644 --- a/contracts/okp4-law-stone/examples/multiple-sources/README.md +++ b/contracts/okp4-law-stone/examples/multiple-sources/README.md @@ -23,14 +23,14 @@ Where: - `{contract_name}`: Only informative, represents the corresponding smart contract name or type (e.g. `okp4-objectarium`); - `{contract_address}`: The smart contract to query, concerning the `okp4-law-stone` it must be a `okp4-objectarium` contract; -- `{contract_query}`: The JSON query to perform on the targeted smart contract, URL encoded. In our case an `ObjectData` query, for example: `%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`; +- `{contract_query}`: The JSON query to perform on the targeted smart contract, URL encoded. In our case an `ObjectData` query, for example: `%7B%22object_data%22%3A%7B%22id%22%3A%22b118d79b4a368028b34d564448e5f1082e098613434370f3c15d6a2bf9979dfc%22%7D%7D`; ## Instantiate First the `template.pl` program must be stored on a `okp4-objectarium` and the `gov.pl` updated with the right URI in the `consult(File).` predicate, the URI should be in the form: ```bash -cosmwasm:okp4-objectarium:${STORAGE_ADDRESS}?query=%7B%22object_data%22%3A%7B%22id%22%3A%221a88ca1632c7323c0aa594000cda26ed9f48b36351c29c3d1e35e0a0474e862e%22%7D%7D +cosmwasm:okp4-objectarium:${STORAGE_ADDRESS}?query=%7B%22object_data%22%3A%7B%22id%22%3A%22b118d79b4a368028b34d564448e5f1082e098613434370f3c15d6a2bf9979dfc%22%7D%7D ``` The instantiate will take as parameters the base64 encoded program and the address of a `okp4-objectarium` contract, on which the program will be stored and pinned, the `template.pl` object will also be pinned to ensure all the needed resources stays available: @@ -41,7 +41,6 @@ okp4d tx wasm instantiate $CODE_ID \ --from $ADDR \ --admin $ADMIN_ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"program\":\"$(cat gov.pl | base64)\", \"storage_address\": \"$STORAGE_ADDR\"}" ``` @@ -53,7 +52,7 @@ By using the `Ask` query we can provide Prolog predicates to be evaluated agains ```bash okp4d query wasm contract-state smart $CONTRACT_ADDR \ - "{\"ask\": {\"query\": \"can('change_governance', 'did:key:okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6').\"}}" + "{\"ask\": {\"query\": \"can('change_governance', 'did:example:okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6').\"}}" ``` ## Break @@ -68,6 +67,5 @@ By breaking the stone, you will not be able to query it anymore. okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ '"break_stone"' ``` diff --git a/contracts/okp4-law-stone/examples/multiple-sources/gov.pl b/contracts/okp4-law-stone/examples/multiple-sources/gov.pl index b760aa1c..b654fb5b 100644 --- a/contracts/okp4-law-stone/examples/multiple-sources/gov.pl +++ b/contracts/okp4-law-stone/examples/multiple-sources/gov.pl @@ -1,9 +1,9 @@ -:- consult('cosmwasm:okp4-objectarium:${STORAGE_ADDRESS}?query=%7B%22object_data%22%3A%7B%22id%22%3A%221a88ca1632c7323c0aa594000cda26ed9f48b36351c29c3d1e35e0a0474e862e%22%7D%7D'). +:- consult('cosmwasm:okp4-objectarium:${STORAGE_ADDRESS}?query=%7B%22object_data%22%3A%7B%22id%22%3A%22b118d79b4a368028b34d564448e5f1082e098613434370f3c15d6a2bf9979dfc%22%7D%7D'). admin_addr('okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6'). allow_denom('uknow'). -allow_did_method('key'). +allow_did_method('example'). allow_addr(Addr) :- bech32_address(-('okp4', _), Addr). min_exec_workflow_amount(1000000). diff --git a/contracts/okp4-law-stone/examples/multiple-sources/template.pl b/contracts/okp4-law-stone/examples/multiple-sources/template.pl index 33c1a6e3..6becce5a 100644 --- a/contracts/okp4-law-stone/examples/multiple-sources/template.pl +++ b/contracts/okp4-law-stone/examples/multiple-sources/template.pl @@ -1,5 +1,5 @@ valid_did(DID, Addr) :- - did_components(DID, did(Method, Addr, _, _, _)), + did_components(DID, did_components(Method, Addr, _, _, _)), allow_did_method(Method), allow_addr(Addr). diff --git a/contracts/okp4-law-stone/examples/single-source/README.md b/contracts/okp4-law-stone/examples/single-source/README.md index 4f626b24..cf36b0de 100644 --- a/contracts/okp4-law-stone/examples/single-source/README.md +++ b/contracts/okp4-law-stone/examples/single-source/README.md @@ -8,9 +8,9 @@ The spirit here is to provide a `okp4-law-stone` smart contract instance providi You'll find in the [gov.pl](gov.pl) Prolog program some predicates defining the rules allowing to perform some typical Dataspaces actions. -The `can(Action, DID)` predicate will allow or not an action for a `did` (i.e. Decentralized Identifier), a `did` being expected to have the form: `did:key:${OKP4_ADDRESS}`. We can describe the action rules as follows: +The `can(Action, DID)` predicate will allow or not an action for a `did` (i.e. Decentralized Identifier), a `did` being expected to have the form: `did:example:${OKP4_ADDRESS}`. We can describe the action rules as follows: -- `change_governance`: Only the did admin can do it: `did:key:okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6`; +- `change_governance`: Only the did admin can do it: `did:example:okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6`; - `exec_workflow`: Only a valid DID having a minimum spendable of `1000000uknow`; - `create_dataset` Only a valid DID having a minimum spendable of `10000uknow`; - `create_service` Only a valid DID having a minimum spendable of `100000uknow`; @@ -25,7 +25,6 @@ okp4d tx wasm instantiate $CODE_ID \ --from $ADDR \ --admin $ADMIN_ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"program\":\"$(cat gov.pl | base64)\", \"storage_address\": \"$STORAGE_ADDR\"}" ``` @@ -37,7 +36,7 @@ By using the `Ask` query we can provide Prolog predicates to be evaluated agains ```bash okp4d query wasm contract-state smart $CONTRACT_ADDR \ - "{\"ask\": {\"query\": \"can('change_governance', 'did:key:okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6').\"}}" + "{\"ask\": {\"query\": \"can('change_governance', 'did:example:okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6').\"}}" ``` ## Break @@ -52,6 +51,5 @@ By breaking the stone, you will not be able to query it anymore. okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ '"break_stone"' ``` diff --git a/contracts/okp4-law-stone/examples/single-source/gov.pl b/contracts/okp4-law-stone/examples/single-source/gov.pl index bdf9d2d7..94f93d44 100644 --- a/contracts/okp4-law-stone/examples/single-source/gov.pl +++ b/contracts/okp4-law-stone/examples/single-source/gov.pl @@ -1,11 +1,11 @@ admin_addr('okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6'). allow_denom('uknow'). -allow_did_method('key'). +allow_did_method('example'). allow_addr(Addr) :- bech32_address(-('okp4', _), Addr). valid_did(DID, Addr) :- - did_components(DID, did(Method, Addr, _, _, _)), + did_components(DID, did_components(Method, Addr, _, _, _)), allow_did_method(Method), allow_addr(Addr). diff --git a/contracts/okp4-law-stone/src/contract.rs b/contracts/okp4-law-stone/src/contract.rs index 94d7b202..cf26226a 100644 --- a/contracts/okp4-law-stone/src/contract.rs +++ b/contracts/okp4-law-stone/src/contract.rs @@ -272,7 +272,7 @@ mod tests { use okp4_logic_bindings::testing::mock::mock_dependencies_with_logic_handler; use okp4_logic_bindings::uri::CosmwasmUri; use okp4_logic_bindings::{ - Answer, AskResponse, LogicCustomQuery, Result as LogicResult, Substitution, Term, + Answer, AskResponse, LogicCustomQuery, Result as LogicResult, Substitution, }; use okp4_objectarium::msg::PageInfo; use std::collections::VecDeque; @@ -300,15 +300,13 @@ mod tests { gas_used: 1000, answer: Some(Answer { success: true, + error: None, has_more: false, variables: vec!["Files".to_string()], results: vec![LogicResult { substitutions: vec![Substitution { variable: "Files".to_string(), - term: Term { - name: deps_name, - arguments: vec![], - }, + expression: deps_name, }], }], }), @@ -462,15 +460,13 @@ mod tests { gas_used: 1000, answer: Some(Answer { success: true, + error: None, has_more: false, variables: vec!["Foo".to_string()], results: vec![LogicResult { substitutions: vec![Substitution { variable: "Foo".to_string(), - term: Term { - name: "bar".to_string(), - arguments: vec![], - }, + expression: "bar".to_string(), }], }], }), diff --git a/contracts/okp4-law-stone/src/helper.rs b/contracts/okp4-law-stone/src/helper.rs index ce31050c..3b33b1dd 100644 --- a/contracts/okp4-law-stone/src/helper.rs +++ b/contracts/okp4-law-stone/src/helper.rs @@ -53,8 +53,7 @@ pub fn ask_response_to_objects( .flat_map(|r: &okp4_logic_bindings::Result| r.substitutions.clone()) .filter(|s| s.variable == variable) .map(|s: Substitution| { - s.term - .parse() + s.parse_expression() .map_err(|e| ContractError::LogicAskResponse(LogicAskResponseError::Parse(e))) .and_then(term_as_vec) }) @@ -72,7 +71,7 @@ pub fn ask_response_to_objects( mod tests { use super::*; use okp4_logic_bindings::error::TermParseError; - use okp4_logic_bindings::{Answer, Term}; + use okp4_logic_bindings::Answer; #[test] fn logic_to_objects() { @@ -105,15 +104,13 @@ mod tests { results: vec![okp4_logic_bindings::Result { substitutions: vec![Substitution { variable: "X".to_string(), - term: Term { - name: case.0, - arguments: vec![], - } + expression: case.0, }] }], has_more: false, success: true, variables: vec![], + error: None, }), height: 1, gas_used: 1, diff --git a/contracts/okp4-objectarium/README.md b/contracts/okp4-objectarium/README.md index 7fcda1f1..040c3b25 100644 --- a/contracts/okp4-objectarium/README.md +++ b/contracts/okp4-objectarium/README.md @@ -63,7 +63,6 @@ okp4d tx wasm instantiate $CODE_ID \ --from $ADDR \ --admin $ADMIN_ADDR \ --gas 1000000 \ - --broadcast-mode block \ '{"bucket":"my-bucket"}' ``` @@ -75,7 +74,6 @@ We can store an object by providing its data in base64 encoded, we can pin the s okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"store_object\":{\"data\": \"$(cat my-data | base64)\",\"pin\":true}}" ``` @@ -87,13 +85,11 @@ With the following commands we can pin and unpin existing objects: okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"pin_object\":{\"id\": \"$OBJECT_ID\"}}" okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"unpin_object\":{\"id\": \"$OBJECT_ID\"}}" ``` @@ -103,7 +99,6 @@ And if an object is not pinned, or pinned by the sender of transaction, we can r okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"forget_object\":{\"id\": \"$OBJECT_ID\"}}" ``` diff --git a/docs/okp4-law-stone.md b/docs/okp4-law-stone.md index fbc715a4..5ba60f43 100644 --- a/docs/okp4-law-stone.md +++ b/docs/okp4-law-stone.md @@ -99,6 +99,7 @@ This is only needed as serde-json-\{core,wasm\} has a horrible encoding for Vec& | property | description | | ----------- | -------------------------------------------------- | +| `error` | **string\|null**. | | `has_more` | _(Required.) _ **boolean**. | | `results` | _(Required.) _ **Array<[Result](#result)>**. | | `success` | _(Required.) _ **boolean**. | @@ -120,18 +121,11 @@ A string containing Base64-encoded data. ### Substitution -| property | description | -| ---------- | -------------------------- | -| `term` | _(Required.) _ **object**. | -| `variable` | _(Required.) _ **string**. | - -### Term - -| property | description | -| ----------- | ---------------------------------------------- | -| `arguments` | _(Required.) _ **Array<[Term](#term)>**. | -| `name` | _(Required.) _ **string**. | +| property | description | +| ------------ | -------------------------- | +| `expression` | _(Required.) _ **string**. | +| `variable` | _(Required.) _ **string**. | --- -_Rendered by [Fadroma](https://fadroma.tech) ([@fadroma/schema 1.1.0](https://www.npmjs.com/package/@fadroma/schema)) from `okp4-law-stone.json` (`175af2aa8dc69420`)_ +_Rendered by [Fadroma](https://fadroma.tech) ([@fadroma/schema 1.1.0](https://www.npmjs.com/package/@fadroma/schema)) from `okp4-law-stone.json` (`b4af0e49e5a861ed`)_ diff --git a/docs/okp4-objectarium.md b/docs/okp4-objectarium.md index 51fd29b6..cea0f103 100644 --- a/docs/okp4-objectarium.md +++ b/docs/okp4-objectarium.md @@ -63,7 +63,6 @@ okp4d tx wasm instantiate $CODE_ID \ --from $ADDR \ --admin $ADMIN_ADDR \ --gas 1000000 \ - --broadcast-mode block \ '{"bucket":"my-bucket"}' ``` @@ -75,7 +74,6 @@ We can store an object by providing its data in base64 encoded, we can pin the s okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"store_object\":{\"data\": \"$(cat my-data | base64)\",\"pin\":true}}" ``` @@ -87,13 +85,11 @@ With the following commands we can pin and unpin existing objects: okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"pin_object\":{\"id\": \"$OBJECT_ID\"}}" okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"unpin_object\":{\"id\": \"$OBJECT_ID\"}}" ``` @@ -103,7 +99,6 @@ And if an object is not pinned, or pinned by the sender of transaction, we can r okp4d tx wasm execute $CONTRACT_ADDR \ --from $ADDR \ --gas 1000000 \ - --broadcast-mode block \ "{\"forget_object\":{\"id\": \"$OBJECT_ID\"}}" ``` @@ -516,4 +511,4 @@ A string containing a 128-bit integer in decimal representation. --- -_Rendered by [Fadroma](https://fadroma.tech) ([@fadroma/schema 1.1.0](https://www.npmjs.com/package/@fadroma/schema)) from `okp4-objectarium.json` (`2b01e2531b94fc0e`)_ +_Rendered by [Fadroma](https://fadroma.tech) ([@fadroma/schema 1.1.0](https://www.npmjs.com/package/@fadroma/schema)) from `okp4-objectarium.json` (`37a6830a8446a597`)_ diff --git a/packages/okp4-logic-bindings/src/lib.rs b/packages/okp4-logic-bindings/src/lib.rs index 0c578597..28117b26 100644 --- a/packages/okp4-logic-bindings/src/lib.rs +++ b/packages/okp4-logic-bindings/src/lib.rs @@ -3,7 +3,7 @@ mod query; mod term_parser; pub mod uri; -pub use query::{Answer, AskResponse, LogicCustomQuery, Result, Substitution, Term}; +pub use query::{Answer, AskResponse, LogicCustomQuery, Result, Substitution}; pub use term_parser::TermValue; // Exposed for testing only diff --git a/packages/okp4-logic-bindings/src/query.rs b/packages/okp4-logic-bindings/src/query.rs index b271cbfd..b678e984 100644 --- a/packages/okp4-logic-bindings/src/query.rs +++ b/packages/okp4-logic-bindings/src/query.rs @@ -24,6 +24,7 @@ pub struct AskResponse { #[serde(rename_all = "snake_case")] pub struct Answer { pub success: bool, + pub error: Option, pub has_more: bool, pub variables: Vec, pub results: Vec, @@ -39,19 +40,12 @@ pub struct Result { #[serde(rename_all = "snake_case")] pub struct Substitution { pub variable: String, - pub term: Term, + pub expression: String, } -#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)] -#[serde(rename_all = "snake_case")] -pub struct Term { - pub name: String, - pub arguments: Vec, -} - -impl Term { - pub fn parse(self) -> std::result::Result { - from_str(self.name.as_str()) +impl Substitution { + pub fn parse_expression(self) -> std::result::Result { + from_str(self.expression.as_str()) } } @@ -62,11 +56,11 @@ mod tests { #[test] fn term_parse() { assert_eq!( - Term { - name: "'hello'".to_string(), - arguments: vec![], + Substitution { + variable: "X".to_string(), + expression: "'hello'".to_string(), } - .parse(), + .parse_expression(), Ok(TermValue::Value("hello".to_string())) ); }