import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'; // eslint-disable-next-line import/no-cycle import NyxdQuerier from './nyxd-querier'; import { Delegation, GatewayBond, GatewayOwnershipResponse, LayerDistribution, MixnetContractVersion, MixNodeDetails, MixOwnershipResponse, PagedAllDelegationsResponse, PagedDelegatorDelegationsResponse, PagedGatewayResponse, PagedMixDelegationsResponse, PagedMixNodeBondResponse, PagedMixNodeDetailsResponse, PagedUnbondedMixnodesResponse, StakeSaturationResponse, UnbondedMixnodeResponse, MixNodeBond, MixNodeRewarding, OriginalVestingResponse, VestingAccountInfo, ContractState, VestingAccountsCoinPaged, VestingAccountsPaged, DelegationTimes, Delegations, Period, VestingAccountNode, DelegationBlock } from '@nymproject/types'; import NymApiQuerier, { INymApiQuery } from './nym-api-querier'; import { ICosmWasmQuery } from './types/shared'; import { RewardingParams } from '@nymproject/types'; import { Tendermint34Client } from '@cosmjs/tendermint-rpc'; import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin'; export interface INyxdQuery { // nym-specific implemented inside NymQuerier getContractVersion(mixnetContractAddress: string): Promise; getMixNodeBonds( mixnetContractAddress: string, limit?: number, startAfter?: string, ): Promise; getMixNodesDetailed( mixnetContractAddress: string, limit?: number, startAfter?: string, ): Promise; getGatewaysPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise; getOwnedMixnode(mixnetContractAddress: string, address: string): Promise; ownsGateway(mixnetContractAddress: string, address: string): Promise; getStateParams(mixnetContractAddress: string): Promise; getAllDelegationsPaged( mixnetContractAddress: string, limit?: number, startAfter?: [string, string], ): Promise; getMixNodeDelegationsPaged( mixnetContractAddress: string, mix_id: number, limit?: number, startAfter?: string, ): Promise; getDelegatorDelegationsPaged( mixnetContractAddress: string, delegator: string, limit?: number, startAfter?: string, ): Promise; getDelegationDetails(mixnetContractAddress: string, mix_id: number, delegator: string): Promise; getLayerDistribution(mixnetContractAddress: string): Promise; getRewardParams(mixnetContractAddress: string): Promise; getStakeSaturation(mixnetContractAddress: string, mixId: number): Promise; getUnbondedMixNodeInformation(mixnetContractAddress: string, mixId: number): Promise; getMixnodeRewardingDetails(mixnetContractAddress: string, mixId: number): Promise; } export interface IQueryClient extends ICosmWasmQuery, INyxdQuery, INymApiQuery { } export default class QueryClient extends CosmWasmClient implements IQueryClient { private nyxdQuerier: NyxdQuerier; private nymApiQuerier: NymApiQuerier; private constructor(tmClient: Tendermint34Client, nymApiUrl: string) { super(tmClient); this.nyxdQuerier = new NyxdQuerier(this); this.nymApiQuerier = new NymApiQuerier(nymApiUrl); } public static async connectWithNym(nyxdUrl: string, nymApiUrl: string): Promise { const tmClient = await Tendermint34Client.connect(nyxdUrl); return new QueryClient(tmClient, nymApiUrl); } getContractVersion(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getContractVersion(mixnetContractAddress); } getMixNodeBonds( mixnetContractAddress: string, limit?: number, startAfter?: string, ): Promise { return this.nyxdQuerier.getMixNodeBonds(mixnetContractAddress, limit, startAfter); } getMixNodesDetailed( mixnetContractAddress: string, limit?: number, startAfter?: string, ): Promise { return this.nyxdQuerier.getMixNodesDetailed(mixnetContractAddress, limit, startAfter); } getStakeSaturation(mixnetContractAddress: string, mixId: number): Promise { return this.nyxdQuerier.getStakeSaturation(mixnetContractAddress, mixId); } getMixnodeRewardingDetails(mixnetContractAddress: string, mixId: number): Promise { return this.nyxdQuerier.getMixnodeRewardingDetails(mixnetContractAddress, mixId); } getGatewaysPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise { return this.nyxdQuerier.getGatewaysPaged(mixnetContractAddress, limit, startAfter); } getOwnedMixnode(mixnetContractAddress: string, address: string): Promise { return this.nyxdQuerier.getOwnedMixnode(mixnetContractAddress, address); } ownsGateway(mixnetContractAddress: string, address: string): Promise { return this.nyxdQuerier.ownsGateway(mixnetContractAddress, address); } getUnbondedMixNodes( mixnetContractAddress: string, limit?: number, startAfter?: string, ): Promise { return this.nyxdQuerier.getUnbondedMixNodes(mixnetContractAddress, limit, startAfter); } getUnbondedMixNodeInformation(mixnetContractAddress: string, mixId: number): Promise { return this.nyxdQuerier.getUnbondedMixNodeInformation(mixnetContractAddress, mixId); } getStateParams(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getStateParams(mixnetContractAddress); } getAllDelegationsPaged( mixnetContractAddress: string, limit?: number, startAfter?: [string, string], ): Promise { return this.nyxdQuerier.getAllDelegationsPaged(mixnetContractAddress, limit, startAfter); } getMixNodeDelegationsPaged( mixnetContractAddress: string, mix_id: number, limit?: number, startAfter?: string, ): Promise { return this.nyxdQuerier.getMixNodeDelegationsPaged(mixnetContractAddress, mix_id, limit, startAfter); } getDelegatorDelegationsPaged( mixnetContractAddress: string, delegator: string, limit?: number, startAfter?: string, ): Promise { return this.nyxdQuerier.getDelegatorDelegationsPaged(mixnetContractAddress, delegator, limit, startAfter); } getDelegationDetails(mixnetContractAddress: string, mix_id: number, delegator: string): Promise { return this.nyxdQuerier.getDelegationDetails(mixnetContractAddress, mix_id, delegator); } getLayerDistribution(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getLayerDistribution(mixnetContractAddress); } getRewardParams(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getRewardParams(mixnetContractAddress); } getCachedGateways(): Promise { return this.nymApiQuerier.getCachedGateways(); } getCachedMixnodes(): Promise { return this.nymApiQuerier.getCachedMixnodes(); } getActiveMixnodes(): Promise { return this.nymApiQuerier.getActiveMixnodes(); } getRewardedMixnodes(): Promise { return this.nymApiQuerier.getRewardedMixnodes(); } getSpendableCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getSpendableCoins(vestingContractAddress, vestingAccountAddress); } getVestingAccountsPaged(vestingContractAddress: string): Promise { return this.nyxdQuerier.getVestingAccountsPaged(vestingContractAddress); } getVestingAmountsAccountsPaged(vestingContractAddress: string): Promise { return this.nyxdQuerier.getVestingAmountsAccountsPaged(vestingContractAddress); } getLockedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getLockedTokens(vestingContractAddress, vestingAccountAddress); } getSpendableTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getSpendableTokens(vestingContractAddress, vestingAccountAddress); } getVestedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getVestedTokens(vestingContractAddress, vestingAccountAddress); } getVestingTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getVestingTokens(vestingContractAddress, vestingAccountAddress); } getSpendableVestedTokens(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getSpendableVestedTokens(vestingContractAddress, vestingAccountAddress); } getSpendableRewards(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getSpendableRewards(vestingContractAddress, vestingAccountAddress); } getDelegatedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getDelegatedCoins(vestingContractAddress, vestingAccountAddress); } getPledgedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getPledgedCoins(vestingContractAddress, vestingAccountAddress); } getStakedCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getStakedCoins(vestingContractAddress, vestingAccountAddress); } getWithdrawnCoins(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getWithdrawnCoins(vestingContractAddress, vestingAccountAddress); } getStartTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getStartTime(vestingContractAddress, vestingAccountAddress); } getEndTime(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getEndTime(vestingContractAddress, vestingAccountAddress); } getOriginalVestingDetails(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getOriginalVestingDetails(vestingContractAddress, vestingAccountAddress); } getHistoricStakingRewards(vestingContractAddress: string, vestingAccountAddress: string): Promise { return this.nyxdQuerier.getHistoricStakingRewards(vestingContractAddress, vestingAccountAddress); } getAccountDetails(vestingContractAddress: string, address: string): Promise { return this.nyxdQuerier.getAccountDetails(vestingContractAddress, address); } getMixnode(vestingContractAddress: string, address: string): Promise { return this.nyxdQuerier.getMixnode(vestingContractAddress, address); } getGateway(vestingContractAddress: string, address: string): Promise { return this.nyxdQuerier.getGateway(vestingContractAddress, address); } getDelegationTimes(vestingContractAddress: string, mix_id: number, delegatorAddress: string): Promise { return this.nyxdQuerier.getDelegationTimes(vestingContractAddress, mix_id, delegatorAddress); } getAllDelegations(vestingContractAddress: string): Promise { return this.nyxdQuerier.getAllDelegations(vestingContractAddress); } getDelegation(vestingContractAddress: string, vestingAccountAddress: string, mix_id: number): Promise { return this.nyxdQuerier.getDelegation(vestingContractAddress, vestingAccountAddress, mix_id); } getTotalDelegationAmount(vestingContractAddress: string, vestingAccountAddress: string, mix_id: number, block_timestamp_sec: number): Promise { return this.nyxdQuerier.getTotalDelegationAmount(vestingContractAddress, vestingAccountAddress, mix_id, block_timestamp_sec); } getCurrentVestingPeriod(vestingContractAddress: string, address: string): Promise { return this.nyxdQuerier.getCurrentVestingPeriod(vestingContractAddress, address); } }