fe6c685ab1
* Rename function/variables mixnodes->set * Stub utility interface * Rewarded set contract interface * Move epoch to common, epoch to contract * Move epoch to the chain * Rewarded set validator-api * [ci skip] Generate TS types * Epoch queries * Moved new code to a new module * Restored cosmwasm dependencies to their beta.3 versions for better compatibility with the rest of the codebase * Rewarded set write reorganisation * Stub for validator api module responsible for rewarded set updates * Reorganised validator api cache * Pending contract changes * Relevant updates to the validator client * Updating rewarded set based on contract state * Advancing/Setting current epoch in the contract * Using blocktime as 'now' at startup * Adjusted validator-api side rewarding code * Contract cleanup + query for epoch rewarded set heights * [ci skip] Generate TS types * Simplified rewarder processing loop and initial sync * [ci skip] Generate TS types * Fixed EXISTING query-related unit tests * Fixed existing unit tests for rewarding-related transactions * Cargo fmt * Removed some dead code * Using cosmwasm 1.0.0-beta3 for compatibility [with cw-storage-plus and rest of codebase] * Missing TryInto import * Additional storage and query related unit tests + a bug fix * Transaction-related unit tests + bug fixes * Required migration code * Update common/cosmwasm-smart-contracts/mixnet-contract/src/msg.rs Co-authored-by: Drazen Urch <drazen@urch.eu> * Update common/cosmwasm-smart-contracts/mixnet-contract/src/msg.rs Co-authored-by: Drazen Urch <drazen@urch.eu> * Constant renaming * Changed determining previous epoch return type to Option<Epoch> if they would precede the genesis * Exposed the new endpoint to the wallet * Epoch-related unit tests fixes * Recommended #[must_use] on next_epoch method * Renamed all epoch occurences to interval As they refer to the 'rewarding interval' Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> Co-authored-by: jstuczyn <jstuczyn@users.noreply.github.com>
213 lines
8.1 KiB
TypeScript
213 lines
8.1 KiB
TypeScript
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
|
|
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
|
|
import {
|
|
Account,
|
|
Block,
|
|
Coin,
|
|
DeliverTxResponse,
|
|
IndexedTx,
|
|
SearchTxFilter,
|
|
SearchTxQuery,
|
|
SequenceResponse,
|
|
} from '@cosmjs/stargate';
|
|
import { JsonObject } from '@cosmjs/cosmwasm-stargate/build/queries';
|
|
import { Code, CodeDetails, Contract, ContractCodeHistoryEntry } from '@cosmjs/cosmwasm-stargate/build/cosmwasmclient';
|
|
// eslint-disable-next-line import/no-cycle
|
|
import NymdQuerier from './nymd-querier';
|
|
import {
|
|
ContractStateParams,
|
|
Delegation,
|
|
GatewayBond,
|
|
GatewayOwnershipResponse,
|
|
LayerDistribution,
|
|
MixnetContractVersion,
|
|
MixNodeBond,
|
|
MixOwnershipResponse,
|
|
PagedAllDelegationsResponse,
|
|
PagedDelegatorDelegationsResponse,
|
|
PagedGatewayResponse,
|
|
PagedMixDelegationsResponse,
|
|
PagedMixnodeResponse,
|
|
RewardingStatus,
|
|
} from './types';
|
|
import ValidatorApiQuerier, { IValidatorApiQuery } from './validator-api-querier';
|
|
|
|
export interface ICosmWasmQuery {
|
|
// methods exposed by `CosmWasmClient`
|
|
getChainId(): Promise<string>;
|
|
getHeight(): Promise<number>;
|
|
getAccount(searchAddress: string): Promise<Account | null>;
|
|
getSequence(address: string): Promise<SequenceResponse>;
|
|
getBlock(height?: number): Promise<Block>;
|
|
getBalance(address: string, searchDenom: string): Promise<Coin>;
|
|
getTx(id: string): Promise<IndexedTx | null>;
|
|
searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise<readonly IndexedTx[]>;
|
|
disconnect(): void;
|
|
broadcastTx(tx: Uint8Array, timeoutMs?: number, pollIntervalMs?: number): Promise<DeliverTxResponse>;
|
|
getCodes(): Promise<readonly Code[]>;
|
|
getCodeDetails(codeId: number): Promise<CodeDetails>;
|
|
getContracts(codeId: number): Promise<readonly string[]>;
|
|
getContract(address: string): Promise<Contract>;
|
|
getContractCodeHistory(address: string): Promise<readonly ContractCodeHistoryEntry[]>;
|
|
queryContractRaw(address: string, key: Uint8Array): Promise<Uint8Array | null>;
|
|
queryContractSmart(address: string, queryMsg: Record<string, unknown>): Promise<JsonObject>;
|
|
}
|
|
|
|
export interface INymdQuery {
|
|
// nym-specific implemented inside NymQuerier
|
|
getContractVersion(mixnetContractAddress: string): Promise<MixnetContractVersion>;
|
|
|
|
getMixNodesPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise<PagedMixnodeResponse>;
|
|
getGatewaysPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise<PagedGatewayResponse>;
|
|
ownsMixNode(mixnetContractAddress: string, address: string): Promise<MixOwnershipResponse>;
|
|
ownsGateway(mixnetContractAddress: string, address: string): Promise<GatewayOwnershipResponse>;
|
|
getStateParams(mixnetContractAddress: string): Promise<ContractStateParams>;
|
|
|
|
getAllNetworkDelegationsPaged(
|
|
mixnetContractAddress: string,
|
|
limit?: number,
|
|
startAfter?: [string, string],
|
|
): Promise<PagedAllDelegationsResponse>;
|
|
getMixNodeDelegationsPaged(
|
|
mixnetContractAddress: string,
|
|
mixIdentity: string,
|
|
limit?: number,
|
|
startAfter?: string,
|
|
): Promise<PagedMixDelegationsResponse>;
|
|
getDelegatorDelegationsPaged(
|
|
mixnetContractAddress: string,
|
|
delegator: string,
|
|
limit?: number,
|
|
startAfter?: string,
|
|
): Promise<PagedDelegatorDelegationsResponse>;
|
|
getDelegationDetails(mixnetContractAddress: string, mixIdentity: string, delegator: string): Promise<Delegation>;
|
|
|
|
getLayerDistribution(mixnetContractAddress: string): Promise<LayerDistribution>;
|
|
getRewardPool(mixnetContractAddress: string): Promise<string>;
|
|
getCirculatingSupply(mixnetContractAddress: string): Promise<string>;
|
|
getIntervalRewardPercent(mixnetContractAddress: string): Promise<number>;
|
|
getSybilResistancePercent(mixnetContractAddress: string): Promise<number>;
|
|
getRewardingStatus(
|
|
mixnetContractAddress: string,
|
|
mixIdentity: string,
|
|
rewardingIntervalNonce: number,
|
|
): Promise<RewardingStatus>;
|
|
}
|
|
|
|
export interface IQueryClient extends ICosmWasmQuery, INymdQuery, IValidatorApiQuery {}
|
|
|
|
export default class QueryClient extends CosmWasmClient implements IQueryClient {
|
|
private nymdQuerier: NymdQuerier;
|
|
|
|
private validatorApiQuerier: ValidatorApiQuerier;
|
|
|
|
private constructor(tmClient: Tendermint34Client, validatorApiUrl: string) {
|
|
super(tmClient);
|
|
this.nymdQuerier = new NymdQuerier(this);
|
|
this.validatorApiQuerier = new ValidatorApiQuerier(validatorApiUrl);
|
|
}
|
|
|
|
public static async connectWithNym(nymdUrl: string, validatorApiUrl: string): Promise<QueryClient> {
|
|
const tmClient = await Tendermint34Client.connect(nymdUrl);
|
|
return new QueryClient(tmClient, validatorApiUrl);
|
|
}
|
|
|
|
getContractVersion(mixnetContractAddress: string): Promise<MixnetContractVersion> {
|
|
return this.nymdQuerier.getContractVersion(mixnetContractAddress);
|
|
}
|
|
|
|
getMixNodesPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise<PagedMixnodeResponse> {
|
|
return this.nymdQuerier.getMixNodesPaged(mixnetContractAddress, limit, startAfter);
|
|
}
|
|
|
|
getGatewaysPaged(mixnetContractAddress: string, limit?: number, startAfter?: string): Promise<PagedGatewayResponse> {
|
|
return this.nymdQuerier.getGatewaysPaged(mixnetContractAddress, limit, startAfter);
|
|
}
|
|
|
|
ownsMixNode(mixnetContractAddress: string, address: string): Promise<MixOwnershipResponse> {
|
|
return this.nymdQuerier.ownsMixNode(mixnetContractAddress, address);
|
|
}
|
|
|
|
ownsGateway(mixnetContractAddress: string, address: string): Promise<GatewayOwnershipResponse> {
|
|
return this.nymdQuerier.ownsGateway(mixnetContractAddress, address);
|
|
}
|
|
|
|
getStateParams(mixnetContractAddress: string): Promise<ContractStateParams> {
|
|
return this.nymdQuerier.getStateParams(mixnetContractAddress);
|
|
}
|
|
|
|
getAllNetworkDelegationsPaged(
|
|
mixnetContractAddress: string,
|
|
limit?: number,
|
|
startAfter?: [string, string],
|
|
): Promise<PagedAllDelegationsResponse> {
|
|
return this.nymdQuerier.getAllNetworkDelegationsPaged(mixnetContractAddress, limit, startAfter);
|
|
}
|
|
|
|
getMixNodeDelegationsPaged(
|
|
mixnetContractAddress: string,
|
|
mixIdentity: string,
|
|
limit?: number,
|
|
startAfter?: string,
|
|
): Promise<PagedMixDelegationsResponse> {
|
|
return this.nymdQuerier.getMixNodeDelegationsPaged(mixnetContractAddress, mixIdentity, limit, startAfter);
|
|
}
|
|
|
|
getDelegatorDelegationsPaged(
|
|
mixnetContractAddress: string,
|
|
delegator: string,
|
|
limit?: number,
|
|
startAfter?: string,
|
|
): Promise<PagedDelegatorDelegationsResponse> {
|
|
return this.nymdQuerier.getDelegatorDelegationsPaged(mixnetContractAddress, delegator, limit, startAfter);
|
|
}
|
|
|
|
getDelegationDetails(mixnetContractAddress: string, mixIdentity: string, delegator: string): Promise<Delegation> {
|
|
return this.nymdQuerier.getDelegationDetails(mixnetContractAddress, mixIdentity, delegator);
|
|
}
|
|
|
|
getLayerDistribution(mixnetContractAddress: string): Promise<LayerDistribution> {
|
|
return this.nymdQuerier.getLayerDistribution(mixnetContractAddress);
|
|
}
|
|
|
|
getRewardPool(mixnetContractAddress: string): Promise<string> {
|
|
return this.nymdQuerier.getRewardPool(mixnetContractAddress);
|
|
}
|
|
|
|
getCirculatingSupply(mixnetContractAddress: string): Promise<string> {
|
|
return this.nymdQuerier.getCirculatingSupply(mixnetContractAddress);
|
|
}
|
|
|
|
getIntervalRewardPercent(mixnetContractAddress: string): Promise<number> {
|
|
return this.nymdQuerier.getIntervalRewardPercent(mixnetContractAddress);
|
|
}
|
|
|
|
getSybilResistancePercent(mixnetContractAddress: string): Promise<number> {
|
|
return this.nymdQuerier.getSybilResistancePercent(mixnetContractAddress);
|
|
}
|
|
|
|
getRewardingStatus(
|
|
mixnetContractAddress: string,
|
|
mixIdentity: string,
|
|
rewardingIntervalNonce: number,
|
|
): Promise<RewardingStatus> {
|
|
return this.nymdQuerier.getRewardingStatus(mixnetContractAddress, mixIdentity, rewardingIntervalNonce);
|
|
}
|
|
|
|
getCachedGateways(): Promise<GatewayBond[]> {
|
|
return this.validatorApiQuerier.getCachedGateways();
|
|
}
|
|
|
|
getCachedMixnodes(): Promise<MixNodeBond[]> {
|
|
return this.validatorApiQuerier.getCachedMixnodes();
|
|
}
|
|
|
|
getActiveMixnodes(): Promise<MixNodeBond[]> {
|
|
return this.validatorApiQuerier.getActiveMixnodes();
|
|
}
|
|
|
|
getRewardedMixnodes(): Promise<MixNodeBond[]> {
|
|
return this.validatorApiQuerier.getRewardedMixnodes();
|
|
}
|
|
}
|