2021-09-06 20:06:41 +03:00
|
|
|
import { FluencePeer } from "@fluencelabs/fluence";
|
2021-09-06 20:43:42 +03:00
|
|
|
import { registerCalc, CalcDef, demoCalculation } from "./_aqua/calc";
|
2021-09-06 20:06:41 +03:00
|
|
|
|
2021-09-06 20:43:42 +03:00
|
|
|
class Calc implements CalcDef {
|
2021-09-06 20:06:41 +03:00
|
|
|
private _state: number = 0;
|
|
|
|
|
2021-09-06 20:43:42 +03:00
|
|
|
add(n: number) {
|
2021-09-06 20:06:41 +03:00
|
|
|
this._state += n;
|
|
|
|
}
|
|
|
|
|
2021-09-06 20:43:42 +03:00
|
|
|
subtract(n: number) {
|
2021-09-06 20:06:41 +03:00
|
|
|
this._state -= n;
|
|
|
|
}
|
|
|
|
|
2021-09-06 20:43:42 +03:00
|
|
|
multiply(n: number) {
|
2021-09-06 20:06:41 +03:00
|
|
|
this._state *= n;
|
|
|
|
}
|
|
|
|
|
2021-09-06 20:43:42 +03:00
|
|
|
divide(n: number) {
|
2021-09-06 20:06:41 +03:00
|
|
|
this._state /= n;
|
|
|
|
}
|
|
|
|
|
2021-09-06 20:43:42 +03:00
|
|
|
reset() {
|
2021-09-06 20:06:41 +03:00
|
|
|
this._state = 0;
|
|
|
|
}
|
|
|
|
|
2021-09-06 20:43:42 +03:00
|
|
|
getResult() {
|
2021-09-06 20:06:41 +03:00
|
|
|
return this._state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
await FluencePeer.default.init();
|
|
|
|
|
|
|
|
registerCalc(new Calc());
|
|
|
|
|
|
|
|
const res = await demoCalculation();
|
|
|
|
|
|
|
|
console.log("Calculation result is: ", res);
|
|
|
|
|
|
|
|
await FluencePeer.default.uninit();
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|