-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.ts
90 lines (74 loc) · 2.25 KB
/
types.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
export type PublicKey = string;
export type Value = string;
export interface ScpSlices {
threshold: number;
validators: PublicKey[];
innerSets?: ScpSlices[];
}
export interface ScpNominate {
voted: Value[];
accepted: Value[];
}
export interface ScpBallot {
value: Value[];
counter: number;
}
export interface ScpPrepare {
ballot: ScpBallot; // current & highest prepare vote
prepared: ScpBallot | null; // highest accepted prepared ballot
aCounter: number; // lowest non-aborted ballot counter or 0
hCounter: number; // h.counter or 0 if h == NULL
cCounter: number; // c.counter or 0 if !c || !hCounter
}
export interface ScpCommit {
ballot: ScpBallot;
preparedCounter: number;
hCounter: number;
cCounter: number;
}
export interface ScpExternalize {
commit: ScpBallot;
hCounter: number;
}
export interface BaseMessageEnvelope {
message: ScpNominate | ScpPrepare | ScpCommit | ScpExternalize;
type: 'ScpNominate' | 'ScpPrepare' | 'ScpCommit' | 'ScpExternalize';
sender: PublicKey;
slices: ScpSlices;
timestamp: number;
slot: number;
}
export interface ScpNominateEnvelope extends BaseMessageEnvelope {
type: 'ScpNominate';
message: ScpNominate;
}
export interface ScpPrepareEnvelope extends BaseMessageEnvelope {
type: 'ScpPrepare';
message: ScpPrepare;
}
export interface ScpCommitEnvelope extends BaseMessageEnvelope {
type: 'ScpCommit';
message: ScpCommit;
}
export interface ScpExternalizeEnvelope extends BaseMessageEnvelope {
type: 'ScpExternalize';
message: ScpExternalize;
}
export type MessageEnvelope = ScpNominateEnvelope | ScpPrepareEnvelope | ScpCommitEnvelope | ScpExternalizeEnvelope;
export type TransactionHash = string;
export type BroadcastFunction = (envelope: MessageEnvelope, sendAnyways?: boolean) => void;
export type ValidationFunction = (transactionHash: TransactionHash) => Promise<boolean>;
export type InputFunction = () => Promise<TransactionHash[]>;
export interface ProtocolOptions {
self: PublicKey;
slices: ScpSlices;
slot: number;
logDebug: boolean;
logMessages: boolean;
logLevel?: 'debug' | 'info' | 'error' | 'warn' | 'verbose' | 'debug';
}
export interface ProtocolFunctions {
broadcast: BroadcastFunction;
validate: ValidationFunction;
getInput: InputFunction;
}