update aqua, fix typos

This commit is contained in:
boneyard93501 2021-08-14 21:00:37 -05:00
parent ae3b23c99e
commit c958dbb8e1
8 changed files with 91 additions and 360 deletions

View File

@ -33,7 +33,7 @@ cargo install mrepl
cargo install marine
npm -g install @fluencelabs/aqua-cli
npm -g install @fluencelabs/flidst
npm -g install @fluencelabs/fldist
```
To compile the code to the wasi target:
@ -114,7 +114,7 @@ func ts_getter(node: string) -> []u64:
res: *u64
on node:
k <- Op.string_to_b58(node)
nodes <- Kademlia.neighborhood(k, false)
nodes <- Kademlia.neighborhood(k, nil, nil)
for n <- nodes par:
on n:
try:

View File

@ -14,7 +14,7 @@
(seq
(seq
(call node ("op" "string_to_b58") [node] k)
(call node ("kad" "neighborhood") [k false] nodes)
(call node ("kad" "neighborhood") [k $nil $nil] nodes)
)
(fold nodes n
(par

View File

@ -1,206 +0,0 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.8-157
*
*/
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
export async function ts_getter(client: FluenceClient, node: string, config?: {ttl?: number}): Promise<number[]> {
let request: RequestFlow;
const promise = new Promise<number[]>((resolve, reject) => {
request = new RequestFlowBuilder()
.disableInjections()
.withTTL(config?.ttl || 5000)
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "node") [] node)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(call node ("op" "string_to_b58") [node] k)
(call node ("kad" "neighborhood") [k false] nodes)
)
(fold nodes n
(par
(seq
(xor
(call n ("peer" "timestamp_ms") [] $res)
(null)
)
(call node ("op" "noop") [])
)
(next n)
)
)
)
(call node ("op" "identity") [$res.$.[9]!])
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call -relay- ("op" "noop") [])
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [$res])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.on('getDataSrv', 'node', () => {return node;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for ts_getter');
})
.build();
});
await client.initiateFlow(request!);
return promise;
}
export async function ts_oracle(client: FluenceClient, node: string, oracle_service_id: string, min_points: number, config?: {ttl?: number}): Promise<{err_str:string;freq:number;mode:number;n:number;raw_data:number[]}> {
let request: RequestFlow;
const promise = new Promise<{err_str:string;freq:number;mode:number;n:number;raw_data:number[]}>((resolve, reject) => {
request = new RequestFlowBuilder()
.disableInjections()
.withTTL(config?.ttl || 5000)
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "node") [] node)
)
(call %init_peer_id% ("getDataSrv" "oracle_service_id") [] oracle_service_id)
)
(call %init_peer_id% ("getDataSrv" "min_points") [] min_points)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(call node ("op" "string_to_b58") [node] k)
(call node ("kad" "neighborhood") [k false] nodes)
)
(fold nodes n
(par
(seq
(xor
(call n ("peer" "timestamp_ms") [] $res)
(null)
)
(call node ("op" "noop") [])
)
(next n)
)
)
)
(call node ("op" "identity") [$res.$.[9]!])
)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(call -relay- ("op" "noop") [])
)
)
)
(xor
(call node (oracle_service_id "point_estimate") [$res min_points] oracle)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
)
(call -relay- ("op" "noop") [])
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [oracle])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'oracle_service_id', () => {return oracle_service_id;});
h.on('getDataSrv', 'min_points', () => {return min_points;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for ts_oracle');
})
.build();
});
await client.initiateFlow(request!);
return promise;
}

View File

@ -1,48 +0,0 @@
(xor
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "node") [] node)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(call node ("op" "string_to_b58") [node] k)
(call node ("kad" "neighborhood") [k false] nodes)
)
(fold nodes n
(par
(seq
(xor
(call n ("peer" "timestamp_ms") [] $res)
(null)
)
(call node ("op" "noop") [])
)
(next n)
)
)
)
(call node ("op" "identity") [$res.$.[9]!])
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call -relay- ("op" "noop") [])
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [$res])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)

View File

@ -1,66 +0,0 @@
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "node") [] node)
)
(call %init_peer_id% ("getDataSrv" "oracle_service_id") [] oracle_service_id)
)
(call %init_peer_id% ("getDataSrv" "min_points") [] min_points)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(call node ("op" "string_to_b58") [node] k)
(call node ("kad" "neighborhood") [k false] nodes)
)
(fold nodes n
(par
(seq
(xor
(call n ("peer" "timestamp_ms") [] $res)
(null)
)
(call node ("op" "noop") [])
)
(next n)
)
)
)
(call node ("op" "identity") [$res.$.[9]!])
)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(call -relay- ("op" "noop") [])
)
)
)
(xor
(call node (oracle_service_id "point_estimate") [$res min_points] oracle)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
)
(call -relay- ("op" "noop") [])
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [oracle])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)

View File

@ -4,6 +4,16 @@ alias Field : []string
alias Argument : []string
alias Bytes : []u8
alias PeerId : string
alias Pairs : [][]string
alias Base58String : string
alias Hash : string
-- There are two types of dependencies: named and by-hash.
-- name:foobar specifies dependency by module name, points to a module with import name 'foobar'
-- hash:04dc884... specifies dependency by module hash
-- By-hash dependencies are preffered since they are determenistic
-- while by-name dependency can yield different modules at different points in time
alias Dependency : string
data Service:
id: string
@ -24,11 +34,6 @@ data Interface:
function_signatures: []FunctionSignature
record_types: []RecordType
data ServiceInfo:
blueprint_id: string
service_id: string
interface: Interface
data Info:
external_addresses: []string
@ -42,12 +47,12 @@ data Module:
data AddBlueprint:
name: string
dependencies: []string
dependencies: []Dependency
data Blueprint:
id: string
name: string
dependencies: []string
dependencies: []Dependency
data ScriptInfo:
id: string
@ -63,20 +68,25 @@ data Contact:
service Op("op"):
-- does nothing
noop()
-- returns length of the passed array
array_length(array: []string) -> u32
-- takes any number of arguments and wraps them into a single array
array(a: string, b: string, c: string) -> []string
array(a: string, b: ?string, c: ?string, d: ?string) -> []string
-- takes any number of arrays and flattens them by concatenating
concat(a: []string, b: []string, c: []string) -> []string
concat(a: []string, b: ?[]string, c: ?[]string, d: ?[]string) -> []string
-- takes a single argument and returns it back
identity(s: ?string) -> ?string
string_to_b58(s: string) -> string
string_from_b58(b: string) -> string
bytes_to_b58(bs: []u8) -> string
bytes_from_b58(b: string) -> []u8
string_to_b58(s: string) -> Base58String
string_from_b58(b: Base58String) -> string
bytes_to_b58(bs: []u8) -> Base58String
bytes_from_b58(b: Base58String) -> []u8
-- Applies SHA256 to the given string
-- Argument: s - string to apply sha256 to
-- Argument: s - string to apply sha256 to (hash is applied to utf8 bytes of s)
-- Returns: returns sha256 multihash encoded as base58
sha256_string(s: string) -> string
sha256_string(s: string) -> Base58String
-- concatenate strings (in AIR it takes any number of arguments)
concat_strings(a: string, b: string) -> string
service Peer("peer"):
-- Checks if there is a direct connection to the peer identified by a given PeerId
@ -86,10 +96,10 @@ service Peer("peer"):
-- Initiates a connection to the specified peer
-- Arguments:
-- PeerId id of the target peer
-- [Multiaddr] an array of target peer's addresses
-- id - id of the target peer
-- multiaddrs an array of target peer's addresses
-- Returns: bool - true if connection was successful
connect(id: PeerId, multiaddrs: []string) -> bool
connect(id: PeerId, multiaddrs: ?[]string) -> bool
-- Resolves the contact of a peer via Kademlia
-- Argument: PeerId id of the target peer
-- Returns: Contact - true if connection was successful
@ -107,26 +117,30 @@ service Peer("peer"):
service Kademlia("kad"):
-- Instructs node to return the locally-known nodes
-- in the Kademlia neighborhood for a given key
neighborhood(key: PeerId, already_hashed: bool) -> []PeerId
-- Arguments:
-- key base58 string
-- already_hashed default false; if set to true, key is considered to be a SHA256 multihash
-- count default 20; limits number of returned nodes
neighborhood(key: Base58String, already_hashed: ?bool, count: ?u32) -> []PeerId
-- Merges given lists and sorts them by distance to target
-- Arguments:
-- target base58 string; result is sorted by XOR distance to target
-- left list of base58 strings
-- right list of base58 strings
-- count how many items to return
-- target base58 string; result is sorted by XOR distance to target
-- left list of base58 strings
-- right list of base58 strings
-- count how many items to return; default 20
-- Returns: list of base58 strings sorted by distance to target; list will contain at most count elements
merge(target: string, left: []string, right: []string, count: u32) -> []string
merge(target: Base58String, left: []string, right: []string, count: ?u32) -> []string
service Srv("srv"):
-- Used to create a service on a certain node
-- Arguments:
-- blueprint_id ID of the blueprint that has been added to the node specified in the service call by the dist add_blueprint service.
-- blueprint_id ID of the blueprint that has been added to the node specified in the service call by the dist add_blueprint service.
-- Returns: service_id the service ID of the created service.
create(blueprint_id: string) -> string
-- Used to remove a service from a certain node
-- Arguments:
-- service_id ID of the service to remove
-- service_id ID of the service to remove
remove(service_id: string)
-- Returns a list of services running on a peer
@ -134,9 +148,9 @@ service Srv("srv"):
-- Adds an alias on service, so, service could be called
-- not only by service_id but by alias as well.
-- Argument:
-- alias - settable service name
-- service_id ID of the service whose interface you want to name.
-- Arguments:
-- alias - settable service name
-- service_id ID of the service whose interface you want to name.
add_alias(alias: string, service_id: string)
-- Resolves given alias to a service id
@ -147,23 +161,54 @@ service Srv("srv"):
-- Retrieves the functional interface of a service running
-- on the node specified in the service call
-- Argument: service_id ID of the service whose interface you want to retrieve.
get_interface(service_id: string) -> ServiceInfo
get_interface(service_id: string) -> Interface
service Dist("dist"):
-- Constructs a ModuleConfig structure
-- Arguments:
-- module_name - import name of the module
-- mem_pages_count - Maximum memory size accessible by a module in Wasm pages (64 Kb)
-- logger_enabled - Defines whether Marine should provide a special host log_utf8_string function for this module
-- preopened_files - Files available for this module. Module can access only files from this list
-- envs - environment variables available for this module
-- mapped_dirs - Directory mapping, e.g. [["/sites", "./web/data"]] so all
-- reads & writes to /sites will actually to go ./web/data
-- mounted_binaries - Mapping of host binaries available to call from module,
-- e.g. [["curl", "/usr/bin/curl"]] will allow module to
-- call /usr/bin/curl binary as function 'curl'
-- logging_mask - Binary mask to enable & disable logging targets. Targets are
-- configured in WasmLoggerBuilder::with_target_map
-- mem_pages_count - Maximum memory size accessible by a module in Wasm pages (64 Kb)
make_module_config(name: string, mem_pages_count: ?u32, logger_enabled: ?bool, preopened_files: ?[]string, envs: ?Pairs, mapped_dirs: ?Pairs, mounted_binaries: ?Pairs, logging_mask: ?i32) -> ModuleConfig
-- Constructs a ModuleConfig structure
-- Arguments:
-- module_name - import name of the module
default_module_config(module_name: string) -> ModuleConfig
-- Used to add modules to the node specified in the service call
-- Arguments:
-- bytes a base64 string containing the .wasm module to add.
-- config module info
-- Returns: blake3 hash of the module
-- bytes a base64 string containing the .wasm module to add.
-- config module info
-- Returns: blake3 hash of the module
add_module(wasm_b56_content: Bytes, conf: ModuleConfig) -> string
-- Adds module by copying it from Particle Vault directory
-- Arguments:
-- path path or a filename
-- config - module config
add_module_from_vault(path: string, config: ModuleConfig) -> Hash
-- Get a list of modules available on the node
list_modules() -> []Module
-- Get the interface of a module
get_interface(module_id: string) -> Interface
-- Used to add a blueprint to the node specified in the service call
-- Creates Blueprint structure from from blueprint name and dependencies (modules)
make_blueprint(name: string, dependencies: []Dependency) -> AddBlueprint
-- Add a blueprint to the node
add_blueprint(blueprint: AddBlueprint) -> string
-- Used to get the blueprints available on the node specified in the service call.
@ -172,7 +217,13 @@ service Dist("dist"):
service Script("script"):
-- Adds the given script to a node
add(air_content: string, run_every: string) -> string
-- Arguments:
-- air_script - raw AIR script without any undefined variables
-- interval - if not set, script will be ran only once
-- if set, script will be ran once in the interval
-- (NOTE: actual interval may vary by up to 3 seconds)
-- TODO: change interval to ?u64 when node API is updated
add(air_script: string, interval: ?string) -> string
-- Removes recurring script from a node. Only a creator of the script can delete it
remove(script_id: string) -> bool

View File

@ -15,7 +15,7 @@ func ts_getter(node: string) -> []u64:
-- get the base58 representation of the peer id
k <- Op.string_to_b58(node)
-- find all (default 20) neighborhood peers from k
nodes <- Kademlia.neighborhood(k, false)
nodes <- Kademlia.neighborhood(k, nil, nil)
-- for each peer in our neighborhood and in parallel
for n <- nodes par:
on n:

View File

@ -19,7 +19,7 @@ func ts_getter(node: string) -> []u64:
res: *u64
on node:
k <- Op.string_to_b58(node)
nodes <- Kademlia.neighborhood(k, false)
nodes <- Kademlia.neighborhood(k, nil, nil)
for n <- nodes par:
on n:
try: