Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getRPCEndpoint(): Promise {
if (this.rpc && this.cacheExpiry && this.cacheExpiry < new Date()) {
const ping = await this.rpc.ping();
if (ping <= 1000) {
return this.rpc.net;
}
}
const rpcAddress = await getRPCEndpoint(this.url);
this.rpc = new rpc.RPCClient(rpcAddress);
this.cacheExpiry = new Date(new Date().getTime() + 5 * 60000);
return this.rpc.net;
}
const clients = rpcs.map(r => new rpc.RPCClient(r.url));
return await raceToSuccess(clients.map(c => c.ping().then(_ => c.net)));
public constructor(url: string) {
this.url = url;
this.rpc = new rpc.RPCClient(url);
log.info(`Created NeoCli Provider: ${this.url}`);
}
public getRPCEndpoint(noCache?: boolean | undefined): Promise {
public async getRPCEndpoint(noCache = false): Promise {
if (
!noCache &&
this.rpc &&
this.cacheExpiry &&
this.cacheExpiry < new Date()
) {
const ping = await this.rpc.ping();
if (ping <= 1000) {
return this.rpc.net;
}
}
const rpcAddress = await getRPCEndpoint(this.url);
this.rpc = new rpc.RPCClient(rpcAddress);
this.cacheExpiry = new Date(new Date().getTime() + 5 * 60000);
return this.rpc.net;
}