-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathepoch.ts
145 lines (145 loc) · 5.53 KB
/
epoch.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
import { Timestamp } from '../google/protobuf/timestamp';
import { Duration, DurationAmino, DurationSDKType } from '../google/protobuf/duration';
import { BinaryReader, BinaryWriter } from '../binary';
import { toTimestamp, fromTimestamp } from '../helpers';
export interface Epoch {
genesisTime: Date | undefined;
epochDuration: Duration | undefined;
currentEpoch: bigint;
currentEpochStartTime: Date | undefined;
currentEpochHeight: bigint;
}
export interface EpochProtoMsg {
typeUrl: '/seiprotocol.seichain.epoch.Epoch';
value: Uint8Array;
}
export interface EpochAmino {
genesis_time?: string | undefined;
epoch_duration?: DurationAmino | undefined;
current_epoch: string;
current_epoch_start_time?: string | undefined;
current_epoch_height: string;
}
export interface EpochAminoMsg {
type: '/seiprotocol.seichain.epoch.Epoch';
value: EpochAmino;
}
export interface EpochSDKType {
genesis_time: Date | undefined;
epoch_duration: DurationSDKType | undefined;
current_epoch: bigint;
current_epoch_start_time: Date | undefined;
current_epoch_height: bigint;
}
function createBaseEpoch(): Epoch {
return {
genesisTime: new Date(),
epochDuration: Duration.fromPartial({}),
currentEpoch: BigInt(0),
currentEpochStartTime: new Date(),
currentEpochHeight: BigInt(0)
};
}
export const Epoch = {
typeUrl: '/seiprotocol.seichain.epoch.Epoch',
encode(message: Epoch, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
if (message.genesisTime !== undefined) {
Timestamp.encode(toTimestamp(message.genesisTime), writer.uint32(10).fork()).ldelim();
}
if (message.epochDuration !== undefined) {
Duration.encode(message.epochDuration, writer.uint32(18).fork()).ldelim();
}
if (message.currentEpoch !== BigInt(0)) {
writer.uint32(24).uint64(message.currentEpoch);
}
if (message.currentEpochStartTime !== undefined) {
Timestamp.encode(toTimestamp(message.currentEpochStartTime), writer.uint32(34).fork()).ldelim();
}
if (message.currentEpochHeight !== BigInt(0)) {
writer.uint32(40).int64(message.currentEpochHeight);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): Epoch {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseEpoch();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.genesisTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
break;
case 2:
message.epochDuration = Duration.decode(reader, reader.uint32());
break;
case 3:
message.currentEpoch = reader.uint64();
break;
case 4:
message.currentEpochStartTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
break;
case 5:
message.currentEpochHeight = reader.int64();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromPartial(object: Partial<Epoch>): Epoch {
const message = createBaseEpoch();
message.genesisTime = object.genesisTime ?? undefined;
message.epochDuration = object.epochDuration !== undefined && object.epochDuration !== null ? Duration.fromPartial(object.epochDuration) : undefined;
message.currentEpoch = object.currentEpoch !== undefined && object.currentEpoch !== null ? BigInt(object.currentEpoch.toString()) : BigInt(0);
message.currentEpochStartTime = object.currentEpochStartTime ?? undefined;
message.currentEpochHeight =
object.currentEpochHeight !== undefined && object.currentEpochHeight !== null ? BigInt(object.currentEpochHeight.toString()) : BigInt(0);
return message;
},
fromAmino(object: EpochAmino): Epoch {
const message = createBaseEpoch();
if (object.genesis_time !== undefined && object.genesis_time !== null) {
message.genesisTime = fromTimestamp(Timestamp.fromAmino(object.genesis_time));
}
if (object.epoch_duration !== undefined && object.epoch_duration !== null) {
message.epochDuration = Duration.fromAmino(object.epoch_duration);
}
if (object.current_epoch !== undefined && object.current_epoch !== null) {
message.currentEpoch = BigInt(object.current_epoch);
}
if (object.current_epoch_start_time !== undefined && object.current_epoch_start_time !== null) {
message.currentEpochStartTime = fromTimestamp(Timestamp.fromAmino(object.current_epoch_start_time));
}
if (object.current_epoch_height !== undefined && object.current_epoch_height !== null) {
message.currentEpochHeight = BigInt(object.current_epoch_height);
}
return message;
},
toAmino(message: Epoch): EpochAmino {
const obj: any = {};
obj.genesis_time = message.genesisTime ? Timestamp.toAmino(toTimestamp(message.genesisTime)) : undefined;
obj.epoch_duration = message.epochDuration ? Duration.toAmino(message.epochDuration) : undefined;
obj.current_epoch = message.currentEpoch ? message.currentEpoch.toString() : '0';
obj.current_epoch_start_time = message.currentEpochStartTime ? Timestamp.toAmino(toTimestamp(message.currentEpochStartTime)) : undefined;
obj.current_epoch_height = message.currentEpochHeight ? message.currentEpochHeight.toString() : '0';
return obj;
},
fromAminoMsg(object: EpochAminoMsg): Epoch {
return Epoch.fromAmino(object.value);
},
fromProtoMsg(message: EpochProtoMsg): Epoch {
return Epoch.decode(message.value);
},
toProto(message: Epoch): Uint8Array {
return Epoch.encode(message).finish();
},
toProtoMsg(message: Epoch): EpochProtoMsg {
return {
typeUrl: '/seiprotocol.seichain.epoch.Epoch',
value: Epoch.encode(message).finish()
};
}
};