@wireio/opp-solidity-models 1.0.0 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # @wireio/opp-solidity-models
2
-
3
- Auto-generated protobuf Solidity contracts.
4
-
5
- ## Usage
6
-
7
- Import contracts from `@wireio/opp-solidity-models/contracts/`.
8
-
9
- ## Generated from
10
-
11
- Proto source: `Wire-Network/wire-sysio/libraries/opp#feature/protobuf-support-for-opp`
1
+ # @wireio/opp-solidity-models
2
+
3
+ Auto-generated protobuf Solidity contracts.
4
+
5
+ ## Usage
6
+
7
+ Import contracts from `@wireio/opp-solidity-models/contracts/`.
8
+
9
+ ## Generated from
10
+
11
+ Proto source: `Wire-Network/wire-sysio/libraries/opp#feature/protobuf-support-for-opp`
@@ -4,7 +4,8 @@ pragma solidity >=0.8.0 <0.9.0;
4
4
  // Auto-generated by protoc-gen-solidity from sysio/opp/opp.proto
5
5
  // DO NOT EDIT
6
6
 
7
- import {ProtobufRuntime} from "./ProtobufRuntime.sol";
7
+ import {ProtobufRuntime} from "../../ProtobufRuntime.sol";
8
+ import {ChainId, ChainIdCodec, ChainSignature, ChainSignatureCodec, EncodingFlags, EncodingFlagsCodec} from "./types/Types.sol";
8
9
 
9
10
  struct Endpoints {
10
11
  ChainId start;
@@ -28,7 +29,7 @@ struct MessagePayload {
28
29
  }
29
30
 
30
31
  struct AttestationEntry {
31
- uint64 type;
32
+ uint64 type_;
32
33
  uint32 dataSize;
33
34
  bytes data;
34
35
  }
@@ -53,25 +54,25 @@ struct Envelope {
53
54
 
54
55
  library EndpointsCodec {
55
56
 
56
- function encode(Endpoints memory msg) internal pure returns (bytes memory) {
57
+ function encode(Endpoints memory endpoints) internal pure returns (bytes memory) {
57
58
  bytes memory buf = "";
58
59
 
59
60
  // field 1: start
60
61
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0xa));
61
- bytes memory start_encoded = ChainIdCodec.encode(msg.start);
62
+ bytes memory start_encoded = ChainIdCodec.encode(endpoints.start);
62
63
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(start_encoded.length)));
63
64
  buf = abi.encodePacked(buf, start_encoded);
64
65
 
65
66
  // field 2: end
66
67
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x12));
67
- bytes memory end_encoded = ChainIdCodec.encode(msg.end);
68
+ bytes memory end_encoded = ChainIdCodec.encode(endpoints.end);
68
69
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(end_encoded.length)));
69
70
  buf = abi.encodePacked(buf, end_encoded);
70
71
 
71
72
  return buf;
72
73
  }
73
74
 
74
- function decode(bytes memory data) internal pure returns (Endpoints memory msg) {
75
+ function decode(bytes memory data) internal pure returns (Endpoints memory endpoints) {
75
76
  uint256 pos = 0;
76
77
  uint256 end = data.length;
77
78
 
@@ -79,29 +80,20 @@ library EndpointsCodec {
79
80
  uint64 tag;
80
81
  (tag, pos) = ProtobufRuntime._decode_key(data, pos);
81
82
 
82
- // solhint-disable-next-line no-empty-blocks
83
- switch (tag) {
84
- case 10:
85
- {
86
- uint64 _len;
87
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
88
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
89
- msg.start = ChainIdCodec.decode(_sub);
90
- pos += uint256(_len);
91
- }
92
- break;
93
- case 18:
94
- {
95
- uint64 _len;
96
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
97
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
98
- msg.end = ChainIdCodec.decode(_sub);
99
- pos += uint256(_len);
100
- }
101
- break;
102
- default:
103
- pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
104
- break;
83
+ if (tag == 10) {
84
+ uint64 _len;
85
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
86
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
87
+ endpoints.start = ChainIdCodec.decode(_sub);
88
+ pos += uint256(_len);
89
+ } else if (tag == 18) {
90
+ uint64 _len;
91
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
92
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
93
+ endpoints.end = ChainIdCodec.decode(_sub);
94
+ pos += uint256(_len);
95
+ } else {
96
+ pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
105
97
  }
106
98
  }
107
99
  }
@@ -109,49 +101,49 @@ library EndpointsCodec {
109
101
 
110
102
  library MessageHeaderCodec {
111
103
 
112
- function encode(MessageHeader memory msg) internal pure returns (bytes memory) {
104
+ function encode(MessageHeader memory messageHeader) internal pure returns (bytes memory) {
113
105
  bytes memory buf = "";
114
106
 
115
107
  // field 1: endpoints
116
108
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0xa));
117
- bytes memory endpoints_encoded = EndpointsCodec.encode(msg.endpoints);
109
+ bytes memory endpoints_encoded = EndpointsCodec.encode(messageHeader.endpoints);
118
110
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(endpoints_encoded.length)));
119
111
  buf = abi.encodePacked(buf, endpoints_encoded);
120
112
 
121
113
  // field 2: message_id
122
114
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x12));
123
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.messageId));
115
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(messageHeader.messageId));
124
116
 
125
117
  // field 3: previous_message_id
126
118
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x1a));
127
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.previousMessageId));
119
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(messageHeader.previousMessageId));
128
120
 
129
121
  // field 4: encoding_flags
130
122
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x22));
131
- bytes memory encodingFlags_encoded = EncodingFlagsCodec.encode(msg.encodingFlags);
123
+ bytes memory encodingFlags_encoded = EncodingFlagsCodec.encode(messageHeader.encodingFlags);
132
124
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(encodingFlags_encoded.length)));
133
125
  buf = abi.encodePacked(buf, encodingFlags_encoded);
134
126
 
135
127
  // field 5: payload_size
136
128
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x28));
137
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(msg.payloadSize));
129
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(messageHeader.payloadSize));
138
130
 
139
131
  // field 6: payload_checksum
140
132
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x32));
141
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.payloadChecksum));
133
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(messageHeader.payloadChecksum));
142
134
 
143
135
  // field 7: timestamp
144
136
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x38));
145
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(msg.timestamp));
137
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(messageHeader.timestamp));
146
138
 
147
139
  // field 8: header_checksum
148
140
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x42));
149
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.headerChecksum));
141
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(messageHeader.headerChecksum));
150
142
 
151
143
  return buf;
152
144
  }
153
145
 
154
- function decode(bytes memory data) internal pure returns (MessageHeader memory msg) {
146
+ function decode(bytes memory data) internal pure returns (MessageHeader memory messageHeader) {
155
147
  uint256 pos = 0;
156
148
  uint256 end = data.length;
157
149
 
@@ -159,47 +151,34 @@ library MessageHeaderCodec {
159
151
  uint64 tag;
160
152
  (tag, pos) = ProtobufRuntime._decode_key(data, pos);
161
153
 
162
- // solhint-disable-next-line no-empty-blocks
163
- switch (tag) {
164
- case 10:
165
- {
166
- uint64 _len;
167
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
168
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
169
- msg.endpoints = EndpointsCodec.decode(_sub);
170
- pos += uint256(_len);
171
- }
172
- break;
173
- case 18:
174
- (msg.messageId, pos) = ProtobufRuntime._decode_bytes(data, pos);
175
- break;
176
- case 26:
177
- (msg.previousMessageId, pos) = ProtobufRuntime._decode_bytes(data, pos);
178
- break;
179
- case 34:
180
- {
181
- uint64 _len;
182
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
183
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
184
- msg.encodingFlags = EncodingFlagsCodec.decode(_sub);
185
- pos += uint256(_len);
186
- }
187
- break;
188
- case 40:
189
- (msg.payloadSize, pos) = ProtobufRuntime._decode_varint(data, pos);
190
- break;
191
- case 50:
192
- (msg.payloadChecksum, pos) = ProtobufRuntime._decode_bytes(data, pos);
193
- break;
194
- case 56:
195
- (msg.timestamp, pos) = ProtobufRuntime._decode_varint(data, pos);
196
- break;
197
- case 66:
198
- (msg.headerChecksum, pos) = ProtobufRuntime._decode_bytes(data, pos);
199
- break;
200
- default:
201
- pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
202
- break;
154
+ if (tag == 10) {
155
+ uint64 _len;
156
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
157
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
158
+ messageHeader.endpoints = EndpointsCodec.decode(_sub);
159
+ pos += uint256(_len);
160
+ } else if (tag == 18) {
161
+ (messageHeader.messageId, pos) = ProtobufRuntime._decode_bytes(data, pos);
162
+ } else if (tag == 26) {
163
+ (messageHeader.previousMessageId, pos) = ProtobufRuntime._decode_bytes(data, pos);
164
+ } else if (tag == 34) {
165
+ uint64 _len;
166
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
167
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
168
+ messageHeader.encodingFlags = EncodingFlagsCodec.decode(_sub);
169
+ pos += uint256(_len);
170
+ } else if (tag == 40) {
171
+ { uint64 _v;
172
+ (_v, pos) = ProtobufRuntime._decode_varint(data, pos);
173
+ messageHeader.payloadSize = uint32(_v); }
174
+ } else if (tag == 50) {
175
+ (messageHeader.payloadChecksum, pos) = ProtobufRuntime._decode_bytes(data, pos);
176
+ } else if (tag == 56) {
177
+ (messageHeader.timestamp, pos) = ProtobufRuntime._decode_varint(data, pos);
178
+ } else if (tag == 66) {
179
+ (messageHeader.headerChecksum, pos) = ProtobufRuntime._decode_bytes(data, pos);
180
+ } else {
181
+ pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
203
182
  }
204
183
  }
205
184
  }
@@ -207,17 +186,17 @@ library MessageHeaderCodec {
207
186
 
208
187
  library MessagePayloadCodec {
209
188
 
210
- function encode(MessagePayload memory msg) internal pure returns (bytes memory) {
189
+ function encode(MessagePayload memory messagePayload) internal pure returns (bytes memory) {
211
190
  bytes memory buf = "";
212
191
 
213
192
  // field 1: version
214
193
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x8));
215
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(msg.version));
194
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(messagePayload.version));
216
195
 
217
196
  // field 2: attestations
218
- for (uint256 _i_attestations = 0; _i_attestations < msg.attestations.length; _i_attestations++) {
197
+ for (uint256 _i_attestations = 0; _i_attestations < messagePayload.attestations.length; _i_attestations++) {
219
198
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x12));
220
- bytes memory _elem = AttestationEntryCodec.encode(msg.attestations[_i_attestations]);
199
+ bytes memory _elem = AttestationEntryCodec.encode(messagePayload.attestations[_i_attestations]);
221
200
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(_elem.length)));
222
201
  buf = abi.encodePacked(buf, _elem);
