diff --git a/aqua-examples/price-oracle/web/.gitignore b/aqua-examples/price-oracle/web/.gitignore index 4d29575..5c13a3a 100644 --- a/aqua-examples/price-oracle/web/.gitignore +++ b/aqua-examples/price-oracle/web/.gitignore @@ -21,3 +21,11 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + + +# fluence + +src/_aqua/* + +public/*.wasm +public/runnerScript.* \ No newline at end of file diff --git a/aqua-examples/price-oracle/web/public/runnerScript.web.js b/aqua-examples/price-oracle/web/public/runnerScript.web.js deleted file mode 100644 index c754cf8..0000000 --- a/aqua-examples/price-oracle/web/public/runnerScript.web.js +++ /dev/null @@ -1 +0,0 @@ -!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=9)}([function(e,t,r){"use strict";t.a={isWorkerRuntime:function(){const e="undefined"!=typeof self&&"undefined"!=typeof Window&&self instanceof Window;return!("undefined"==typeof self||!self.postMessage||e)},postMessageToMaster:function(e,t){self.postMessage(e,t)},subscribeToMasterMessages:function(e){const t=t=>{e(t.data)};return self.addEventListener("message",t),()=>{self.removeEventListener("message",t)}}}},function(e,t,r){"use strict";r.d(t,"a",(function(){return i})),r.d(t,"b",(function(){return u}));const n={deserialize:e=>Object.assign(Error(e.message),{name:e.name,stack:e.stack}),serialize:e=>({__error_marker:"$$error",message:e.message,name:e.name,stack:e.stack})};let o={deserialize(e){return(t=e)&&"object"==typeof t&&"__error_marker"in t&&"$$error"===t.__error_marker?n.deserialize(e):e;var t},serialize:e=>e instanceof Error?n.serialize(e):e};function i(e){return o.deserialize(e)}function u(e){return o.serialize(e)}},function(e,t,r){"use strict";var n,o;r.d(t,"a",(function(){return n})),r.d(t,"b",(function(){return o})),function(e){e.cancel="cancel",e.run="run"}(n||(n={})),function(e){e.error="error",e.init="init",e.result="result",e.running="running",e.uncaughtError="uncaughtError"}(o||(o={}))},function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));Symbol("thread.errors"),Symbol("thread.events"),Symbol("thread.terminate");const n=Symbol("thread.transferable");Symbol("thread.worker");function o(e){return e&&"object"==typeof e&&e[n]}},function(e,t,r){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n="undefined"!=typeof window&&void 0!==window.document,o=void 0!==e&&null!=e.versions&&null!=e.versions.node,i="object"===("undefined"==typeof self?"undefined":r(self))&&self.constructor&&"DedicatedWorkerGlobalScope"===self.constructor.name,u="undefined"!=typeof window&&"nodejs"===window.name||"undefined"!=typeof navigator&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")),s="undefined"!=typeof Deno&&void 0!==Deno.core;t.isBrowser=n,t.isWebWorker=i,t.isNode=o,t.isJsDom=u,t.isDeno=s}).call(this,r(5))},function(e,t){var r,n,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function s(e){if(r===setTimeout)return setTimeout(e,0);if((r===i||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:i}catch(e){r=i}try{n="function"==typeof clearTimeout?clearTimeout:u}catch(e){n=u}}();var a,c=[],l=!1,f=-1;function p(){l&&a&&(l=!1,a.length?c=a.concat(c):f=-1,c.length&&d())}function d(){if(!l){var e=s(p);l=!0;for(var t=c.length;t;){for(a=c,c=[];++f1)for(var r=1;r=i)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return"[Circular]"}default:return e}})),a=n[r];r=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),y(r)?n.showHidden=r:r&&t._extend(n,r),h(n.showHidden)&&(n.showHidden=!1),h(n.depth)&&(n.depth=2),h(n.colors)&&(n.colors=!1),h(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=a),l(n,e,n.depth)}function a(e,t){var r=s.styles[t];return r?"["+s.colors[r][0]+"m"+e+"["+s.colors[r][1]+"m":e}function c(e,t){return e}function l(e,r,n){if(e.customInspect&&r&&E(r.inspect)&&r.inspect!==t.inspect&&(!r.constructor||r.constructor.prototype!==r)){var o=r.inspect(n,e);return g(o)||(o=l(e,o,n)),o}var i=function(e,t){if(h(t))return e.stylize("undefined","undefined");if(g(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(_(t))return e.stylize(""+t,"number");if(y(t))return e.stylize(""+t,"boolean");if(b(t))return e.stylize("null","null")}(e,r);if(i)return i;var u=Object.keys(r),s=function(e){var t={};return e.forEach((function(e,r){t[e]=!0})),t}(u);if(e.showHidden&&(u=Object.getOwnPropertyNames(r)),O(r)&&(u.indexOf("message")>=0||u.indexOf("description")>=0))return f(r);if(0===u.length){if(E(r)){var a=r.name?": "+r.name:"";return e.stylize("[Function"+a+"]","special")}if(m(r))return e.stylize(RegExp.prototype.toString.call(r),"regexp");if(w(r))return e.stylize(Date.prototype.toString.call(r),"date");if(O(r))return f(r)}var c,v="",j=!1,M=["{","}"];(d(r)&&(j=!0,M=["[","]"]),E(r))&&(v=" [Function"+(r.name?": "+r.name:"")+"]");return m(r)&&(v=" "+RegExp.prototype.toString.call(r)),w(r)&&(v=" "+Date.prototype.toUTCString.call(r)),O(r)&&(v=" "+f(r)),0!==u.length||j&&0!=r.length?n<0?m(r)?e.stylize(RegExp.prototype.toString.call(r),"regexp"):e.stylize("[Object]","special"):(e.seen.push(r),c=j?function(e,t,r,n,o){for(var i=[],u=0,s=t.length;u=0&&0,e+t.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60)return r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1];return r[0]+t+" "+e.join(", ")+" "+r[1]}(c,v,M)):M[0]+v+M[1]}function f(e){return"["+Error.prototype.toString.call(e)+"]"}function p(e,t,r,n,o,i){var u,s,a;if((a=Object.getOwnPropertyDescriptor(t,o)||{value:t[o]}).get?s=a.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):a.set&&(s=e.stylize("[Setter]","special")),P(n,o)||(u="["+o+"]"),s||(e.seen.indexOf(a.value)<0?(s=b(r)?l(e,a.value,null):l(e,a.value,r-1)).indexOf("\n")>-1&&(s=i?s.split("\n").map((function(e){return" "+e})).join("\n").substr(2):"\n"+s.split("\n").map((function(e){return" "+e})).join("\n")):s=e.stylize("[Circular]","special")),h(u)){if(i&&o.match(/^\d+$/))return s;(u=JSON.stringify(""+o)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(u=u.substr(1,u.length-2),u=e.stylize(u,"name")):(u=u.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),u=e.stylize(u,"string"))}return u+": "+s}function d(e){return Array.isArray(e)}function y(e){return"boolean"==typeof e}function b(e){return null===e}function _(e){return"number"==typeof e}function g(e){return"string"==typeof e}function h(e){return void 0===e}function m(e){return v(e)&&"[object RegExp]"===j(e)}function v(e){return"object"==typeof e&&null!==e}function w(e){return v(e)&&"[object Date]"===j(e)}function O(e){return v(e)&&("[object Error]"===j(e)||e instanceof Error)}function E(e){return"function"==typeof e}function j(e){return Object.prototype.toString.call(e)}function M(e){return e<10?"0"+e.toString(10):e.toString(10)}t.debuglog=function(r){if(h(i)&&(i=e.env.NODE_DEBUG||""),r=r.toUpperCase(),!u[r])if(new RegExp("\\b"+r+"\\b","i").test(i)){var n=e.pid;u[r]=function(){var e=t.format.apply(t,arguments);console.error("%s %d: %s",r,n,e)}}else u[r]=function(){};return u[r]},t.inspect=s,s.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},s.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},t.isArray=d,t.isBoolean=y,t.isNull=b,t.isNullOrUndefined=function(e){return null==e},t.isNumber=_,t.isString=g,t.isSymbol=function(e){return"symbol"==typeof e},t.isUndefined=h,t.isRegExp=m,t.isObject=v,t.isDate=w,t.isError=O,t.isFunction=E,t.isPrimitive=function(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||void 0===e},t.isBuffer=r(11);var T=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function x(){var e=new Date,t=[M(e.getHours()),M(e.getMinutes()),M(e.getSeconds())].join(":");return[e.getDate(),T[e.getMonth()],t].join(" ")}function P(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.log=function(){console.log("%s - %s",x(),t.format.apply(t,arguments))},t.inherits=r(12),t._extend=function(e,t){if(!t||!v(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e};var S="undefined"!=typeof Symbol?Symbol("util.promisify.custom"):void 0;function k(e,t){if(!e){var r=new Error("Promise was rejected with a falsy value");r.reason=e,e=r}return t(e)}t.promisify=function(e){if("function"!=typeof e)throw new TypeError('The "original" argument must be of type Function');if(S&&e[S]){var t;if("function"!=typeof(t=e[S]))throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(t,S,{value:t,enumerable:!1,writable:!1,configurable:!0}),t}function t(){for(var t,r,n=new Promise((function(e,n){t=e,r=n})),o=[],i=0;i0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]!!e&&("symbol"==typeof Symbol.observable&&"function"==typeof e[Symbol.observable]?e===e[Symbol.observable]():"function"==typeof e["@@observable"]&&e===e["@@observable"]())},function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__);var _fluencelabs_avm__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(7),_fluencelabs_avm__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_fluencelabs_avm__WEBPACK_IMPORTED_MODULE_0__),browser_or_node__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(4),browser_or_node__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(browser_or_node__WEBPACK_IMPORTED_MODULE_1__),threads__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(13);const logFunction=(e,t)=>{switch(e){case"error":console.error(t);break;case"warn":console.warn(t);break;case"info":console.info(t);break;case"debug":case"trace":console.log(t)}};let airInterpreter="not-set";const toExpose={init:async(logLevel,loadMethod)=>{let module;if(browser_or_node__WEBPACK_IMPORTED_MODULE_1__.isBrowser||browser_or_node__WEBPACK_IMPORTED_MODULE_1__.isWebWorker){if("fetch-from-url"!==loadMethod.method)throw new Error("Only 'fetch-from-url' is supported for browsers");const e=loadMethod.baseUrl+"/"+loadMethod.filePath;try{module=await WebAssembly.compileStreaming(fetch(e))}catch(t){throw new Error(`Failed to load ${e}. This usually means that the web server is not serving avm file correctly. Original error: ${t.toString()}`)}}else{if(!browser_or_node__WEBPACK_IMPORTED_MODULE_1__.isNode)throw new Error("Environment not supported");if("read-from-fs"!==loadMethod.method)throw new Error("Only 'read-from-fs' is supported for nodejs");try{const fs=eval("require")("fs"),file=fs.readFileSync(loadMethod.filePath);module=await WebAssembly.compile(file)}catch(e){throw new Error(`Failed to load ${loadMethod.filePath}. Did you forget to install @fluencelabs/avm? Original error: ${e.toString()}`)}}airInterpreter=await _fluencelabs_avm__WEBPACK_IMPORTED_MODULE_0__.AirInterpreter.create(module,logLevel,logFunction)},terminate:async()=>{airInterpreter="not-set"},run:async(e,t,r,n,o)=>{if("not-set"===airInterpreter)throw new Error("Interpreter is not initialized");if("terminated"===airInterpreter)throw new Error("Interpreter is terminated");return airInterpreter.invoke(e,t,r,n,o)}};Object(threads__WEBPACK_IMPORTED_MODULE_2__.a)(toExpose)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.invoke=t.getStringFromWasm0=t.main=void 0,t.main=function(e){e.main()};var n=0,o=null;function i(e){return null!==o&&o.buffer===e.memory.buffer||(o=new Uint8Array(e.memory.buffer)),o}var u=new("undefined"==typeof TextEncoder?r(6).TextEncoder:TextEncoder)("utf-8"),s="function"==typeof u.encodeInto?function(e,t){return u.encodeInto(e,t)}:function(e,t){var r=u.encode(e);return t.set(r),{read:e.length,written:r.length}};function a(e,t,r,o){if(void 0===o){var a=u.encode(t),c=r(a.length);return i(e).subarray(c,c+a.length).set(a),n=a.length,c}for(var l=t.length,f=r(l),p=i(e),d=0;d127)break;p[f+d]=y}if(d!==l){0!==d&&(t=t.slice(d)),f=o(f,l,l=d+3*t.length);var b=i(e).subarray(f+d,f+l);d+=s(t,b).written}return n=d,f}function c(e,t,r){var o=r(1*t.length);return i(e).set(t,o/1),n=t.length,o}var l=null;function f(e){return null!==l&&l.buffer===e.memory.buffer||(l=new Int32Array(e.memory.buffer)),l}var p=new("undefined"==typeof TextDecoder?r(6).TextDecoder:TextDecoder)("utf-8",{ignoreBOM:!0,fatal:!0});function d(e,t,r){return p.decode(i(e).subarray(t,t+r))}p.decode(),t.getStringFromWasm0=d,t.invoke=function(e,t,r,o,i,u,s){try{var l=a(e,t,e.__wbindgen_malloc,e.__wbindgen_realloc),p=n,y=c(e,r,e.__wbindgen_malloc),b=n,_=c(e,o,e.__wbindgen_malloc),g=n,h=c(e,i,e.__wbindgen_malloc),m=n,v=c(e,u,e.__wbindgen_malloc),w=n,O=a(e,s,e.__wbindgen_malloc,e.__wbindgen_realloc),E=n;e.invoke(8,l,p,y,b,_,g,h,m,v,w,O,E);var j=f(e)[2],M=f(e)[3];return d(e,j,M)}finally{e.__wbindgen_free(j,M)}}},function(e,t){e.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},function(e,t,r){"use strict";(function(e){r.d(t,"a",(function(){return m}));var n=r(8),o=r.n(n),i=r(1),u=r(3),s=r(2),a=r(0),c=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function u(e){try{a(n.next(e))}catch(e){i(e)}}function s(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,s)}a((n=n.apply(e,t||[])).next())}))};a.a.isWorkerRuntime;let l=!1;const f=new Map,p=e=>e&&e.type===s.a.run,d=e=>o()(e)||function(e){return e&&"object"==typeof e&&"function"==typeof e.subscribe}(e);function y(e){return Object(u.a)(e)?{payload:e.send,transferables:e.transferables}:{payload:e,transferables:void 0}}function b(e,t){const{payload:r,transferables:n}=y(t),o={type:s.b.error,uid:e,error:Object(i.b)(r)};a.a.postMessageToMaster(o,n)}function _(e,t,r){const{payload:n,transferables:o}=y(r),i={type:s.b.result,uid:e,complete:!!t||void 0,payload:n};a.a.postMessageToMaster(i,o)}function g(e){try{const t={type:s.b.uncaughtError,error:Object(i.b)(e)};a.a.postMessageToMaster(t)}catch(t){console.error("Not reporting uncaught error back to master thread as it occured while reporting an uncaught error already.\nLatest error:",t,"\nOriginal error:",e)}}function h(e,t,r){return c(this,void 0,void 0,(function*(){let n;try{n=t(...r)}catch(t){return b(e,t)}const o=d(n)?"observable":"promise";if(function(e,t){const r={type:s.b.running,uid:e,resultType:t};a.a.postMessageToMaster(r)}(e,o),d(n)){const t=n.subscribe(t=>_(e,!1,Object(i.b)(t)),t=>{b(e,Object(i.b)(t)),f.delete(e)},()=>{_(e,!0),f.delete(e)});f.set(e,t)}else try{const t=yield n;_(e,!0,Object(i.b)(t))}catch(t){b(e,Object(i.b)(t))}}))}function m(e){if(!a.a.isWorkerRuntime())throw Error("expose() called in the master thread.");if(l)throw Error("expose() called more than once. This is not possible. Pass an object to expose() if you want to expose multiple functions.");if(l=!0,"function"==typeof e)a.a.subscribeToMasterMessages(t=>{p(t)&&!t.method&&h(t.uid,e,t.args.map(i.a))}),function(){const e={type:s.b.init,exposed:{type:"function"}};a.a.postMessageToMaster(e)}();else{if("object"!=typeof e||!e)throw Error("Invalid argument passed to expose(). Expected a function or an object, got: "+e);a.a.subscribeToMasterMessages(t=>{p(t)&&t.method&&h(t.uid,e[t.method],t.args.map(i.a))});!function(e){const t={type:s.b.init,exposed:{type:"module",methods:e}};a.a.postMessageToMaster(t)}(Object.keys(e).filter(t=>"function"==typeof e[t]))}a.a.subscribeToMasterMessages(e=>{if((t=e)&&t.type===s.a.cancel){const t=e.uid,r=f.get(t);r&&(r.unsubscribe(),f.delete(t))}var t})}"undefined"!=typeof self&&"function"==typeof self.addEventListener&&a.a.isWorkerRuntime()&&(self.addEventListener("error",e=>{setTimeout(()=>g(e.error||e),250)}),self.addEventListener("unhandledrejection",e=>{const t=e.reason;t&&"string"==typeof t.message&&setTimeout(()=>g(t),250)})),void 0!==e&&"function"==typeof e.on&&a.a.isWorkerRuntime()&&(e.on("uncaughtException",e=>{setTimeout(()=>g(e),250)}),e.on("unhandledRejection",e=>{e&&"string"==typeof e.message&&setTimeout(()=>g(e),250)}))}).call(this,r(5))}]); \ No newline at end of file diff --git a/aqua-examples/price-oracle/web/src/_aqua/get_crypto_prices.ts b/aqua-examples/price-oracle/web/src/_aqua/get_crypto_prices.ts deleted file mode 100644 index 25a6e54..0000000 --- a/aqua-examples/price-oracle/web/src/_aqua/get_crypto_prices.ts +++ /dev/null @@ -1,412 +0,0 @@ -/** - * - * This file is auto-generated. Do not edit manually: changes may be erased. - * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. - * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues - * Aqua version: 0.6.0-277 - * - */ -import { Fluence, FluencePeer } from '@fluencelabs/fluence'; -import { - CallParams, - callFunction, - registerService, -} from '@fluencelabs/fluence/dist/internal/compilerSupport/v2'; - - -// Services - -export interface MeanServiceDef { - mean: (data: number[], callParams: CallParams<'data'>) => { error_msg: string; result: number; success: boolean; } | Promise<{ error_msg: string; result: number; success: boolean; }>; -} -export function registerMeanService(serviceId: string, service: MeanServiceDef): void; -export function registerMeanService(peer: FluencePeer, serviceId: string, service: MeanServiceDef): void; - - -export function registerMeanService(...args: any) { - registerService( - args, - { - "functions" : [ - { - "functionName" : "mean", - "argDefs" : [ - { - "name" : "data", - "argType" : { - "tag" : "primitive" - } - } - ], - "returnType" : { - "tag" : "primitive" - } - } - ] -} - ); -} - - - -export interface F64OpDef { - identity: (x: number, callParams: CallParams<'x'>) => number | Promise; -} -export function registerF64Op(service: F64OpDef): void; -export function registerF64Op(serviceId: string, service: F64OpDef): void; -export function registerF64Op(peer: FluencePeer, service: F64OpDef): void; -export function registerF64Op(peer: FluencePeer, serviceId: string, service: F64OpDef): void; - - -export function registerF64Op(...args: any) { - registerService( - args, - { - "defaultServiceId" : "op", - "functions" : [ - { - "functionName" : "identity", - "argDefs" : [ - { - "name" : "x", - "argType" : { - "tag" : "primitive" - } - } - ], - "returnType" : { - "tag" : "primitive" - } - } - ] -} - ); -} - - - -export interface PriceGetterServiceDef { - price_getter: (coin: string, currency: string, timestamp_ms: number, callParams: CallParams<'coin' | 'currency' | 'timestamp_ms'>) => { error_msg: string; result: number; success: boolean; } | Promise<{ error_msg: string; result: number; success: boolean; }>; -} -export function registerPriceGetterService(serviceId: string, service: PriceGetterServiceDef): void; -export function registerPriceGetterService(peer: FluencePeer, serviceId: string, service: PriceGetterServiceDef): void; - - -export function registerPriceGetterService(...args: any) { - registerService( - args, - { - "functions" : [ - { - "functionName" : "price_getter", - "argDefs" : [ - { - "name" : "coin", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "currency", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "timestamp_ms", - "argType" : { - "tag" : "primitive" - } - } - ], - "returnType" : { - "tag" : "primitive" - } - } - ] -} - ); -} - -// Functions -export type Get_price_parArgMean_topo = { node: string; service_id: string; } -export type Get_price_parResult = { error_msg: string; result: number; success: boolean; } -export function get_price_par( - coin: string, - currency: string, - getter_topo: { node: string; service_id: string; }[], - mean_topo: Get_price_parArgMean_topo, - config?: {ttl?: number} -): Promise; - -export function get_price_par( - peer: FluencePeer, - coin: string, - currency: string, - getter_topo: { node: string; service_id: string; }[], - mean_topo: Get_price_parArgMean_topo, - config?: {ttl?: number} -): Promise; - -export function get_price_par(...args: any) { - - let script = ` - (xor - (seq - (seq - (seq - (seq - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "coin") [] coin) - ) - (call %init_peer_id% ("getDataSrv" "currency") [] currency) - ) - (call %init_peer_id% ("getDataSrv" "getter_topo") [] getter_topo) - ) - (call %init_peer_id% ("getDataSrv" "mean_topo") [] mean_topo) - ) - (new $prices - (seq - (par - (fold getter_topo topo - (par - (seq - (seq - (call -relay- ("op" "noop") []) - (xor - (seq - (seq - (seq - (call topo.$.node! ("peer" "timestamp_ms") [] ts_ms) - (call topo.$.node! (topo.$.service_id! "price_getter") [coin currency ts_ms] res) - ) - (call topo.$.node! ("op" "identity") [res.$.result!] $prices) - ) - (call topo.$.node! ("op" "noop") []) - ) - (seq - (call -relay- ("op" "noop") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) - ) - ) - ) - (call mean_topo.$.node! ("op" "noop") []) - ) - (next topo) - ) - ) - (null) - ) - (xor - (seq - (seq - (call mean_topo.$.node! ("op" "identity") [$prices.$.[1]!]) - (call mean_topo.$.node! (mean_topo.$.service_id! "mean") [$prices] result) - ) - (call -relay- ("op" "noop") []) - ) - (seq - (call -relay- ("op" "noop") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) - ) - ) - ) - ) - ) - (xor - (call %init_peer_id% ("callbackSrv" "response") [result]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) - ) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) - ) - ` - return callFunction( - args, - { - "functionName" : "get_price_par", - "returnType" : { - "tag" : "primitive" - }, - "argDefs" : [ - { - "name" : "coin", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "currency", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "getter_topo", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "mean_topo", - "argType" : { - "tag" : "primitive" - } - } - ], - "names" : { - "relay" : "-relay-", - "getDataSrv" : "getDataSrv", - "callbackSrv" : "callbackSrv", - "responseSrv" : "callbackSrv", - "responseFnName" : "response", - "errorHandlingSrv" : "errorHandlingSrv", - "errorFnName" : "error" - } -}, - script - ) -} - - -export type Get_priceResult = { error_msg: string; result: number; success: boolean; } -export function get_price( - coin: string, - currency: string, - node: string, - pg_sid: string, - mean_sid: string, - config?: {ttl?: number} -): Promise; - -export function get_price( - peer: FluencePeer, - coin: string, - currency: string, - node: string, - pg_sid: string, - mean_sid: string, - config?: {ttl?: number} -): Promise; - -export function get_price(...args: any) { - - let script = ` - (xor - (seq - (seq - (seq - (seq - (seq - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "coin") [] coin) - ) - (call %init_peer_id% ("getDataSrv" "currency") [] currency) - ) - (call %init_peer_id% ("getDataSrv" "node") [] node) - ) - (call %init_peer_id% ("getDataSrv" "pg_sid") [] pg_sid) - ) - (call %init_peer_id% ("getDataSrv" "mean_sid") [] mean_sid) - ) - (new $prices - (seq - (call -relay- ("op" "noop") []) - (xor - (seq - (seq - (seq - (seq - (seq - (seq - (seq - (seq - (call node ("op" "string_to_b58") [node] k) - (call node ("peer" "timestamp_ms") [] ts_ms0) - ) - (call node (pg_sid "price_getter") [coin currency ts_ms0] res0) - ) - (call node ("op" "identity") [res0.$.result!] $prices) - ) - (call node ("peer" "timestamp_ms") [] ts_ms1) - ) - (call node (pg_sid "price_getter") [coin currency ts_ms1] res1) - ) - (call node ("op" "identity") [res1.$.result!] $prices) - ) - (call node (mean_sid "mean") [$prices] result) - ) - (call -relay- ("op" "noop") []) - ) - (seq - (call -relay- ("op" "noop") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) - ) - ) - ) - ) - ) - (xor - (call %init_peer_id% ("callbackSrv" "response") [result]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) - ) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) - ) - ` - return callFunction( - args, - { - "functionName" : "get_price", - "returnType" : { - "tag" : "primitive" - }, - "argDefs" : [ - { - "name" : "coin", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "currency", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "node", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "pg_sid", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "mean_sid", - "argType" : { - "tag" : "primitive" - } - } - ], - "names" : { - "relay" : "-relay-", - "getDataSrv" : "getDataSrv", - "callbackSrv" : "callbackSrv", - "responseSrv" : "callbackSrv", - "responseFnName" : "response", - "errorHandlingSrv" : "errorHandlingSrv", - "errorFnName" : "error" - } -}, - script - ) -}