-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathcosmos.ts
425 lines (371 loc) · 8.78 KB
/
cosmos.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
import { Bytes } from '../common/collections';
export namespace cosmos {
export class Block {
constructor(
public header: Header,
public evidence: EvidenceList,
public lastCommit: Commit,
public resultBeginBlock: ResponseBeginBlock,
public resultEndBlock: ResponseEndBlock,
public transactions: Array<TxResult>,
public validatorUpdates: Array<Validator>,
) {}
}
export class HeaderOnlyBlock {
constructor(public header: Header) {}
}
export class EventData {
constructor(
public event: Event,
public block: HeaderOnlyBlock,
public tx: TransactionContext,
) {}
}
export class TransactionData {
constructor(
public tx: TxResult,
public block: HeaderOnlyBlock,
) {}
}
export class MessageData {
constructor(
public message: Any,
public block: HeaderOnlyBlock,
public tx: TransactionContext,
) {}
}
export class TransactionContext {
constructor(
public hash: Bytes,
public index: u32,
public code: u32,
public gasWanted: i64,
public gasUsed: i64,
) {}
}
export class Header {
constructor(
public version: Consensus,
public chainId: string,
public height: u64,
public time: Timestamp,
public lastBlockId: BlockID,
public lastCommitHash: Bytes,
public dataHash: Bytes,
public validatorsHash: Bytes,
public nextValidatorsHash: Bytes,
public consensusHash: Bytes,
public appHash: Bytes,
public lastResultsHash: Bytes,
public evidenceHash: Bytes,
public proposerAddress: Bytes,
public hash: Bytes,
) {}
}
export class Consensus {
constructor(
public block: u64,
public app: u64,
) {}
}
export class Timestamp {
constructor(
public seconds: i64,
public nanos: i32,
) {}
}
export class BlockID {
constructor(
public hash: Bytes,
public partSetHeader: PartSetHeader,
) {}
}
export class PartSetHeader {
constructor(
public total: u32,
public hash: Bytes,
) {}
}
export class EvidenceList {
constructor(public evidence: Array<Evidence>) {}
}
export class Evidence {
constructor(
public duplicateVoteEvidence: DuplicateVoteEvidence,
public lightClientAttackEvidence: LightClientAttackEvidence,
) {}
}
export class DuplicateVoteEvidence {
constructor(
public voteA: EventVote,
public voteB: EventVote,
public totalVotingPower: i64,
public validatorPower: i64,
public timestamp: Timestamp,
) {}
}
export class EventVote {
constructor(
public eventVoteType: SignedMsgType,
public height: u64,
public round: i32,
public blockId: BlockID,
public timestamp: Timestamp,
public validatorAddress: Bytes,
public validatorIndex: i32,
public signature: Bytes,
) {}
}
export enum SignedMsgType {
SIGNED_MSG_TYPE_UNKNOWN = 0,
SIGNED_MSG_TYPE_PREVOTE = 1,
SIGNED_MSG_TYPE_PRECOMMIT = 2,
SIGNED_MSG_TYPE_PROPOSAL = 32,
}
export class LightClientAttackEvidence {
constructor(
public conflictingBlock: LightBlock,
public commonHeight: i64,
public byzantineValidators: Array<Validator>,
public totalVotingPower: i64,
public timestamp: Timestamp,
) {}
}
export class LightBlock {
constructor(
public signedHeader: SignedHeader,
public validatorSet: ValidatorSet,
) {}
}
export class SignedHeader {
constructor(
public header: Header,
public commit: Commit,
) {}
}
export class Commit {
constructor(
public height: i64,
public round: i32,
public blockId: BlockID,
public signatures: Array<CommitSig>,
) {}
}
export class CommitSig {
constructor(
public blockIdFlag: BlockIDFlag,
public validatorAddress: Bytes,
public timestamp: Timestamp,
public signature: Bytes,
) {}
}
export enum BlockIDFlag {
BLOCK_ID_FLAG_UNKNOWN = 0,
BLOCK_ID_FLAG_ABSENT = 1,
BLOCK_ID_FLAG_COMMIT = 2,
BLOCK_ID_FLAG_NIL = 3,
}
export class ValidatorSet {
constructor(
public validators: Array<Validator>,
public proposer: Validator,
public totalVotingPower: i64,
) {}
}
export class Validator {
constructor(
public address: Bytes,
public pubKey: PublicKey,
public votingPower: i64,
public proposerPriority: i64,
) {}
}
export class PublicKey {
constructor(
public ed25519: Bytes,
public secp256k1: Bytes,
) {}
}
export class ResponseBeginBlock {
constructor(public events: Array<Event>) {}
}
export class Event {
constructor(
public eventType: string,
public attributes: Array<EventAttribute>,
) {}
getAttribute(key: string): EventAttribute | null {
for (let i = 0; i < this.attributes.length; i++) {
if (this.attributes[i].key == key) {
return this.attributes[i];
}
}
return null;
}
getAttributeValue(key: string): string {
const attribute = this.getAttribute(key);
return attribute ? attribute.value : '';
}
}
export class EventAttribute {
constructor(
public key: string,
public value: string,
public index: bool,
) {}
}
export class ResponseEndBlock {
constructor(
public validatorUpdates: Array<ValidatorUpdate>,
public consensusParamUpdates: ConsensusParams,
public events: Array<Event>,
) {}
}
export class ValidatorUpdate {
constructor(
public address: Bytes,
public pubKey: PublicKey,
public power: i64,
) {}
}
export class ConsensusParams {
constructor(
public block: BlockParams,
public evidence: EvidenceParams,
public validator: ValidatorParams,
public version: VersionParams,
) {}
}
export class BlockParams {
constructor(
public maxBytes: i64,
public maxGas: i64,
) {}
}
export class EvidenceParams {
constructor(
public maxAgeNumBlocks: i64,
public maxAgeDuration: Duration,
public maxBytes: i64,
) {}
}
export class Duration {
constructor(
public seconds: i64,
public nanos: i32,
) {}
}
export class ValidatorParams {
constructor(public pubKeyTypes: Array<string>) {}
}
export class VersionParams {
constructor(public appVersion: u64) {}
}
export class TxResult {
constructor(
public height: u64,
public index: u32,
public tx: Tx,
public result: ResponseDeliverTx,
public hash: Bytes,
) {}
}
export class Tx {
constructor(
public body: TxBody,
public authInfo: AuthInfo,
public signatures: Array<Bytes>,
) {}
}
export class TxBody {
constructor(
public messages: Array<Any>,
public memo: string,
public timeoutHeight: u64,
public extensionOptions: Array<Any>,
public nonCriticalExtensionOptions: Array<Any>,
) {}
}
export class Any {
constructor(
public typeUrl: string,
public value: Bytes,
) {}
}
export class AuthInfo {
constructor(
public signerInfos: Array<SignerInfo>,
public fee: Fee,
public tip: Tip,
) {}
}
export class SignerInfo {
constructor(
public publicKey: Any,
public modeInfo: ModeInfo,
public sequence: u64,
) {}
}
export class ModeInfo {
constructor(
public single: ModeInfoSingle,
public multi: ModeInfoMulti,
) {}
}
export class ModeInfoSingle {
constructor(public mode: SignMode) {}
}
export enum SignMode {
SIGN_MODE_UNSPECIFIED = 0,
SIGN_MODE_DIRECT = 1,
SIGN_MODE_TEXTUAL = 2,
SIGN_MODE_LEGACY_AMINO_JSON = 127,
}
export class ModeInfoMulti {
constructor(
public bitarray: CompactBitArray,
public modeInfos: Array<ModeInfo>,
) {}
}
export class CompactBitArray {
constructor(
public extraBitsStored: u32,
public elems: Bytes,
) {}
}
export class Fee {
constructor(
public amount: Array<Coin>,
public gasLimit: u64,
public payer: string,
public granter: string,
) {}
}
export class Coin {
constructor(
public denom: string,
public amount: string,
) {}
}
export class Tip {
constructor(
public amount: Array<Coin>,
public tipper: string,
) {}
}
export class ResponseDeliverTx {
constructor(
public code: u32,
public data: Bytes,
public log: string,
public info: string,
public gasWanted: i64,
public gasUsed: i64,
public events: Array<Event>,
public codespace: string,
) {}
}
export class ValidatorSetUpdates {
constructor(public validatorUpdates: Array<Validator>) {}
}
}