223
202
  }
@@ -225,31 +204,39 @@ library MessagePayloadCodec {
225
204
  return buf;
226
205
  }
227
206
 
228
- function decode(bytes memory data) internal pure returns (MessagePayload memory msg) {
207
+ function decode(bytes memory data) internal pure returns (MessagePayload memory messagePayload) {
229
208
  uint256 pos = 0;
230
209
  uint256 end = data.length;
231
210
 
211
+ uint256 _count_attestations = 0;
212
+ {
213
+ uint256 _pos = 0;
214
+ while (_pos < end) {
215
+ uint64 _tag;
216
+ (_tag, _pos) = ProtobufRuntime._decode_key(data, _pos);
217
+ if (_tag == 18) { _count_attestations++; }
218
+ _pos = ProtobufRuntime._skip_field(data, _pos, _tag & 0x07);
219
+ }
220
+ }
221
+ messagePayload.attestations = new AttestationEntry[](_count_attestations);
222
+ uint256 _idx_attestations = 0;
223
+
232
224
  while (pos < end) {
233
225
  uint64 tag;
234
226
  (tag, pos) = ProtobufRuntime._decode_key(data, pos);
235
227
 
236
- // solhint-disable-next-line no-empty-blocks
237
- switch (tag) {
238
- case 8:
239
- (msg.version, pos) = ProtobufRuntime._decode_varint(data, pos);
240
- break;
241
- case 18:
242
- {
243
- uint64 _len;
244
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
245
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
246
- msg.attestations.push(AttestationEntryCodec.decode(_sub));
247
- pos += uint256(_len);
248
- }
249
- break;
250
- default:
251
- pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
252
- break;
228
+ if (tag == 8) {
229
+ { uint64 _v;
230
+ (_v, pos) = ProtobufRuntime._decode_varint(data, pos);
231
+ messagePayload.version = uint32(_v); }
232
+ } else if (tag == 18) {
233
+ uint64 _len;
234
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
235
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
236
+ messagePayload.attestations[_idx_attestations++] = AttestationEntryCodec.decode(_sub);
237
+ pos += uint256(_len);
238
+ } else {
239
+ pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
253
240
  }
254
241
  }
255
242
  }
@@ -257,25 +244,25 @@ library MessagePayloadCodec {
257
244
 
258
245
  library AttestationEntryCodec {
259
246
 
260
- function encode(AttestationEntry memory msg) internal pure returns (bytes memory) {
247
+ function encode(AttestationEntry memory attestationEntry) internal pure returns (bytes memory) {
261
248
  bytes memory buf = "";
262
249
 
263
250
  // field 1: type
264
251
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x8));
265
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(msg.type));
252
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(attestationEntry.type_));
266
253
 
267
254
  // field 2: data_size
268
255
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x10));
269
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(msg.dataSize));
256
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(attestationEntry.dataSize));
270
257
 
