60 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-09-10 20:08:58 +03:00
import { Fluence } from "@fluencelabs/fluence";
2021-09-07 03:22:08 +03:00
import { krasnodar } from "@fluencelabs/fluence-network-environment";
import { registerCalc, CalcDef } 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;
}
}
2021-09-07 03:22:08 +03:00
const keypress = async () => {
process.stdin.setRawMode(true);
return new Promise<void>((resolve) =>
process.stdin.once("data", () => {
process.stdin.setRawMode(false);
resolve();
})
);
};
2021-09-06 20:06:41 +03:00
async function main() {
2021-09-10 20:08:58 +03:00
await Fluence.start({
2021-09-07 03:22:08 +03:00
connectTo: krasnodar[0],
});
2021-09-06 20:06:41 +03:00
registerCalc(new Calc());
2021-09-07 03:22:08 +03:00
console.log("application started");
2021-09-10 20:08:58 +03:00
console.log("peer id is: ", Fluence.getStatus().peerId);
console.log("relay is: ", Fluence.getStatus().relayPeerId);
2021-09-07 03:22:08 +03:00
console.log("press any key to continue");
await keypress();
2021-09-06 20:06:41 +03:00
2021-09-10 20:08:58 +03:00
await Fluence.stop();
2021-09-06 20:06:41 +03:00
}
main();