@wireio/opp-solidity-models 1.0.0 → 1.0.7
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 +17 -11
- package/contracts/sysio/opp/Opp.sol +182 -208
- package/contracts/sysio/opp/attestations/Attestations.sol +294 -329
- package/contracts/sysio/opp/types/Types.sol +66 -91
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +4 -0
- package/index.ts +5 -0
- package/package.json +19 -11
- package/sysio/opp/attestations/attestations.d.ts +336 -0
- package/sysio/opp/attestations/attestations.d.ts.map +1 -0
- package/sysio/opp/attestations/attestations.js +670 -0
- package/sysio/opp/attestations/attestations.ts +895 -0
- package/sysio/opp/opp.d.ts +218 -0
- package/sysio/opp/opp.d.ts.map +1 -0
- package/sysio/opp/opp.js +451 -0
- package/sysio/opp/opp.ts +625 -0
- package/sysio/opp/types/types.d.ts +483 -0
- package/sysio/opp/types/types.d.ts.map +1 -0
- package/sysio/opp/types/types.js +666 -0
- package/sysio/opp/types/types.ts +747 -0
- package/index.mjs +0 -2
package/README.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
# @wireio/opp-solidity-models
|
|
2
|
+
|
|
3
|
+
Auto-generated protobuf Solidity contracts and TypeScript types.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Import contracts from `@wireio/opp-solidity-models/contracts/`.
|
|
8
|
+
|
|
9
|
+
Import TypeScript types:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { ... } from "@wireio/opp-solidity-models";
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Generated from
|
|
16
|
+
|
|
17
|
+
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 "
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
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
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
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
|
-
|
|
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
|
-
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
|
|
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(
|
|
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 <
|
|
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(
|
|
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
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
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
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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
|
|
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
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 <
|
|
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(
|
|
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
|
|
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
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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
|
}
|