271
258
  // field 3: data
272
259
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x1a));
273
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.data));
260
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(attestationEntry.data));
274
261
 
275
262
  return buf;
276
263
  }
277
264
 
278
- function decode(bytes memory data) internal pure returns (AttestationEntry memory msg) {
265
+ function decode(bytes memory data) internal pure returns (AttestationEntry memory attestationEntry) {
279
266
  uint256 pos = 0;
280
267
  uint256 end = data.length;
281
268
 
@@ -283,20 +270,16 @@ library AttestationEntryCodec {
283
270
  uint64 tag;
284
271
  (tag, pos) = ProtobufRuntime._decode_key(data, pos);
285
272
 
286
- // solhint-disable-next-line no-empty-blocks
287
- switch (tag) {
288
- case 8:
289
- (msg.type, pos) = ProtobufRuntime._decode_varint(data, pos);
290
- break;
291
- case 16:
292
- (msg.dataSize, pos) = ProtobufRuntime._decode_varint(data, pos);
293
- break;
294
- case 26:
295
- (msg.data, pos) = ProtobufRuntime._decode_bytes(data, pos);
296
- break;
297
- default:
298
- pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
299
- break;
273
+ if (tag == 8) {
274
+ (attestationEntry.type_, pos) = ProtobufRuntime._decode_varint(data, pos);
275
+ } else if (tag == 16) {
276
+ { uint64 _v;
277
+ (_v, pos) = ProtobufRuntime._decode_varint(data, pos);
278
+ attestationEntry.dataSize = uint32(_v); }
279
+ } else if (tag == 26) {
280
+ (attestationEntry.data, pos) = ProtobufRuntime._decode_bytes(data, pos);
281
+ } else {
282
+ pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
300
283
  }
301
284
  }
302
285
  }
@@ -304,25 +287,25 @@ library AttestationEntryCodec {
304
287
 
305
288
  library MessageCodec {
306
289
 
307
- function encode(Message memory msg) internal pure returns (bytes memory) {
290
+ function encode(Message memory message) internal pure returns (bytes memory) {
308
291
  bytes memory buf = "";
309
292
 
310
293
  // field 1: header
311
294
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0xa));
312
- bytes memory header_encoded = MessageHeaderCodec.encode(msg.header);
295
+ bytes memory header_encoded = MessageHeaderCodec.encode(message.header);
313
296
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(header_encoded.length)));
314
297
  buf = abi.encodePacked(buf, header_encoded);
315
298
 
316
299
  // field 2: payload
317
300
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x12));
318
- bytes memory payload_encoded = MessagePayloadCodec.encode(msg.payload);
301
+ bytes memory payload_encoded = MessagePayloadCodec.encode(message.payload);
319
302
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(payload_encoded.length)));
320
303
  buf = abi.encodePacked(buf, payload_encoded);
321
304
 
322
305
  return buf;
323
306
  }
324
307
 
