diff --git a/predicates/bech32_address_2.md b/predicates/bech32_address_2.md index c2a17b9f14a..7ded8852508 100644 --- a/predicates/bech32_address_2.md +++ b/predicates/bech32_address_2.md @@ -42,12 +42,15 @@ bech32_address(Address, 'okp415wn30a9z4uc692s0kkx5fp5d4qfr3ac7sj9dqn'). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Address"] -results: -- substitutions: - - variable: Address - expression: "okp4-[163,167,23,244,162,175,49,162,170,15,181,141,68,134,141,168,18,56,247,30]" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Address"] + results: + - substitutions: + - variable: Address + expression: "okp4-[163,167,23,244,162,175,49,162,170,15,181,141,68,134,141,168,18,56,247,30]" ``` ### Decode Hrp and Address from a bech32 address @@ -68,14 +71,17 @@ bech32_address(-(Hrp, Address), 'okp415wn30a9z4uc692s0kkx5fp5d4qfr3ac7sj9dqn'). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Hrp", "Address"] -results: -- substitutions: - - variable: Hrp - expression: "okp4" - - variable: Address - expression: "[163,167,23,244,162,175,49,162,170,15,181,141,68,134,141,168,18,56,247,30]" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Hrp", "Address"] + results: + - substitutions: + - variable: Hrp + expression: "okp4" + - variable: Address + expression: "[163,167,23,244,162,175,49,162,170,15,181,141,68,134,141,168,18,56,247,30]" ``` ### Extract Address only for OKP4 bech32 address @@ -95,12 +101,15 @@ bech32_address(-(okp4, Address), 'okp415wn30a9z4uc692s0kkx5fp5d4qfr3ac7sj9dqn'). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Address"] -results: -- substitutions: - - variable: Address - expression: "[163,167,23,244,162,175,49,162,170,15,181,141,68,134,141,168,18,56,247,30]" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Address"] + results: + - substitutions: + - variable: Address + expression: "[163,167,23,244,162,175,49,162,170,15,181,141,68,134,141,168,18,56,247,30]" ``` ### Encode Address Pair into Bech32 Address @@ -119,12 +128,15 @@ bech32_address(-('okp4', [163,167,23,244,162,175,49,162,170,15,181,141,68,134,14 - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Bech32"] -results: -- substitutions: - - variable: Bech32 - expression: "okp415wn30a9z4uc692s0kkx5fp5d4qfr3ac7sj9dqn" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Bech32"] + results: + - substitutions: + - variable: Bech32 + expression: "okp415wn30a9z4uc692s0kkx5fp5d4qfr3ac7sj9dqn" ``` ### Check if a bech32 address is part of the okp4 protocol @@ -149,9 +161,12 @@ okp4_addr('okp41p8u47en82gmzfm259y6z93r9qe63l25dfwwng6'). - **Then** the answer we get is: ``` yaml -has_more: false -results: -- substitutions: +height: 42 +gas_used: 2222 +answer: + has_more: false + results: + - substitutions: ``` ### Error on Incorrect Bech32 Address format @@ -172,10 +187,13 @@ bech32_address(Address, okp4incorrect). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Address"] -results: -- error: "error(domain_error(encoding(bech32),okp4incorrect),[d,e,c,o,d,i,n,g, ,b,e,c,h,3,2, ,f,a,i,l,e,d,:, ,i,n,v,a,l,i,d, ,s,e,p,a,r,a,t,o,r, ,i,n,d,e,x, ,-,1],bech32_address/2)" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Address"] + results: + - error: "error(domain_error(encoding(bech32),okp4incorrect),[d,e,c,o,d,i,n,g, ,b,e,c,h,3,2, ,f,a,i,l,e,d,:, ,i,n,v,a,l,i,d, ,s,e,p,a,r,a,t,o,r, ,i,n,d,e,x, ,-,1],bech32_address/2)" ``` ### Error on Incorrect Bech32 Address type @@ -196,8 +214,11 @@ bech32_address(-('okp4', X), foo(bar)). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["X"] -results: -- error: "error(type_error(atom,foo(bar)),bech32_address/2)" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["X"] + results: + - error: "error(type_error(atom,foo(bar)),bech32_address/2)" ``` diff --git a/predicates/block_height_1.md b/predicates/block_height_1.md index 7f12d96cf48..a50a5447a30 100644 --- a/predicates/block_height_1.md +++ b/predicates/block_height_1.md @@ -43,12 +43,15 @@ block_height(Height). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Height"] -results: -- substitutions: - - variable: Height - expression: "100" +height: 100 +gas_used: 2222 +answer: + has_more: false + variables: ["Height"] + results: + - substitutions: + - variable: Height + expression: "100" ``` ### Check that the block height is greater than a certain value @@ -75,10 +78,13 @@ Height > 100. - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Height"] -results: -- substitutions: - - variable: Height - expression: "101" +height: 101 +gas_used: 2223 +answer: + has_more: false + variables: ["Height"] + results: + - substitutions: + - variable: Height + expression: "101" ``` diff --git a/predicates/block_time_1.md b/predicates/block_time_1.md index ef30d09dcdc..fa279111a87 100644 --- a/predicates/block_time_1.md +++ b/predicates/block_time_1.md @@ -43,12 +43,15 @@ block_time(Time). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Time"] -results: -- substitutions: - - variable: Time - expression: "1709550216" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Time"] + results: + - substitutions: + - variable: Time + expression: "1709550216" ``` ### Check that the block time is greater than a certain time @@ -76,10 +79,13 @@ Time > 1709550216. - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Time"] -results: -- substitutions: - - variable: Time - expression: "1709550217" +height: 42 +gas_used: 2223 +answer: + has_more: false + variables: ["Time"] + results: + - substitutions: + - variable: Time + expression: "1709550217" ``` diff --git a/predicates/consult_1.md b/predicates/consult_1.md index c37133987fc..60956062423 100644 --- a/predicates/consult_1.md +++ b/predicates/consult_1.md @@ -64,12 +64,15 @@ hello(Who). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Who"] -results: -- substitutions: - - variable: Who - expression: "['W',o,r,l,d,!]" +height: 42 +gas_used: 2224 +answer: + has_more: false + variables: ["Who"] + results: + - substitutions: + - variable: Who + expression: "['W',o,r,l,d,!]" ``` ### Consult a Prolog program which also consults another Prolog program @@ -117,23 +120,26 @@ response: | - **Given** the query: ``` prolog -consult('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false'), -program(X). + consult('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false'), + program(X). ``` - **When** the query is run (limited to 2 solutions) - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["X"] -results: -- substitutions: - - variable: X - expression: "b" -- substitutions: - - variable: X - expression: "a" +height: 42 +gas_used: 2223 +answer: + has_more: false + variables: ["X"] + results: + - substitutions: + - variable: X + expression: "b" + - substitutions: + - variable: X + expression: "a" ``` ### Consult several Prolog programs @@ -187,13 +193,16 @@ source_file(File). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["File"] -results: -- substitutions: - - variable: File - expression: "'cosmwasm:storage:okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%225d3933430d0a12794fae719e0db87b6ec5f549b2%22%7D%7D&base64Decode=false'" -- substitutions: - - variable: File - expression: "'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false'" +height: 42 +gas_used: 2223 +answer: + has_more: false + variables: ["File"] + results: + - substitutions: + - variable: File + expression: "'cosmwasm:storage:okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%225d3933430d0a12794fae719e0db87b6ec5f549b2%22%7D%7D&base64Decode=false'" + - substitutions: + - variable: File + expression: "'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false'" ``` diff --git a/predicates/current_output_1.md b/predicates/current_output_1.md new file mode 100644 index 00000000000..db1e0cad8be --- /dev/null +++ b/predicates/current_output_1.md @@ -0,0 +1,215 @@ +--- +sidebar_position: 10 +--- +[//]: # (This file is auto-generated. Please do not modify it yourself.) + +# current_output/1 + +## Description + +`current_output/1` is a predicate that unifies the given term with the current output stream. + +## Signature + +```text +current_output(-Stream) is det +``` + +where: + +- Stream represents the current output stream. + +This predicate connects to the default output stream available for user interactions, allowing the user to perform write operations. + +The outcome of the stream's content throughout the execution of a query is provided as a string within the user\_output field in the query's response. However, it's important to note that the maximum length of the output is constrained by the max\_query\_output\_size setting, meaning only the final max\_query\_output\_size bytes \(not characters\) of the output are included in the response. + +## Examples + +### Write a char to the current output + +This scenario demonstrates how to write a character to the current output, and get the content in the response of the +request. + +Here's the steps of the scenario: + +- **Given** the module configuration: + +``` json +{ + "limits": { + "max_user_output_size": "5" + } +} +``` + +- **Given** the program: + +``` prolog +write_char_to_user_output(C) :- + current_output(UserStream), % get the current output stream + put_char(UserStream, C). % write the char to the user stream +``` + +- **Given** the query: + +``` prolog +write_char_to_user_output(x). +``` + +- **When** the query is run +- **Then** the answer we get is: + +``` yaml +height: 42 +gas_used: 2241 +answer: + has_more: false + variables: + results: + - substitutions: +user_output: | + x +``` + +### Write characters to the current output (without limit) + +This scenario demonstrates how to write some characters to the current output, and get the content in the response of the +request. This is helpful for debugging purposes. + +Here's the steps of the scenario: + +- **Given** the module configuration: + +``` json +{ + "limits": { + "max_user_output_size": "15" + } +} +``` + +- **Given** the program: + +``` prolog +log_message(Message) :- + current_output(UserStream), % get the current output stream + write(UserStream, Message), % write the message to the user stream + put_char(UserStream, '\n'). +``` + +- **Given** the query: + +``` prolog +log_message('Hello world!'). +``` + +- **When** the query is run +- **Then** the answer we get is: + +``` yaml +height: 42 +gas_used: 2248 +answer: + has_more: false + variables: + results: + - substitutions: +user_output: | + Hello world! + +``` + +### Write characters to the current output (with limit) + +This scenario demonstrates the process of writing characters to the current user output, with a limit configured +in the logic module. So if the message is longer than this limit, the output will be truncated. + +Here's the steps of the scenario: + +- **Given** the module configuration: + +``` json +{ + "limits": { + "max_user_output_size": "5" + } +} +``` + +- **Given** the program: + +``` prolog +log_message(Message) :- + current_output(UserStream), % get the current output stream + write(UserStream, Message). % write the message to the user stream +``` + +- **Given** the query: + +``` prolog +log_message('Hello world!'). +``` + +- **When** the query is run +- **Then** the answer we get is: + +``` yaml +height: 42 +gas_used: 2241 +answer: + has_more: false + variables: + results: + - substitutions: +user_output: | + orld! +``` + +### Write UTF-8 character to the current output (with limit) + +This scenario illustrates the impact of UTF-8 characters on output limits measured in bytes, not character count. +Characters such as emojis require more space; for example, the wizard emoji (🧙) occupies 4 bytes, effectively counting +as four units. As a result, the limit is reached more quickly with these characters, which means that the number of +characters in the user output is less than expected. + +Here's the steps of the scenario: + +- **Given** the module configuration: + +``` json +{ + "limits": { + "max_user_output_size": "5" + } +} +``` + +- **Given** the program: + +``` prolog +log_message([]). +log_message([H|T]) :- + current_output(UserStream), + put_char(UserStream, H), + log_message(T). +``` + +- **Given** the query: + +``` prolog +log_message("Hello 🧙!"). +``` + +- **When** the query is run +- **Then** the answer we get is: + +``` yaml +height: 42 +gas_used: 2255 +answer: + has_more: false + variables: + results: + - substitutions: +user_output: "🧙!" +``` diff --git a/predicates/did_components_2.md b/predicates/did_components_2.md index 994af983c04..7b99e219e1d 100644 --- a/predicates/did_components_2.md +++ b/predicates/did_components_2.md @@ -1,5 +1,5 @@ --- -sidebar_position: 10 +sidebar_position: 11 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) diff --git a/predicates/ecdsa_verify_4.md b/predicates/ecdsa_verify_4.md index 98f9bdc99b9..465511f0f8c 100644 --- a/predicates/ecdsa_verify_4.md +++ b/predicates/ecdsa_verify_4.md @@ -1,5 +1,5 @@ --- -sidebar_position: 11 +sidebar_position: 12 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) diff --git a/predicates/eddsa_verify_4.md b/predicates/eddsa_verify_4.md index 7fe4308adfe..a27e5f4a53a 100644 --- a/predicates/eddsa_verify_4.md +++ b/predicates/eddsa_verify_4.md @@ -1,5 +1,5 @@ --- -sidebar_position: 12 +sidebar_position: 13 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) diff --git a/predicates/hex_bytes_2.md b/predicates/hex_bytes_2.md index 7efaa96c21f..a10d7fc9964 100644 --- a/predicates/hex_bytes_2.md +++ b/predicates/hex_bytes_2.md @@ -1,5 +1,5 @@ --- -sidebar_position: 13 +sidebar_position: 14 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) diff --git a/predicates/json_prolog_2.md b/predicates/json_prolog_2.md index 3384ff859c1..bd803abf752 100644 --- a/predicates/json_prolog_2.md +++ b/predicates/json_prolog_2.md @@ -1,5 +1,5 @@ --- -sidebar_position: 14 +sidebar_position: 15 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) diff --git a/predicates/open_3.md b/predicates/open_3.md index 3c01ad69c34..debe8deec6c 100644 --- a/predicates/open_3.md +++ b/predicates/open_3.md @@ -1,5 +1,5 @@ --- -sidebar_position: 16 +sidebar_position: 17 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) @@ -61,8 +61,11 @@ open( - **Then** the answer we get is: ``` yaml -has_more: false -variables: -results: -- substitutions: +height: 42 +gas_used: 2223 +answer: + has_more: false + variables: + results: + - substitutions: ``` diff --git a/predicates/open_4.md b/predicates/open_4.md index 8acfcf3367b..7ec4a306f1c 100644 --- a/predicates/open_4.md +++ b/predicates/open_4.md @@ -1,5 +1,5 @@ --- -sidebar_position: 15 +sidebar_position: 16 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) @@ -99,12 +99,15 @@ open(URI, read, _, []). - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["URI"] -results: -- substitutions: - - variable: URI - expression: "'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false'" +height: 42 +gas_used: 2228 +answer: + has_more: false + variables: ["URI"] + results: + - substitutions: + - variable: URI + expression: "'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false'" ``` ### Open an existing resource and read its content @@ -148,12 +151,15 @@ read_resource('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Chars"] -results: -- substitutions: - - variable: Chars - expression: "'Hello, World!'" +height: 42 +gas_used: 2224 +answer: + has_more: false + variables: ["Chars"] + results: + - substitutions: + - variable: Chars + expression: "'Hello, World!'" ``` ### Open an existing resource and read its content (base64-encoded) @@ -195,12 +201,15 @@ read_resource('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Chars"] -results: -- substitutions: - - variable: Chars - expression: "'Hello, World!'" +height: 42 +gas_used: 2224 +answer: + has_more: false + variables: ["Chars"] + results: + - substitutions: + - variable: Chars + expression: "'Hello, World!'" ``` ### Try to open a non-existing resource @@ -219,10 +228,13 @@ open('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Stream"] -results: -- error: "error(existence_error(source_sink,cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=foo),open/4)" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Stream"] + results: + - error: "error(existence_error(source_sink,cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=foo),open/4)" ``` ### Try to open a resource for writing @@ -242,10 +254,13 @@ open('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Stream"] -results: -- error: "error(permission_error(input,stream,cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=foo),open/4)" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Stream"] + results: + - error: "error(permission_error(input,stream,cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=foo),open/4)" ``` ### Try to open a resource for appending @@ -265,10 +280,13 @@ open('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Stream"] -results: -- error: "error(permission_error(input,stream,cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=foo),open/4)" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Stream"] + results: + - error: "error(permission_error(input,stream,cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=foo),open/4)" ``` ### Pass incorrect options to open/4 @@ -287,8 +305,11 @@ open('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts - **Then** the answer we get is: ``` yaml -has_more: false -variables: ["Stream"] -results: -- error: "error(domain_error(empty_list,[non_existing_option]),open/4)" +height: 42 +gas_used: 2222 +answer: + has_more: false + variables: ["Stream"] + results: + - error: "error(domain_error(empty_list,[non_existing_option]),open/4)" ``` diff --git a/predicates/read_string_3.md b/predicates/read_string_3.md index 7daa11f5abb..c59005cc33a 100644 --- a/predicates/read_string_3.md +++ b/predicates/read_string_3.md @@ -1,5 +1,5 @@ --- -sidebar_position: 17 +sidebar_position: 18 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) diff --git a/predicates/source_file_1.md b/predicates/source_file_1.md index 5730d22a63b..17052a0adce 100644 --- a/predicates/source_file_1.md +++ b/predicates/source_file_1.md @@ -1,5 +1,5 @@ --- -sidebar_position: 18 +sidebar_position: 19 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) diff --git a/predicates/string_bytes_3.md b/predicates/string_bytes_3.md index 9e4c3cde452..c58eb1954c8 100644 --- a/predicates/string_bytes_3.md +++ b/predicates/string_bytes_3.md @@ -1,5 +1,5 @@ --- -sidebar_position: 19 +sidebar_position: 20 --- [//]: # (This file is auto-generated. Please do not modify it yourself.) diff --git a/predicates/uri_encoded_3.md b/predicates/uri_encoded_3.md index 3697e6e2277..983b97fbe48 100644 --- a/predicates/uri_encoded_3.md +++ b/predicates/uri_encoded_3.md @@ -1,5 +1,5 @@ --- -sidebar_position: 20 +sidebar_position: 21 --- [//]: # (This file is auto-generated. Please do not modify it yourself.)