/
MsgVote.ts
109 lines (96 loc) · 2.63 KB
/
MsgVote.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { JSONSerializable } from '../../../util/json';
import { AccAddress } from '../../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgVote as MsgVote_pb } from '@terra-money/terra.proto/cosmos/gov/v1beta1/tx';
import { VoteOption } from '@terra-money/terra.proto/cosmos/gov/v1beta1/gov';
import * as Long from 'long';
/**
* Vote for a proposal
*/
export class MsgVote extends JSONSerializable<
MsgVote.Amino,
MsgVote.Data,
MsgVote.Proto
> {
/**
* @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 option: VoteOption
) {
super();
}
public static fromAmino(data: MsgVote.Amino): MsgVote {
const {
value: { proposal_id, voter, option },
} = data;
return new MsgVote(Number.parseInt(proposal_id), voter, option);
}
public toAmino(): MsgVote.Amino {
const { proposal_id, voter, option } = this;
return {
type: 'gov/MsgVote',
value: {
proposal_id: proposal_id.toFixed(),
voter,
option,
},
};
}
public static fromData(data: MsgVote.Data): MsgVote {
const { proposal_id, voter, option } = data;
return new MsgVote(Number.parseInt(proposal_id), voter, option);
}
public toData(): MsgVote.Data {
const { proposal_id, voter, option } = this;
return {
'@type': '/cosmos.gov.v1beta1.MsgVote',
proposal_id: proposal_id.toFixed(),
voter,
option,
};
}
public static fromProto(proto: MsgVote.Proto): MsgVote {
return new MsgVote(proto.proposalId.toNumber(), proto.voter, proto.option);
}
public toProto(): MsgVote.Proto {
const { proposal_id, voter, option } = this;
return MsgVote_pb.fromPartial({
option,
proposalId: Long.fromNumber(proposal_id),
voter,
});
}
public packAny(): Any {
return Any.fromPartial({
typeUrl: '/cosmos.gov.v1beta1.MsgVote',
value: MsgVote_pb.encode(this.toProto()).finish(),
});
}
public static unpackAny(msgAny: Any): MsgVote {
return MsgVote.fromProto(MsgVote_pb.decode(msgAny.value));
}
}
export namespace MsgVote {
export const Option = VoteOption;
export type Option = VoteOption;
export interface Amino {
type: 'gov/MsgVote';
value: {
proposal_id: string;
voter: AccAddress;
option: VoteOption;
};
}
export interface Data {
'@type': '/cosmos.gov.v1beta1.MsgVote';
proposal_id: string;
voter: AccAddress;
option: Option;
}
export type Proto = MsgVote_pb;
}