325
- function decode(bytes memory data) internal pure returns (Message memory msg) {
308
+ function decode(bytes memory data) internal pure returns (Message memory message) {
326
309
  uint256 pos = 0;
327
310
  uint256 end = data.length;
328
311
 
@@ -330,29 +313,20 @@ library MessageCodec {
330
313
  uint64 tag;
331
314
  (tag, pos) = ProtobufRuntime._decode_key(data, pos);
332
315
 
333
- // solhint-disable-next-line no-empty-blocks
334
- switch (tag) {
335
- case 10:
336
- {
337
- uint64 _len;
338
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
339
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
340
- msg.header = MessageHeaderCodec.decode(_sub);
341
- pos += uint256(_len);
342
- }
343
- break;
344
- case 18:
345
- {
346
- uint64 _len;
347
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
348
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
349
- msg.payload = MessagePayloadCodec.decode(_sub);
350
- pos += uint256(_len);
351
- }
352
- break;
353
- default:
354
- pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
355
- break;
316
+ if (tag == 10) {
317
+ uint64 _len;
318
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
319
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
320
+ message.header = MessageHeaderCodec.decode(_sub);
321
+ pos += uint256(_len);
322
+ } else if (tag == 18) {
323
+ uint64 _len;
324
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
325
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
326
+ message.payload = MessagePayloadCodec.decode(_sub);
327
+ pos += uint256(_len);
328
+ } else {
329
+ pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
356
330
  }
357
331
  }
358
332
  }
@@ -360,51 +334,51 @@ library MessageCodec {
360
334
 
361
335
  library EnvelopeCodec {
362
336
 
363
- function encode(Envelope memory msg) internal pure returns (bytes memory) {
337
+ function encode(Envelope memory envelope) internal pure returns (bytes memory) {
364
338
  bytes memory buf = "";
365
339
 
366
340
  // field 1: envelope_hash
367
341
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0xa));
368
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.envelopeHash));
342
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(envelope.envelopeHash));
369
343
 
370
344
  // field 2: endpoints
371
345
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x12));
372
- bytes memory endpoints_encoded = EndpointsCodec.encode(msg.endpoints);
346
+ bytes memory endpoints_encoded = EndpointsCodec.encode(envelope.endpoints);
373
347
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(endpoints_encoded.length)));
374
348
  buf = abi.encodePacked(buf, endpoints_encoded);
375
349
 
376
350
  // field 5: epoch_timestamp
377
351
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x28));
378
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(msg.epochTimestamp));
352
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(envelope.epochTimestamp));
379
353
 
380
354
  // field 6: epoch_index
381
355
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x30));
382
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(msg.epochIndex));
356
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(envelope.epochIndex));
383
357
 
384
358
  // field 7: epoch_envelope_index
385
359
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x38));
386
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(msg.epochEnvelopeIndex));
360
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(envelope.epochEnvelopeIndex));
387
361
 
388
362
  // field 15: merkle
389
363
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x7a));
390
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.merkle));
364
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(envelope.merkle));
391
365
 
392
366
  // field 20: previous_envelope_hash
393
367
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0xa2));
394
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.previousEnvelopeHash));
368
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(envelope.previousEnvelopeHash));
395
369
 
396
370
  // field 30: start_message_id
397
371
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0xf2));
398
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.startMessageId));
372
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(envelope.startMessageId));
399
373
 
400
374
  // field 31: end_message_id
401
375
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0xfa));
402
- buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(msg.endMessageId));
376
+ buf = abi.encodePacked(buf, ProtobufRuntime._encode_bytes(envelope.endMessageId));
403
377
 
404
378
  // field 50: signatures
405
- for (uint256 _i_signatures = 0; _i_signatures < msg.signatures.length; _i_signatures++) {
379
+ for (uint256 _i_signatures = 0; _i_signatures < envelope.signatures.length; _i_signatures++) {
406
380
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_key(0x192));
407
- bytes memory _elem = ChainSignatureCodec.encode(msg.signatures[_i_signatures]);
381
+ bytes memory _elem = ChainSignatureCodec.encode(envelope.signatures[_i_signatures]);
408
382
  buf = abi.encodePacked(buf, ProtobufRuntime._encode_varint(uint64(_elem.length)));
409
383
  buf = abi.encodePacked(buf, _elem);
410
384
  }
@@ -412,61 +386,61 @@ library EnvelopeCodec {
412
386
  return buf;
413
387
  }
414
388
 
415
- function decode(bytes memory data) internal pure returns (Envelope memory msg) {
389
+ function decode(bytes memory data) internal pure returns (Envelope memory envelope) {
416
390
  uint256 pos = 0;
417
391
  uint256 end = data.length;
418
392
 
393
+ uint256 _count_signatures = 0;
394
+ {
395
+ uint256 _pos = 0;
396
+ while (_pos < end) {
397
+ uint64 _tag;
398
+ (_tag, _pos) = ProtobufRuntime._decode_key(data, _pos);
399
+ if (_tag == 402) { _count_signatures++; }
400
+ _pos = ProtobufRuntime._skip_field(data, _pos, _tag & 0x07);
401
+ }
402
+ }
403
+ envelope.signatures = new ChainSignature[](_count_signatures);
404
+ uint256 _idx_signatures = 0;
405
+
419
406
  while (pos < end) {
420
407
  uint64 tag;
421
408
  (tag, pos) = ProtobufRuntime._decode_key(data, pos);
422
409
 
423
- // solhint-disable-next-line no-empty-blocks
424
- switch (tag) {
425
- case 10:
426
- (msg.envelopeHash, pos) = ProtobufRuntime._decode_bytes(data, pos);
427
- break;
428
- case 18:
429
- {
430
- uint64 _len;
431
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
432
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
433
- msg.endpoints = EndpointsCodec.decode(_sub);
434
- pos += uint256(_len);
435
- }
436
- break;
437
- case 40:
438
- (msg.epochTimestamp, pos) = ProtobufRuntime._decode_varint(data, pos);
439
- break;
440
- case 48:
441
- (msg.epochIndex, pos) = ProtobufRuntime._decode_varint(data, pos);
442
- break;
443
- case 56:
444
- (msg.epochEnvelopeIndex, pos) = ProtobufRuntime._decode_varint(data, pos);
445
- break;
446
- case 122:
447
- (msg.merkle, pos) = ProtobufRuntime._decode_bytes(data, pos);
448
- break;
449
- case 162:
450
- (msg.previousEnvelopeHash, pos) = ProtobufRuntime._decode_bytes(data, pos);
451
- break;
452
- case 242:
453
- (msg.startMessageId, pos) = ProtobufRuntime._decode_bytes(data, pos);
454
- break;
455
- case 250:
456
- (msg.endMessageId, pos) = ProtobufRuntime._decode_bytes(data, pos);
457
- break;
458
- case 402:
459
- {
460
- uint64 _len;
461
- (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
462
- bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
463
- msg.signatures.push(ChainSignatureCodec.decode(_sub));
464
- pos += uint256(_len);
465
- }
466
- break;
467
- default:
468
- pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
469
- break;
410
+ if (tag == 10) {
411
+ (envelope.envelopeHash, pos) = ProtobufRuntime._decode_bytes(data, pos);
412
+ } else if (tag == 18) {
413
+ uint64 _len;
414
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
415
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
416
+ envelope.endpoints = EndpointsCodec.decode(_sub);
417
+ pos += uint256(_len);
418
+ } else if (tag == 40) {
419
+ (envelope.epochTimestamp, pos) = ProtobufRuntime._decode_varint(data, pos);
420
+ } else if (tag == 48) {
421
+ { uint64 _v;
422
+ (_v, pos) = ProtobufRuntime._decode_varint(data, pos);
423
+ envelope.epochIndex = uint32(_v); }
424
+ } else if (tag == 56) {
425
+ { uint64 _v;
426
+ (_v, pos) = ProtobufRuntime._decode_varint(data, pos);
427
+ envelope.epochEnvelopeIndex = uint32(_v); }
428
+ } else if (tag == 122) {
429
+ (envelope.merkle, pos) = ProtobufRuntime._decode_bytes(data, pos);
430
+ } else if (tag == 162) {
431
+ (envelope.previousEnvelopeHash, pos) = ProtobufRuntime._decode_bytes(data, pos);
432
+ } else if (tag == 242) {
433
+ (envelope.startMessageId, pos) = ProtobufRuntime._decode_bytes(data, pos);
434
+ } else if (tag == 250) {
435
+ (envelope.endMessageId, pos) = ProtobufRuntime._decode_bytes(data, pos);
436
+ } else if (tag == 402) {
437
+ uint64 _len;
438
+ (_len, pos) = ProtobufRuntime._decode_varint(data, pos);
439
+ bytes memory _sub = ProtobufRuntime._slice(data, pos, pos + uint256(_len));
440
+ envelope.signatures[_idx_signatures++] = ChainSignatureCodec.decode(_sub);
441
+ pos += uint256(_len);
442
+ } else {
443
+ pos = ProtobufRuntime._skip_field(data, pos, tag & 0x07);
470
444
  }
471
445
  }
472
446
  }