This repository was archived by the owner on Feb 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathSCPStatement.cs
200 lines (192 loc) · 8.79 KB
/
SCPStatement.cs
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
// Automatically generated by xdrgen
// DO NOT EDIT or your changes may be overwritten
namespace Stellar.Generated
{
// === xdr source ============================================================
// struct SCPStatement
// {
// NodeID nodeID; // v
// uint64 slotIndex; // i
//
// union switch (SCPStatementType type)
// {
// case SCP_ST_PREPARE:
// struct
// {
// Hash quorumSetHash; // D
// SCPBallot ballot; // b
// SCPBallot* prepared; // p
// SCPBallot* preparedPrime; // p'
// uint32 nC; // c.n
// uint32 nH; // h.n
// } prepare;
// case SCP_ST_CONFIRM:
// struct
// {
// SCPBallot ballot; // b
// uint32 nPrepared; // p.n
// uint32 nCommit; // c.n
// uint32 nH; // h.n
// Hash quorumSetHash; // D
// } confirm;
// case SCP_ST_EXTERNALIZE:
// struct
// {
// SCPBallot commit; // c
// uint32 nH; // h.n
// Hash commitQuorumSetHash; // D used before EXTERNALIZE
// } externalize;
// case SCP_ST_NOMINATE:
// SCPNomination nominate;
// }
// pledges;
// };
// ===========================================================================
public class SCPStatement {
public SCPStatement () {}
public NodeID NodeID { get; set; }
public Uint64 SlotIndex { get; set; }
public SCPStatementPledges Pledges { get; set; }
public static void Encode(IByteWriter stream, SCPStatement encodedSCPStatement) {
NodeID.Encode(stream, encodedSCPStatement.NodeID);
Uint64.Encode(stream, encodedSCPStatement.SlotIndex);
SCPStatementPledges.Encode(stream, encodedSCPStatement.Pledges);
}
public static SCPStatement Decode(IByteReader stream) {
SCPStatement decodedSCPStatement = new SCPStatement();
decodedSCPStatement.NodeID = NodeID.Decode(stream);
decodedSCPStatement.SlotIndex = Uint64.Decode(stream);
decodedSCPStatement.Pledges = SCPStatementPledges.Decode(stream);
return decodedSCPStatement;
}
public class SCPStatementPledges {
public SCPStatementPledges () {}
public SCPStatementType Discriminant { get; set; } = new SCPStatementType();
public SCPStatementPrepare Prepare { get; set; } = default(SCPStatementPrepare);
public SCPStatementConfirm Confirm { get; set; } = default(SCPStatementConfirm);
public SCPStatementExternalize Externalize { get; set; } = default(SCPStatementExternalize);
public SCPNomination Nominate { get; set; } = default(SCPNomination);
public static void Encode(IByteWriter stream, SCPStatementPledges encodedSCPStatementPledges) {
XdrEncoding.EncodeInt32((int)encodedSCPStatementPledges.Discriminant.InnerValue, stream);
switch (encodedSCPStatementPledges.Discriminant.InnerValue) {
case SCPStatementType.SCPStatementTypeEnum.SCP_ST_PREPARE:
SCPStatementPrepare.Encode(stream, encodedSCPStatementPledges.Prepare);
break;
case SCPStatementType.SCPStatementTypeEnum.SCP_ST_CONFIRM:
SCPStatementConfirm.Encode(stream, encodedSCPStatementPledges.Confirm);
break;
case SCPStatementType.SCPStatementTypeEnum.SCP_ST_EXTERNALIZE:
SCPStatementExternalize.Encode(stream, encodedSCPStatementPledges.Externalize);
break;
case SCPStatementType.SCPStatementTypeEnum.SCP_ST_NOMINATE:
SCPNomination.Encode(stream, encodedSCPStatementPledges.Nominate);
break;
}
}
public static SCPStatementPledges Decode(IByteReader stream) {
SCPStatementPledges decodedSCPStatementPledges = new SCPStatementPledges();
decodedSCPStatementPledges.Discriminant = SCPStatementType.Decode(stream);
switch (decodedSCPStatementPledges.Discriminant.InnerValue) {
case SCPStatementType.SCPStatementTypeEnum.SCP_ST_PREPARE:
decodedSCPStatementPledges.Prepare = SCPStatementPrepare.Decode(stream);
break;
case SCPStatementType.SCPStatementTypeEnum.SCP_ST_CONFIRM:
decodedSCPStatementPledges.Confirm = SCPStatementConfirm.Decode(stream);
break;
case SCPStatementType.SCPStatementTypeEnum.SCP_ST_EXTERNALIZE:
decodedSCPStatementPledges.Externalize = SCPStatementExternalize.Decode(stream);
break;
case SCPStatementType.SCPStatementTypeEnum.SCP_ST_NOMINATE:
decodedSCPStatementPledges.Nominate = SCPNomination.Decode(stream);
break;
}
return decodedSCPStatementPledges;
}
public class SCPStatementPrepare {
public SCPStatementPrepare () {}
public Hash QuorumSetHash { get; set; }
public SCPBallot Ballot { get; set; }
public SCPBallot Prepared { get; set; }
public SCPBallot PreparedPrime { get; set; }
public Uint32 NC { get; set; }
public Uint32 NH { get; set; }
public static void Encode(IByteWriter stream, SCPStatementPrepare encodedSCPStatementPrepare) {
Hash.Encode(stream, encodedSCPStatementPrepare.QuorumSetHash);
SCPBallot.Encode(stream, encodedSCPStatementPrepare.Ballot);
if (encodedSCPStatementPrepare.Prepared != null) {
XdrEncoding.EncodeInt32(1, stream);
SCPBallot.Encode(stream, encodedSCPStatementPrepare.Prepared);
} else {
XdrEncoding.EncodeInt32(0, stream);
}
if (encodedSCPStatementPrepare.PreparedPrime != null) {
XdrEncoding.EncodeInt32(1, stream);
SCPBallot.Encode(stream, encodedSCPStatementPrepare.PreparedPrime);
} else {
XdrEncoding.EncodeInt32(0, stream);
}
Uint32.Encode(stream, encodedSCPStatementPrepare.NC);
Uint32.Encode(stream, encodedSCPStatementPrepare.NH);
}
public static SCPStatementPrepare Decode(IByteReader stream) {
SCPStatementPrepare decodedSCPStatementPrepare = new SCPStatementPrepare();
decodedSCPStatementPrepare.QuorumSetHash = Hash.Decode(stream);
decodedSCPStatementPrepare.Ballot = SCPBallot.Decode(stream);
int preparedPresent = XdrEncoding.DecodeInt32(stream);
if (preparedPresent != 0) {
decodedSCPStatementPrepare.Prepared = SCPBallot.Decode(stream);
}
int preparedPrimePresent = XdrEncoding.DecodeInt32(stream);
if (preparedPrimePresent != 0) {
decodedSCPStatementPrepare.PreparedPrime = SCPBallot.Decode(stream);
}
decodedSCPStatementPrepare.NC = Uint32.Decode(stream);
decodedSCPStatementPrepare.NH = Uint32.Decode(stream);
return decodedSCPStatementPrepare;
}
}
public class SCPStatementConfirm {
public SCPStatementConfirm () {}
public SCPBallot Ballot { get; set; }
public Uint32 NPrepared { get; set; }
public Uint32 NCommit { get; set; }
public Uint32 NH { get; set; }
public Hash QuorumSetHash { get; set; }
public static void Encode(IByteWriter stream, SCPStatementConfirm encodedSCPStatementConfirm) {
SCPBallot.Encode(stream, encodedSCPStatementConfirm.Ballot);
Uint32.Encode(stream, encodedSCPStatementConfirm.NPrepared);
Uint32.Encode(stream, encodedSCPStatementConfirm.NCommit);
Uint32.Encode(stream, encodedSCPStatementConfirm.NH);
Hash.Encode(stream, encodedSCPStatementConfirm.QuorumSetHash);
}
public static SCPStatementConfirm Decode(IByteReader stream) {
SCPStatementConfirm decodedSCPStatementConfirm = new SCPStatementConfirm();
decodedSCPStatementConfirm.Ballot = SCPBallot.Decode(stream);
decodedSCPStatementConfirm.NPrepared = Uint32.Decode(stream);
decodedSCPStatementConfirm.NCommit = Uint32.Decode(stream);
decodedSCPStatementConfirm.NH = Uint32.Decode(stream);
decodedSCPStatementConfirm.QuorumSetHash = Hash.Decode(stream);
return decodedSCPStatementConfirm;
}
}
public class SCPStatementExternalize {
public SCPStatementExternalize () {}
public SCPBallot Commit { get; set; }
public Uint32 NH { get; set; }
public Hash CommitQuorumSetHash { get; set; }
public static void Encode(IByteWriter stream, SCPStatementExternalize encodedSCPStatementExternalize) {
SCPBallot.Encode(stream, encodedSCPStatementExternalize.Commit);
Uint32.Encode(stream, encodedSCPStatementExternalize.NH);
Hash.Encode(stream, encodedSCPStatementExternalize.CommitQuorumSetHash);
}
public static SCPStatementExternalize Decode(IByteReader stream) {
SCPStatementExternalize decodedSCPStatementExternalize = new SCPStatementExternalize();
decodedSCPStatementExternalize.Commit = SCPBallot.Decode(stream);
decodedSCPStatementExternalize.NH = Uint32.Decode(stream);
decodedSCPStatementExternalize.CommitQuorumSetHash = Hash.Decode(stream);
return decodedSCPStatementExternalize;
}
}
}
}
}