-
Notifications
You must be signed in to change notification settings - Fork 22
/
MsgCreatePeriodicVestingAccount.ts
168 lines (155 loc) 路 5 KB
/
MsgCreatePeriodicVestingAccount.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
import { Period } from '../Period';
import { JSONSerializable } from '../../../util/json';
import { AccAddress } from '../../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgCreatePeriodicVestingAccount as MsgCreatePeriodicVestingAccount_pb } from '@terra-money/terra.proto/cosmos/vesting/v1beta1/tx';
import Long from 'long';
/**
* CreatePeriodicVestingAccount defines a method that enables creating a periodic vesting account.
*/
export class MsgCreatePeriodicVestingAccount extends JSONSerializable<
MsgCreatePeriodicVestingAccount.Amino,
MsgCreatePeriodicVestingAccount.Data,
MsgCreatePeriodicVestingAccount.Proto
> {
/**
* @param from_address sender's address
* @param to_address recipient's address
*/
constructor(
public from_address: AccAddress,
public to_address: AccAddress,
public start_time: number,
public vesting_periods: Period[]
) {
super();
}
public static fromAmino(
data: MsgCreatePeriodicVestingAccount.Amino,
isClassic?: boolean
): MsgCreatePeriodicVestingAccount {
if (isClassic) {
throw new Error('Not supported for the network');
}
const {
value: { from_address, to_address, start_time, vesting_periods },
} = data;
return new MsgCreatePeriodicVestingAccount(
from_address,
to_address,
Number.parseInt(start_time),
vesting_periods.map(p => Period.fromAmino(p, isClassic))
);
}
public toAmino(isClassic?: boolean): MsgCreatePeriodicVestingAccount.Amino {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { from_address, to_address, start_time, vesting_periods } = this;
return {
type: 'cosmos-sdk/MsgCreatePeriodicVestingAccount',
value: {
from_address,
to_address,
start_time: start_time.toFixed(),
vesting_periods: vesting_periods.map(p => p.toAmino(isClassic)),
},
};
}
public static fromData(
data: MsgCreatePeriodicVestingAccount.Data,
isClassic?: boolean
): MsgCreatePeriodicVestingAccount {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { from_address, to_address, start_time, vesting_periods } = data;
return new MsgCreatePeriodicVestingAccount(
from_address,
to_address,
Number.parseInt(start_time),
vesting_periods.map(p => Period.fromData(p, isClassic))
);
}
public toData(isClassic?: boolean): MsgCreatePeriodicVestingAccount.Data {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { from_address, to_address, start_time, vesting_periods } = this;
return {
'@type': '/cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount',
from_address,
to_address,
start_time: start_time.toFixed(),
vesting_periods: vesting_periods.map(p => p.toData(isClassic)),
};
}
public static fromProto(
proto: MsgCreatePeriodicVestingAccount.Proto,
isClassic?: boolean
): MsgCreatePeriodicVestingAccount {
if (isClassic) {
throw new Error('Not supported for the network');
}
return new MsgCreatePeriodicVestingAccount(
proto.fromAddress,
proto.toAddress,
proto.startTime.toNumber(),
proto.vestingPeriods.map(p => Period.fromProto(p, isClassic))
);
}
public toProto(isClassic?: boolean): MsgCreatePeriodicVestingAccount.Proto {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { from_address, to_address, start_time, vesting_periods } = this;
return MsgCreatePeriodicVestingAccount_pb.fromPartial({
fromAddress: from_address,
toAddress: to_address,
startTime: Long.fromNumber(start_time),
vestingPeriods: vesting_periods.map(p => p.toProto(isClassic)),
});
}
public packAny(isClassic?: boolean): Any {
if (isClassic) {
throw new Error('Not supported for the network');
}
return Any.fromPartial({
typeUrl: '/cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount',
value: MsgCreatePeriodicVestingAccount_pb.encode(
this.toProto(isClassic)
).finish(),
});
}
public static unpackAny(
msgAny: Any,
isClassic?: boolean
): MsgCreatePeriodicVestingAccount {
if (isClassic) {
throw new Error('Not supported for the network');
}
return MsgCreatePeriodicVestingAccount.fromProto(
MsgCreatePeriodicVestingAccount_pb.decode(msgAny.value),
isClassic
);
}
}
export namespace MsgCreatePeriodicVestingAccount {
export interface Amino {
type: 'cosmos-sdk/MsgCreatePeriodicVestingAccount';
value: {
from_address: AccAddress;
to_address: AccAddress;
start_time: string;
vesting_periods: Period.Amino[];
};
}
export interface Data {
'@type': '/cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount';
from_address: AccAddress;
to_address: AccAddress;
start_time: string;
vesting_periods: Period.Data[];
}
export type Proto = MsgCreatePeriodicVestingAccount_pb;
}