Update flunce-js examples

This commit is contained in:
Pavel Murygin 2021-10-21 23:15:13 +03:00
parent 1cb4613c30
commit 0b8637aa4c
7 changed files with 570 additions and 414 deletions

View File

@ -8,7 +8,7 @@
"name": "getting-started-browser",
"version": "0.1.0",
"dependencies": {
"@fluencelabs/fluence": "0.12.0",
"@fluencelabs/fluence": "^0.14.2",
"@fluencelabs/fluence-network-environment": "1.0.10",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
@ -24,7 +24,7 @@
"web-vitals": "^1.1.2"
},
"devDependencies": {
"@fluencelabs/aqua": "^0.3.0-226",
"@fluencelabs/aqua": "^0.4.0-234",
"@fluencelabs/aqua-lib": "0.1.9",
"chokidar-cli": "^2.1.0",
"node-sass": "^6.0.1"
@ -1904,14 +1904,16 @@
}
},
"node_modules/@fluencelabs/aqua": {
"version": "0.3.0-226",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.3.0-226.tgz",
"integrity": "sha512-9o0TdgsVNcBvifqo7VqIkN62P9EReE0LUxgWG1rGHi9yxJiGElvEBvrVUzqShffF66Ene7VGEe85lhFIGCfDgg==",
"version": "0.4.0-234",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.4.0-234.tgz",
"integrity": "sha512-7ysLPh3R4gAfXgO24OGT7rP5UGKUHs7ipfx4HTJsYZahZ0rMbWA98uC/aM3+q0WH1WEowyV16zvGACONFLZ5RA==",
"dev": true,
"dependencies": {
"@fluencelabs/fluence": "0.12.1"
},
"bin": {
"aqua": "index.js",
"aqua-cli": "error.js",
"aqua-j": "index-java.js"
"aqua-cli": "error.js"
}
},
"node_modules/@fluencelabs/aqua-lib": {
@ -1920,18 +1922,11 @@
"integrity": "sha512-WLvwrH98R4BT7NHrzYkJE8f0G61BZi3lVog/W3pmyzYjufxTtxoAS28Zqycbt0ZVpUTfIC016QKu58b4SbhZWw==",
"dev": true
},
"node_modules/@fluencelabs/avm": {
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"dependencies": {
"base64-js": "1.5.1"
}
},
"node_modules/@fluencelabs/fluence": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.12.0.tgz",
"integrity": "sha512-eYg3CflqeqlWUoaXXXUBxls7Pzjytp1nkHZWoe39bL7poF20T1BuTovNWo/jTWma5HS4L1FaAGGRNaMcN0wFHQ==",
"node_modules/@fluencelabs/aqua/node_modules/@fluencelabs/fluence": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.12.1.tgz",
"integrity": "sha512-JrMKMHjYILAHQsLLd5H0fLt/UMZv+/PQYxJYe6h9HFyJlZrN1bUV+EcZnUw1u3DZE5k/RXBx0udfmkahggwrqA==",
"dev": true,
"dependencies": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.4",
@ -1947,16 +1942,85 @@
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"noble-ed25519": "^1.2.5",
"peer-id": "0.15.3",
"uuid": "8.3.0"
}
},
"node_modules/@fluencelabs/aqua/node_modules/async": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==",
"dev": true
},
"node_modules/@fluencelabs/aqua/node_modules/loglevel": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.7.0.tgz",
"integrity": "sha512-i2sY04nal5jDcagM3FMfG++T69GEEM8CYuOfeOIvmXzOIcwE9a/CJPR0MFM97pYMj/u10lzz7/zd7+qwhrBTqQ==",
"dev": true,
"engines": {
"node": ">= 0.6.0"
},
"funding": {
"type": "tidelift",
"url": "https://tidelift.com/subscription/pkg/npm-loglevel?utm_medium=referral&utm_source=npm_fund"
}
},
"node_modules/@fluencelabs/aqua/node_modules/uuid": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.0.tgz",
"integrity": "sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==",
"dev": true,
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/@fluencelabs/avm": {
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"dev": true,
"dependencies": {
"base64-js": "1.5.1"
}
},
"node_modules/@fluencelabs/fluence": {
"version": "0.14.2",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.14.2.tgz",
"integrity": "sha512-Cf5Ii6dpVSSi839jB7H0Y9k07xncYdHiTNKp4LlPg6inXuy2OPb2E7qF5DXlMM9O1dBb/UJTa4jZlQDsgWriiQ==",
"dependencies": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.15.4",
"async": "3.2.0",
"base64-js": "1.5.1",
"bs58": "4.0.1",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
"it-pipe": "1.1.0",
"libp2p": "0.32.3",
"libp2p-crypto": "0.19.7",
"libp2p-mplex": "0.10.4",
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"peer-id": "0.15.3",
"rxjs": "^7.3.0",
"ts-pattern": "^3.3.3",
"uuid": "8.3.0"
}
},
"node_modules/@fluencelabs/fluence-network-environment": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence-network-environment/-/fluence-network-environment-1.0.10.tgz",
"integrity": "sha512-aaWZDDFIIasSTgdFdw1KEz+boZMSn7pXffUENZNLX4DrP11rC3AEX4c8GnIJQbWqGsouOFZOPna2DSG6o2rLNQ=="
},
"node_modules/@fluencelabs/fluence/node_modules/@fluencelabs/avm": {
"version": "0.15.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.15.4.tgz",
"integrity": "sha512-NLZDq83ocJ1Helm0D8kPMSSkjxH0y+Tujg0px773zjIShbh3jgiJOjAW1xCYgTt9K0LqepjP0bWX4/8nUZfr7g==",
"dependencies": {
"base64-js": "1.5.1"
}
},
"node_modules/@fluencelabs/fluence/node_modules/async": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
@ -16089,11 +16153,6 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
},
"node_modules/noble-ed25519": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/noble-ed25519/-/noble-ed25519-1.2.5.tgz",
"integrity": "sha512-7vst+4UhM5QU3jJ3pUqPMKBCOePrxBojmoQa59qcSnYvjFF/T4jqb4WISlfslcWyBw7G5H9V/acpcAxMd8DzUQ=="
},
"node_modules/node-addon-api": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
@ -20185,6 +20244,19 @@
"aproba": "^1.1.1"
}
},
"node_modules/rxjs": {
"version": "7.4.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.4.0.tgz",
"integrity": "sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==",
"dependencies": {
"tslib": "~2.1.0"
}
},
"node_modules/rxjs/node_modules/tslib": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz",
"integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A=="
},
"node_modules/safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
@ -22270,6 +22342,11 @@
"resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz",
"integrity": "sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA=="
},
"node_modules/ts-pattern": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-3.3.3.tgz",
"integrity": "sha512-Z5EFi6g6wyX3uDFHqxF5W5c5h663oZg9O6aOiAT7fqNu0HPSfCxtHzrQ7SblTy738Mrg2Ezorky8H5aUOm8Pvg=="
},
"node_modules/ts-pnp": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/ts-pnp/-/ts-pnp-1.2.0.tgz",
@ -26004,10 +26081,57 @@
}
},
"@fluencelabs/aqua": {
"version": "0.3.0-226",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.3.0-226.tgz",
"integrity": "sha512-9o0TdgsVNcBvifqo7VqIkN62P9EReE0LUxgWG1rGHi9yxJiGElvEBvrVUzqShffF66Ene7VGEe85lhFIGCfDgg==",
"dev": true
"version": "0.4.0-234",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.4.0-234.tgz",
"integrity": "sha512-7ysLPh3R4gAfXgO24OGT7rP5UGKUHs7ipfx4HTJsYZahZ0rMbWA98uC/aM3+q0WH1WEowyV16zvGACONFLZ5RA==",
"dev": true,
"requires": {
"@fluencelabs/fluence": "0.12.1"
},
"dependencies": {
"@fluencelabs/fluence": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.12.1.tgz",
"integrity": "sha512-JrMKMHjYILAHQsLLd5H0fLt/UMZv+/PQYxJYe6h9HFyJlZrN1bUV+EcZnUw1u3DZE5k/RXBx0udfmkahggwrqA==",
"dev": true,
"requires": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.4",
"async": "3.2.0",
"base64-js": "1.5.1",
"bs58": "4.0.1",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
"it-pipe": "1.1.0",
"libp2p": "0.32.3",
"libp2p-crypto": "0.19.7",
"libp2p-mplex": "0.10.4",
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"peer-id": "0.15.3",
"uuid": "8.3.0"
}
},
"async": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==",
"dev": true
},
"loglevel": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.7.0.tgz",
"integrity": "sha512-i2sY04nal5jDcagM3FMfG++T69GEEM8CYuOfeOIvmXzOIcwE9a/CJPR0MFM97pYMj/u10lzz7/zd7+qwhrBTqQ==",
"dev": true
},
"uuid": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.0.tgz",
"integrity": "sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==",
"dev": true
}
}
},
"@fluencelabs/aqua-lib": {
"version": "0.1.9",
@ -26019,17 +26143,18 @@
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"dev": true,
"requires": {
"base64-js": "1.5.1"
}
},
"@fluencelabs/fluence": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.12.0.tgz",
"integrity": "sha512-eYg3CflqeqlWUoaXXXUBxls7Pzjytp1nkHZWoe39bL7poF20T1BuTovNWo/jTWma5HS4L1FaAGGRNaMcN0wFHQ==",
"version": "0.14.2",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.14.2.tgz",
"integrity": "sha512-Cf5Ii6dpVSSi839jB7H0Y9k07xncYdHiTNKp4LlPg6inXuy2OPb2E7qF5DXlMM9O1dBb/UJTa4jZlQDsgWriiQ==",
"requires": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.4",
"@fluencelabs/avm": "0.15.4",
"async": "3.2.0",
"base64-js": "1.5.1",
"bs58": "4.0.1",
@ -26042,11 +26167,20 @@
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"noble-ed25519": "^1.2.5",
"peer-id": "0.15.3",
"rxjs": "^7.3.0",
"ts-pattern": "^3.3.3",
"uuid": "8.3.0"
},
"dependencies": {
"@fluencelabs/avm": {
"version": "0.15.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.15.4.tgz",
"integrity": "sha512-NLZDq83ocJ1Helm0D8kPMSSkjxH0y+Tujg0px773zjIShbh3jgiJOjAW1xCYgTt9K0LqepjP0bWX4/8nUZfr7g==",
"requires": {
"base64-js": "1.5.1"
}
},
"async": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
@ -36953,11 +37087,6 @@
}
}
},
"noble-ed25519": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/noble-ed25519/-/noble-ed25519-1.2.5.tgz",
"integrity": "sha512-7vst+4UhM5QU3jJ3pUqPMKBCOePrxBojmoQa59qcSnYvjFF/T4jqb4WISlfslcWyBw7G5H9V/acpcAxMd8DzUQ=="
},
"node-addon-api": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
@ -40165,6 +40294,21 @@
"aproba": "^1.1.1"
}
},
"rxjs": {
"version": "7.4.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.4.0.tgz",
"integrity": "sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==",
"requires": {
"tslib": "~2.1.0"
},
"dependencies": {
"tslib": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz",
"integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A=="
}
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
@ -41851,6 +41995,11 @@
"resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz",
"integrity": "sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA=="
},
"ts-pattern": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-3.3.3.tgz",
"integrity": "sha512-Z5EFi6g6wyX3uDFHqxF5W5c5h663oZg9O6aOiAT7fqNu0HPSfCxtHzrQ7SblTy738Mrg2Ezorky8H5aUOm8Pvg=="
},
"ts-pnp": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/ts-pnp/-/ts-pnp-1.2.0.tgz",

View File

@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@fluencelabs/fluence": "0.12.0",
"@fluencelabs/fluence": "^0.14.2",
"@fluencelabs/fluence-network-environment": "1.0.10",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
@ -45,7 +45,7 @@
]
},
"devDependencies": {
"@fluencelabs/aqua": "^0.3.0-226",
"@fluencelabs/aqua": "^0.4.0-234",
"@fluencelabs/aqua-lib": "0.1.9",
"chokidar-cli": "^2.1.0",
"node-sass": "^6.0.1"

View File

@ -1,103 +1,83 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* 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
* Aqua version: 0.4.0-234
*
*/
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
callFunction,
registerService,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v2';
// Services
// Functions
export function getRelayTime(relayPeerId: string, config?: {ttl?: number}) : Promise<number>;
export function getRelayTime(peer: FluencePeer, relayPeerId: string, config?: {ttl?: number}) : Promise<number>;
export function getRelayTime(...args: any) {
let peer: FluencePeer;
let relayPeerId: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
relayPeerId = args[1];
config = args[2];
} else {
peer = Fluence.getPeer();
relayPeerId = 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
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "relayPeerId") [] relayPeerId)
)
(call -relay- ("op" "noop") [])
)
(xor
(call relayPeerId ("peer" "timestamp_ms") [] ts)
(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") [ts])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
export function getRelayTime(relayPeerId: string, config?: {ttl?: number}): Promise<number>;
export function getRelayTime(peer: FluencePeer, relayPeerId: string, config?: {ttl?: number}): Promise<number>;
export function getRelayTime(...args: any) {
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'relayPeerId', () => {return relayPeerId;});
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 getRelayTime');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
let script = `
(xor
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "relayPeerId") [] relayPeerId)
)
(call -relay- ("op" "noop") [])
)
(xor
(call relayPeerId ("peer" "timestamp_ms") [] ts)
(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") [ts])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`
return callFunction(
args,
{
"functionName" : "getRelayTime",
"returnType" : {
"tag" : "primitive"
},
"argDefs" : [
{
"name" : "relayPeerId",
"argType" : {
"tag" : "primitive"
}
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
],
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
}

View File

@ -9,11 +9,11 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@fluencelabs/fluence": "0.12.0",
"@fluencelabs/fluence": "^0.14.2",
"@fluencelabs/fluence-network-environment": "1.0.10"
},
"devDependencies": {
"@fluencelabs/aqua": "^0.3.0-226",
"@fluencelabs/aqua": "^0.4.0-234",
"chokidar-cli": "^3.0.0",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
@ -72,28 +72,32 @@
}
},
"node_modules/@fluencelabs/aqua": {
"version": "0.3.0-226",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.3.0-226.tgz",
"integrity": "sha512-9o0TdgsVNcBvifqo7VqIkN62P9EReE0LUxgWG1rGHi9yxJiGElvEBvrVUzqShffF66Ene7VGEe85lhFIGCfDgg==",
"version": "0.4.0-234",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.4.0-234.tgz",
"integrity": "sha512-7ysLPh3R4gAfXgO24OGT7rP5UGKUHs7ipfx4HTJsYZahZ0rMbWA98uC/aM3+q0WH1WEowyV16zvGACONFLZ5RA==",
"dev": true,
"dependencies": {
"@fluencelabs/fluence": "0.12.1"
},
"bin": {
"aqua": "index.js",
"aqua-cli": "error.js",
"aqua-j": "index-java.js"
"aqua-cli": "error.js"
}
},
"node_modules/@fluencelabs/avm": {
"node_modules/@fluencelabs/aqua/node_modules/@fluencelabs/avm": {
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"dev": true,
"dependencies": {
"base64-js": "1.5.1"
}
},
"node_modules/@fluencelabs/fluence": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.12.0.tgz",
"integrity": "sha512-eYg3CflqeqlWUoaXXXUBxls7Pzjytp1nkHZWoe39bL7poF20T1BuTovNWo/jTWma5HS4L1FaAGGRNaMcN0wFHQ==",
"node_modules/@fluencelabs/aqua/node_modules/@fluencelabs/fluence": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.12.1.tgz",
"integrity": "sha512-JrMKMHjYILAHQsLLd5H0fLt/UMZv+/PQYxJYe6h9HFyJlZrN1bUV+EcZnUw1u3DZE5k/RXBx0udfmkahggwrqA==",
"dev": true,
"dependencies": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.4",
@ -109,11 +113,43 @@
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"noble-ed25519": "^1.2.5",
"peer-id": "0.15.3",
"uuid": "8.3.0"
}
},
"node_modules/@fluencelabs/avm": {
"version": "0.15.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.15.4.tgz",
"integrity": "sha512-NLZDq83ocJ1Helm0D8kPMSSkjxH0y+Tujg0px773zjIShbh3jgiJOjAW1xCYgTt9K0LqepjP0bWX4/8nUZfr7g==",
"dependencies": {
"base64-js": "1.5.1"
}
},
"node_modules/@fluencelabs/fluence": {
"version": "0.14.2",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.14.2.tgz",
"integrity": "sha512-Cf5Ii6dpVSSi839jB7H0Y9k07xncYdHiTNKp4LlPg6inXuy2OPb2E7qF5DXlMM9O1dBb/UJTa4jZlQDsgWriiQ==",
"dependencies": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.15.4",
"async": "3.2.0",
"base64-js": "1.5.1",
"bs58": "4.0.1",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
"it-pipe": "1.1.0",
"libp2p": "0.32.3",
"libp2p-crypto": "0.19.7",
"libp2p-mplex": "0.10.4",
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"peer-id": "0.15.3",
"rxjs": "^7.3.0",
"ts-pattern": "^3.3.3",
"uuid": "8.3.0"
}
},
"node_modules/@fluencelabs/fluence-network-environment": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence-network-environment/-/fluence-network-environment-1.0.10.tgz",
@ -2246,11 +2282,6 @@
"node": ">= 0.4.0"
}
},
"node_modules/noble-ed25519": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/noble-ed25519/-/noble-ed25519-1.2.5.tgz",
"integrity": "sha512-7vst+4UhM5QU3jJ3pUqPMKBCOePrxBojmoQa59qcSnYvjFF/T4jqb4WISlfslcWyBw7G5H9V/acpcAxMd8DzUQ=="
},
"node_modules/node-addon-api": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
@ -2693,6 +2724,14 @@
"node": ">= 4"
}
},
"node_modules/rxjs": {
"version": "7.4.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.4.0.tgz",
"integrity": "sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==",
"dependencies": {
"tslib": "~2.1.0"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
@ -2956,6 +2995,16 @@
}
}
},
"node_modules/ts-pattern": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-3.3.3.tgz",
"integrity": "sha512-Z5EFi6g6wyX3uDFHqxF5W5c5h663oZg9O6aOiAT7fqNu0HPSfCxtHzrQ7SblTy738Mrg2Ezorky8H5aUOm8Pvg=="
},
"node_modules/tslib": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz",
"integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A=="
},
"node_modules/tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
@ -3236,26 +3285,64 @@
}
},
"@fluencelabs/aqua": {
"version": "0.3.0-226",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.3.0-226.tgz",
"integrity": "sha512-9o0TdgsVNcBvifqo7VqIkN62P9EReE0LUxgWG1rGHi9yxJiGElvEBvrVUzqShffF66Ene7VGEe85lhFIGCfDgg==",
"dev": true
"version": "0.4.0-234",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua/-/aqua-0.4.0-234.tgz",
"integrity": "sha512-7ysLPh3R4gAfXgO24OGT7rP5UGKUHs7ipfx4HTJsYZahZ0rMbWA98uC/aM3+q0WH1WEowyV16zvGACONFLZ5RA==",
"dev": true,
"requires": {
"@fluencelabs/fluence": "0.12.1"
},
"dependencies": {
"@fluencelabs/avm": {
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"dev": true,
"requires": {
"base64-js": "1.5.1"
}
},
"@fluencelabs/fluence": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.12.1.tgz",
"integrity": "sha512-JrMKMHjYILAHQsLLd5H0fLt/UMZv+/PQYxJYe6h9HFyJlZrN1bUV+EcZnUw1u3DZE5k/RXBx0udfmkahggwrqA==",
"dev": true,
"requires": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.4",
"async": "3.2.0",
"base64-js": "1.5.1",
"bs58": "4.0.1",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
"it-pipe": "1.1.0",
"libp2p": "0.32.3",
"libp2p-crypto": "0.19.7",
"libp2p-mplex": "0.10.4",
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"peer-id": "0.15.3",
"uuid": "8.3.0"
}
}
}
},
"@fluencelabs/avm": {
"version": "0.14.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.14.4.tgz",
"integrity": "sha512-XyR+1H5k0CAc+mDHOkl81viX8XeW1Yqbw793xbsfUfju5bUb/hqk+gHv3q8lAFdbrCG5P45gdOT08a5RNODZaQ==",
"version": "0.15.4",
"resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.15.4.tgz",
"integrity": "sha512-NLZDq83ocJ1Helm0D8kPMSSkjxH0y+Tujg0px773zjIShbh3jgiJOjAW1xCYgTt9K0LqepjP0bWX4/8nUZfr7g==",
"requires": {
"base64-js": "1.5.1"
}
},
"@fluencelabs/fluence": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.12.0.tgz",
"integrity": "sha512-eYg3CflqeqlWUoaXXXUBxls7Pzjytp1nkHZWoe39bL7poF20T1BuTovNWo/jTWma5HS4L1FaAGGRNaMcN0wFHQ==",
"version": "0.14.2",
"resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.14.2.tgz",
"integrity": "sha512-Cf5Ii6dpVSSi839jB7H0Y9k07xncYdHiTNKp4LlPg6inXuy2OPb2E7qF5DXlMM9O1dBb/UJTa4jZlQDsgWriiQ==",
"requires": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.14.4",
"@fluencelabs/avm": "0.15.4",
"async": "3.2.0",
"base64-js": "1.5.1",
"bs58": "4.0.1",
@ -3268,8 +3355,9 @@
"libp2p-websockets": "0.16.1",
"loglevel": "1.7.0",
"multiaddr": "10.0.0",
"noble-ed25519": "^1.2.5",
"peer-id": "0.15.3",
"rxjs": "^7.3.0",
"ts-pattern": "^3.3.3",
"uuid": "8.3.0"
}
},
@ -5042,11 +5130,6 @@
"resolved": "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz",
"integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg=="
},
"noble-ed25519": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/noble-ed25519/-/noble-ed25519-1.2.5.tgz",
"integrity": "sha512-7vst+4UhM5QU3jJ3pUqPMKBCOePrxBojmoQa59qcSnYvjFF/T4jqb4WISlfslcWyBw7G5H9V/acpcAxMd8DzUQ=="
},
"node-addon-api": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
@ -5368,6 +5451,14 @@
"resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz",
"integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg=="
},
"rxjs": {
"version": "7.4.0",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.4.0.tgz",
"integrity": "sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==",
"requires": {
"tslib": "~2.1.0"
}
},
"safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
@ -5559,6 +5650,16 @@
"yn": "3.1.1"
}
},
"ts-pattern": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-3.3.3.tgz",
"integrity": "sha512-Z5EFi6g6wyX3uDFHqxF5W5c5h663oZg9O6aOiAT7fqNu0HPSfCxtHzrQ7SblTy738Mrg2Ezorky8H5aUOm8Pvg=="
},
"tslib": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz",
"integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A=="
},
"tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",

