mirror of
https://github.com/fluencelabs/examples
synced 2025-04-25 02:32:16 +00:00
Better src directory structure
This commit is contained in:
parent
0da5d61357
commit
2c720ae318
@ -1,2 +1,2 @@
|
||||
dist/
|
||||
src/echo_greeter.ts
|
||||
src/_aqua
|
@ -19,7 +19,7 @@
|
||||
"it-all": "^1.0.5"
|
||||
},
|
||||
"scripts": {
|
||||
"compile-aqua": "aqua -i ../aqua-scripts -o src/",
|
||||
"compile-aqua": "aqua -i ../aqua-scripts -o src/_aqua",
|
||||
"prebuild": "npm run compile-aqua",
|
||||
"build": "tsc",
|
||||
"prestart:local": "npm run build",
|
||||
|
@ -1,199 +0,0 @@
|
||||
"use strict";
|
||||
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 });
|
||||
exports.get_price_par = exports.get_price = void 0;
|
||||
var api_unstable_1 = require("@fluencelabs/fluence/dist/api.unstable");
|
||||
// Services
|
||||
//Srv
|
||||
//defaultId = "srv"
|
||||
//add_alias: (alias: string, service_id: string) => void
|
||||
//create: (blueprint_id: string) => string
|
||||
//get_interface: (service_id: string) => {function_signatures:{arguments:string[][];name:string;output_types:string[]}[];record_types:{fields:string[][];id:number;name:string}[]}
|
||||
//list: () => {blueprint_id:string;id:string;owner_id:string}[]
|
||||
//remove: (service_id: string) => void
|
||||
//resolve_alias: (alias: string) => string
|
||||
//END Srv
|
||||
//Peer
|
||||
//defaultId = "peer"
|
||||
//connect: (id: string, multiaddrs: string[] | null) => boolean
|
||||
//get_contact: (peer: string) => {addresses:string[];peer_id:string}
|
||||
//identify: () => {external_addresses:string[]}
|
||||
//is_connected: (peer: string) => boolean
|
||||
//timestamp_ms: () => number
|
||||
//timestamp_sec: () => number
|
||||
//END Peer
|
||||
//Op
|
||||
//defaultId = "op"
|
||||
//array: (a: string, b: string | null, c: string | null, d: string | null) => string[]
|
||||
//array_length: (array: string[]) => number
|
||||
//bytes_from_b58: (b: string) => number[]
|
||||
//bytes_to_b58: (bs: number[]) => string
|
||||
//concat: (a: string[], b: string[] | null, c: string[] | null, d: string[] | null) => string[]
|
||||
//identity: (s: string | null) => string | null
|
||||
//noop: () => void
|
||||
//sha256_string: (s: string) => string
|
||||
//string_from_b58: (b: string) => string
|
||||
//string_to_b58: (s: string) => string
|
||||
//END Op
|
||||
//Kademlia
|
||||
//defaultId = "kad"
|
||||
//merge: (target: string, left: string[], right: string[], count: number | null) => string[]
|
||||
//neighborhood: (key: string, already_hashed: boolean | null, count: number | null) => string[]
|
||||
//END Kademlia
|
||||
//MeanService
|
||||
//defaultId = undefined
|
||||
//mean: (data: number[]) => {error_msg:string;result:number;success:boolean}
|
||||
//END MeanService
|
||||
//Script
|
||||
//defaultId = "script"
|
||||
//add: (air_script: string, interval: string | null) => string
|
||||
//list: () => {failures:number;id:string;interval:string;owner:string;src:string}
|
||||
//remove: (script_id: string) => boolean
|
||||
//END Script
|
||||
//Dist
|
||||
//defaultId = "dist"
|
||||
//add_blueprint: (blueprint: {dependencies:string[];name:string}) => string
|
||||
//add_module: (wasm_b56_content: number[], conf: {name:string}) => string
|
||||
//get_interface: (module_id: string) => {function_signatures:{arguments:string[][];name:string;output_types:string[]}[];record_types:{fields:string[][];id:number;name:string}[]}
|
||||
//list_blueprints: () => {dependencies:string[];id:string;name:string}[]
|
||||
//list_modules: () => {config:{name:string};hash:string;name:string}[]
|
||||
//make_blueprint: (name: string, dependencies: string[]) => {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) => {name:string}
|
||||
//END Dist
|
||||
//F64Op
|
||||
//defaultId = "op"
|
||||
//identity: (x: number) => number
|
||||
//END F64Op
|
||||
//PriceGetterService
|
||||
//defaultId = undefined
|
||||
//price_getter: (coin: string, currency: string, timestamp_ms: number) => {error_msg:string;result:number;success:boolean}
|
||||
//END PriceGetterService
|
||||
// Functions
|
||||
function get_price(client, coin, currency, node, pg_sid, mean_sid, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\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\" \"coin\") [] coin)\n )\n (call %init_peer_id% (\"getDataSrv\" \"currency\") [] currency)\n )\n (call %init_peer_id% (\"getDataSrv\" \"node\") [] node)\n )\n (call %init_peer_id% (\"getDataSrv\" \"pg_sid\") [] pg_sid)\n )\n (call %init_peer_id% (\"getDataSrv\" \"mean_sid\") [] mean_sid)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call node (\"op\" \"string_to_b58\") [node] k)\n (call node (\"peer\" \"timestamp_ms\") [] ts_ms0)\n )\n (call node (pg_sid \"price_getter\") [coin currency ts_ms0] res0)\n )\n (call node (\"op\" \"identity\") [res0.$.result!] $prices)\n )\n (call node (\"peer\" \"timestamp_ms\") [] ts_ms1)\n )\n (call node (pg_sid \"price_getter\") [coin currency ts_ms1] res1)\n )\n (call node (\"op\" \"identity\") [res1.$.result!] $prices)\n )\n (call node (mean_sid \"mean\") [$prices] result)\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\") [result])\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 client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'coin', function () { return coin; });
|
||||
h.on('getDataSrv', 'currency', function () { return currency; });
|
||||
h.on('getDataSrv', 'node', function () { return node; });
|
||||
h.on('getDataSrv', 'pg_sid', function () { return pg_sid; });
|
||||
h.on('getDataSrv', 'mean_sid', function () { return mean_sid; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for get_price');
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.get_price = get_price;
|
||||
function get_price_par(client, coin, currency, getter_topo, mean_topo, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\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\" \"coin\") [] coin)\n )\n (call %init_peer_id% (\"getDataSrv\" \"currency\") [] currency)\n )\n (call %init_peer_id% (\"getDataSrv\" \"getter_topo\") [] getter_topo)\n )\n (call %init_peer_id% (\"getDataSrv\" \"mean_topo\") [] mean_topo)\n )\n (fold getter_topo topo\n (par\n (seq\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (xor\n (seq\n (seq\n (seq\n (call topo.$.node! (\"op\" \"string_to_b58\") [topo.$.node!] k)\n (call topo.$.node! (\"peer\" \"timestamp_ms\") [] ts_ms)\n )\n (call topo.$.node! (topo.$.service_id! \"price_getter\") [coin currency ts_ms] res)\n )\n (call topo.$.node! (\"op\" \"identity\") [res.$.result!] $prices)\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 topo)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$prices.$.[2]!])\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call mean_topo.$.node! (mean_topo.$.service_id! \"mean\") [$prices] result)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [result])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'coin', function () { return coin; });
|
||||
h.on('getDataSrv', 'currency', function () { return currency; });
|
||||
h.on('getDataSrv', 'getter_topo', function () { return getter_topo; });
|
||||
h.on('getDataSrv', 'mean_topo', function () { return mean_topo; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for get_price_par');
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.get_price_par = get_price_par;
|
@ -1,133 +0,0 @@
|
||||
"use strict";
|
||||
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 });
|
||||
exports.get_price_par = exports.get_price = void 0;
|
||||
var api_unstable_1 = require("@fluencelabs/fluence/dist/api.unstable");
|
||||
function get_price(client, coin, currency, node, pg_sid, mean_sid, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\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\" \"coin\") [] coin)\n )\n (call %init_peer_id% (\"getDataSrv\" \"currency\") [] currency)\n )\n (call %init_peer_id% (\"getDataSrv\" \"node\") [] node)\n )\n (call %init_peer_id% (\"getDataSrv\" \"pg_sid\") [] pg_sid)\n )\n (call %init_peer_id% (\"getDataSrv\" \"mean_sid\") [] mean_sid)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call node (\"op\" \"string_to_b58\") [node] k)\n (call node (\"peer\" \"timestamp_ms\") [] ts_ms0)\n )\n (call node (pg_sid \"price_getter\") [coin currency ts_ms0] res0)\n )\n (call node (\"op\" \"identity\") [res0.$.result!] $prices)\n )\n (call node (\"peer\" \"timestamp_ms\") [] ts_ms1)\n )\n (call node (pg_sid \"price_getter\") [coin currency ts_ms1] res1)\n )\n (call node (\"op\" \"identity\") [res1.$.result!] $prices)\n )\n (call node (mean_sid \"mean\") [$prices] result)\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\") [result])\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 client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'coin', function () { return coin; });
|
||||
h.on('getDataSrv', 'currency', function () { return currency; });
|
||||
h.on('getDataSrv', 'node', function () { return node; });
|
||||
h.on('getDataSrv', 'pg_sid', function () { return pg_sid; });
|
||||
h.on('getDataSrv', 'mean_sid', function () { return mean_sid; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for get_price');
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.get_price = get_price;
|
||||
function get_price_par(client, coin, currency, getter_topo, mean_topo, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\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\" \"coin\") [] coin)\n )\n (call %init_peer_id% (\"getDataSrv\" \"currency\") [] currency)\n )\n (call %init_peer_id% (\"getDataSrv\" \"getter_topo\") [] getter_topo)\n )\n (call %init_peer_id% (\"getDataSrv\" \"mean_topo\") [] mean_topo)\n )\n (fold getter_topo topo\n (par\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (xor\n (seq\n (seq\n (seq\n (call topo.$.node! (\"op\" \"string_to_b58\") [topo.$.node!] k)\n (call topo.$.node! (\"peer\" \"timestamp_ms\") [] ts_ms)\n )\n (call topo.$.node! (topo.$.service_id! \"price_getter\") [coin currency ts_ms] res)\n )\n (call topo.$.node! (\"op\" \"identity\") [res.$.result!] $prices)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call mean_topo.$.node! (\"op\" \"noop\") [])\n )\n (next topo)\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call mean_topo.$.node! (mean_topo.$.service_id! \"mean\") [$prices] result)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [result])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'coin', function () { return coin; });
|
||||
h.on('getDataSrv', 'currency', function () { return currency; });
|
||||
h.on('getDataSrv', 'getter_topo', function () { return getter_topo; });
|
||||
h.on('getDataSrv', 'mean_topo', function () { return mean_topo; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for get_price_par');
|
||||
});
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.get_price_par = get_price_par;
|
@ -1,101 +0,0 @@
|
||||
"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 get_crypto_prices_1 = require("./_aqua/get_crypto_prices");
|
||||
var getter_topo;
|
||||
var mean_topo;
|
||||
getter_topo = Array({
|
||||
node: "12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS",
|
||||
service_id: "c315073d-4311-4db3-be57-8f154f032d28",
|
||||
}, {
|
||||
node: "12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi",
|
||||
service_id: "25f9123a-f386-4cb2-9c1e-bb7c247c9c09",
|
||||
});
|
||||
mean_topo = {
|
||||
node: "12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS",
|
||||
service_id: "dd47389f-25d9-4870-a2a9-909359e73580",
|
||||
};
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var network_result, network_result_par;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
console.log("hello crypto investors");
|
||||
// setLogLevel('DEBUG');
|
||||
return [4 /*yield*/, fluence_1.FluencePeer.default.init({ connectTo: fluence_network_environment_1.krasnodar[2] })];
|
||||
case 1:
|
||||
// setLogLevel('DEBUG');
|
||||
_a.sent();
|
||||
console.log("created a fluence client %s with relay %s", fluence_1.FluencePeer.default.connectionInfo.selfPeerId, fluence_1.FluencePeer.default.connectionInfo.connectedRelay);
|
||||
return [4 /*yield*/, get_crypto_prices_1.get_price("ethereum", "usd", "12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi", "25f9123a-f386-4cb2-9c1e-bb7c247c9c09", "b2790307-055e-41ca-9640-3c41856d464b")];
|
||||
case 2:
|
||||
network_result = _a.sent();
|
||||
console.log("seq result: ", network_result);
|
||||
return [4 /*yield*/, get_crypto_prices_1.get_price_par("ethereum", "usd", getter_topo, mean_topo)];
|
||||
case 3:
|
||||
network_result_par = _a.sent();
|
||||
console.log("par result: ", network_result_par);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
main()
|
||||
.then(function () { return process.exit(0); })
|
||||
.catch(function (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user