-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Governance breaking changes for Columbus-5 (#125)
* build: v2.0.5 * feat(gov): add MsgWeightedVote * feat(gov): fix breaking changes (Vote option and Proposal status became number) * dep: update
- Loading branch information
Showing
10 changed files
with
1,972 additions
and
2,288 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { JSONSerializable } from '../../util/json'; | ||
import { AccAddress } from '../bech32'; | ||
|
||
/** | ||
* Stores vote information for a proposal | ||
*/ | ||
export class Vote extends JSONSerializable<Vote.Data> { | ||
/** | ||
* @param proposal_id ID of proposal to vote on | ||
* @param voter voter's account address | ||
* @param option one of voting options | ||
*/ | ||
constructor( | ||
public proposal_id: number, | ||
public voter: AccAddress, | ||
public options: Vote.Options, | ||
public option?: Vote.Option // undefined except proposals in voting status | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromData(data: Vote.Data): Vote { | ||
const { proposal_id, voter, options, option } = data; | ||
|
||
return new Vote( | ||
parseInt(proposal_id), | ||
voter, | ||
options.map(({ option, weight }) => ({ | ||
option: Vote.OptionMapping[option], | ||
weight, | ||
})), | ||
option ? Vote.OptionMapping[option] : undefined | ||
); | ||
} | ||
|
||
public toData(): Vote.Data { | ||
const { proposal_id, voter, options, option } = this; | ||
|
||
const res: Vote.Data = { | ||
proposal_id: proposal_id.toFixed(), | ||
voter, | ||
options: options.map(({ option, weight }) => ({ | ||
option: Object.keys(Vote.OptionMapping).indexOf(option), | ||
weight, | ||
})), | ||
}; | ||
|
||
if (option) { | ||
res.option = Object.keys(Vote.OptionMapping).indexOf(option); | ||
} | ||
|
||
return res; | ||
} | ||
} | ||
|
||
export namespace Vote { | ||
export type Options = { | ||
option: Option; | ||
weight: string; | ||
}[]; | ||
|
||
/** Voting options */ | ||
export enum Option { | ||
/** - */ | ||
EMPTY = 'Empty', | ||
|
||
/** Vote yes */ | ||
YES = 'Yes', | ||
|
||
/** Do not vote */ | ||
ABSTAIN = 'Abstain', | ||
|
||
/** Vote no */ | ||
NO = 'No', | ||
|
||
/** Vote No with the option to veto if passed */ | ||
NO_WITH_VETO = 'NoWithVeto', | ||
} | ||
|
||
export const OptionMapping: { [key: number]: Option } = { | ||
0: Option.EMPTY, | ||
1: Option.YES, | ||
2: Option.ABSTAIN, | ||
3: Option.NO, | ||
4: Option.NO_WITH_VETO, | ||
}; | ||
|
||
export interface Data { | ||
proposal_id: string; | ||
voter: AccAddress; | ||
option?: number; // undefined except proposals in voting status | ||
options: { | ||
option: number; | ||
weight: string; // Dec | ||
}[]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { JSONSerializable } from '../../../util/json'; | ||
import { AccAddress } from '../../bech32'; | ||
import { MsgVote } from './MsgVote'; | ||
|
||
/** | ||
* Weighted vote for a proposal | ||
*/ | ||
export class MsgVoteWeighted extends JSONSerializable<MsgVoteWeighted.Data> { | ||
/** | ||
* @param proposal_id ID of proposal to vote on | ||
* @param voter voter's account address | ||
* @param option one of voting options | ||
*/ | ||
constructor( | ||
public proposal_id: number, | ||
public voter: AccAddress, | ||
public options: MsgVoteWeighted.Options | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromData(data: MsgVoteWeighted.Data): MsgVoteWeighted { | ||
const { | ||
value: { proposal_id, voter, options }, | ||
} = data; | ||
return new MsgVoteWeighted(Number.parseInt(proposal_id), voter, options); | ||
} | ||
|
||
public toData(): MsgVoteWeighted.Data { | ||
const { proposal_id, voter, options } = this; | ||
return { | ||
type: 'gov/MsgVoteWeighted', | ||
value: { | ||
proposal_id: proposal_id.toFixed(), | ||
voter, | ||
options, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
export namespace MsgVoteWeighted { | ||
export type Options = { | ||
option: MsgVote.Option; | ||
weight: string; | ||
}[]; | ||
|
||
export interface Data { | ||
type: 'gov/MsgVoteWeighted'; | ||
value: { | ||
proposal_id: string; | ||
voter: AccAddress; | ||
options: Options; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters