Skip to content

Commit

Permalink
chore: add info index file
Browse files Browse the repository at this point in the history
  • Loading branch information
ruijialin-avalabs committed Oct 18, 2024
1 parent f958498 commit 1094ede
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/info/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { AVAX_PUBLIC_URL } from '../constants/public-urls';
import { Api } from '../vms/common/baseApi';
import type {
GetBlockchainIDResponse,
GetNetworkIdResponse,
GetNetworkNameResponse,
GetNodeIdResponse,
GetNodeIpResponse,
GetNodeVersionReply,
GetPeersResponse,
GetTxFeeResponse,
isBootstrapped,
UptimeResponse,
GetUpgradesInfoResponse,
} from './model';

export class InfoApi extends Api {
constructor(private readonly baseURL: string = AVAX_PUBLIC_URL) {
super(baseURL, '/ext/info', 'info');
}

getNodeVersion(): Promise<GetNodeVersionReply> {
return this.callRpc<GetNodeVersionReply>('getNodeVersion');
}

async getNodeId(): Promise<GetNodeIdResponse> {
return this.callRpc<GetNodeIdResponse>('getNodeID');
}

getNodeIp(): Promise<GetNodeIpResponse> {
return this.callRpc<GetNodeIpResponse>('getNodeIP');
}

getNetworkId(): Promise<GetNetworkIdResponse> {
return this.callRpc<GetNetworkIdResponse>('getNetworkID');
}

getNetworkName(): Promise<GetNetworkNameResponse> {
return this.callRpc<GetNetworkNameResponse>('getNetworkName');
}

getBlockchainId(alias: string): Promise<GetBlockchainIDResponse> {
return this.callRpc<GetBlockchainIDResponse>('getBlockchainID', { alias });
}

peers(nodeIDs?: string[]): Promise<GetPeersResponse> {
return this.callRpc<GetPeersResponse>('peers', { nodeIDs });
}

isBootstrapped(chain: string): Promise<isBootstrapped> {
return this.callRpc<isBootstrapped>('peers', { chain });
}
/**
* @link https://docs.avax.network/apis/avalanchego/apis/info#infogettxfee
*/
async getTxFee(): Promise<GetTxFeeResponse> {
const resp = await this.callRpc<GetTxFeeResponse>('getTxFee');

return {
txFee: BigInt(resp.txFee),
createAssetTxFee: BigInt(resp.createAssetTxFee),
createSubnetTxFee: BigInt(resp.createSubnetTxFee),
transformSubnetTxFee: BigInt(resp.transformSubnetTxFee),
createBlockchainTxFee: BigInt(resp.createBlockchainTxFee),
addPrimaryNetworkValidatorFee: BigInt(resp.addPrimaryNetworkValidatorFee),
addPrimaryNetworkDelegatorFee: BigInt(resp.addPrimaryNetworkDelegatorFee),
addSubnetValidatorFee: BigInt(resp.addSubnetValidatorFee),
addSubnetDelegatorFee: BigInt(resp.addSubnetDelegatorFee),
};
}

uptime(): Promise<UptimeResponse> {
return this.callRpc<UptimeResponse>('uptime');
}

getVMs(): Promise<Map<string, string[]>> {
return this.callRpc<Map<string, string[]>>('getVMs');
}

// Post-Etna API

// get upgrades info
getUpgradesInfo(): Promise<GetUpgradesInfoResponse> {
return this.callRpc<GetUpgradesInfoResponse>('upgrades');
}
}
2 changes: 2 additions & 0 deletions src/info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './api';
export * from './model';

0 comments on commit 1094ede

Please sign in to comment.