mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
update gateway to new js client
This commit is contained in:
parent
0fa3eac2c4
commit
e8fc89f28a
@ -5,15 +5,15 @@
|
||||
* 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.9.3
|
||||
* Aqua version: 0.10.1
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from '@fluencelabs/fluence';
|
||||
|
||||
import {
|
||||
callFunction$$,
|
||||
registerService$$,
|
||||
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v4.js';
|
||||
v5_callFunction as callFunction$$,
|
||||
v5_registerService as registerService$$,
|
||||
} from '@fluencelabs/js-client.api';
|
||||
|
||||
|
||||
|
||||
// Services
|
||||
@ -23,30 +23,30 @@ export interface LoggerDef {
|
||||
}
|
||||
export function registerLogger(service: LoggerDef): void;
|
||||
export function registerLogger(serviceId: string, service: LoggerDef): void;
|
||||
export function registerLogger(peer: FluencePeer, service: LoggerDef): void;
|
||||
export function registerLogger(peer: FluencePeer, serviceId: string, service: LoggerDef): void;
|
||||
export function registerLogger(peer: IFluenceClient$$, service: LoggerDef): void;
|
||||
export function registerLogger(peer: IFluenceClient$$, serviceId: string, service: LoggerDef): void;
|
||||
|
||||
export interface EthCallerDef {
|
||||
eth_call: (uri: string, method: string, jsonArgs: string[], callParams: CallParams$$<'uri' | 'method' | 'jsonArgs'>) => { error: string; success: boolean; value: string; } | Promise<{ error: string; success: boolean; value: string; }>;
|
||||
}
|
||||
export function registerEthCaller(serviceId: string, service: EthCallerDef): void;
|
||||
export function registerEthCaller(peer: FluencePeer, serviceId: string, service: EthCallerDef): void;
|
||||
export function registerEthCaller(peer: IFluenceClient$$, serviceId: string, service: EthCallerDef): void;
|
||||
|
||||
export interface CounterDef {
|
||||
incrementAndReturn: (callParams: CallParams$$<null>) => number | Promise<number>;
|
||||
}
|
||||
export function registerCounter(service: CounterDef): void;
|
||||
export function registerCounter(serviceId: string, service: CounterDef): void;
|
||||
export function registerCounter(peer: FluencePeer, service: CounterDef): void;
|
||||
export function registerCounter(peer: FluencePeer, serviceId: string, service: CounterDef): void;
|
||||
export function registerCounter(peer: IFluenceClient$$, service: CounterDef): void;
|
||||
export function registerCounter(peer: IFluenceClient$$, serviceId: string, service: CounterDef): void;
|
||||
|
||||
export interface NumOpDef {
|
||||
identity: (n: number, callParams: CallParams$$<'n'>) => number | Promise<number>;
|
||||
}
|
||||
export function registerNumOp(service: NumOpDef): void;
|
||||
export function registerNumOp(serviceId: string, service: NumOpDef): void;
|
||||
export function registerNumOp(peer: FluencePeer, service: NumOpDef): void;
|
||||
export function registerNumOp(peer: FluencePeer, serviceId: string, service: NumOpDef): void;
|
||||
export function registerNumOp(peer: IFluenceClient$$, service: NumOpDef): void;
|
||||
export function registerNumOp(peer: IFluenceClient$$, serviceId: string, service: NumOpDef): void;
|
||||
|
||||
|
||||
// Functions
|
||||
@ -63,7 +63,7 @@ export function roundRobinEth(
|
||||
): Promise<RoundRobinEthResult>;
|
||||
|
||||
export function roundRobinEth(
|
||||
peer: FluencePeer,
|
||||
peer: IFluenceClient$$,
|
||||
uris: string[],
|
||||
method: string,
|
||||
jsonArgs: string[],
|
||||
@ -80,7 +80,7 @@ export function empty(
|
||||
): Promise<EmptyResult>;
|
||||
|
||||
export function empty(
|
||||
peer: FluencePeer,
|
||||
peer: IFluenceClient$$,
|
||||
config?: {ttl?: number}
|
||||
): Promise<EmptyResult>;
|
||||
|
||||
@ -96,7 +96,7 @@ export function randomLoadBalancing(
|
||||
): Promise<RandomLoadBalancingResult>;
|
||||
|
||||
export function randomLoadBalancing(
|
||||
peer: FluencePeer,
|
||||
peer: IFluenceClient$$,
|
||||
uris: string[],
|
||||
method: string,
|
||||
jsonArgs: string[],
|
||||
@ -116,7 +116,7 @@ export function randomLoadBalancingEth(
|
||||
): Promise<RandomLoadBalancingEthResult>;
|
||||
|
||||
export function randomLoadBalancingEth(
|
||||
peer: FluencePeer,
|
||||
peer: IFluenceClient$$,
|
||||
uris: string[],
|
||||
method: string,
|
||||
jsonArgs: string[],
|
||||
@ -138,7 +138,7 @@ export function roundRobin(
|
||||
): Promise<RoundRobinResult>;
|
||||
|
||||
export function roundRobin(
|
||||
peer: FluencePeer,
|
||||
peer: IFluenceClient$$,
|
||||
uris: string[],
|
||||
method: string,
|
||||
jsonArgs: string[],
|
||||
@ -160,7 +160,7 @@ export function call(
|
||||
): Promise<CallResult>;
|
||||
|
||||
export function call(
|
||||
peer: FluencePeer,
|
||||
peer: IFluenceClient$$,
|
||||
uri: string,
|
||||
method: string,
|
||||
jsonArgs: string[],
|
||||
|
@ -1,17 +1,19 @@
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
/**
|
||||
*
|
||||
* 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.9.3
|
||||
* Aqua version: 0.10.1
|
||||
*
|
||||
*/
|
||||
import { FluencePeer } from '@fluencelabs/fluence';
|
||||
|
||||
import {
|
||||
callFunction$$,
|
||||
registerService$$,
|
||||
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v4.js';
|
||||
v5_callFunction as callFunction$$,
|
||||
v5_registerService as registerService$$,
|
||||
} from '@fluencelabs/js-client.api';
|
||||
|
||||
|
||||
|
||||
// Services
|
||||
@ -243,8 +245,11 @@ export function roundRobinEth(...args) {
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("op" "array_length") [uris] array_length)
|
||||
(call %init_peer_id% ("math" "rem") [requestNumber array_length] rem)
|
||||
(seq
|
||||
(ap uris uris_to_functor)
|
||||
(ap uris_to_functor.length uris_length)
|
||||
)
|
||||
(call %init_peer_id% ("math" "rem") [requestNumber uris_length] rem)
|
||||
)
|
||||
(call %init_peer_id% ("logger" "logCall") [uris.$.[rem]!])
|
||||
)
|
||||
@ -747,8 +752,11 @@ export function roundRobin(...args) {
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("op" "array_length") [uris] array_length)
|
||||
(call %init_peer_id% ("math" "rem") [requestNumber array_length] rem)
|
||||
(seq
|
||||
(ap uris uris_to_functor)
|
||||
(ap uris_to_functor.length uris_length)
|
||||
)
|
||||
(call %init_peer_id% ("math" "rem") [requestNumber uris_length] rem)
|
||||
)
|
||||
(call %init_peer_id% ("logger" "logCall") [uris.$.[rem]!])
|
||||
)
|
||||
@ -997,3 +1005,5 @@ export function call(...args) {
|
||||
script
|
||||
)
|
||||
}
|
||||
|
||||
/* eslint-enable */
|
@ -44,7 +44,7 @@ func roundRobin(uris: []string, method: string, jsonArgs: []string, serviceId: s
|
||||
Counter counterServiceId
|
||||
requestNumber <- Counter.incrementAndReturn()
|
||||
on INIT_PEER_ID:
|
||||
providerNumber = requestNumber % Op.array_length(uris)
|
||||
providerNumber = requestNumber % uris.length
|
||||
Logger.logCall(uris[providerNumber])
|
||||
<- callFunc(uris[providerNumber], method, jsonArgs, serviceId)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -25,6 +25,7 @@
|
||||
"@fluencelabs/fluence": "0.28.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/aqua-api": "0.9.3"
|
||||
"@fluencelabs/js-client.node": "0.6.4",
|
||||
"@fluencelabs/js-client.api": "0.11.3"
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
import express from "express";
|
||||
import bodyParser from "body-parser";
|
||||
import {JSONRPCServer} from "json-rpc-2.0";
|
||||
import {FluencePeer} from "@fluencelabs/fluence";
|
||||
import {Fluence} from '@fluencelabs/js-client.api';
|
||||
import "@fluencelabs/js-client.node"
|
||||
import {randomLoadBalancingEth, registerCounter, registerLogger, roundRobinEth} from "../aqua-compiled/rpc.js";
|
||||
import {readArguments} from "./arguments.js";
|
||||
import {readConfig} from "./config.js";
|
||||
@ -34,11 +35,11 @@ const route = "/";
|
||||
const server = new JSONRPCServer();
|
||||
|
||||
// initialize fluence client
|
||||
const fluence = new FluencePeer();
|
||||
await fluence.start({connectTo: config.relay});
|
||||
await Fluence.connect(config.relay);
|
||||
const peerId = (await Fluence.getClient()).getPeerId()
|
||||
|
||||
// handler for logger
|
||||
registerLogger(fluence, {
|
||||
registerLogger({
|
||||
log: s => {
|
||||
console.log("log: " + s);
|
||||
},
|
||||
@ -48,7 +49,7 @@ registerLogger(fluence, {
|
||||
})
|
||||
|
||||
let counter = 0;
|
||||
registerCounter(fluence, "counter", {
|
||||
registerCounter("counter", {
|
||||
incrementAndReturn: () => {
|
||||
counter++;
|
||||
console.log("Counter: " + counter)
|
||||
@ -57,16 +58,16 @@ registerCounter(fluence, "counter", {
|
||||
})
|
||||
|
||||
const counterServiceId = config.counterServiceId || 'counter'
|
||||
const counterPeerId = config.counterPeerId || fluence.getStatus().peerId
|
||||
const counterPeerId = config.counterPeerId || peerId
|
||||
|
||||
async function methodHandler(req, method) {
|
||||
console.log(`Receiving request '${method}'`);
|
||||
let result;
|
||||
if (!config.mode || config.mode === "random") {
|
||||
result = await randomLoadBalancingEth(fluence, config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId);
|
||||
result = await randomLoadBalancingEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId);
|
||||
} else if (config.mode === "round-robin") {
|
||||
console.log("peerId: " + fluence.getStatus().peerId)
|
||||
result = await roundRobinEth(fluence, config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId, counterServiceId, counterPeerId,
|
||||
console.log("peerId: " + peerId)
|
||||
result = await roundRobinEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId, counterServiceId, counterPeerId,
|
||||
config.serviceId);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user