Skip to content

Instantly share code, notes, and snippets.

@j0nl1
Last active May 17, 2023 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j0nl1/22dde0ef0bfaf1c0bea870a0a39e039e to your computer and use it in GitHub Desktop.
Save j0nl1/22dde0ef0bfaf1c0bea870a0a39e039e to your computer and use it in GitHub Desktop.
Proposal for new types generation in cosmwasm/ts-codegen
export type Decimal = string;
export type Timestamp = Uint64;
export type Uint64 = string;
type ThresholdResponseAbsoluteCount = {
absolute_count: {
total_weight: number;
weight: number;
};
};
type ThresholdResponseAbsolutePercentage = {
absolute_percentage: {
percentage: Decimal;
total_weight: number;
};
};
type ThresholdResponseThresholdQuorum = {
threshold_quorum: {
quorum: Decimal;
threshold: Decimal;
total_weight: number;
};
};
export type ThresholdResponse = ThresholdResponseAbsoluteCount | ThresholdResponseAbsolutePercentage | ThresholdResponseThresholdQuorum;
export type ExpirationAtHeigh = { at_height: number };
export type ExpirationAtTime = { at_time: Timestamp };
export type ExpirationNever = { never: {} };
export type Expiration = ExpirationAtHeigh | ExpirationAtTime | ExpirationNever;
export interface FinalInterface {
description: string;
expires: Expiration;
id: number;
proposer: string;
threshold: ThresholdResponse;
title: string;
}
export interface ProposalInterface<E = Expiration, T = ThresholdResponse> {
description: string;
expires: E extends ExpirationNever
? ExpirationNever
: E extends ExpirationAtTime
? ExpirationAtTime
: E extends ExpirationNever
? ExpirationNever
: E;
id: number;
proposer: string;
threshold: T extends ThresholdResponseAbsoluteCount
? ThresholdResponseAbsoluteCount
: T extends ThresholdResponseAbsolutePercentage
? ThresholdResponseAbsolutePercentage
: T extends ThresholdResponseThresholdQuorum
? ThresholdResponseThresholdQuorum
: T;
title: string;
}
const proposalResponse = {} as FinalInterface;
const firstProposal = {} as ProposalInterface<ExpirationAtHeigh, ThresholdResponseAbsoluteCount>;
proposalResponse.expires.never;
proposalResponse.threshold.absolute_count.total_weight;
firstProposal.expires.at_height;
firstProposal.threshold.absolute_count.total_weight;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment