-
Notifications
You must be signed in to change notification settings - Fork 27
/
Period.ts
86 lines (73 loc) · 1.92 KB
/
Period.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
import { Coins } from '../Coins';
import { Period as Period_pb } from '@terra-money/terra.proto/cosmos/vesting/v1beta1/vesting';
import { JSONSerializable } from '../../util/json';
import Long from 'long';
/**
* Period defines a length of time and amount of coins that will vest.
*/
export class Period extends JSONSerializable<
Period.Amino,
Period.Data,
Period.Proto
> {
public amount: Coins;
/**
* @param length
* @param amount
*/
constructor(public length: number, amount: Coins.Input) {
super();
this.amount = new Coins(amount);
}
public static fromAmino(data: Period.Amino, _?: boolean): Period {
_;
const { length, amount } = data;
return new Period(Number.parseInt(length), Coins.fromAmino(amount));
}
public toAmino(_?: boolean): Period.Amino {
_;
const { length, amount } = this;
const res: Period.Amino = {
length: length.toFixed(),
amount: amount.toAmino(),
};
return res;
}
public static fromData(data: Period.Data, _?: boolean): Period {
_;
const { length, amount } = data;
return new Period(Number.parseInt(length), Coins.fromData(amount));
}
public toData(_?: boolean): Period.Data {
_;
const { length, amount } = this;
const res: Period.Amino = {
length: length.toFixed(),
amount: amount.toData(),
};
return res;
}
public static fromProto(proto: Period.Proto, _?: boolean): Period {
_;
return new Period(proto.length.toNumber(), Coins.fromProto(proto.amount));
}
public toProto(_?: boolean): Period.Proto {
_;
const { length, amount } = this;
return Period_pb.fromPartial({
length: Long.fromNumber(length),
amount: amount.toProto(),
});
}
}
export namespace Period {
export interface Amino {
length: string;
amount: Coins.Amino;
}
export interface Data {
length: string;
amount: Coins.Data;
}
export type Proto = Period_pb;
}