/* * Copyright 2021 - Nym Technologies SA * SPDX-License-Identifier: Apache-2.0 */ import { JsonObject } from '@cosmjs/cosmwasm-stargate/build/queries'; // eslint-disable-next-line import/no-cycle import { INymdQuery } from './query-client'; import { ContractStateParams, Delegation, GatewayOwnershipResponse, LayerDistribution, MixnetContractVersion, MixOwnershipResponse, PagedAllDelegationsResponse, PagedDelegatorDelegationsResponse, PagedGatewayResponse, PagedMixDelegationsResponse, PagedMixnodeResponse, RewardingIntervalResponse, RewardingStatus, } from './types'; interface SmartContractQuery { queryContractSmart(address: string, queryMsg: Record): Promise; } export default class NymdQuerier implements INymdQuery { client: SmartContractQuery; constructor(client: SmartContractQuery) { this.client = client; } getContractVersion(mixnetContractAddress: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_contract_version: {}, }); } getMixNodesPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_mix_nodes: { limit, start_after: startAfter, }, }); } getGatewaysPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_gateways: { limit, start_after: startAfter, }, }); } ownsMixNode(mixnetContractAddress: string, address: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { owns_mixnode: { address, }, }); } ownsGateway(mixnetContractAddress: string, address: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { owns_gateway: { address, }, }); } getStateParams(mixnetContractAddress: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { state_params: {}, }); } getCurrentRewardingInterval(mixnetContractAddress: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { current_rewarding_interval: {}, }); } getAllNetworkDelegationsPaged( mixnetContractAddress: string, limit?: number, startAfter?: [string, string], ): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_all_network_delegations: { start_after: startAfter, limit, }, }); } getMixNodeDelegationsPaged( mixnetContractAddress: string, mixIdentity: string, limit?: number, startAfter?: string, ): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_mixnode_delegations: { mix_identity: mixIdentity, start_after: startAfter, limit, }, }); } getDelegatorDelegationsPaged( mixnetContractAddress: string, delegator: string, limit?: number, startAfter?: string, ): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_delegator_delegations: { delegator, start_after: startAfter, limit, }, }); } getDelegationDetails(mixnetContractAddress: string, mixIdentity: string, delegator: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_delegation_details: { mix_identity: mixIdentity, delegator, }, }); } getLayerDistribution(mixnetContractAddress: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { layer_distribution: {}, }); } getRewardPool(mixnetContractAddress: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_reward_pool: {}, }); } getCirculatingSupply(mixnetContractAddress: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_circulating_supply: {}, }); } getEpochRewardPercent(mixnetContractAddress: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_epoch_reward_percent: {}, }); } getSybilResistancePercent(mixnetContractAddress: string): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_sybil_resistance_percent: {}, }); } getRewardingStatus( mixnetContractAddress: string, mixIdentity: string, rewardingIntervalNonce: number, ): Promise { return this.client.queryContractSmart(mixnetContractAddress, { get_rewarding_status: { mix_identity: mixIdentity, rewarding_interval_nonce: rewardingIntervalNonce, }, }); } }