add quickstart 4 examples (#26)

* init quickstart 4

* fix Op indentation

* update packages
This commit is contained in:
boneyard93501 2021-10-12 11:47:57 -05:00 committed by GitHub
parent ad6a72bb92
commit 7795d24f34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 8016 additions and 0 deletions

View File

@ -0,0 +1,5 @@
debug/
target/
Cargo.lock
**/*.bk
**/*.bak

View File

@ -0,0 +1,22 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["boneyard93501 <4523011+boneyard93501@users.noreply.github.com>"]
edition = "2018"
description = "adder, a Marine wasi module"
license = "Apache-2.0"
[[bin]]
name = "adder"
path = "src/main.rs"
[dependencies]
marine-rs-sdk = { version = "0.6.11", features = ["logger"] }
log = "0.4.14"
[dev-dependencies]
marine-rs-sdk-test = "0.2.0"
[dev]
[profile.release]
opt-level = "s"

View File

@ -0,0 +1,6 @@
modules_dir = "artifacts/"
[[module]]
name = "adder"
mem_pages_count = 1
logger_enabled = true

View File

@ -0,0 +1,3 @@
{
"name": "adder"
}

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash -o errexit -o nounset -o pipefail
cargo update --aggressive
mkdir -p artifacts
rm -f artifacts/*.wasm
marine build --release
cp target/wasm32-wasi/release/adder.wasm artifacts/

View File

@ -0,0 +1,40 @@
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use marine_rs_sdk::{marine, module_manifest, WasmLoggerBuilder};
module_manifest!();
pub fn main() {
WasmLoggerBuilder::new().build().unwrap();
}
#[marine]
pub fn add_one(value: u64) -> u64 {
value + 1
}
#[cfg(test)]
mod tests {
use marine_rs_sdk_test::marine_test;
#[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts")]
fn test_greeting(adder: marine_test_env::adder::ModuleInterface) {
let value = 5;
let res = adder.add_one(value);
assert_eq!(value + 1, res);
}
}

View File

@ -0,0 +1,57 @@
-- service interface for Wasm module
service AddOne:
add_one: u64 -> u64
-- identity service for formatting stream var
service MyOp("op"):
identity(u: u64)
-- convenience struc for (Peer Id, Service Id) tuples
data NodeServiceTuple:
node_id: string
service_id: string
func add_one(value: u64, node: string, service_id: string) -> u64:
on node:
AddOne service_id
res <- AddOne.add_one(value)
<- res
func add_one_three_times(value: u64, ns_tuples: []NodeServiceTuple) -> u64:
on ns_tuples!0.node_id:
AddOne ns_tuples!0.service_id
res1 <- AddOne.add_one(value)
on ns_tuples!1.node_id:
AddOne ns_tuples!1.service_id
res2 <- AddOne.add_one(res1)
on ns_tuples!2.node_id:
AddOne ns_tuples!2.service_id
res3 <- AddOne.add_one(res2)
<- res3
func add_one_par(value: u64, ns_tuples: []NodeServiceTuple) -> []u64:
res: *u64
for ns <- ns_tuples par:
on ns.node_id:
AddOne ns.service_id
res <- AddOne.add_one(value)
MyOp.identity(res!2)
<- res
data ValueNodeService:
node_id: string
service_id: string
value: u64
func add_one_par_alt(payload: []ValueNodeService) -> []u64:
res: *u64
for vns <- payload par:
on vns.node_id:
AddOne vns.service_id
res <- AddOne.add_one(vns.value)
MyOp.identity(res!2)
<- res

View File

@ -0,0 +1,233 @@
-- Default public interface of Fluence nodes
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
blueprint_id: string
owner_id: string
data FunctionSignature:
arguments: []Argument
name: string
output_types: []string
data RecordType:
fields: []Field
id: u64
name: string
data Interface:
function_signatures: []FunctionSignature
record_types: []RecordType
data Info:
external_addresses: []string
data ModuleConfig:
name: string
data Module:
name: string
hash: string
config: ModuleConfig
data AddBlueprint:
name: string
dependencies: []Dependency
data Blueprint:
id: string
name: string
dependencies: []Dependency
data ScriptInfo:
id: string
src: string
failures: u32
interval: string
owner: string
data Contact:
peer_id: string
addresses: []string
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, d: ?string) -> []string
-- takes any number of arrays and flattens them by concatenating
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) -> 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 (hash is applied to utf8 bytes of s)
-- Returns: returns sha256 multihash encoded as base58
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
-- Argument: PeerId id of the peer to check if there's a connection with
-- Returns: bool - true if connected to the peer, false otherwise
is_connected(peer: PeerId) -> bool
-- Initiates a connection to the specified peer
-- Arguments:
-- 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
-- Resolves the contact of a peer via Kademlia
-- Argument: PeerId id of the target peer
-- Returns: Contact - true if connection was successful
get_contact(peer: PeerId) -> Contact
-- Get information about the peer
identify() -> Info
-- Get Unix timestamp in milliseconds
timestamp_ms() -> u64
-- Get Unix timestamp in seconds
timestamp_sec() -> u64
service Kademlia("kad"):
-- Instructs node to return the locally-known nodes
-- in the Kademlia neighborhood for a given key
-- 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; default 20
-- Returns: list of base58 strings sorted by distance to target; list will contain at most count elements
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.
-- 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
remove(service_id: string)
-- Returns a list of services running on a peer
list() -> []Service
-- Adds an alias on service, so, service could be called
-- not only by service_id but by alias as well.
-- 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
-- If there's no such alias, throws an error
-- Returns: service id associated with the given alias
resolve_alias(alias: string) -> string
-- 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) -> 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
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
-- 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.
-- A blueprint is an object of the following structure
list_blueprints() -> []Blueprint
service Script("script"):
-- Adds the given script to a node
-- 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
-- Returns a list of existing scripts on the node.
-- Each object in the list is of the following structure
list() -> ScriptInfo

View File

@ -0,0 +1,344 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.add_one_par_alt = exports.add_one_par = exports.add_one_three_times = exports.add_one = exports.registerMyOp = exports.registerAddOne = void 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.3.0-226
*
*/
var fluence_1 = require("@fluencelabs/fluence");
var v1_1 = require("@fluencelabs/fluence/dist/internal/compilerSupport/v1");
function registerAddOne() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var serviceId;
var service;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
}
else {
peer = fluence_1.Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
}
else if (typeof args[1] === 'string') {
serviceId = args[1];
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(fluence_1.FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
}
else if (typeof args[1] === 'object') {
service = args[1];
}
else {
service = args[2];
}
peer.internals.callServiceHandler.use(function (req, resp, next) {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'add_one') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
arg0: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.add_one(req.args[0], callParams);
}
next();
});
}
exports.registerAddOne = registerAddOne;
function registerMyOp() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var serviceId;
var service;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
}
else {
peer = fluence_1.Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
}
else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "op";
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(fluence_1.FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
}
else if (typeof args[1] === 'object') {
service = args[1];
}
else {
service = args[2];
}
peer.internals.callServiceHandler.use(function (req, resp, next) {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'identity') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
u: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
service.identity(req.args[0], callParams);
resp.result = {};
}
next();
});
}
exports.registerMyOp = registerMyOp;
function add_one() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var value;
var node;
var service_id;
var config;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
value = args[1];
node = args[2];
service_id = args[3];
config = args[4];
}
else {
peer = fluence_1.Fluence.getPeer();
value = args[0];
node = args[1];
service_id = args[2];
config = args[3];
}
var request;
var promise = new Promise(function (resolve, reject) {
var r = new v1_1.RequestFlowBuilder()
.disableInjections()
.withRawScript("\n (xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"value\") [] value)\n )\n (call %init_peer_id% (\"getDataSrv\" \"node\") [] node)\n )\n (call %init_peer_id% (\"getDataSrv\" \"service_id\") [] service_id)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call node (service_id \"add_one\") [value] res)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n)\n\n ")
.configHandler(function (h) {
h.on('getDataSrv', '-relay-', function () {
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'value', function () { return value; });
h.on('getDataSrv', 'node', function () { return node; });
h.on('getDataSrv', 'service_id', function () { return service_id; });
h.onEvent('callbackSrv', 'response', function (args) {
var res = args[0];
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', function (args) {
var err = args[0];
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(function () {
reject('Request timed out for add_one');
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request);
return promise;
}
exports.add_one = add_one;
function add_one_three_times() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var value;
var ns_tuples;
var config;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
value = args[1];
ns_tuples = args[2];
config = args[3];
}
else {
peer = fluence_1.Fluence.getPeer();
value = args[0];
ns_tuples = args[1];
config = args[2];
}
var request;
var promise = new Promise(function (resolve, reject) {
var r = new v1_1.RequestFlowBuilder()
.disableInjections()
.withRawScript("\n (xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"value\") [] value)\n )\n (call %init_peer_id% (\"getDataSrv\" \"ns_tuples\") [] ns_tuples)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call ns_tuples.$.[0].node_id! (ns_tuples.$.[0].service_id! \"add_one\") [value] res1)\n )\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n )\n )\n (xor\n (call ns_tuples.$.[1].node_id! (ns_tuples.$.[1].service_id! \"add_one\") [res1] res2)\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n )\n )\n (xor\n (call ns_tuples.$.[2].node_id! (ns_tuples.$.[2].service_id! \"add_one\") [res2] res3)\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [res3])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 5])\n)\n\n ")
.configHandler(function (h) {
h.on('getDataSrv', '-relay-', function () {
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'value', function () { return value; });
h.on('getDataSrv', 'ns_tuples', function () { return ns_tuples; });
h.onEvent('callbackSrv', 'response', function (args) {
var res = args[0];
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', function (args) {
var err = args[0];
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(function () {
reject('Request timed out for add_one_three_times');
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request);
return promise;
}
exports.add_one_three_times = add_one_three_times;
function add_one_par() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var value;
var ns_tuples;
var config;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
value = args[1];
ns_tuples = args[2];
config = args[3];
}
else {
peer = fluence_1.Fluence.getPeer();
value = args[0];
ns_tuples = args[1];
config = args[2];
}
var request;
var promise = new Promise(function (resolve, reject) {
var r = new v1_1.RequestFlowBuilder()
.disableInjections()
.withRawScript("\n (xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"value\") [] value)\n )\n (call %init_peer_id% (\"getDataSrv\" \"ns_tuples\") [] ns_tuples)\n )\n (fold ns_tuples ns\n (par\n (seq\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call ns.$.node_id! (ns.$.service_id! \"add_one\") [value] $res)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (call %init_peer_id% (\"op\" \"noop\") [])\n )\n (next ns)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[2]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n)\n\n ")
.configHandler(function (h) {
h.on('getDataSrv', '-relay-', function () {
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'value', function () { return value; });
h.on('getDataSrv', 'ns_tuples', function () { return ns_tuples; });
h.onEvent('callbackSrv', 'response', function (args) {
var res = args[0];
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', function (args) {
var err = args[0];
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(function () {
reject('Request timed out for add_one_par');
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request);
return promise;
}
exports.add_one_par = add_one_par;
function add_one_par_alt() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var payload;
var config;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
payload = args[1];
config = args[2];
}
else {
peer = fluence_1.Fluence.getPeer();
payload = args[0];
config = args[1];
}
var request;
var promise = new Promise(function (resolve, reject) {
var r = new v1_1.RequestFlowBuilder()
.disableInjections()
.withRawScript("\n (xor\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"payload\") [] payload)\n )\n (fold payload vns\n (par\n (seq\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call vns.$.node_id! (vns.$.service_id! \"add_one\") [vns.$.value!] $res)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (call %init_peer_id% (\"op\" \"noop\") [])\n )\n (next vns)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[2]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n)\n\n ")
.configHandler(function (h) {
h.on('getDataSrv', '-relay-', function () {
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'payload', function () { return payload; });
h.onEvent('callbackSrv', 'response', function (args) {
var res = args[0];
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', function (args) {
var err = args[0];
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(function () {
reject('Request timed out for add_one_par_alt');
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request);
return promise;
}
exports.add_one_par_alt = add_one_par_alt;

View File

@ -0,0 +1,548 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerDist = exports.registerScript = exports.registerKademlia = exports.registerOp = exports.registerPeer = exports.registerSrv = void 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.3.0-226
*
*/
var fluence_1 = require("@fluencelabs/fluence");
var v1_1 = require("@fluencelabs/fluence/dist/internal/compilerSupport/v1");
function registerSrv() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var serviceId;
var service;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
}
else {
peer = fluence_1.Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
}
else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "srv";
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(fluence_1.FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
}
else if (typeof args[1] === 'object') {
service = args[1];
}
else {
service = args[2];
}
peer.internals.callServiceHandler.use(function (req, resp, next) {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'add_alias') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
alias: req.tetraplets[0], service_id: req.tetraplets[1]
} });
resp.retCode = v1_1.ResultCodes.success;
service.add_alias(req.args[0], req.args[1], callParams);
resp.result = {};
}
if (req.fnName === 'create') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
blueprint_id: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.create(req.args[0], callParams);
}
if (req.fnName === 'get_interface') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
service_id: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.get_interface(req.args[0], callParams);
}
if (req.fnName === 'list') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.list(callParams);
}
if (req.fnName === 'remove') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
service_id: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
service.remove(req.args[0], callParams);
resp.result = {};
}
if (req.fnName === 'resolve_alias') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
alias: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.resolve_alias(req.args[0], callParams);
}
next();
});
}
exports.registerSrv = registerSrv;
function registerPeer() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var serviceId;
var service;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
}
else {
peer = fluence_1.Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
}
else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "peer";
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(fluence_1.FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
}
else if (typeof args[1] === 'object') {
service = args[1];
}
else {
service = args[2];
}
peer.internals.callServiceHandler.use(function (req, resp, next) {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'connect') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
id: req.tetraplets[0], multiaddrs: req.tetraplets[1]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.connect(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], callParams);
}
if (req.fnName === 'get_contact') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
peer: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.get_contact(req.args[0], callParams);
}
if (req.fnName === 'identify') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.identify(callParams);
}
if (req.fnName === 'is_connected') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
peer: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.is_connected(req.args[0], callParams);
}
if (req.fnName === 'timestamp_ms') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.timestamp_ms(callParams);
}
if (req.fnName === 'timestamp_sec') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.timestamp_sec(callParams);
}
next();
});
}
exports.registerPeer = registerPeer;
function registerOp() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var serviceId;
var service;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
}
else {
peer = fluence_1.Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
}
else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "op";
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(fluence_1.FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
}
else if (typeof args[1] === 'object') {
service = args[1];
}
else {
service = args[2];
}
peer.internals.callServiceHandler.use(function (req, resp, next) {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'array') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
a: req.tetraplets[0], b: req.tetraplets[1], c: req.tetraplets[2], d: req.tetraplets[3]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.array(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], req.args[2].length === 0 ? null : req.args[2][0], req.args[3].length === 0 ? null : req.args[3][0], callParams);
}
if (req.fnName === 'array_length') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
array: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.array_length(req.args[0], callParams);
}
if (req.fnName === 'bytes_from_b58') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
b: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.bytes_from_b58(req.args[0], callParams);
}
if (req.fnName === 'bytes_to_b58') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
bs: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.bytes_to_b58(req.args[0], callParams);
}
if (req.fnName === 'concat') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
a: req.tetraplets[0], b: req.tetraplets[1], c: req.tetraplets[2], d: req.tetraplets[3]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.concat(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], req.args[2].length === 0 ? null : req.args[2][0], req.args[3].length === 0 ? null : req.args[3][0], callParams);
}
if (req.fnName === 'concat_strings') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
a: req.tetraplets[0], b: req.tetraplets[1]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.concat_strings(req.args[0], req.args[1], callParams);
}
if (req.fnName === 'identity') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
s: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
var respResult = service.identity(req.args[0].length === 0 ? null : req.args[0][0], callParams);
resp.result = respResult === null ? [] : [respResult];
}
if (req.fnName === 'noop') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {} });
resp.retCode = v1_1.ResultCodes.success;
service.noop(callParams);
resp.result = {};
}
if (req.fnName === 'sha256_string') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
s: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.sha256_string(req.args[0], callParams);
}
if (req.fnName === 'string_from_b58') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
b: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.string_from_b58(req.args[0], callParams);
}
if (req.fnName === 'string_to_b58') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
s: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.string_to_b58(req.args[0], callParams);
}
next();
});
}
exports.registerOp = registerOp;
function registerKademlia() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var serviceId;
var service;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
}
else {
peer = fluence_1.Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
}
else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "kad";
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(fluence_1.FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
}
else if (typeof args[1] === 'object') {
service = args[1];
}
else {
service = args[2];
}
peer.internals.callServiceHandler.use(function (req, resp, next) {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'merge') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
target: req.tetraplets[0], left: req.tetraplets[1], right: req.tetraplets[2], count: req.tetraplets[3]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.merge(req.args[0], req.args[1], req.args[2], req.args[3].length === 0 ? null : req.args[3][0], callParams);
}
if (req.fnName === 'neighborhood') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
key: req.tetraplets[0], already_hashed: req.tetraplets[1], count: req.tetraplets[2]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.neighborhood(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], req.args[2].length === 0 ? null : req.args[2][0], callParams);
}
next();
});
}
exports.registerKademlia = registerKademlia;
function registerScript() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var serviceId;
var service;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
}
else {
peer = fluence_1.Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
}
else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "script";
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(fluence_1.FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
}
else if (typeof args[1] === 'object') {
service = args[1];
}
else {
service = args[2];
}
peer.internals.callServiceHandler.use(function (req, resp, next) {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'add') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
air_script: req.tetraplets[0], interval: req.tetraplets[1]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.add(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], callParams);
}
if (req.fnName === 'list') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.list(callParams);
}
if (req.fnName === 'remove') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
script_id: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.remove(req.args[0], callParams);
}
next();
});
}
exports.registerScript = registerScript;
function registerDist() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var peer;
var serviceId;
var service;
if (fluence_1.FluencePeer.isInstance(args[0])) {
peer = args[0];
}
else {
peer = fluence_1.Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
}
else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "dist";
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(fluence_1.FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
}
else if (typeof args[1] === 'object') {
service = args[1];
}
else {
service = args[2];
}
peer.internals.callServiceHandler.use(function (req, resp, next) {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'add_blueprint') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
blueprint: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.add_blueprint(req.args[0], callParams);
}
if (req.fnName === 'add_module') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
wasm_b56_content: req.tetraplets[0], conf: req.tetraplets[1]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.add_module(req.args[0], req.args[1], callParams);
}
if (req.fnName === 'add_module_from_vault') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
path: req.tetraplets[0], config: req.tetraplets[1]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.add_module_from_vault(req.args[0], req.args[1], callParams);
}
if (req.fnName === 'default_module_config') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
module_name: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.default_module_config(req.args[0], callParams);
}
if (req.fnName === 'get_interface') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
module_id: req.tetraplets[0]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.get_interface(req.args[0], callParams);
}
if (req.fnName === 'list_blueprints') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.list_blueprints(callParams);
}
if (req.fnName === 'list_modules') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.list_modules(callParams);
}
if (req.fnName === 'make_blueprint') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
name: req.tetraplets[0], dependencies: req.tetraplets[1]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.make_blueprint(req.args[0], req.args[1], callParams);
}
if (req.fnName === 'make_module_config') {
var callParams = __assign(__assign({}, req.particleContext), { tetraplets: {
name: req.tetraplets[0], mem_pages_count: req.tetraplets[1], logger_enabled: req.tetraplets[2], preopened_files: req.tetraplets[3], envs: req.tetraplets[4], mapped_dirs: req.tetraplets[5], mounted_binaries: req.tetraplets[6], logging_mask: req.tetraplets[7]
} });
resp.retCode = v1_1.ResultCodes.success;
resp.result = service.make_module_config(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], req.args[2].length === 0 ? null : req.args[2][0], req.args[3].length === 0 ? null : req.args[3][0], req.args[4].length === 0 ? null : req.args[4][0], req.args[5].length === 0 ? null : req.args[5][0], req.args[6].length === 0 ? null : req.args[6][0], req.args[7].length === 0 ? null : req.args[7][0], callParams);
}
next();
});
}
exports.registerDist = registerDist;
// Functions