View File

@ -11,13 +11,13 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@fluencelabs/aqua": "^0.3.0-226",
"@fluencelabs/aqua": "^0.4.0-234",
"chokidar-cli": "^3.0.0",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
},
"dependencies": {
"@fluencelabs/fluence": "0.12.0",
"@fluencelabs/fluence": "^0.14.2",
"@fluencelabs/fluence-network-environment": "1.0.10"
}
}

View File

@ -1,167 +1,117 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* 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
* Aqua version: 0.4.0-234
*
*/
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
callFunction,
registerService,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v2';
// Services
export interface CalcDef {
add: (n: number, callParams: CallParams<'n'>) => void;
divide: (n: number, callParams: CallParams<'n'>) => void;
getResult: (callParams: CallParams<null>) => number;
multiply: (n: number, callParams: CallParams<'n'>) => void;
reset: (callParams: CallParams<null>) => void;
subtract: (n: number, callParams: CallParams<'n'>) => void;
}
export function registerCalc(service: CalcDef): void;
export interface CalcDef {
add: (n: number, callParams: CallParams<'n'>) => void | Promise<void>;
divide: (n: number, callParams: CallParams<'n'>) => void | Promise<void>;
getResult: (callParams: CallParams<null>) => number | Promise<number>;
multiply: (n: number, callParams: CallParams<'n'>) => void | Promise<void>;
reset: (callParams: CallParams<null>) => void | Promise<void>;
subtract: (n: number, callParams: CallParams<'n'>) => void | Promise<void>;
}
export function registerCalc(service: CalcDef): void;
export function registerCalc(serviceId: string, service: CalcDef): void;
export function registerCalc(peer: FluencePeer, service: CalcDef): void;
export function registerCalc(peer: FluencePeer, serviceId: string, service: CalcDef): void;
export function registerCalc(...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 = "calc"
export function registerCalc(...args: any) {
registerService(
args,
{
"defaultServiceId" : "calc",
"functions" : [
{
"functionName" : "add",
"argDefs" : [
{
"name" : "n",
"argType" : {
"tag" : "primitive"
}
}
],
"returnType" : {
"tag" : "void"
}
},
{
"functionName" : "divide",
"argDefs" : [
{
"name" : "n",
"argType" : {
"tag" : "primitive"
}
}
],
"returnType" : {
"tag" : "void"
}
},
{
"functionName" : "getResult",
"argDefs" : [
],
"returnType" : {
"tag" : "primitive"
}
},
{
"functionName" : "multiply",
"argDefs" : [
{
"name" : "n",
"argType" : {
"tag" : "primitive"
}
}
],
"returnType" : {
"tag" : "void"
}
},
{
"functionName" : "reset",
"argDefs" : [
],
"returnType" : {
"tag" : "void"
}
},
{
"functionName" : "subtract",
"argDefs" : [
{
"name" : "n",
"argType" : {
"tag" : "primitive"
}
}
],
"returnType" : {
"tag" : "void"
}
}
]
}
);
}
// 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: {
n: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
service.add(req.args[0], callParams); resp.result = {}
}
if (req.fnName === 'divide') {
const callParams = {
...req.particleContext,
tetraplets: {
n: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
service.divide(req.args[0], callParams); resp.result = {}
}
if (req.fnName === 'getResult') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
resp.result = service.getResult(callParams)
}
if (req.fnName === 'multiply') {
const callParams = {
...req.particleContext,
tetraplets: {
n: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
service.multiply(req.args[0], callParams); resp.result = {}
}
if (req.fnName === 'reset') {
const callParams = {
...req.particleContext,
tetraplets: {
},
};
resp.retCode = ResultCodes.success;
service.reset(callParams); resp.result = {}
}
if (req.fnName === 'subtract') {
const callParams = {
...req.particleContext,
tetraplets: {
n: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
service.subtract(req.args[0], callParams); resp.result = {}
}
next();
});
}
// Functions

View File

@ -1,122 +1,98 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* 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
* Aqua version: 0.4.0-234
*
*/
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
callFunction,
registerService,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v2';
// Services
// Functions
export function demoCalculation(config?: {ttl?: number}) : Promise<number>;
export function demoCalculation(peer: FluencePeer, config?: {ttl?: number}) : Promise<number>;
export function demoCalculation(...args: any) {
let peer: FluencePeer;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
config = args[1];
} else {
peer = Fluence.getPeer();
config = args[0];
}
let request: RequestFlow;
const promise = new Promise<number>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call -relay- ("op" "noop") [])
)
(call "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e" ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(seq
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "add") [10])
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "multiply") [5])
)
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "subtract") [8])
)
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "divide") [6])
)
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "getResult") [] res)
)
(seq
(seq
(seq
(call "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e" ("op" "noop") [])
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(call -relay- ("op" "noop") [])
)
)
export function demoCalculation(config?: {ttl?: number}): Promise<number>;
export function demoCalculation(peer: FluencePeer, config?: {ttl?: number}): Promise<number>;
export function demoCalculation(...args: any) {
let script = `
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call -relay- ("op" "noop") [])
)
(call "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e" ("op" "noop") [])
)
(xor
(seq
(seq
(seq
(seq
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "add") [10])
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "multiply") [5])
)
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "subtract") [8])
)
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "divide") [6])
)
(call "12D3KooWLBkw4Tz8bRoSriy5WEpHyWfU11jEK3b5yCa7FBRDRWH3" ("calc" "getResult") [] res)
)
(seq
(seq
(seq
(call "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e" ("op" "noop") [])
(call -relay- ("op" "noop") [])
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(call -relay- ("op" "noop") [])
)
)
)
(call "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e" ("op" "noop") [])
)
(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])
)
`
return callFunction(
args,
{
"functionName" : "demoCalculation",
"returnType" : {
"tag" : "primitive"
},
"argDefs" : [
],
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
(call "12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e" ("op" "noop") [])
)
(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.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 demoCalculation');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}