f6a79ce7c3
* Renaming validator-api to nym-api * nym-api: simplified crate name * Added nym-api rename to changelog * Changed some output messages * Renamed validator-api-requests to nym-api requests * Removing more references to validator-api-requests * Additional lockfile name changes after full build * Removing mistakenly added merge files * ibid * ibid * Getting rid of ref to validator_api deep inside validator-client * Fixing file storage paths * Renaming struct function names referring to validator_api * Simplifying struct init * Fixed up all other instances of nym_api. * Renaming validatorApi to nymApi in TypeScript client for consistency v * Found a few more Rust instances * Changed examples in TypeScript SDK * Found one more instance of the use of validator instead of nym apis * Aliasing config key name for deserialization to preserve compatibility with old configs
76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
/*
|
|
* Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import axios from 'axios';
|
|
import { GatewayBond, MixNodeBond } from './types';
|
|
|
|
export const NYM_API_VERSION = '/v1';
|
|
export const NYM_API_GATEWAYS_PATH = `${NYM_API_VERSION}/gateways`;
|
|
export const NYM_API_MIXNODES_PATH = `${NYM_API_VERSION}/mixnodes`;
|
|
export const NYM_API_ACTIVE_MIXNODES_PATH = `${NYM_API_VERSION}/mixnodes/active`;
|
|
export const NYM_API_REWARDED_MIXNODES_PATH = `${NYM_API_VERSION}/mixnodes/rewarded`;
|
|
|
|
export interface INymApiQuery {
|
|
getCachedMixnodes(): Promise<MixNodeBond[]>;
|
|
|
|
getCachedGateways(): Promise<GatewayBond[]>;
|
|
|
|
getActiveMixnodes(): Promise<MixNodeBond[]>;
|
|
|
|
getRewardedMixnodes(): Promise<MixNodeBond[]>;
|
|
}
|
|
|
|
export default class NymApiQuerier implements INymApiQuery {
|
|
nymApiUrl: string;
|
|
|
|
constructor(nymApiUrl: string) {
|
|
this.nymApiUrl = nymApiUrl;
|
|
}
|
|
|
|
async getCachedMixnodes(): Promise<MixNodeBond[]> {
|
|
const url = new URL(this.nymApiUrl);
|
|
url.pathname += NYM_API_MIXNODES_PATH;
|
|
|
|
const response = await axios.get(url.toString());
|
|
if (response.status === 200) {
|
|
return response.data;
|
|
}
|
|
throw new Error('None of the provided validator APIs seem to be alive');
|
|
}
|
|
|
|
async getCachedGateways(): Promise<GatewayBond[]> {
|
|
const url = new URL(this.nymApiUrl);
|
|
url.pathname += NYM_API_GATEWAYS_PATH;
|
|
|
|
const response = await axios.get(url.toString());
|
|
if (response.status === 200) {
|
|
return response.data;
|
|
}
|
|
throw new Error('None of the provided validator APIs seem to be alive');
|
|
}
|
|
|
|
async getActiveMixnodes(): Promise<MixNodeBond[]> {
|
|
const url = new URL(this.nymApiUrl);
|
|
url.pathname += NYM_API_ACTIVE_MIXNODES_PATH;
|
|
|
|
const response = await axios.get(url.toString());
|
|
if (response.status === 200) {
|
|
return response.data;
|
|
}
|
|
throw new Error('None of the provided validator APIs seem to be alive');
|
|
}
|
|
|
|
async getRewardedMixnodes(): Promise<MixNodeBond[]> {
|
|
const url = new URL(this.nymApiUrl);
|
|
url.pathname += NYM_API_REWARDED_MIXNODES_PATH;
|
|
|
|
const response = await axios.get(url.toString());
|
|
if (response.status === 200) {
|
|
return response.data;
|
|
}
|
|
throw new Error('None of the provided validator APIs seem to be alive');
|
|
}
|
|
}
|