View File

@ -0,0 +1,130 @@
"use strict";
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var fluence_1 = require("@fluencelabs/fluence");
var fluence_network_environment_1 = require("@fluencelabs/fluence-network-environment");
var adder_1 = require("./compiled-aqua/adder");
var topos = [
{
"node_id": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
"service_id": "7b2ab89f-0897-4537-b726-8120b405074d"
},
{
"node_id": "12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA",
"service_id": "e013f18a-200f-4249-8303-d42d10d3ce46"
},
{
"node_id": "12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr",
"service_id": "191ef700-fd13-4151-9b7c-3fabfe3c0387"
}
];
var topos_alt = [
{
"value": 5,
"node_id": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
"service_id": "7b2ab89f-0897-4537-b726-8120b405074d"
},
{
"value": 10,
"node_id": "12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA",
"service_id": "e013f18a-200f-4249-8303-d42d10d3ce46"
},
{
"value": 15,
"node_id": "12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr",
"service_id": "191ef700-fd13-4151-9b7c-3fabfe3c0387"
}
];
var value = 5;
// let greeting_service =
function main() {
return __awaiter(this, void 0, void 0, function () {
var basic_add, seq_add, par_add, par_add_alt;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
// console.log("hello");
// setLogLevel('DEBUG');
return [4 /*yield*/, fluence_1.Fluence.start({ connectTo: fluence_network_environment_1.krasnodar[2] })];
case 1:
// console.log("hello");
// setLogLevel('DEBUG');
_a.sent();
console.log("created a Fluence client %s with relay %s", fluence_1.Fluence.getStatus().peerId, fluence_1.Fluence.getStatus().relayPeerId);
return [4 /*yield*/, adder_1.add_one(value, topos[0].node_id, topos[0].service_id)];
case 2:
basic_add = _a.sent();
console.log("add_one to ", value, " equals ", basic_add);
return [4 /*yield*/, adder_1.add_one_three_times(value, topos)];
case 3:
seq_add = _a.sent();
console.log("add_one sequentially equals ", seq_add);
return [4 /*yield*/, adder_1.add_one_par(value, topos)];
case 4:
par_add = _a.sent();
console.log("add_one parallel equals ", par_add);
return [4 /*yield*/, adder_1.add_one_par_alt(topos_alt)];
case 5:
par_add_alt = _a.sent();
console.log("add_one parallel alt equals ", par_add_alt);
return [2 /*return*/];
}
});
});
}
main()
.then(function () { return process.exit(0); })
.catch(function (error) {
console.error(error);
process.exit(1);
});

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,49 @@
{
"name": "quickstart-4-example",
"version": "0.1.0",
"description": "Fluence Quickstart-4 Examples",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts",
"files": [
"dist/*"
],
"bic": [
"client-peer/*",
"*.aqua",
"package-lock.json"
],
"dependencies": {
"@fluencelabs/aqua-lib": "^0.1.14",
"@fluencelabs/fluence": "^0.12.0",
"@fluencelabs/fluence-network-environment": "^1.0.10",
"it-all": "^1.0.5"
},
"scripts": {
"compile-aqua": "aqua -i ../aqua-scripts -o src/compiled-aqua/",
"prebuild": "npm run compile-aqua",
"build": "tsc",
"prestart:local": "npm run build",
"start:local": "node dist/src/index.js local",
"prestart:remote": "npm run build",
"start:remote": "node dist/src/index.js krasnodar",
"start": "npm run start:remote"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fluencelabs/examples/quickstart"
},
"keywords": [
"aqua",
"fluence"
],
"author": "Fluence Labs",
"license": "MIT",
"bugs": {
"url": "git+https://github.com/fluencelabs/examples/issues"
},
"homepage": "git+https://github.com/fluencelabs/examples/aqua-examples/echo-greeter#readme",
"devDependencies": {
"@fluencelabs/aqua": "^0.3.0-226",
"typescript": "^3.9.5"
}
}

