*Reformat
This commit is contained in:
parent
55a0684628
commit
091240fe3e
|
@ -17,7 +17,7 @@ export default class RpcNetwork {
|
||||||
|
|
||||||
constructor(dht = new DHT()) {
|
constructor(dht = new DHT()) {
|
||||||
this._dht = dht;
|
this._dht = dht;
|
||||||
this._ready = this._dht.ready()
|
this._ready = this._dht.ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
get ready(): Promise<void> {
|
get ready(): Promise<void> {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { clearTimeout, setTimeout } from "timers";
|
import { clearTimeout, setTimeout } from "timers";
|
||||||
import RpcNetwork from "./rpcNetwork.js";
|
import RpcNetwork from "./rpcNetwork.js";
|
||||||
import { pack, unpack } from "msgpackr";
|
import { pack, unpack } from "msgpackr";
|
||||||
import {RPCRequest, RPCResponse} from "./types";
|
import { RPCRequest, RPCResponse } from "./types";
|
||||||
|
|
||||||
export default class RpcQuery {
|
export default class RpcQuery {
|
||||||
private _network: RpcNetwork;
|
private _network: RpcNetwork;
|
||||||
|
@ -42,7 +42,7 @@ export default class RpcQuery {
|
||||||
this._promiseResolve = resolve;
|
this._promiseResolve = resolve;
|
||||||
});
|
});
|
||||||
|
|
||||||
this._timeoutTimer =
|
this._timeoutTimer =
|
||||||
this._timeoutTimer ??
|
this._timeoutTimer ??
|
||||||
setTimeout(
|
setTimeout(
|
||||||
this.handeTimeout.bind(this),
|
this.handeTimeout.bind(this),
|
||||||
|
@ -93,7 +93,10 @@ export default class RpcQuery {
|
||||||
responses[responseIndex]++;
|
responses[responseIndex]++;
|
||||||
}
|
}
|
||||||
for (const responseIndex in responses) {
|
for (const responseIndex in responses) {
|
||||||
if (responses[responseIndex] / responseStoreKeys.length >= this._network.majorityThreshold) {
|
if (
|
||||||
|
responses[responseIndex] / responseStoreKeys.length >=
|
||||||
|
this._network.majorityThreshold
|
||||||
|
) {
|
||||||
const response: RPCResponse | null =
|
const response: RPCResponse | null =
|
||||||
responseStore[responseStoreKeys[parseInt(responseIndex, 10)]];
|
responseStore[responseStoreKeys[parseInt(responseIndex, 10)]];
|
||||||
|
|
||||||
|
|
18
src/types.ts
18
src/types.ts
|
@ -1,15 +1,15 @@
|
||||||
export interface RPCRequest {
|
export interface RPCRequest {
|
||||||
force: boolean;
|
force: boolean;
|
||||||
chain: string;
|
chain: string;
|
||||||
query: string;
|
query: string;
|
||||||
data: any;
|
data: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RPCResponse {
|
export interface RPCResponse {
|
||||||
updated: number;
|
updated: number;
|
||||||
data:
|
data:
|
||||||
| any
|
| any
|
||||||
| {
|
| {
|
||||||
error: string | boolean;
|
error: string | boolean;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue