generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #602 from okp4/test/stream
Test/stream
- Loading branch information
Showing
24 changed files
with
1,181 additions
and
484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
--- | ||
sidebar_position: 8 | ||
--- | ||
[//]: # (This file is auto-generated. Please do not modify it yourself.) | ||
|
||
# consult/1 | ||
|
||
## Description | ||
|
||
`consult/1` is a predicate which read files as Prolog source code. | ||
|
||
## Signature | ||
|
||
```text | ||
consult(+Files) is det | ||
``` | ||
|
||
where: | ||
|
||
- Files represents the source files to be loaded. It can be an atom or a list of atoms representing the source files. | ||
|
||
The Files argument are typically URIs that point to the sources file to be loaded through the Virtual File System \(VFS\). Please refer to the open/4 predicate for more information about the VFS. | ||
|
||
## Examples | ||
|
||
### Consult a Prolog program | ||
|
||
This scenario demonstrates how to consult (load) a Prolog program from a CosmWasm smart contract. | ||
|
||
Assuming the existence of a CosmWasm smart contract configured to store a Prolog program, we construct a URI to specifically | ||
identify this smart contract and pinpoint the Prolog program we want to consult via a query message. | ||
|
||
Here's the steps of the scenario: | ||
|
||
- **Given** the CosmWasm smart contract "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht" and the behavior: | ||
|
||
``` yaml | ||
message: | | ||
{ | ||
"object_data": { | ||
"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05" | ||
} | ||
} | ||
response: | | ||
hello("World!"). | ||
``` | ||
- **Given** the program: | ||
``` prolog | ||
:- | ||
uri_encoded(query_value, '{"object_data":{"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05"}}', Query), | ||
atom_concat('cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?base64Decode=false&query=', Query, URI), | ||
consult(URI). | ||
``` | ||
|
||
- **Given** the query: | ||
|
||
``` prolog | ||
hello(Who). | ||
``` | ||
|
||
- **When** the query is run | ||
- **Then** the answer we get is: | ||
|
||
``` yaml | ||
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 | ||
This scenario demonstrates the capability of a Prolog program to consult another Prolog program. This is useful for | ||
modularizing Prolog programs and reusing code. | ||
Here's the steps of the scenario: | ||
- **Given** the CosmWasm smart contract "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht" and the behavior: | ||
``` yaml | ||
message: | | ||
{ | ||
"object_data": { | ||
"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05" | ||
} | ||
} | ||
response: | | ||
:- consult('cosmwasm:storage:okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%225d3933430d0a12794fae719e0db87b6ec5f549b2%22%7D%7D&base64Decode=false'). | ||
a. | ||
``` | ||
- **Given** the CosmWasm smart contract "okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk" and the behavior: | ||
``` yaml | ||
message: | | ||
{ | ||
"object_data": { | ||
"id": "5d3933430d0a12794fae719e0db87b6ec5f549b2" | ||
} | ||
} | ||
response: | | ||
b. | ||
``` | ||
- **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'), | ||
a, b. | ||
``` | ||
|
||
- **When** the query is run (limited to 2 solutions) | ||
- **Then** the answer we get is: | ||
|
||
``` yaml | ||
has_more: false | ||
variables: | ||
results: | ||
- substitutions: | ||
``` | ||
### Consult several Prolog programs | ||
This scenario demonstrates the consultation of several Prolog programs from different CosmWasm smart contracts. | ||
Here's the steps of the scenario: | ||
- **Given** the CosmWasm smart contract "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht" and the behavior: | ||
``` yaml | ||
message: | | ||
{ | ||
"object_data": { | ||
"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05" | ||
} | ||
} | ||
response: | | ||
program(a). | ||
``` | ||
- **Given** the CosmWasm smart contract "okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk" and the behavior: | ||
``` yaml | ||
message: | | ||
{ | ||
"object_data": { | ||
"id": "5d3933430d0a12794fae719e0db87b6ec5f549b2" | ||
} | ||
} | ||
response: | | ||
program(b). | ||
``` | ||
- **Given** the program: | ||
``` prolog | ||
:- consult([ | ||
'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false', | ||
'cosmwasm:storage:okp412ssv28mzr02jffvy4x39akrpky9ykfafzyjzmvgsqqdw78yjevpqgmqnmk?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%225d3933430d0a12794fae719e0db87b6ec5f549b2%22%7D%7D&base64Decode=false' | ||
]). | ||
``` | ||
|
||
- **Given** the query: | ||
|
||
``` prolog | ||
source_file(File). | ||
``` | ||
|
||
- **When** the query is run (limited to 2 solutions) | ||
- **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'" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
sidebar_position: 16 | ||
--- | ||
[//]: # (This file is auto-generated. Please do not modify it yourself.) | ||
|
||
# open/3 | ||
|
||
## Description | ||
|
||
`open/3` is a predicate which opens a stream to a source or sink. This predicate is a shorthand for open/4 with an empty list of options. | ||
|
||
## Signature | ||
|
||
```text | ||
open(+SourceSink, +Mode, -Stream) | ||
``` | ||
|
||
where: | ||
|
||
- SourceSink is an atom representing the source or sink of the stream, which is typically a URI. | ||
- Mode is an atom representing the mode of the stream to be opened. It can be one of "read", "write", or "append". | ||
- Stream is the stream to be opened. | ||
|
||
open/3 gives True when SourceSink can be opened in Mode. | ||
|
||
## Examples | ||
|
||
### Open a resource for reading | ||
|
||
This scenario showcases the procedure for accessing a resource stored within a CosmWasm smart contract for reading | ||
purposes and obtaining the stream's properties. | ||
|
||
See the `open/4` predicate for a more detailed example. | ||
|
||
Here's the steps of the scenario: | ||
|
||
- **Given** the CosmWasm smart contract "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht" and the behavior: | ||
|
||
``` yaml | ||
message: | | ||
{ | ||
"object_data": { | ||
"id": "4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05" | ||
} | ||
} | ||
response: | | ||
Hello, World! | ||
``` | ||
- **Given** the query: | ||
``` prolog | ||
open( | ||
'cosmwasm:storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D&base64Decode=false', | ||
read, | ||
_ | ||
). | ||
``` | ||
|
||
- **When** the query is run | ||
- **Then** the answer we get is: | ||
|
||
``` yaml | ||
has_more: false | ||
variables: | ||
results: | ||
- substitutions: | ||
``` |
Oops, something went wrong.