import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate'; import { Tendermint34Client } from '@cosmjs/tendermint-rpc'; import { Account, Block, Coin, DeliverTxResponse, IndexedTx, SearchTxFilter, SearchTxQuery, SequenceResponse, } from '@cosmjs/stargate'; import { Code, CodeDetails, Contract, ContractCodeHistoryEntry } from '@cosmjs/cosmwasm-stargate/build/cosmwasmclient'; // eslint-disable-next-line import/no-cycle import NyxdQuerier from './nyxd-querier'; import { ContractStateParams, Delegation, GatewayBond, GatewayOwnershipResponse, LayerDistribution, MixnetContractVersion, MixNodeBond, MixOwnershipResponse, PagedAllDelegationsResponse, PagedDelegatorDelegationsResponse, PagedGatewayResponse, PagedMixDelegationsResponse, PagedMixnodeResponse, RewardingStatus, } from './types'; import NymApiQuerier, { INymApiQuery as INymApiQuery } from './nym-api-querier'; export interface ICosmWasmQuery { // methods exposed by `CosmWasmClient` getChainId(): Promise; getHeight(): Promise; getAccount(searchAddress: string): Promise; getSequence(address: string): Promise; getBlock(height?: number): Promise; getBalance(address: string, searchDenom: string): Promise; getTx(id: string): Promise; searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise; disconnect(): void; broadcastTx(tx: Uint8Array, timeoutMs?: number, pollIntervalMs?: number): Promise; getCodes(): Promise; getCodeDetails(codeId: number): Promise; getContracts(codeId: number): Promise; getContract(address: string): Promise; getContractCodeHistory(address: string): Promise; queryContractRaw(address: string, key: Uint8Array): Promise; queryContractSmart(address: string, queryMsg: Record): Promise; } export interface INyxdQuery { // nym-specific implemented inside NymQuerier getContractVersion(mixnetContractAddress: string): Promise; getMixNodesPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise; getGatewaysPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise; ownsMixNode(mixnetContractAddress: string, address: string): Promise; ownsGateway(mixnetContractAddress: string, address: string): Promise; getStateParams(mixnetContractAddress: string): Promise; getAllNetworkDelegationsPaged( mixnetContractAddress: string, limit?: number, startAfter?: [string, string], ): Promise; getMixNodeDelegationsPaged( mixnetContractAddress: string, mixIdentity: string, limit?: number, startAfter?: string, ): Promise; getDelegatorDelegationsPaged( mixnetContractAddress: string, delegator: string, limit?: number, startAfter?: string, ): Promise; getDelegationDetails(mixnetContractAddress: string, mixIdentity: string, delegator: string): Promise; getLayerDistribution(mixnetContractAddress: string): Promise; getRewardPool(mixnetContractAddress: string): Promise; getCirculatingSupply(mixnetContractAddress: string): Promise; getIntervalRewardPercent(mixnetContractAddress: string): Promise; getSybilResistancePercent(mixnetContractAddress: string): Promise; getRewardingStatus( mixnetContractAddress: string, mixIdentity: string, rewardingIntervalNonce: 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); } getMixNodesPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise { return this.nyxdQuerier.getMixNodesPaged(mixnetContractAddress, limit, startAfter); } getGatewaysPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise { return this.nyxdQuerier.getGatewaysPaged(mixnetContractAddress, limit, startAfter); } ownsMixNode(mixnetContractAddress: string, address: string): Promise { return this.nyxdQuerier.ownsMixNode(mixnetContractAddress, address); } ownsGateway(mixnetContractAddress: string, address: string): Promise { return this.nyxdQuerier.ownsGateway(mixnetContractAddress, address); } getStateParams(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getStateParams(mixnetContractAddress); } getAllNetworkDelegationsPaged( mixnetContractAddress: string, limit?: number, startAfter?: [string, string], ): Promise { return this.nyxdQuerier.getAllNetworkDelegationsPaged(mixnetContractAddress, limit, startAfter); } getMixNodeDelegationsPaged( mixnetContractAddress: string, mixIdentity: string, limit?: number, startAfter?: string, ): Promise { return this.nyxdQuerier.getMixNodeDelegationsPaged(mixnetContractAddress, mixIdentity, limit, startAfter); } getDelegatorDelegationsPaged( mixnetContractAddress: string, delegator: string, limit?: number, startAfter?: string, ): Promise { return this.nyxdQuerier.getDelegatorDelegationsPaged(mixnetContractAddress, delegator, limit, startAfter); } getDelegationDetails(mixnetContractAddress: string, mixIdentity: string, delegator: string): Promise { return this.nyxdQuerier.getDelegationDetails(mixnetContractAddress, mixIdentity, delegator); } getLayerDistribution(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getLayerDistribution(mixnetContractAddress); } getRewardPool(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getRewardPool(mixnetContractAddress); } getCirculatingSupply(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getCirculatingSupply(mixnetContractAddress); } getIntervalRewardPercent(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getIntervalRewardPercent(mixnetContractAddress); } getSybilResistancePercent(mixnetContractAddress: string): Promise { return this.nyxdQuerier.getSybilResistancePercent(mixnetContractAddress); } getRewardingStatus( mixnetContractAddress: string, mixIdentity: string, rewardingIntervalNonce: number, ): Promise { return this.nyxdQuerier.getRewardingStatus(mixnetContractAddress, mixIdentity, rewardingIntervalNonce); } getCachedGateways(): Promise { return this.nymApiQuerier.getCachedGateways(); } getCachedMixnodes(): Promise { return this.nymApiQuerier.getCachedMixnodes(); } getActiveMixnodes(): Promise { return this.nymApiQuerier.getActiveMixnodes(); } getRewardedMixnodes(): Promise { return this.nymApiQuerier.getRewardedMixnodes(); } }