-
Notifications
You must be signed in to change notification settings - Fork 22
/
MsgCreateVestingAccount.ts
181 lines (167 loc) 路 4.74 KB
/
MsgCreateVestingAccount.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { Coins } from '../../Coins';
import { JSONSerializable } from '../../../util/json';
import { AccAddress } from '../../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgCreateVestingAccount as MsgCreateVestingAccount_pb } from '@terra-money/terra.proto/cosmos/vesting/v1beta1/tx';
import Long from 'long';
/**
* MsgCreateVestingAccount defines a message that enables creating a vesting account.
*/
export class MsgCreateVestingAccount extends JSONSerializable<
MsgCreateVestingAccount.Amino,
MsgCreateVestingAccount.Data,
MsgCreateVestingAccount.Proto
> {
public amount: Coins;
/**
* @param from_address sender's address
* @param to_address recipient's address
* @param amount value of the transaction
*/
constructor(
public from_address: AccAddress,
public to_address: AccAddress,
amount: Coins.Input,
public end_time: number,
public delayed: boolean
) {
super();
this.amount = new Coins(amount);
}
public static fromAmino(
data: MsgCreateVestingAccount.Amino,
isClassic?: boolean
): MsgCreateVestingAccount {
if (isClassic) {
throw new Error('Not supported for the network');
}
const {
value: { from_address, to_address, amount, end_time, delayed },
} = data;
return new MsgCreateVestingAccount(
from_address,
to_address,
Coins.fromAmino(amount),
Number.parseInt(end_time),
delayed
);
}
public toAmino(isClassic?: boolean): MsgCreateVestingAccount.Amino {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { from_address, to_address, amount, end_time, delayed } = this;
return {
type: 'cosmos-sdk/MsgCreateVestingAccount',
value: {
from_address,
to_address,
amount: amount.toAmino(),
end_time: end_time.toFixed(),
delayed,
},
};
}
public static fromData(
data: MsgCreateVestingAccount.Data,
isClassic?: boolean
): MsgCreateVestingAccount {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { from_address, to_address, amount, end_time, delayed } = data;
return new MsgCreateVestingAccount(
from_address,
to_address,
Coins.fromData(amount),
Number.parseInt(end_time),
delayed
);
}
public toData(isClassic?: boolean): MsgCreateVestingAccount.Data {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { from_address, to_address, amount, end_time, delayed } = this;
return {
'@type': '/cosmos.vesting.v1beta1.MsgCreateVestingAccount',
from_address,
to_address,
amount: amount.toData(),
end_time: end_time.toFixed(),
delayed,
};
}
public static fromProto(
proto: MsgCreateVestingAccount.Proto,
isClassic?: boolean
): MsgCreateVestingAccount {
if (isClassic) {
throw new Error('Not supported for the network');
}
return new MsgCreateVestingAccount(
proto.fromAddress,
proto.toAddress,
Coins.fromProto(proto.amount),
proto.endTime.toNumber(),
proto.delayed
);
}
public toProto(isClassic?: boolean): MsgCreateVestingAccount.Proto {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { from_address, to_address, amount, end_time, delayed } = this;
return MsgCreateVestingAccount_pb.fromPartial({
fromAddress: from_address,
toAddress: to_address,
amount: amount.toProto(),
endTime: Long.fromNumber(end_time),
delayed,
});
}
public packAny(isClassic?: boolean): Any {
if (isClassic) {
throw new Error('Not supported for the network');
}
return Any.fromPartial({
typeUrl: '/cosmos.vesting.v1beta1.MsgCreateVestingAccount',
value: MsgCreateVestingAccount_pb.encode(
this.toProto(isClassic)
).finish(),
});
}
public static unpackAny(
msgAny: Any,
isClassic?: boolean
): MsgCreateVestingAccount {
if (isClassic) {
throw new Error('Not supported for the network');
}
return MsgCreateVestingAccount.fromProto(
MsgCreateVestingAccount_pb.decode(msgAny.value),
isClassic
);
}
}
export namespace MsgCreateVestingAccount {
export interface Amino {
type: 'cosmos-sdk/MsgCreateVestingAccount';
value: {
from_address: AccAddress;
to_address: AccAddress;
amount: Coins.Amino;
end_time: string;
delayed: boolean;
};
}
export interface Data {
'@type': '/cosmos.vesting.v1beta1.MsgCreateVestingAccount';
from_address: AccAddress;
to_address: AccAddress;
amount: Coins.Data;
end_time: string;
delayed: boolean;
}
export type Proto = MsgCreateVestingAccount_pb;
}