View File

@ -0,0 +1,565 @@
/**
*
* 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.3.0-226
*
*/
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
// Services
export interface AddOneDef {
add_one: (arg0: number, callParams: CallParams<'arg0'>) => number;
}
export function registerAddOne(serviceId: string, service: AddOneDef): void;
export function registerAddOne(peer: FluencePeer, serviceId: string, service: AddOneDef): void;
export function registerAddOne(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'add_one') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.add_one(req.args[0], callParams)
}
next();
});
}
export interface MyOpDef {
identity: (u: number, callParams: CallParams<'u'>) => void;
}
export function registerMyOp(service: MyOpDef): void;
export function registerMyOp(serviceId: string, service: MyOpDef): void;
export function registerMyOp(peer: FluencePeer, service: MyOpDef): void;
export function registerMyOp(peer: FluencePeer, serviceId: string, service: MyOpDef): void;
export function registerMyOp(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "op"
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'identity') {
const callParams = {
...req.particleContext,
tetraplets: {
u: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
service.identity(req.args[0], callParams); resp.result = {}
}
next();
});
}
// Functions
export function add_one(value: number, node: string, service_id: string, config?: {ttl?: number}) : Promise<number>;
export function add_one(peer: FluencePeer, value: number, node: string, service_id: string, config?: {ttl?: number}) : Promise<number>;
export function add_one(...args: any) {
let peer: FluencePeer;
let value: any;
let node: any;
let service_id: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
value = args[1];
node = args[2];
service_id = args[3];
config = args[4];
} else {
peer = Fluence.getPeer();
value = args[0];
node = args[1];
service_id = args[2];
config = args[3];
}
let request: RequestFlow;
const promise = new Promise<number>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "value") [] value)
)
(call %init_peer_id% ("getDataSrv" "node") [] node)
)
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(call -relay- ("op" "noop") [])
(call node (service_id "add_one") [value] res)
)
(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 peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'value', () => {return value;});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'service_id', () => {return service_id;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for add_one');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function add_one_three_times(value: number, ns_tuples: {node_id:string;service_id:string}[], config?: {ttl?: number}) : Promise<number>;
export function add_one_three_times(peer: FluencePeer, value: number, ns_tuples: {node_id:string;service_id:string}[], config?: {ttl?: number}) : Promise<number>;
export function add_one_three_times(...args: any) {
let peer: FluencePeer;
let value: any;
let ns_tuples: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
value = args[1];
ns_tuples = args[2];
config = args[3];
} else {
peer = Fluence.getPeer();
value = args[0];
ns_tuples = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<number>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "value") [] value)
)
(call %init_peer_id% ("getDataSrv" "ns_tuples") [] ns_tuples)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(call -relay- ("op" "noop") [])
(call ns_tuples.$.[0].node_id! (ns_tuples.$.[0].service_id! "add_one") [value] res1)
)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(call -relay- ("op" "noop") [])
)
)
)
(xor
(call ns_tuples.$.[1].node_id! (ns_tuples.$.[1].service_id! "add_one") [res1] res2)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
(call -relay- ("op" "noop") [])
)
)
)
(xor
(call ns_tuples.$.[2].node_id! (ns_tuples.$.[2].service_id! "add_one") [res2] res3)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
)
(call -relay- ("op" "noop") [])
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [res3])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'value', () => {return value;});
h.on('getDataSrv', 'ns_tuples', () => {return ns_tuples;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for add_one_three_times');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function add_one_par(value: number, ns_tuples: {node_id:string;service_id:string}[], config?: {ttl?: number}) : Promise<number[]>;
export function add_one_par(peer: FluencePeer, value: number, ns_tuples: {node_id:string;service_id:string}[], config?: {ttl?: number}) : Promise<number[]>;
export function add_one_par(...args: any) {
let peer: FluencePeer;
let value: any;
let ns_tuples: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
value = args[1];
ns_tuples = args[2];
config = args[3];
} else {
peer = Fluence.getPeer();
value = args[0];
ns_tuples = args[1];
config = args[2];
}
let request: RequestFlow;
const promise = new Promise<number[]>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "value") [] value)
)
(call %init_peer_id% ("getDataSrv" "ns_tuples") [] ns_tuples)
)
(fold ns_tuples ns
(par
(seq
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(call -relay- ("op" "noop") [])
(call ns.$.node_id! (ns.$.service_id! "add_one") [value] $res)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("op" "noop") [])
)
(next ns)
)
)
)
(call %init_peer_id% ("op" "identity") [$res.$.[2]!])
)
(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 peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'value', () => {return value;});
h.on('getDataSrv', 'ns_tuples', () => {return ns_tuples;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for add_one_par');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}
export function add_one_par_alt(payload: {node_id:string;service_id:string;value:number}[], config?: {ttl?: number}) : Promise<number[]>;
export function add_one_par_alt(peer: FluencePeer, payload: {node_id:string;service_id:string;value:number}[], config?: {ttl?: number}) : Promise<number[]>;
export function add_one_par_alt(...args: any) {
let peer: FluencePeer;
let payload: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
payload = args[1];
config = args[2];
} else {
peer = Fluence.getPeer();
payload = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<number[]>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "payload") [] payload)
)
(fold payload vns
(par
(seq
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(call -relay- ("op" "noop") [])
(call vns.$.node_id! (vns.$.service_id! "add_one") [vns.$.value!] $res)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("op" "noop") [])
)
(next vns)
)
)
)
(call %init_peer_id% ("op" "identity") [$res.$.[2]!])
)
(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 peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'payload', () => {return payload;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for add_one_par_alt');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}

View File

@ -0,0 +1,921 @@
/**
*
* 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.3.0-226
*
*/
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
// Services
export interface SrvDef {
add_alias: (alias: string, service_id: string, callParams: CallParams<'alias' | 'service_id'>) => void;
create: (blueprint_id: string, callParams: CallParams<'blueprint_id'>) => string;
get_interface: (service_id: string, callParams: CallParams<'service_id'>) => {function_signatures:{arguments:string[][];name:string;output_types:string[]}[];record_types:{fields:string[][];id:number;name:string}[]};
list: (callParams: CallParams<null>) => {blueprint_id:string;id:string;owner_id:string}[];
remove: (service_id: string, callParams: CallParams<'service_id'>) => void;
resolve_alias: (alias: string, callParams: CallParams<'alias'>) => string;
}
export function registerSrv(service: SrvDef): void;
export function registerSrv(serviceId: string, service: SrvDef): void;
export function registerSrv(peer: FluencePeer, service: SrvDef): void;
export function registerSrv(peer: FluencePeer, serviceId: string, service: SrvDef): void;
export function registerSrv(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "srv"
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'add_alias') {
const callParams = {
...req.particleContext,
tetraplets: {
alias: req.tetraplets[0],service_id: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
service.add_alias(req.args[0], req.args[1], callParams); resp.result = {}
}
if (req.fnName === 'create') {
const callParams = {
...req.particleContext,
tetraplets: {
blueprint_id: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.create(req.args[0], callParams)
}
if (req.fnName === 'get_interface') {
const callParams = {
...req.particleContext,
tetraplets: {
service_id: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.get_interface(req.args[0], callParams)
}
if (req.fnName === 'list') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
resp.result = service.list(callParams)
}
if (req.fnName === 'remove') {
const callParams = {
...req.particleContext,
tetraplets: {
service_id: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
service.remove(req.args[0], callParams); resp.result = {}
}
if (req.fnName === 'resolve_alias') {
const callParams = {
...req.particleContext,
tetraplets: {
alias: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.resolve_alias(req.args[0], callParams)
}
next();
});
}
export interface PeerDef {
connect: (id: string, multiaddrs: string[] | null, callParams: CallParams<'id' | 'multiaddrs'>) => boolean;
get_contact: (peer: string, callParams: CallParams<'peer'>) => {addresses:string[];peer_id:string};
identify: (callParams: CallParams<null>) => {external_addresses:string[]};
is_connected: (peer: string, callParams: CallParams<'peer'>) => boolean;
timestamp_ms: (callParams: CallParams<null>) => number;
timestamp_sec: (callParams: CallParams<null>) => number;
}
export function registerPeer(service: PeerDef): void;
export function registerPeer(serviceId: string, service: PeerDef): void;
export function registerPeer(peer: FluencePeer, service: PeerDef): void;
export function registerPeer(peer: FluencePeer, serviceId: string, service: PeerDef): void;
export function registerPeer(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "peer"
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'connect') {
const callParams = {
...req.particleContext,
tetraplets: {
id: req.tetraplets[0],multiaddrs: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.connect(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], callParams)
}
if (req.fnName === 'get_contact') {
const callParams = {
...req.particleContext,
tetraplets: {
peer: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.get_contact(req.args[0], callParams)
}
if (req.fnName === 'identify') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
resp.result = service.identify(callParams)
}
if (req.fnName === 'is_connected') {
const callParams = {
...req.particleContext,
tetraplets: {
peer: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.is_connected(req.args[0], callParams)
}
if (req.fnName === 'timestamp_ms') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
resp.result = service.timestamp_ms(callParams)
}
if (req.fnName === 'timestamp_sec') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
resp.result = service.timestamp_sec(callParams)
}
next();
});
}
export interface OpDef {
array: (a: string, b: string | null, c: string | null, d: string | null, callParams: CallParams<'a' | 'b' | 'c' | 'd'>) => string[];
array_length: (array: string[], callParams: CallParams<'array'>) => number;
bytes_from_b58: (b: string, callParams: CallParams<'b'>) => number[];
bytes_to_b58: (bs: number[], callParams: CallParams<'bs'>) => string;
concat: (a: string[], b: string[] | null, c: string[] | null, d: string[] | null, callParams: CallParams<'a' | 'b' | 'c' | 'd'>) => string[];
concat_strings: (a: string, b: string, callParams: CallParams<'a' | 'b'>) => string;
identity: (s: string | null, callParams: CallParams<'s'>) => string | null;
noop: (callParams: CallParams<null>) => void;
sha256_string: (s: string, callParams: CallParams<'s'>) => string;
string_from_b58: (b: string, callParams: CallParams<'b'>) => string;
string_to_b58: (s: string, callParams: CallParams<'s'>) => string;
}
export function registerOp(service: OpDef): void;
export function registerOp(serviceId: string, service: OpDef): void;
export function registerOp(peer: FluencePeer, service: OpDef): void;
export function registerOp(peer: FluencePeer, serviceId: string, service: OpDef): void;
export function registerOp(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "op"
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'array') {
const callParams = {
...req.particleContext,
tetraplets: {
a: req.tetraplets[0],b: req.tetraplets[1],c: req.tetraplets[2],d: req.tetraplets[3]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.array(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], req.args[2].length === 0 ? null : req.args[2][0], req.args[3].length === 0 ? null : req.args[3][0], callParams)
}
if (req.fnName === 'array_length') {
const callParams = {
...req.particleContext,
tetraplets: {
array: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.array_length(req.args[0], callParams)
}
if (req.fnName === 'bytes_from_b58') {
const callParams = {
...req.particleContext,
tetraplets: {
b: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.bytes_from_b58(req.args[0], callParams)
}
if (req.fnName === 'bytes_to_b58') {
const callParams = {
...req.particleContext,
tetraplets: {
bs: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.bytes_to_b58(req.args[0], callParams)
}
if (req.fnName === 'concat') {
const callParams = {
...req.particleContext,
tetraplets: {
a: req.tetraplets[0],b: req.tetraplets[1],c: req.tetraplets[2],d: req.tetraplets[3]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.concat(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], req.args[2].length === 0 ? null : req.args[2][0], req.args[3].length === 0 ? null : req.args[3][0], callParams)
}
if (req.fnName === 'concat_strings') {
const callParams = {
...req.particleContext,
tetraplets: {
a: req.tetraplets[0],b: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.concat_strings(req.args[0], req.args[1], callParams)
}
if (req.fnName === 'identity') {
const callParams = {
...req.particleContext,
tetraplets: {
s: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
var respResult = service.identity(req.args[0].length === 0 ? null : req.args[0][0], callParams);
resp.result = respResult === null ? [] : [respResult]
}
if (req.fnName === 'noop') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
service.noop(callParams); resp.result = {}
}
if (req.fnName === 'sha256_string') {
const callParams = {
...req.particleContext,
tetraplets: {
s: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.sha256_string(req.args[0], callParams)
}
if (req.fnName === 'string_from_b58') {
const callParams = {
...req.particleContext,
tetraplets: {
b: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.string_from_b58(req.args[0], callParams)
}
if (req.fnName === 'string_to_b58') {
const callParams = {
...req.particleContext,
tetraplets: {
s: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.string_to_b58(req.args[0], callParams)
}
next();
});
}
export interface KademliaDef {
merge: (target: string, left: string[], right: string[], count: number | null, callParams: CallParams<'target' | 'left' | 'right' | 'count'>) => string[];
neighborhood: (key: string, already_hashed: boolean | null, count: number | null, callParams: CallParams<'key' | 'already_hashed' | 'count'>) => string[];
}
export function registerKademlia(service: KademliaDef): void;
export function registerKademlia(serviceId: string, service: KademliaDef): void;
export function registerKademlia(peer: FluencePeer, service: KademliaDef): void;
export function registerKademlia(peer: FluencePeer, serviceId: string, service: KademliaDef): void;
export function registerKademlia(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "kad"
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'merge') {
const callParams = {
...req.particleContext,
tetraplets: {
target: req.tetraplets[0],left: req.tetraplets[1],right: req.tetraplets[2],count: req.tetraplets[3]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.merge(req.args[0], req.args[1], req.args[2], req.args[3].length === 0 ? null : req.args[3][0], callParams)
}
if (req.fnName === 'neighborhood') {
const callParams = {
...req.particleContext,
tetraplets: {
key: req.tetraplets[0],already_hashed: req.tetraplets[1],count: req.tetraplets[2]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.neighborhood(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], req.args[2].length === 0 ? null : req.args[2][0], callParams)
}
next();
});
}
export interface ScriptDef {
add: (air_script: string, interval: string | null, callParams: CallParams<'air_script' | 'interval'>) => string;
list: (callParams: CallParams<null>) => {failures:number;id:string;interval:string;owner:string;src:string};
remove: (script_id: string, callParams: CallParams<'script_id'>) => boolean;
}
export function registerScript(service: ScriptDef): void;
export function registerScript(serviceId: string, service: ScriptDef): void;
export function registerScript(peer: FluencePeer, service: ScriptDef): void;
export function registerScript(peer: FluencePeer, serviceId: string, service: ScriptDef): void;
export function registerScript(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "script"
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'add') {
const callParams = {
...req.particleContext,
tetraplets: {
air_script: req.tetraplets[0],interval: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.add(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], callParams)
}
if (req.fnName === 'list') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
resp.result = service.list(callParams)
}
if (req.fnName === 'remove') {
const callParams = {
...req.particleContext,
tetraplets: {
script_id: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.remove(req.args[0], callParams)
}
next();
});
}
export interface DistDef {
add_blueprint: (blueprint: {dependencies:string[];name:string}, callParams: CallParams<'blueprint'>) => string;
add_module: (wasm_b56_content: number[], conf: {name:string}, callParams: CallParams<'wasm_b56_content' | 'conf'>) => string;
add_module_from_vault: (path: string, config: {name:string}, callParams: CallParams<'path' | 'config'>) => string;
default_module_config: (module_name: string, callParams: CallParams<'module_name'>) => {name:string};
get_interface: (module_id: string, callParams: CallParams<'module_id'>) => {function_signatures:{arguments:string[][];name:string;output_types:string[]}[];record_types:{fields:string[][];id:number;name:string}[]};
list_blueprints: (callParams: CallParams<null>) => {dependencies:string[];id:string;name:string}[];
list_modules: (callParams: CallParams<null>) => {config:{name:string};hash:string;name:string}[];
make_blueprint: (name: string, dependencies: string[], callParams: CallParams<'name' | 'dependencies'>) => {dependencies:string[];name:string};
make_module_config: (name: string, mem_pages_count: number | null, logger_enabled: boolean | null, preopened_files: string[] | null, envs: string[][] | null, mapped_dirs: string[][] | null, mounted_binaries: string[][] | null, logging_mask: number | null, callParams: CallParams<'name' | 'mem_pages_count' | 'logger_enabled' | 'preopened_files' | 'envs' | 'mapped_dirs' | 'mounted_binaries' | 'logging_mask'>) => {name:string};
}
export function registerDist(service: DistDef): void;
export function registerDist(serviceId: string, service: DistDef): void;
export function registerDist(peer: FluencePeer, service: DistDef): void;
export function registerDist(peer: FluencePeer, serviceId: string, service: DistDef): void;
export function registerDist(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "dist"
}
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
} else {
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'add_blueprint') {
const callParams = {
...req.particleContext,
tetraplets: {
blueprint: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.add_blueprint(req.args[0], callParams)
}
if (req.fnName === 'add_module') {
const callParams = {
...req.particleContext,
tetraplets: {
wasm_b56_content: req.tetraplets[0],conf: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.add_module(req.args[0], req.args[1], callParams)
}
if (req.fnName === 'add_module_from_vault') {
const callParams = {
...req.particleContext,
tetraplets: {
path: req.tetraplets[0],config: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.add_module_from_vault(req.args[0], req.args[1], callParams)
}
if (req.fnName === 'default_module_config') {
const callParams = {
...req.particleContext,
tetraplets: {
module_name: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.default_module_config(req.args[0], callParams)
}
if (req.fnName === 'get_interface') {
const callParams = {
...req.particleContext,
tetraplets: {
module_id: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.get_interface(req.args[0], callParams)
}
if (req.fnName === 'list_blueprints') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
resp.result = service.list_blueprints(callParams)
}
if (req.fnName === 'list_modules') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
resp.result = service.list_modules(callParams)
}
if (req.fnName === 'make_blueprint') {
const callParams = {
...req.particleContext,
tetraplets: {
name: req.tetraplets[0],dependencies: req.tetraplets[1]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.make_blueprint(req.args[0], req.args[1], callParams)
}
if (req.fnName === 'make_module_config') {
const callParams = {
...req.particleContext,
tetraplets: {
name: req.tetraplets[0],mem_pages_count: req.tetraplets[1],logger_enabled: req.tetraplets[2],preopened_files: req.tetraplets[3],envs: req.tetraplets[4],mapped_dirs: req.tetraplets[5],mounted_binaries: req.tetraplets[6],logging_mask: req.tetraplets[7]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.make_module_config(req.args[0], req.args[1].length === 0 ? null : req.args[1][0], req.args[2].length === 0 ? null : req.args[2][0], req.args[3].length === 0 ? null : req.args[3][0], req.args[4].length === 0 ? null : req.args[4][0], req.args[5].length === 0 ? null : req.args[5][0], req.args[6].length === 0 ? null : req.args[6][0], req.args[7].length === 0 ? null : req.args[7][0], callParams)
}
next();
});
}
// Functions

View File

@ -0,0 +1,115 @@
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Fluence, setLogLevel, FluencePeer } from "@fluencelabs/fluence";
import { krasnodar, Node } from "@fluencelabs/fluence-network-environment";
import { add_one, add_one_par, add_one_three_times, add_one_par_alt } from "./compiled-aqua/adder";
interface NodeServiceTuple {
node_id: string;
service_id: string;
}
let topos: Array<NodeServiceTuple> = [
{
"node_id": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
"service_id": "7b2ab89f-0897-4537-b726-8120b405074d"
},
{
"node_id": "12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA",
"service_id": "e013f18a-200f-4249-8303-d42d10d3ce46"
},
{
"node_id": "12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr",
"service_id": "191ef700-fd13-4151-9b7c-3fabfe3c0387"
}
];
interface ValueNodeService {
value: number,
node_id: string;
service_id: string;
}
let topos_alt: Array<ValueNodeService> = [
{
"value": 5,
"node_id": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
"service_id": "7b2ab89f-0897-4537-b726-8120b405074d"
},
{
"value": 10,
"node_id": "12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA",
"service_id": "e013f18a-200f-4249-8303-d42d10d3ce46"
},
{
"value": 15,
"node_id": "12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr",
"service_id": "191ef700-fd13-4151-9b7c-3fabfe3c0387"
}
];
let value = 5;
// let greeting_service =
async function main() {
// console.log("hello");
// setLogLevel('DEBUG');
await Fluence.start({ connectTo: krasnodar[2] });
console.log(
"created a Fluence client %s with relay %s",
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId
);
let basic_add = await add_one(
value,
topos[0].node_id,
topos[0].service_id
);
console.log("add_one to ", value, " equals ", basic_add);
let seq_add = await add_one_three_times(
value,
topos
);
console.log("add_one sequentially equals ", seq_add);
let par_add = await add_one_par(
value,
topos
);
console.log("add_one parallel equals ", par_add);
let par_add_alt = await add_one_par_alt(
topos_alt
);
console.log("add_one parallel alt equals ", par_add_alt);
return;
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@ -0,0 +1,62 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": ".", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

View File

@ -0,0 +1,37 @@
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "value") [] value)
)
(call %init_peer_id% ("getDataSrv" "node") [] node)
)
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(call -relay- ("op" "noop") [])
(call node (service_id "add_one") [value] res)
)
(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

@ -0,0 +1,45 @@
(xor
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "value") [] value)
)
(call %init_peer_id% ("getDataSrv" "ns_tuples") [] ns_tuples)
)
(fold ns_tuples ns
(par
(seq
(seq
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(call -relay- ("op" "noop") [])
(call ns.$.node_id! (ns.$.service_id! "add_one") [value] $res)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("op" "identity") [$res.$.[2]!])
)
(call %init_peer_id% ("op" "noop") [])
)
(next ns)
)
)
)
(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

@ -0,0 +1,42 @@
(xor
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "payload") [] payload)
)
(fold payload vns
(par
(seq
(seq
(seq
(seq
(call -relay- ("op" "noop") [])
(xor
(seq
(call -relay- ("op" "noop") [])
(call vns.$.node_id! (vns.$.service_id! "add_one") [vns.$.value!] $res)
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
)
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("op" "identity") [$res.$.[2]!])
)
(call %init_peer_id% ("op" "noop") [])
)
(next vns)
)
)
)
(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

@ -0,0 +1,58 @@
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "value") [] value)
)
(call %init_peer_id% ("getDataSrv" "ns_tuples") [] ns_tuples)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(call -relay- ("op" "noop") [])
(call ns_tuples.$.[0].node_id! (ns_tuples.$.[0].service_id! "add_one") [value] res1)
)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(call -relay- ("op" "noop") [])
)
)
)
(xor
(call ns_tuples.$.[1].node_id! (ns_tuples.$.[1].service_id! "add_one") [res1] res2)
(seq
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
(call -relay- ("op" "noop") [])
)
)
)
(xor
(call ns_tuples.$.[2].node_id! (ns_tuples.$.[2].service_id! "add_one") [res2] res3)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
)
(call -relay- ("op" "noop") [])
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [res3])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)

View File

@ -0,0 +1,14 @@
[
{
"node_id": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
"service_id": "7b2ab89f-0897-4537-b726-8120b405074d"
},
{
"node_id": "12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA",
"service_id": "e013f18a-200f-4249-8303-d42d10d3ce46"
},
{
"node_id": "12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr",
"service_id": "191ef700-fd13-4151-9b7c-3fabfe3c0387"
}
]