@ckb-ccc/core 0.0.2-alpha.2 → 0.0.2
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/.prettierignore +12 -0
- package/dist/address/address.advanced.d.ts +29 -3
- package/dist/address/address.advanced.d.ts.map +1 -1
- package/dist/address/address.advanced.js +70 -28
- package/dist/address/advanced.d.ts +1 -28
- package/dist/address/advanced.d.ts.map +1 -1
- package/dist/address/advanced.js +1 -75
- package/dist/address/index.d.ts +10 -13
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +21 -25
- package/dist/advanced.js +2 -31
- package/dist/advancedBarrel.d.ts +1 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/advancedBarrel.js +4 -19
- package/dist/barrel.d.ts +4 -2
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +10 -24
- package/dist/bytes/index.d.ts +7 -0
- package/dist/bytes/index.d.ts.map +1 -0
- package/dist/bytes/index.js +34 -0
- package/dist/ckb/advanced.d.ts +3 -2
- package/dist/ckb/advanced.d.ts.map +1 -1
- package/dist/ckb/advanced.js +3 -18
- package/dist/ckb/index.d.ts +2 -3
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +2 -19
- package/dist/ckb/molecule.advanced/generated.d.ts.map +1 -0
- package/dist/ckb/{types/molecule.advanced → molecule.advanced}/generated.js +444 -231
- package/dist/ckb/molecule.advanced/index.d.ts +6 -0
- package/dist/ckb/molecule.advanced/index.d.ts.map +1 -0
- package/dist/ckb/molecule.advanced/index.js +7 -0
- package/dist/ckb/{types/script.advanced.d.ts → script.advanced.d.ts} +1 -0
- package/dist/ckb/script.advanced.d.ts.map +1 -0
- package/dist/ckb/script.advanced.js +13 -0
- package/dist/ckb/script.d.ts +29 -0
- package/dist/ckb/script.d.ts.map +1 -0
- package/dist/ckb/script.js +61 -0
- package/dist/ckb/{types/transaction.advanced.d.ts → transaction.advanced.d.ts} +1 -0
- package/dist/ckb/transaction.advanced.d.ts.map +1 -0
- package/dist/ckb/transaction.advanced.js +9 -0
- package/dist/ckb/transaction.d.ts +142 -0
- package/dist/ckb/transaction.d.ts.map +1 -0
- package/dist/ckb/transaction.js +227 -0
- package/dist/client/advanced.js +2 -18
- package/dist/client/client.d.ts +5 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +2 -5
- package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +7 -10
- package/dist/client/clientPublicMainnet.d.ts +2 -2
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +4 -8
- package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +7 -10
- package/dist/client/clientPublicTestnet.d.ts +2 -2
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +4 -8
- package/dist/client/clientTypes.js +1 -2
- package/dist/client/index.js +4 -20
- package/dist/client/jsonRpc/advanced.d.ts +36 -36
- package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
- package/dist/client/jsonRpc/advanced.js +13 -17
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +5 -13
- package/dist/fixedPoint/index.d.ts +7 -0
- package/dist/fixedPoint/index.d.ts.map +1 -0
- package/dist/fixedPoint/index.js +22 -0
- package/dist/{ckb/hasher.advanced.d.ts → hasher/advanced.d.ts} +1 -1
- package/dist/hasher/advanced.d.ts.map +1 -0
- package/dist/{ckb/hasher.d.ts → hasher/index.d.ts} +3 -2
- package/dist/hasher/index.d.ts.map +1 -0
- package/dist/hasher/index.js +18 -0
- package/dist/hex/index.d.ts +5 -0
- package/dist/hex/index.d.ts.map +1 -0
- package/dist/hex/index.js +5 -0
- package/dist/index.js +2 -31
- package/dist/num/index.d.ts +13 -0
- package/dist/num/index.d.ts.map +1 -0
- package/dist/num/index.js +36 -0
- package/dist/signer/helpers.d.ts +3 -3
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +9 -10
- package/dist/signer/index.d.ts +2 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +4 -18
- package/dist/signer/signer.d.ts +12 -3
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +13 -6
- package/dist/signer/signerReadonly.d.ts +8 -0
- package/dist/signer/signerReadonly.d.ts.map +1 -0
- package/dist/signer/signerReadonly.js +9 -0
- package/dist/{ckb/viewerCkbScript.d.ts → signer/signerReadonlyCkbScript.d.ts} +6 -5
- package/dist/signer/signerReadonlyCkbScript.d.ts.map +1 -0
- package/dist/signer/signerReadonlyCkbScript.js +17 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/package.json +5 -3
- package/src/address/address.advanced.ts +76 -19
- package/src/address/advanced.ts +1 -59
- package/src/address/index.ts +46 -28
- package/src/advancedBarrel.ts +1 -0
- package/src/barrel.ts +4 -2
- package/src/bytes/index.ts +46 -0
- package/src/ckb/advanced.ts +3 -2
- package/src/ckb/index.ts +2 -3
- package/src/ckb/{types/molecule.advanced → molecule.advanced}/generated.d.ts +18 -7
- package/src/ckb/{types/molecule.advanced → molecule.advanced}/generated.js +551 -123
- package/src/ckb/molecule.advanced/index.ts +11 -0
- package/src/ckb/{types/script.advanced.ts → script.advanced.ts} +1 -0
- package/src/ckb/script.ts +94 -0
- package/src/ckb/{types/transaction.advanced.ts → transaction.advanced.ts} +1 -0
- package/src/ckb/transaction.ts +357 -0
- package/src/client/client.ts +6 -4
- package/src/client/clientPublicMainnet.advanced.ts +2 -2
- package/src/client/clientPublicMainnet.ts +2 -2
- package/src/client/clientPublicTestnet.advanced.ts +2 -2
- package/src/client/clientPublicTestnet.ts +2 -2
- package/src/client/clientTypes.ts +1 -1
- package/src/client/jsonRpc/advanced.ts +25 -25
- package/src/client/jsonRpc/index.ts +1 -3
- package/src/fixedPoint/index.ts +30 -0
- package/src/hasher/advanced.ts +1 -0
- package/src/{ckb/hasher.ts → hasher/index.ts} +5 -5
- package/src/hex/index.ts +9 -0
- package/src/index.ts +1 -1
- package/src/num/index.ts +53 -0
- package/src/signer/helpers.ts +9 -6
- package/src/signer/index.ts +3 -1
- package/src/signer/signer.ts +23 -3
- package/src/signer/signerReadonly.ts +13 -0
- package/src/{ckb/viewerCkbScript.ts → signer/signerReadonlyCkbScript.ts} +8 -4
- package/src/utils/index.ts +28 -0
- package/dist/bytes.d.ts +0 -15
- package/dist/bytes.d.ts.map +0 -1
- package/dist/bytes.js +0 -114
- package/dist/ckb/hasher.advanced.d.ts.map +0 -1
- package/dist/ckb/hasher.advanced.js +0 -4
- package/dist/ckb/hasher.d.ts.map +0 -1
- package/dist/ckb/hasher.js +0 -26
- package/dist/ckb/types/advanced.d.ts +0 -4
- package/dist/ckb/types/advanced.d.ts.map +0 -1
- package/dist/ckb/types/advanced.js +0 -32
- package/dist/ckb/types/index.d.ts +0 -3
- package/dist/ckb/types/index.d.ts.map +0 -1
- package/dist/ckb/types/index.js +0 -18
- package/dist/ckb/types/molecule.advanced/generated.d.ts.map +0 -1
- package/dist/ckb/types/molecule.advanced/index.d.ts +0 -2
- package/dist/ckb/types/molecule.advanced/index.d.ts.map +0 -1
- package/dist/ckb/types/molecule.advanced/index.js +0 -17
- package/dist/ckb/types/script.advanced.d.ts.map +0 -1
- package/dist/ckb/types/script.advanced.js +0 -15
- package/dist/ckb/types/script.d.ts +0 -26
- package/dist/ckb/types/script.d.ts.map +0 -1
- package/dist/ckb/types/script.js +0 -75
- package/dist/ckb/types/transaction.advanced.d.ts.map +0 -1
- package/dist/ckb/types/transaction.advanced.js +0 -11
- package/dist/ckb/types/transaction.d.ts +0 -127
- package/dist/ckb/types/transaction.d.ts.map +0 -1
- package/dist/ckb/types/transaction.js +0 -266
- package/dist/ckb/viewerCkbScript.d.ts.map +0 -1
- package/dist/ckb/viewerCkbScript.js +0 -18
- package/dist/fixedPoint.d.ts +0 -9
- package/dist/fixedPoint.d.ts.map +0 -1
- package/dist/fixedPoint.js +0 -30
- package/dist/primitive.d.ts +0 -5
- package/dist/primitive.d.ts.map +0 -1
- package/dist/primitive.js +0 -2
- package/dist/viewer.d.ts +0 -12
- package/dist/viewer.d.ts.map +0 -1
- package/dist/viewer.js +0 -19
- package/src/bytes.ts +0 -127
- package/src/ckb/types/advanced.ts +0 -3
- package/src/ckb/types/index.ts +0 -2
- package/src/ckb/types/molecule.advanced/index.ts +0 -1
- package/src/ckb/types/script.ts +0 -70
- package/src/ckb/types/transaction.ts +0 -366
- package/src/fixedPoint.ts +0 -53
- package/src/primitive.ts +0 -8
- package/src/viewer.ts +0 -22
- /package/dist/ckb/{types/molecule.advanced → molecule.advanced}/generated.d.ts +0 -0
- /package/{src/ckb/hasher.advanced.ts → dist/hasher/advanced.js} +0 -0
- /package/src/ckb/{types/molecule.advanced → molecule.advanced}/blockchain.mol +0 -0
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SerializeTransaction = exports.Transaction = exports.SerializeRawTransaction = exports.RawTransaction = exports.SerializeCellDep = exports.CellDep = exports.SerializeCellOutput = exports.CellOutput = exports.SerializeCellInput = exports.CellInput = exports.SerializeOutPoint = exports.OutPoint = exports.SerializeScript = exports.Script = exports.SerializeCellOutputVec = exports.CellOutputVec = exports.SerializeCellInputVec = exports.CellInputVec = exports.SerializeCellDepVec = exports.CellDepVec = exports.SerializeProposalShortIdVec = exports.ProposalShortIdVec = exports.SerializeTransactionVec = exports.TransactionVec = exports.SerializeUncleBlockVec = exports.UncleBlockVec = exports.SerializeProposalShortId = exports.ProposalShortId = exports.SerializeScriptOpt = exports.ScriptOpt = exports.SerializeByte32Vec = exports.Byte32Vec = exports.SerializeBytesVec = exports.BytesVec = exports.SerializeBytesOptVec = exports.BytesOptVec = exports.SerializeBytesOpt = exports.BytesOpt = exports.SerializeBytes = exports.Bytes = exports.SerializeUint256 = exports.Uint256 = exports.SerializeByte32 = exports.Byte32 = exports.SerializeUint128 = exports.Uint128 = exports.SerializeUint64 = exports.Uint64 = exports.SerializeUint32 = exports.Uint32 = void 0;
|
|
4
|
-
exports.SerializeWitnessArgs = exports.WitnessArgs = exports.SerializeCellbaseWitness = exports.CellbaseWitness = exports.SerializeBlockV1 = exports.BlockV1 = exports.SerializeBlock = exports.Block = exports.SerializeUncleBlock = exports.UncleBlock = exports.SerializeHeader = exports.Header = exports.SerializeRawHeader = exports.RawHeader = void 0;
|
|
5
1
|
function dataLengthError(actual, required) {
|
|
6
2
|
throw new Error(`Invalid data length! Required: ${required}, actual: ${actual}`);
|
|
7
3
|
}
|
|
@@ -42,7 +38,7 @@ function verifyAndExtractOffsets(view, expectedFieldCount, compatible) {
|
|
|
42
38
|
if (itemCount < expectedFieldCount) {
|
|
43
39
|
throw new Error(`Item count not enough! Required: ${expectedFieldCount}, actual: ${itemCount}`);
|
|
44
40
|
}
|
|
45
|
-
else if (
|
|
41
|
+
else if (!compatible && itemCount > expectedFieldCount) {
|
|
46
42
|
throw new Error(`Item count is more than required! Required: ${expectedFieldCount}, actual: ${itemCount}`);
|
|
47
43
|
}
|
|
48
44
|
if (requiredByteLength < firstOffset) {
|
|
@@ -79,7 +75,7 @@ function serializeTable(buffers) {
|
|
|
79
75
|
}
|
|
80
76
|
return buffer;
|
|
81
77
|
}
|
|
82
|
-
class Uint32 {
|
|
78
|
+
export class Uint32 {
|
|
83
79
|
constructor(reader, { validate = true } = {}) {
|
|
84
80
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
85
81
|
if (validate) {
|
|
@@ -105,14 +101,12 @@ class Uint32 {
|
|
|
105
101
|
return 4;
|
|
106
102
|
}
|
|
107
103
|
}
|
|
108
|
-
|
|
109
|
-
function SerializeUint32(value) {
|
|
104
|
+
export function SerializeUint32(value) {
|
|
110
105
|
const buffer = assertArrayBuffer(value);
|
|
111
106
|
assertDataLength(buffer.byteLength, 4);
|
|
112
107
|
return buffer;
|
|
113
108
|
}
|
|
114
|
-
|
|
115
|
-
class Uint64 {
|
|
109
|
+
export class Uint64 {
|
|
116
110
|
constructor(reader, { validate = true } = {}) {
|
|
117
111
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
118
112
|
if (validate) {
|
|
@@ -132,14 +126,12 @@ class Uint64 {
|
|
|
132
126
|
return 8;
|
|
133
127
|
}
|
|
134
128
|
}
|
|
135
|
-
|
|
136
|
-
function SerializeUint64(value) {
|
|
129
|
+
export function SerializeUint64(value) {
|
|
137
130
|
const buffer = assertArrayBuffer(value);
|
|
138
131
|
assertDataLength(buffer.byteLength, 8);
|
|
139
132
|
return buffer;
|
|
140
133
|
}
|
|
141
|
-
|
|
142
|
-
class Uint128 {
|
|
134
|
+
export class Uint128 {
|
|
143
135
|
constructor(reader, { validate = true } = {}) {
|
|
144
136
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
145
137
|
if (validate) {
|
|
@@ -159,14 +151,12 @@ class Uint128 {
|
|
|
159
151
|
return 16;
|
|
160
152
|
}
|
|
161
153
|
}
|
|
162
|
-
|
|
163
|
-
function SerializeUint128(value) {
|
|
154
|
+
export function SerializeUint128(value) {
|
|
164
155
|
const buffer = assertArrayBuffer(value);
|
|
165
156
|
assertDataLength(buffer.byteLength, 16);
|
|
166
157
|
return buffer;
|
|
167
158
|
}
|
|
168
|
-
|
|
169
|
-
class Byte32 {
|
|
159
|
+
export class Byte32 {
|
|
170
160
|
constructor(reader, { validate = true } = {}) {
|
|
171
161
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
172
162
|
if (validate) {
|
|
@@ -186,14 +176,12 @@ class Byte32 {
|
|
|
186
176
|
return 32;
|
|
187
177
|
}
|
|
188
178
|
}
|
|
189
|
-
|
|
190
|
-
function SerializeByte32(value) {
|
|
179
|
+
export function SerializeByte32(value) {
|
|
191
180
|
const buffer = assertArrayBuffer(value);
|
|
192
181
|
assertDataLength(buffer.byteLength, 32);
|
|
193
182
|
return buffer;
|
|
194
183
|
}
|
|
195
|
-
|
|
196
|
-
class Uint256 {
|
|
184
|
+
export class Uint256 {
|
|
197
185
|
constructor(reader, { validate = true } = {}) {
|
|
198
186
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
199
187
|
if (validate) {
|
|
@@ -213,14 +201,12 @@ class Uint256 {
|
|
|
213
201
|
return 32;
|
|
214
202
|
}
|
|
215
203
|
}
|
|
216
|
-
|
|
217
|
-
function SerializeUint256(value) {
|
|
204
|
+
export function SerializeUint256(value) {
|
|
218
205
|
const buffer = assertArrayBuffer(value);
|
|
219
206
|
assertDataLength(buffer.byteLength, 32);
|
|
220
207
|
return buffer;
|
|
221
208
|
}
|
|
222
|
-
|
|
223
|
-
class Bytes {
|
|
209
|
+
export class Bytes {
|
|
224
210
|
constructor(reader, { validate = true } = {}) {
|
|
225
211
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
226
212
|
if (validate) {
|
|
@@ -244,16 +230,14 @@ class Bytes {
|
|
|
244
230
|
return this.view.getUint32(0, true);
|
|
245
231
|
}
|
|
246
232
|
}
|
|
247
|
-
|
|
248
|
-
function SerializeBytes(value) {
|
|
233
|
+
export function SerializeBytes(value) {
|
|
249
234
|
const item = assertArrayBuffer(value);
|
|
250
235
|
const array = new Uint8Array(4 + item.byteLength);
|
|
251
|
-
|
|
236
|
+
new DataView(array.buffer).setUint32(0, item.byteLength, true);
|
|
252
237
|
array.set(new Uint8Array(item), 4);
|
|
253
238
|
return array.buffer;
|
|
254
239
|
}
|
|
255
|
-
|
|
256
|
-
class BytesOpt {
|
|
240
|
+
export class BytesOpt {
|
|
257
241
|
constructor(reader, { validate = true } = {}) {
|
|
258
242
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
259
243
|
if (validate) {
|
|
@@ -272,8 +256,7 @@ class BytesOpt {
|
|
|
272
256
|
return this.view.byteLength > 0;
|
|
273
257
|
}
|
|
274
258
|
}
|
|
275
|
-
|
|
276
|
-
function SerializeBytesOpt(value) {
|
|
259
|
+
export function SerializeBytesOpt(value) {
|
|
277
260
|
if (value) {
|
|
278
261
|
return SerializeBytes(value);
|
|
279
262
|
}
|
|
@@ -281,8 +264,7 @@ function SerializeBytesOpt(value) {
|
|
|
281
264
|
return new ArrayBuffer(0);
|
|
282
265
|
}
|
|
283
266
|
}
|
|
284
|
-
|
|
285
|
-
class BytesOptVec {
|
|
267
|
+
export class BytesOptVec {
|
|
286
268
|
constructor(reader, { validate = true } = {}) {
|
|
287
269
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
288
270
|
if (validate) {
|
|
@@ -292,7 +274,9 @@ class BytesOptVec {
|
|
|
292
274
|
validate(compatible = false) {
|
|
293
275
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
294
276
|
for (let i = 0; i < offsets.length - 1; i++) {
|
|
295
|
-
new BytesOpt(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
277
|
+
new BytesOpt(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
278
|
+
validate: false,
|
|
279
|
+
}).validate();
|
|
296
280
|
}
|
|
297
281
|
}
|
|
298
282
|
length() {
|
|
@@ -310,15 +294,15 @@ class BytesOptVec {
|
|
|
310
294
|
if (i + 1 < this.length()) {
|
|
311
295
|
offset_end = this.view.getUint32(start + 4, true);
|
|
312
296
|
}
|
|
313
|
-
return new BytesOpt(this.view.buffer.slice(offset, offset_end), {
|
|
297
|
+
return new BytesOpt(this.view.buffer.slice(offset, offset_end), {
|
|
298
|
+
validate: false,
|
|
299
|
+
});
|
|
314
300
|
}
|
|
315
301
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
return serializeTable(value.map(item => SerializeBytesOpt(item)));
|
|
302
|
+
export function SerializeBytesOptVec(value) {
|
|
303
|
+
return serializeTable(value.map((item) => SerializeBytesOpt(item)));
|
|
319
304
|
}
|
|
320
|
-
|
|
321
|
-
class BytesVec {
|
|
305
|
+
export class BytesVec {
|
|
322
306
|
constructor(reader, { validate = true } = {}) {
|
|
323
307
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
324
308
|
if (validate) {
|
|
@@ -328,7 +312,9 @@ class BytesVec {
|
|
|
328
312
|
validate(compatible = false) {
|
|
329
313
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
330
314
|
for (let i = 0; i < offsets.length - 1; i++) {
|
|
331
|
-
new Bytes(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
315
|
+
new Bytes(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
316
|
+
validate: false,
|
|
317
|
+
}).validate();
|
|
332
318
|
}
|
|
333
319
|
}
|
|
334
320
|
length() {
|
|
@@ -346,15 +332,15 @@ class BytesVec {
|
|
|
346
332
|
if (i + 1 < this.length()) {
|
|
347
333
|
offset_end = this.view.getUint32(start + 4, true);
|
|
348
334
|
}
|
|
349
|
-
return new Bytes(this.view.buffer.slice(offset, offset_end), {
|
|
335
|
+
return new Bytes(this.view.buffer.slice(offset, offset_end), {
|
|
336
|
+
validate: false,
|
|
337
|
+
});
|
|
350
338
|
}
|
|
351
339
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return serializeTable(value.map(item => SerializeBytes(item)));
|
|
340
|
+
export function SerializeBytesVec(value) {
|
|
341
|
+
return serializeTable(value.map((item) => SerializeBytes(item)));
|
|
355
342
|
}
|
|
356
|
-
|
|
357
|
-
class Byte32Vec {
|
|
343
|
+
export class Byte32Vec {
|
|
358
344
|
constructor(reader, { validate = true } = {}) {
|
|
359
345
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
360
346
|
if (validate) {
|
|
@@ -379,18 +365,16 @@ class Byte32Vec {
|
|
|
379
365
|
return this.view.getUint32(0, true);
|
|
380
366
|
}
|
|
381
367
|
}
|
|
382
|
-
|
|
383
|
-
function SerializeByte32Vec(value) {
|
|
368
|
+
export function SerializeByte32Vec(value) {
|
|
384
369
|
const array = new Uint8Array(4 + Byte32.size() * value.length);
|
|
385
|
-
|
|
370
|
+
new DataView(array.buffer).setUint32(0, value.length, true);
|
|
386
371
|
for (let i = 0; i < value.length; i++) {
|
|
387
372
|
const itemBuffer = SerializeByte32(value[i]);
|
|
388
373
|
array.set(new Uint8Array(itemBuffer), 4 + i * Byte32.size());
|
|
389
374
|
}
|
|
390
375
|
return array.buffer;
|
|
391
376
|
}
|
|
392
|
-
|
|
393
|
-
class ScriptOpt {
|
|
377
|
+
export class ScriptOpt {
|
|
394
378
|
constructor(reader, { validate = true } = {}) {
|
|
395
379
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
396
380
|
if (validate) {
|
|
@@ -409,8 +393,7 @@ class ScriptOpt {
|
|
|
409
393
|
return this.view.byteLength > 0;
|
|
410
394
|
}
|
|
411
395
|
}
|
|
412
|
-
|
|
413
|
-
function SerializeScriptOpt(value) {
|
|
396
|
+
export function SerializeScriptOpt(value) {
|
|
414
397
|
if (value) {
|
|
415
398
|
return SerializeScript(value);
|
|
416
399
|
}
|
|
@@ -418,8 +401,7 @@ function SerializeScriptOpt(value) {
|
|
|
418
401
|
return new ArrayBuffer(0);
|
|
419
402
|
}
|
|
420
403
|
}
|
|
421
|
-
|
|
422
|
-
class ProposalShortId {
|
|
404
|
+
export class ProposalShortId {
|
|
423
405
|
constructor(reader, { validate = true } = {}) {
|
|
424
406
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
425
407
|
if (validate) {
|
|
@@ -439,14 +421,12 @@ class ProposalShortId {
|
|
|
439
421
|
return 10;
|
|
440
422
|
}
|
|
441
423
|
}
|
|
442
|
-
|
|
443
|
-
function SerializeProposalShortId(value) {
|
|
424
|
+
export function SerializeProposalShortId(value) {
|
|
444
425
|
const buffer = assertArrayBuffer(value);
|
|
445
426
|
assertDataLength(buffer.byteLength, 10);
|
|
446
427
|
return buffer;
|
|
447
428
|
}
|
|
448
|
-
|
|
449
|
-
class UncleBlockVec {
|
|
429
|
+
export class UncleBlockVec {
|
|
450
430
|
constructor(reader, { validate = true } = {}) {
|
|
451
431
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
452
432
|
if (validate) {
|
|
@@ -456,7 +436,9 @@ class UncleBlockVec {
|
|
|
456
436
|
validate(compatible = false) {
|
|
457
437
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
458
438
|
for (let i = 0; i < offsets.length - 1; i++) {
|
|
459
|
-
new UncleBlock(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
439
|
+
new UncleBlock(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
440
|
+
validate: false,
|
|
441
|
+
}).validate();
|
|
460
442
|
}
|
|
461
443
|
}
|
|
462
444
|
length() {
|
|
@@ -474,15 +456,15 @@ class UncleBlockVec {
|
|
|
474
456
|
if (i + 1 < this.length()) {
|
|
475
457
|
offset_end = this.view.getUint32(start + 4, true);
|
|
476
458
|
}
|
|
477
|
-
return new UncleBlock(this.view.buffer.slice(offset, offset_end), {
|
|
459
|
+
return new UncleBlock(this.view.buffer.slice(offset, offset_end), {
|
|
460
|
+
validate: false,
|
|
461
|
+
});
|
|
478
462
|
}
|
|
479
463
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
return serializeTable(value.map(item => SerializeUncleBlock(item)));
|
|
464
|
+
export function SerializeUncleBlockVec(value) {
|
|
465
|
+
return serializeTable(value.map((item) => SerializeUncleBlock(item)));
|
|
483
466
|
}
|
|
484
|
-
|
|
485
|
-
class TransactionVec {
|
|
467
|
+
export class TransactionVec {
|
|
486
468
|
constructor(reader, { validate = true } = {}) {
|
|
487
469
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
488
470
|
if (validate) {
|
|
@@ -492,7 +474,9 @@ class TransactionVec {
|
|
|
492
474
|
validate(compatible = false) {
|
|
493
475
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
494
476
|
for (let i = 0; i < offsets.length - 1; i++) {
|
|
495
|
-
new Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
477
|
+
new Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
478
|
+
validate: false,
|
|
479
|
+
}).validate();
|
|
496
480
|
}
|
|
497
481
|
}
|
|
498
482
|
length() {
|
|
@@ -510,15 +494,15 @@ class TransactionVec {
|
|
|
510
494
|
if (i + 1 < this.length()) {
|
|
511
495
|
offset_end = this.view.getUint32(start + 4, true);
|
|
512
496
|
}
|
|
513
|
-
return new Transaction(this.view.buffer.slice(offset, offset_end), {
|
|
497
|
+
return new Transaction(this.view.buffer.slice(offset, offset_end), {
|
|
498
|
+
validate: false,
|
|
499
|
+
});
|
|
514
500
|
}
|
|
515
501
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
return serializeTable(value.map(item => SerializeTransaction(item)));
|
|
502
|
+
export function SerializeTransactionVec(value) {
|
|
503
|
+
return serializeTable(value.map((item) => SerializeTransaction(item)));
|
|
519
504
|
}
|
|
520
|
-
|
|
521
|
-
class ProposalShortIdVec {
|
|
505
|
+
export class ProposalShortIdVec {
|
|
522
506
|
constructor(reader, { validate = true } = {}) {
|
|
523
507
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
524
508
|
if (validate) {
|
|
@@ -543,18 +527,16 @@ class ProposalShortIdVec {
|
|
|
543
527
|
return this.view.getUint32(0, true);
|
|
544
528
|
}
|
|
545
529
|
}
|
|
546
|
-
|
|
547
|
-
function SerializeProposalShortIdVec(value) {
|
|
530
|
+
export function SerializeProposalShortIdVec(value) {
|
|
548
531
|
const array = new Uint8Array(4 + ProposalShortId.size() * value.length);
|
|
549
|
-
|
|
532
|
+
new DataView(array.buffer).setUint32(0, value.length, true);
|
|
550
533
|
for (let i = 0; i < value.length; i++) {
|
|
551
534
|
const itemBuffer = SerializeProposalShortId(value[i]);
|
|
552
535
|
array.set(new Uint8Array(itemBuffer), 4 + i * ProposalShortId.size());
|
|
553
536
|
}
|
|
554
537
|
return array.buffer;
|
|
555
538
|
}
|
|
556
|
-
|
|
557
|
-
class CellDepVec {
|
|
539
|
+
export class CellDepVec {
|
|
558
540
|
constructor(reader, { validate = true } = {}) {
|
|
559
541
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
560
542
|
if (validate) {
|
|
@@ -579,18 +561,16 @@ class CellDepVec {
|
|
|
579
561
|
return this.view.getUint32(0, true);
|
|
580
562
|
}
|
|
581
563
|
}
|
|
582
|
-
|
|
583
|
-
function SerializeCellDepVec(value) {
|
|
564
|
+
export function SerializeCellDepVec(value) {
|
|
584
565
|
const array = new Uint8Array(4 + CellDep.size() * value.length);
|
|
585
|
-
|
|
566
|
+
new DataView(array.buffer).setUint32(0, value.length, true);
|
|
586
567
|
for (let i = 0; i < value.length; i++) {
|
|
587
568
|
const itemBuffer = SerializeCellDep(value[i]);
|
|
588
569
|
array.set(new Uint8Array(itemBuffer), 4 + i * CellDep.size());
|
|
589
570
|
}
|
|
590
571
|
return array.buffer;
|
|
591
572
|
}
|
|
592
|
-
|
|
593
|
-
class CellInputVec {
|
|
573
|
+
export class CellInputVec {
|
|
594
574
|
constructor(reader, { validate = true } = {}) {
|
|
595
575
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
596
576
|
if (validate) {
|
|
@@ -615,18 +595,16 @@ class CellInputVec {
|
|
|
615
595
|
return this.view.getUint32(0, true);
|
|
616
596
|
}
|
|
617
597
|
}
|
|
618
|
-
|
|
619
|
-
function SerializeCellInputVec(value) {
|
|
598
|
+
export function SerializeCellInputVec(value) {
|
|
620
599
|
const array = new Uint8Array(4 + CellInput.size() * value.length);
|
|
621
|
-
|
|
600
|
+
new DataView(array.buffer).setUint32(0, value.length, true);
|
|
622
601
|
for (let i = 0; i < value.length; i++) {
|
|
623
602
|
const itemBuffer = SerializeCellInput(value[i]);
|
|
624
603
|
array.set(new Uint8Array(itemBuffer), 4 + i * CellInput.size());
|
|
625
604
|
}
|
|
626
605
|
return array.buffer;
|
|
627
606
|
}
|
|
628
|
-
|
|
629
|
-
class CellOutputVec {
|
|
607
|
+
export class CellOutputVec {
|
|
630
608
|
constructor(reader, { validate = true } = {}) {
|
|
631
609
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
632
610
|
if (validate) {
|
|
@@ -636,7 +614,9 @@ class CellOutputVec {
|
|
|
636
614
|
validate(compatible = false) {
|
|
637
615
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
638
616
|
for (let i = 0; i < offsets.length - 1; i++) {
|
|
639
|
-
new CellOutput(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
617
|
+
new CellOutput(this.view.buffer.slice(offsets[i], offsets[i + 1]), {
|
|
618
|
+
validate: false,
|
|
619
|
+
}).validate();
|
|
640
620
|
}
|
|
641
621
|
}
|
|
642
622
|
length() {
|
|
@@ -654,15 +634,15 @@ class CellOutputVec {
|
|
|
654
634
|
if (i + 1 < this.length()) {
|
|
655
635
|
offset_end = this.view.getUint32(start + 4, true);
|
|
656
636
|
}
|
|
657
|
-
return new CellOutput(this.view.buffer.slice(offset, offset_end), {
|
|
637
|
+
return new CellOutput(this.view.buffer.slice(offset, offset_end), {
|
|
638
|
+
validate: false,
|
|
639
|
+
});
|
|
658
640
|
}
|
|
659
641
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
return serializeTable(value.map(item => SerializeCellOutput(item)));
|
|
642
|
+
export function SerializeCellOutputVec(value) {
|
|
643
|
+
return serializeTable(value.map((item) => SerializeCellOutput(item)));
|
|
663
644
|
}
|
|
664
|
-
|
|
665
|
-
class Script {
|
|
645
|
+
export class Script {
|
|
666
646
|
constructor(reader, { validate = true } = {}) {
|
|
667
647
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
668
648
|
if (validate) {
|
|
@@ -671,17 +651,23 @@ class Script {
|
|
|
671
651
|
}
|
|
672
652
|
validate(compatible = false) {
|
|
673
653
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
674
|
-
new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
654
|
+
new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
655
|
+
validate: false,
|
|
656
|
+
}).validate();
|
|
675
657
|
if (offsets[2] - offsets[1] !== 1) {
|
|
676
658
|
throw new Error(`Invalid offset for hashType: ${offsets[1]} - ${offsets[2]}`);
|
|
677
659
|
}
|
|
678
|
-
new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), {
|
|
660
|
+
new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), {
|
|
661
|
+
validate: false,
|
|
662
|
+
}).validate();
|
|
679
663
|
}
|
|
680
664
|
getCodeHash() {
|
|
681
665
|
const start = 4;
|
|
682
666
|
const offset = this.view.getUint32(start, true);
|
|
683
667
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
684
|
-
return new Byte32(this.view.buffer.slice(offset, offset_end), {
|
|
668
|
+
return new Byte32(this.view.buffer.slice(offset, offset_end), {
|
|
669
|
+
validate: false,
|
|
670
|
+
});
|
|
685
671
|
}
|
|
686
672
|
getHashType() {
|
|
687
673
|
const start = 8;
|
|
@@ -693,11 +679,12 @@ class Script {
|
|
|
693
679
|
const start = 12;
|
|
694
680
|
const offset = this.view.getUint32(start, true);
|
|
695
681
|
const offset_end = this.view.byteLength;
|
|
696
|
-
return new Bytes(this.view.buffer.slice(offset, offset_end), {
|
|
682
|
+
return new Bytes(this.view.buffer.slice(offset, offset_end), {
|
|
683
|
+
validate: false,
|
|
684
|
+
});
|
|
697
685
|
}
|
|
698
686
|
}
|
|
699
|
-
|
|
700
|
-
function SerializeScript(value) {
|
|
687
|
+
export function SerializeScript(value) {
|
|
701
688
|
const buffers = [];
|
|
702
689
|
buffers.push(SerializeByte32(value.codeHash));
|
|
703
690
|
const hashTypeView = new DataView(new ArrayBuffer(1));
|
|
@@ -706,8 +693,7 @@ function SerializeScript(value) {
|
|
|
706
693
|
buffers.push(SerializeBytes(value.args));
|
|
707
694
|
return serializeTable(buffers);
|
|
708
695
|
}
|
|
709
|
-
|
|
710
|
-
class OutPoint {
|
|
696
|
+
export class OutPoint {
|
|
711
697
|
constructor(reader, { validate = true } = {}) {
|
|
712
698
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
713
699
|
if (validate) {
|
|
@@ -715,7 +701,9 @@ class OutPoint {
|
|
|
715
701
|
}
|
|
716
702
|
}
|
|
717
703
|
getTxHash() {
|
|
718
|
-
return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), {
|
|
704
|
+
return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), {
|
|
705
|
+
validate: false,
|
|
706
|
+
});
|
|
719
707
|
}
|
|
720
708
|
getIndex() {
|
|
721
709
|
return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false });
|
|
@@ -729,16 +717,14 @@ class OutPoint {
|
|
|
729
717
|
return 0 + Byte32.size() + Uint32.size();
|
|
730
718
|
}
|
|
731
719
|
}
|
|
732
|
-
|
|
733
|
-
function SerializeOutPoint(value) {
|
|
720
|
+
export function SerializeOutPoint(value) {
|
|
734
721
|
const array = new Uint8Array(0 + Byte32.size() + Uint32.size());
|
|
735
722
|
const view = new DataView(array.buffer);
|
|
736
723
|
array.set(new Uint8Array(SerializeByte32(value.txHash)), 0);
|
|
737
724
|
array.set(new Uint8Array(SerializeUint32(value.index)), 0 + Byte32.size());
|
|
738
725
|
return array.buffer;
|
|
739
726
|
}
|
|
740
|
-
|
|
741
|
-
class CellInput {
|
|
727
|
+
export class CellInput {
|
|
742
728
|
constructor(reader, { validate = true } = {}) {
|
|
743
729
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
744
730
|
if (validate) {
|
|
@@ -746,7 +732,9 @@ class CellInput {
|
|
|
746
732
|
}
|
|
747
733
|
}
|
|
748
734
|
getSince() {
|
|
749
|
-
return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), {
|
|
735
|
+
return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), {
|
|
736
|
+
validate: false,
|
|
737
|
+
});
|
|
750
738
|
}
|
|
751
739
|
getPreviousOutput() {
|
|
752
740
|
return new OutPoint(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + OutPoint.size()), { validate: false });
|
|
@@ -760,16 +748,14 @@ class CellInput {
|
|
|
760
748
|
return 0 + Uint64.size() + OutPoint.size();
|
|
761
749
|
}
|
|
762
750
|
}
|
|
763
|
-
|
|
764
|
-
function SerializeCellInput(value) {
|
|
751
|
+
export function SerializeCellInput(value) {
|
|
765
752
|
const array = new Uint8Array(0 + Uint64.size() + OutPoint.size());
|
|
766
753
|
const view = new DataView(array.buffer);
|
|
767
754
|
array.set(new Uint8Array(SerializeUint64(value.since)), 0);
|
|
768
755
|
array.set(new Uint8Array(SerializeOutPoint(value.previousOutput)), 0 + Uint64.size());
|
|
769
756
|
return array.buffer;
|
|
770
757
|
}
|
|
771
|
-
|
|
772
|
-
class CellOutput {
|
|
758
|
+
export class CellOutput {
|
|
773
759
|
constructor(reader, { validate = true } = {}) {
|
|
774
760
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
775
761
|
if (validate) {
|
|
@@ -778,39 +764,49 @@ class CellOutput {
|
|
|
778
764
|
}
|
|
779
765
|
validate(compatible = false) {
|
|
780
766
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
781
|
-
new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
782
|
-
|
|
783
|
-
|
|
767
|
+
new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
768
|
+
validate: false,
|
|
769
|
+
}).validate();
|
|
770
|
+
new Script(this.view.buffer.slice(offsets[1], offsets[2]), {
|
|
771
|
+
validate: false,
|
|
772
|
+
}).validate();
|
|
773
|
+
new ScriptOpt(this.view.buffer.slice(offsets[2], offsets[3]), {
|
|
774
|
+
validate: false,
|
|
775
|
+
}).validate();
|
|
784
776
|
}
|
|
785
777
|
getCapacity() {
|
|
786
778
|
const start = 4;
|
|
787
779
|
const offset = this.view.getUint32(start, true);
|
|
788
780
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
789
|
-
return new Uint64(this.view.buffer.slice(offset, offset_end), {
|
|
781
|
+
return new Uint64(this.view.buffer.slice(offset, offset_end), {
|
|
782
|
+
validate: false,
|
|
783
|
+
});
|
|
790
784
|
}
|
|
791
785
|
getLock() {
|
|
792
786
|
const start = 8;
|
|
793
787
|
const offset = this.view.getUint32(start, true);
|
|
794
788
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
795
|
-
return new Script(this.view.buffer.slice(offset, offset_end), {
|
|
789
|
+
return new Script(this.view.buffer.slice(offset, offset_end), {
|
|
790
|
+
validate: false,
|
|
791
|
+
});
|
|
796
792
|
}
|
|
797
793
|
getType() {
|
|
798
794
|
const start = 12;
|
|
799
795
|
const offset = this.view.getUint32(start, true);
|
|
800
796
|
const offset_end = this.view.byteLength;
|
|
801
|
-
return new ScriptOpt(this.view.buffer.slice(offset, offset_end), {
|
|
797
|
+
return new ScriptOpt(this.view.buffer.slice(offset, offset_end), {
|
|
798
|
+
validate: false,
|
|
799
|
+
});
|
|
802
800
|
}
|
|
803
801
|
}
|
|
804
|
-
|
|
805
|
-
function SerializeCellOutput(value) {
|
|
802
|
+
export function SerializeCellOutput(value) {
|
|
806
803
|
const buffers = [];
|
|
807
804
|
buffers.push(SerializeUint64(value.capacity));
|
|
808
805
|
buffers.push(SerializeScript(value.lock));
|
|
809
806
|
buffers.push(SerializeScriptOpt(value.type));
|
|
810
807
|
return serializeTable(buffers);
|
|
811
808
|
}
|
|
812
|
-
|
|
813
|
-
class CellDep {
|
|
809
|
+
export class CellDep {
|
|
814
810
|
constructor(reader, { validate = true } = {}) {
|
|
815
811
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
816
812
|
if (validate) {
|
|
@@ -818,7 +814,9 @@ class CellDep {
|
|
|
818
814
|
}
|
|
819
815
|
}
|
|
820
816
|
getOutPoint() {
|
|
821
|
-
return new OutPoint(this.view.buffer.slice(0, 0 + OutPoint.size()), {
|
|
817
|
+
return new OutPoint(this.view.buffer.slice(0, 0 + OutPoint.size()), {
|
|
818
|
+
validate: false,
|
|
819
|
+
});
|
|
822
820
|
}
|
|
823
821
|
getDepType() {
|
|
824
822
|
return this.view.getUint8(0 + OutPoint.size());
|
|
@@ -831,16 +829,14 @@ class CellDep {
|
|
|
831
829
|
return 0 + OutPoint.size() + 1;
|
|
832
830
|
}
|
|
833
831
|
}
|
|
834
|
-
|
|
835
|
-
function SerializeCellDep(value) {
|
|
832
|
+
export function SerializeCellDep(value) {
|
|
836
833
|
const array = new Uint8Array(0 + OutPoint.size() + 1);
|
|
837
834
|
const view = new DataView(array.buffer);
|
|
838
835
|
array.set(new Uint8Array(SerializeOutPoint(value.outPoint)), 0);
|
|
839
836
|
view.setUint8(0 + OutPoint.size(), value.depType);
|
|
840
837
|
return array.buffer;
|
|
841
838
|
}
|
|
842
|
-
|
|
843
|
-
class RawTransaction {
|
|
839
|
+
export class RawTransaction {
|
|
844
840
|
constructor(reader, { validate = true } = {}) {
|
|
845
841
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
846
842
|
if (validate) {
|
|
@@ -849,52 +845,75 @@ class RawTransaction {
|
|
|
849
845
|
}
|
|
850
846
|
validate(compatible = false) {
|
|
851
847
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
852
|
-
new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
new
|
|
856
|
-
|
|
857
|
-
|
|
848
|
+
new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
849
|
+
validate: false,
|
|
850
|
+
}).validate();
|
|
851
|
+
new CellDepVec(this.view.buffer.slice(offsets[1], offsets[2]), {
|
|
852
|
+
validate: false,
|
|
853
|
+
}).validate();
|
|
854
|
+
new Byte32Vec(this.view.buffer.slice(offsets[2], offsets[3]), {
|
|
855
|
+
validate: false,
|
|
856
|
+
}).validate();
|
|
857
|
+
new CellInputVec(this.view.buffer.slice(offsets[3], offsets[4]), {
|
|
858
|
+
validate: false,
|
|
859
|
+
}).validate();
|
|
860
|
+
new CellOutputVec(this.view.buffer.slice(offsets[4], offsets[5]), {
|
|
861
|
+
validate: false,
|
|
862
|
+
}).validate();
|
|
863
|
+
new BytesVec(this.view.buffer.slice(offsets[5], offsets[6]), {
|
|
864
|
+
validate: false,
|
|
865
|
+
}).validate();
|
|
858
866
|
}
|
|
859
867
|
getVersion() {
|
|
860
868
|
const start = 4;
|
|
861
869
|
const offset = this.view.getUint32(start, true);
|
|
862
870
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
863
|
-
return new Uint32(this.view.buffer.slice(offset, offset_end), {
|
|
871
|
+
return new Uint32(this.view.buffer.slice(offset, offset_end), {
|
|
872
|
+
validate: false,
|
|
873
|
+
});
|
|
864
874
|
}
|
|
865
875
|
getCellDeps() {
|
|
866
876
|
const start = 8;
|
|
867
877
|
const offset = this.view.getUint32(start, true);
|
|
868
878
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
869
|
-
return new CellDepVec(this.view.buffer.slice(offset, offset_end), {
|
|
879
|
+
return new CellDepVec(this.view.buffer.slice(offset, offset_end), {
|
|
880
|
+
validate: false,
|
|
881
|
+
});
|
|
870
882
|
}
|
|
871
883
|
getHeaderDeps() {
|
|
872
884
|
const start = 12;
|
|
873
885
|
const offset = this.view.getUint32(start, true);
|
|
874
886
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
875
|
-
return new Byte32Vec(this.view.buffer.slice(offset, offset_end), {
|
|
887
|
+
return new Byte32Vec(this.view.buffer.slice(offset, offset_end), {
|
|
888
|
+
validate: false,
|
|
889
|
+
});
|
|
876
890
|
}
|
|
877
891
|
getInputs() {
|
|
878
892
|
const start = 16;
|
|
879
893
|
const offset = this.view.getUint32(start, true);
|
|
880
894
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
881
|
-
return new CellInputVec(this.view.buffer.slice(offset, offset_end), {
|
|
895
|
+
return new CellInputVec(this.view.buffer.slice(offset, offset_end), {
|
|
896
|
+
validate: false,
|
|
897
|
+
});
|
|
882
898
|
}
|
|
883
899
|
getOutputs() {
|
|
884
900
|
const start = 20;
|
|
885
901
|
const offset = this.view.getUint32(start, true);
|
|
886
902
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
887
|
-
return new CellOutputVec(this.view.buffer.slice(offset, offset_end), {
|
|
903
|
+
return new CellOutputVec(this.view.buffer.slice(offset, offset_end), {
|
|
904
|
+
validate: false,
|
|
905
|
+
});
|
|
888
906
|
}
|
|
889
907
|
getOutputsData() {
|
|
890
908
|
const start = 24;
|
|
891
909
|
const offset = this.view.getUint32(start, true);
|
|
892
910
|
const offset_end = this.view.byteLength;
|
|
893
|
-
return new BytesVec(this.view.buffer.slice(offset, offset_end), {
|
|
911
|
+
return new BytesVec(this.view.buffer.slice(offset, offset_end), {
|
|
912
|
+
validate: false,
|
|
913
|
+
});
|
|
894
914
|
}
|
|
895
915
|
}
|
|
896
|
-
|
|
897
|
-
function SerializeRawTransaction(value) {
|
|
916
|
+
export function SerializeRawTransaction(value) {
|
|
898
917
|
const buffers = [];
|
|
899
918
|
buffers.push(SerializeUint32(value.version));
|
|
900
919
|
buffers.push(SerializeCellDepVec(value.cellDeps));
|
|
@@ -904,8 +923,7 @@ function SerializeRawTransaction(value) {
|
|
|
904
923
|
buffers.push(SerializeBytesVec(value.outputsData));
|
|
905
924
|
return serializeTable(buffers);
|
|
906
925
|
}
|
|
907
|
-
|
|
908
|
-
class Transaction {
|
|
926
|
+
export class Transaction {
|
|
909
927
|
constructor(reader, { validate = true } = {}) {
|
|
910
928
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
911
929
|
if (validate) {
|
|
@@ -914,31 +932,37 @@ class Transaction {
|
|
|
914
932
|
}
|
|
915
933
|
validate(compatible = false) {
|
|
916
934
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
917
|
-
new RawTransaction(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
918
|
-
|
|
935
|
+
new RawTransaction(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
936
|
+
validate: false,
|
|
937
|
+
}).validate();
|
|
938
|
+
new BytesVec(this.view.buffer.slice(offsets[1], offsets[2]), {
|
|
939
|
+
validate: false,
|
|
940
|
+
}).validate();
|
|
919
941
|
}
|
|
920
942
|
getRaw() {
|
|
921
943
|
const start = 4;
|
|
922
944
|
const offset = this.view.getUint32(start, true);
|
|
923
945
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
924
|
-
return new RawTransaction(this.view.buffer.slice(offset, offset_end), {
|
|
946
|
+
return new RawTransaction(this.view.buffer.slice(offset, offset_end), {
|
|
947
|
+
validate: false,
|
|
948
|
+
});
|
|
925
949
|
}
|
|
926
950
|
getWitnesses() {
|
|
927
951
|
const start = 8;
|
|
928
952
|
const offset = this.view.getUint32(start, true);
|
|
929
953
|
const offset_end = this.view.byteLength;
|
|
930
|
-
return new BytesVec(this.view.buffer.slice(offset, offset_end), {
|
|
954
|
+
return new BytesVec(this.view.buffer.slice(offset, offset_end), {
|
|
955
|
+
validate: false,
|
|
956
|
+
});
|
|
931
957
|
}
|
|
932
958
|
}
|
|
933
|
-
|
|
934
|
-
function SerializeTransaction(value) {
|
|
959
|
+
export function SerializeTransaction(value) {
|
|
935
960
|
const buffers = [];
|
|
936
961
|
buffers.push(SerializeRawTransaction(value.raw));
|
|
937
962
|
buffers.push(SerializeBytesVec(value.witnesses));
|
|
938
963
|
return serializeTable(buffers);
|
|
939
964
|
}
|
|
940
|
-
|
|
941
|
-
class RawHeader {
|
|
965
|
+
export class RawHeader {
|
|
942
966
|
constructor(reader, { validate = true } = {}) {
|
|
943
967
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
944
968
|
if (validate) {
|
|
@@ -946,7 +970,9 @@ class RawHeader {
|
|
|
946
970
|
}
|
|
947
971
|
}
|
|
948
972
|
getVersion() {
|
|
949
|
-
return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), {
|
|
973
|
+
return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), {
|
|
974
|
+
validate: false,
|
|
975
|
+
});
|
|
950
976
|
}
|
|
951
977
|
getCompactTarget() {
|
|
952
978
|
return new Uint32(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint32.size()), { validate: false });
|
|
@@ -958,22 +984,102 @@ class RawHeader {
|
|
|
958
984
|
return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false });
|
|
959
985
|
}
|
|
960
986
|
getEpoch() {
|
|
961
|
-
return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size(), 0 +
|
|
987
|
+
return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size(), 0 +
|
|
988
|
+
Uint32.size() +
|
|
989
|
+
Uint32.size() +
|
|
990
|
+
Uint64.size() +
|
|
991
|
+
Uint64.size() +
|
|
992
|
+
Uint64.size()), { validate: false });
|
|
962
993
|
}
|
|
963
994
|
getParentHash() {
|
|
964
|
-
return new Byte32(this.view.buffer.slice(0 +
|
|
995
|
+
return new Byte32(this.view.buffer.slice(0 +
|
|
996
|
+
Uint32.size() +
|
|
997
|
+
Uint32.size() +
|
|
998
|
+
Uint64.size() +
|
|
999
|
+
Uint64.size() +
|
|
1000
|
+
Uint64.size(), 0 +
|
|
1001
|
+
Uint32.size() +
|
|
1002
|
+
Uint32.size() +
|
|
1003
|
+
Uint64.size() +
|
|
1004
|
+
Uint64.size() +
|
|
1005
|
+
Uint64.size() +
|
|
1006
|
+
Byte32.size()), { validate: false });
|
|
965
1007
|
}
|
|
966
1008
|
getTransactionsRoot() {
|
|
967
|
-
return new Byte32(this.view.buffer.slice(0 +
|
|
1009
|
+
return new Byte32(this.view.buffer.slice(0 +
|
|
1010
|
+
Uint32.size() +
|
|
1011
|
+
Uint32.size() +
|
|
1012
|
+
Uint64.size() +
|
|
1013
|
+
Uint64.size() +
|
|
1014
|
+
Uint64.size() +
|
|
1015
|
+
Byte32.size(), 0 +
|
|
1016
|
+
Uint32.size() +
|
|
1017
|
+
Uint32.size() +
|
|
1018
|
+
Uint64.size() +
|
|
1019
|
+
Uint64.size() +
|
|
1020
|
+
Uint64.size() +
|
|
1021
|
+
Byte32.size() +
|
|
1022
|
+
Byte32.size()), { validate: false });
|
|
968
1023
|
}
|
|
969
1024
|
getProposalsHash() {
|
|
970
|
-
return new Byte32(this.view.buffer.slice(0 +
|
|
1025
|
+
return new Byte32(this.view.buffer.slice(0 +
|
|
1026
|
+
Uint32.size() +
|
|
1027
|
+
Uint32.size() +
|
|
1028
|
+
Uint64.size() +
|
|
1029
|
+
Uint64.size() +
|
|
1030
|
+
Uint64.size() +
|
|
1031
|
+
Byte32.size() +
|
|
1032
|
+
Byte32.size(), 0 +
|
|
1033
|
+
Uint32.size() +
|
|
1034
|
+
Uint32.size() +
|
|
1035
|
+
Uint64.size() +
|
|
1036
|
+
Uint64.size() +
|
|
1037
|
+
Uint64.size() +
|
|
1038
|
+
Byte32.size() +
|
|
1039
|
+
Byte32.size() +
|
|
1040
|
+
Byte32.size()), { validate: false });
|
|
971
1041
|
}
|
|
972
1042
|
getExtraHash() {
|
|
973
|
-
return new Byte32(this.view.buffer.slice(0 +
|
|
1043
|
+
return new Byte32(this.view.buffer.slice(0 +
|
|
1044
|
+
Uint32.size() +
|
|
1045
|
+
Uint32.size() +
|
|
1046
|
+
Uint64.size() +
|
|
1047
|
+
Uint64.size() +
|
|
1048
|
+
Uint64.size() +
|
|
1049
|
+
Byte32.size() +
|
|
1050
|
+
Byte32.size() +
|
|
1051
|
+
Byte32.size(), 0 +
|
|
1052
|
+
Uint32.size() +
|
|
1053
|
+
Uint32.size() +
|
|
1054
|
+
Uint64.size() +
|
|
1055
|
+
Uint64.size() +
|
|
1056
|
+
Uint64.size() +
|
|
1057
|
+
Byte32.size() +
|
|
1058
|
+
Byte32.size() +
|
|
1059
|
+
Byte32.size() +
|
|
1060
|
+
Byte32.size()), { validate: false });
|
|
974
1061
|
}
|
|
975
1062
|
getDao() {
|
|
976
|
-
return new Byte32(this.view.buffer.slice(0 +
|
|
1063
|
+
return new Byte32(this.view.buffer.slice(0 +
|
|
1064
|
+
Uint32.size() +
|
|
1065
|
+
Uint32.size() +
|
|
1066
|
+
Uint64.size() +
|
|
1067
|
+
Uint64.size() +
|
|
1068
|
+
Uint64.size() +
|
|
1069
|
+
Byte32.size() +
|
|
1070
|
+
Byte32.size() +
|
|
1071
|
+
Byte32.size() +
|
|
1072
|
+
Byte32.size(), 0 +
|
|
1073
|
+
Uint32.size() +
|
|
1074
|
+
Uint32.size() +
|
|
1075
|
+
Uint64.size() +
|
|
1076
|
+
Uint64.size() +
|
|
1077
|
+
Uint64.size() +
|
|
1078
|
+
Byte32.size() +
|
|
1079
|
+
Byte32.size() +
|
|
1080
|
+
Byte32.size() +
|
|
1081
|
+
Byte32.size() +
|
|
1082
|
+
Byte32.size()), { validate: false });
|
|
977
1083
|
}
|
|
978
1084
|
validate(compatible = false) {
|
|
979
1085
|
assertDataLength(this.view.byteLength, RawHeader.size());
|
|
@@ -989,27 +1095,80 @@ class RawHeader {
|
|
|
989
1095
|
this.getDao().validate(compatible);
|
|
990
1096
|
}
|
|
991
1097
|
static size() {
|
|
992
|
-
return 0 +
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1098
|
+
return (0 +
|
|
1099
|
+
Uint32.size() +
|
|
1100
|
+
Uint32.size() +
|
|
1101
|
+
Uint64.size() +
|
|
1102
|
+
Uint64.size() +
|
|
1103
|
+
Uint64.size() +
|
|
1104
|
+
Byte32.size() +
|
|
1105
|
+
Byte32.size() +
|
|
1106
|
+
Byte32.size() +
|
|
1107
|
+
Byte32.size() +
|
|
1108
|
+
Byte32.size());
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
export function SerializeRawHeader(value) {
|
|
1112
|
+
const array = new Uint8Array(0 +
|
|
1113
|
+
Uint32.size() +
|
|
1114
|
+
Uint32.size() +
|
|
1115
|
+
Uint64.size() +
|
|
1116
|
+
Uint64.size() +
|
|
1117
|
+
Uint64.size() +
|
|
1118
|
+
Byte32.size() +
|
|
1119
|
+
Byte32.size() +
|
|
1120
|
+
Byte32.size() +
|
|
1121
|
+
Byte32.size() +
|
|
1122
|
+
Byte32.size());
|
|
998
1123
|
const view = new DataView(array.buffer);
|
|
999
1124
|
array.set(new Uint8Array(SerializeUint32(value.version)), 0);
|
|
1000
1125
|
array.set(new Uint8Array(SerializeUint32(value.compactTarget)), 0 + Uint32.size());
|
|
1001
1126
|
array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint32.size());
|
|
1002
1127
|
array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size() + Uint32.size() + Uint64.size());
|
|
1003
1128
|
array.set(new Uint8Array(SerializeUint64(value.epoch)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size());
|
|
1004
|
-
array.set(new Uint8Array(SerializeByte32(value.parentHash)), 0 +
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1129
|
+
array.set(new Uint8Array(SerializeByte32(value.parentHash)), 0 +
|
|
1130
|
+
Uint32.size() +
|
|
1131
|
+
Uint32.size() +
|
|
1132
|
+
Uint64.size() +
|
|
1133
|
+
Uint64.size() +
|
|
1134
|
+
Uint64.size());
|
|
1135
|
+
array.set(new Uint8Array(SerializeByte32(value.transactionsRoot)), 0 +
|
|
1136
|
+
Uint32.size() +
|
|
1137
|
+
Uint32.size() +
|
|
1138
|
+
Uint64.size() +
|
|
1139
|
+
Uint64.size() +
|
|
1140
|
+
Uint64.size() +
|
|
1141
|
+
Byte32.size());
|
|
1142
|
+
array.set(new Uint8Array(SerializeByte32(value.proposalsHash)), 0 +
|
|
1143
|
+
Uint32.size() +
|
|
1144
|
+
Uint32.size() +
|
|
1145
|
+
Uint64.size() +
|
|
1146
|
+
Uint64.size() +
|
|
1147
|
+
Uint64.size() +
|
|
1148
|
+
Byte32.size() +
|
|
1149
|
+
Byte32.size());
|
|
1150
|
+
array.set(new Uint8Array(SerializeByte32(value.extraHash)), 0 +
|
|
1151
|
+
Uint32.size() +
|
|
1152
|
+
Uint32.size() +
|
|
1153
|
+
Uint64.size() +
|
|
1154
|
+
Uint64.size() +
|
|
1155
|
+
Uint64.size() +
|
|
1156
|
+
Byte32.size() +
|
|
1157
|
+
Byte32.size() +
|
|
1158
|
+
Byte32.size());
|
|
1159
|
+
array.set(new Uint8Array(SerializeByte32(value.dao)), 0 +
|
|
1160
|
+
Uint32.size() +
|
|
1161
|
+
Uint32.size() +
|
|
1162
|
+
Uint64.size() +
|
|
1163
|
+
Uint64.size() +
|
|
1164
|
+
Uint64.size() +
|
|
1165
|
+
Byte32.size() +
|
|
1166
|
+
Byte32.size() +
|
|
1167
|
+
Byte32.size() +
|
|
1168
|
+
Byte32.size());
|
|
1009
1169
|
return array.buffer;
|
|
1010
1170
|
}
|
|
1011
|
-
|
|
1012
|
-
class Header {
|
|
1171
|
+
export class Header {
|
|
1013
1172
|
constructor(reader, { validate = true } = {}) {
|
|
1014
1173
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
1015
1174
|
if (validate) {
|
|
@@ -1017,7 +1176,9 @@ class Header {
|
|
|
1017
1176
|
}
|
|
1018
1177
|
}
|
|
1019
1178
|
getRaw() {
|
|
1020
|
-
return new RawHeader(this.view.buffer.slice(0, 0 + RawHeader.size()), {
|
|
1179
|
+
return new RawHeader(this.view.buffer.slice(0, 0 + RawHeader.size()), {
|
|
1180
|
+
validate: false,
|
|
1181
|
+
});
|
|
1021
1182
|
}
|
|
1022
1183
|
getNonce() {
|
|
1023
1184
|
return new Uint128(this.view.buffer.slice(0 + RawHeader.size(), 0 + RawHeader.size() + Uint128.size()), { validate: false });
|
|
@@ -1031,16 +1192,14 @@ class Header {
|
|
|
1031
1192
|
return 0 + RawHeader.size() + Uint128.size();
|
|
1032
1193
|
}
|
|
1033
1194
|
}
|
|
1034
|
-
|
|
1035
|
-
function SerializeHeader(value) {
|
|
1195
|
+
export function SerializeHeader(value) {
|
|
1036
1196
|
const array = new Uint8Array(0 + RawHeader.size() + Uint128.size());
|
|
1037
1197
|
const view = new DataView(array.buffer);
|
|
1038
1198
|
array.set(new Uint8Array(SerializeRawHeader(value.raw)), 0);
|
|
1039
1199
|
array.set(new Uint8Array(SerializeUint128(value.nonce)), 0 + RawHeader.size());
|
|
1040
1200
|
return array.buffer;
|
|
1041
1201
|
}
|
|
1042
|
-
|
|
1043
|
-
class UncleBlock {
|
|
1202
|
+
export class UncleBlock {
|
|
1044
1203
|
constructor(reader, { validate = true } = {}) {
|
|
1045
1204
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
1046
1205
|
if (validate) {
|
|
@@ -1049,31 +1208,37 @@ class UncleBlock {
|
|
|
1049
1208
|
}
|
|
1050
1209
|
validate(compatible = false) {
|
|
1051
1210
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
1052
|
-
new Header(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1053
|
-
|
|
1211
|
+
new Header(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1212
|
+
validate: false,
|
|
1213
|
+
}).validate();
|
|
1214
|
+
new ProposalShortIdVec(this.view.buffer.slice(offsets[1], offsets[2]), {
|
|
1215
|
+
validate: false,
|
|
1216
|
+
}).validate();
|
|
1054
1217
|
}
|
|
1055
1218
|
getHeader() {
|
|
1056
1219
|
const start = 4;
|
|
1057
1220
|
const offset = this.view.getUint32(start, true);
|
|
1058
1221
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1059
|
-
return new Header(this.view.buffer.slice(offset, offset_end), {
|
|
1222
|
+
return new Header(this.view.buffer.slice(offset, offset_end), {
|
|
1223
|
+
validate: false,
|
|
1224
|
+
});
|
|
1060
1225
|
}
|
|
1061
1226
|
getProposals() {
|
|
1062
1227
|
const start = 8;
|
|
1063
1228
|
const offset = this.view.getUint32(start, true);
|
|
1064
1229
|
const offset_end = this.view.byteLength;
|
|
1065
|
-
return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), {
|
|
1230
|
+
return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), {
|
|
1231
|
+
validate: false,
|
|
1232
|
+
});
|
|
1066
1233
|
}
|
|
1067
1234
|
}
|
|
1068
|
-
|
|
1069
|
-
function SerializeUncleBlock(value) {
|
|
1235
|
+
export function SerializeUncleBlock(value) {
|
|
1070
1236
|
const buffers = [];
|
|
1071
1237
|
buffers.push(SerializeHeader(value.header));
|
|
1072
1238
|
buffers.push(SerializeProposalShortIdVec(value.proposals));
|
|
1073
1239
|
return serializeTable(buffers);
|
|
1074
1240
|
}
|
|
1075
|
-
|
|
1076
|
-
class Block {
|
|
1241
|
+
export class Block {
|
|
1077
1242
|
constructor(reader, { validate = true } = {}) {
|
|
1078
1243
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
1079
1244
|
if (validate) {
|
|
@@ -1082,38 +1247,53 @@ class Block {
|
|
|
1082
1247
|
}
|
|
1083
1248
|
validate(compatible = false) {
|
|
1084
1249
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
1085
|
-
new Header(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
new
|
|
1250
|
+
new Header(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1251
|
+
validate: false,
|
|
1252
|
+
}).validate();
|
|
1253
|
+
new UncleBlockVec(this.view.buffer.slice(offsets[1], offsets[2]), {
|
|
1254
|
+
validate: false,
|
|
1255
|
+
}).validate();
|
|
1256
|
+
new TransactionVec(this.view.buffer.slice(offsets[2], offsets[3]), {
|
|
1257
|
+
validate: false,
|
|
1258
|
+
}).validate();
|
|
1259
|
+
new ProposalShortIdVec(this.view.buffer.slice(offsets[3], offsets[4]), {
|
|
1260
|
+
validate: false,
|
|
1261
|
+
}).validate();
|
|
1089
1262
|
}
|
|
1090
1263
|
getHeader() {
|
|
1091
1264
|
const start = 4;
|
|
1092
1265
|
const offset = this.view.getUint32(start, true);
|
|
1093
1266
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1094
|
-
return new Header(this.view.buffer.slice(offset, offset_end), {
|
|
1267
|
+
return new Header(this.view.buffer.slice(offset, offset_end), {
|
|
1268
|
+
validate: false,
|
|
1269
|
+
});
|
|
1095
1270
|
}
|
|
1096
1271
|
getUncles() {
|
|
1097
1272
|
const start = 8;
|
|
1098
1273
|
const offset = this.view.getUint32(start, true);
|
|
1099
1274
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1100
|
-
return new UncleBlockVec(this.view.buffer.slice(offset, offset_end), {
|
|
1275
|
+
return new UncleBlockVec(this.view.buffer.slice(offset, offset_end), {
|
|
1276
|
+
validate: false,
|
|
1277
|
+
});
|
|
1101
1278
|
}
|
|
1102
1279
|
getTransactions() {
|
|
1103
1280
|
const start = 12;
|
|
1104
1281
|
const offset = this.view.getUint32(start, true);
|
|
1105
1282
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1106
|
-
return new TransactionVec(this.view.buffer.slice(offset, offset_end), {
|
|
1283
|
+
return new TransactionVec(this.view.buffer.slice(offset, offset_end), {
|
|
1284
|
+
validate: false,
|
|
1285
|
+
});
|
|
1107
1286
|
}
|
|
1108
1287
|
getProposals() {
|
|
1109
1288
|
const start = 16;
|
|
1110
1289
|
const offset = this.view.getUint32(start, true);
|
|
1111
1290
|
const offset_end = this.view.byteLength;
|
|
1112
|
-
return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), {
|
|
1291
|
+
return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), {
|
|
1292
|
+
validate: false,
|
|
1293
|
+
});
|
|
1113
1294
|
}
|
|
1114
1295
|
}
|
|
1115
|
-
|
|
1116
|
-
function SerializeBlock(value) {
|
|
1296
|
+
export function SerializeBlock(value) {
|
|
1117
1297
|
const buffers = [];
|
|
1118
1298
|
buffers.push(SerializeHeader(value.header));
|
|
1119
1299
|
buffers.push(SerializeUncleBlockVec(value.uncles));
|
|
@@ -1121,8 +1301,7 @@ function SerializeBlock(value) {
|
|
|
1121
1301
|
buffers.push(SerializeProposalShortIdVec(value.proposals));
|
|
1122
1302
|
return serializeTable(buffers);
|
|
1123
1303
|
}
|
|
1124
|
-
|
|
1125
|
-
class BlockV1 {
|
|
1304
|
+
export class BlockV1 {
|
|
1126
1305
|
constructor(reader, { validate = true } = {}) {
|
|
1127
1306
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
1128
1307
|
if (validate) {
|
|
@@ -1131,45 +1310,64 @@ class BlockV1 {
|
|
|
1131
1310
|
}
|
|
1132
1311
|
validate(compatible = false) {
|
|
1133
1312
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
1134
|
-
new Header(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
new
|
|
1138
|
-
|
|
1313
|
+
new Header(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1314
|
+
validate: false,
|
|
1315
|
+
}).validate();
|
|
1316
|
+
new UncleBlockVec(this.view.buffer.slice(offsets[1], offsets[2]), {
|
|
1317
|
+
validate: false,
|
|
1318
|
+
}).validate();
|
|
1319
|
+
new TransactionVec(this.view.buffer.slice(offsets[2], offsets[3]), {
|
|
1320
|
+
validate: false,
|
|
1321
|
+
}).validate();
|
|
1322
|
+
new ProposalShortIdVec(this.view.buffer.slice(offsets[3], offsets[4]), {
|
|
1323
|
+
validate: false,
|
|
1324
|
+
}).validate();
|
|
1325
|
+
new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), {
|
|
1326
|
+
validate: false,
|
|
1327
|
+
}).validate();
|
|
1139
1328
|
}
|
|
1140
1329
|
getHeader() {
|
|
1141
1330
|
const start = 4;
|
|
1142
1331
|
const offset = this.view.getUint32(start, true);
|
|
1143
1332
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1144
|
-
return new Header(this.view.buffer.slice(offset, offset_end), {
|
|
1333
|
+
return new Header(this.view.buffer.slice(offset, offset_end), {
|
|
1334
|
+
validate: false,
|
|
1335
|
+
});
|
|
1145
1336
|
}
|
|
1146
1337
|
getUncles() {
|
|
1147
1338
|
const start = 8;
|
|
1148
1339
|
const offset = this.view.getUint32(start, true);
|
|
1149
1340
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1150
|
-
return new UncleBlockVec(this.view.buffer.slice(offset, offset_end), {
|
|
1341
|
+
return new UncleBlockVec(this.view.buffer.slice(offset, offset_end), {
|
|
1342
|
+
validate: false,
|
|
1343
|
+
});
|
|
1151
1344
|
}
|
|
1152
1345
|
getTransactions() {
|
|
1153
1346
|
const start = 12;
|
|
1154
1347
|
const offset = this.view.getUint32(start, true);
|
|
1155
1348
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1156
|
-
return new TransactionVec(this.view.buffer.slice(offset, offset_end), {
|
|
1349
|
+
return new TransactionVec(this.view.buffer.slice(offset, offset_end), {
|
|
1350
|
+
validate: false,
|
|
1351
|
+
});
|
|
1157
1352
|
}
|
|
1158
1353
|
getProposals() {
|
|
1159
1354
|
const start = 16;
|
|
1160
1355
|
const offset = this.view.getUint32(start, true);
|
|
1161
1356
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1162
|
-
return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), {
|
|
1357
|
+
return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), {
|
|
1358
|
+
validate: false,
|
|
1359
|
+
});
|
|
1163
1360
|
}
|
|
1164
1361
|
getExtension() {
|
|
1165
1362
|
const start = 20;
|
|
1166
1363
|
const offset = this.view.getUint32(start, true);
|
|
1167
1364
|
const offset_end = this.view.byteLength;
|
|
1168
|
-
return new Bytes(this.view.buffer.slice(offset, offset_end), {
|
|
1365
|
+
return new Bytes(this.view.buffer.slice(offset, offset_end), {
|
|
1366
|
+
validate: false,
|
|
1367
|
+
});
|
|
1169
1368
|
}
|
|
1170
1369
|
}
|
|
1171
|
-
|
|
1172
|
-
function SerializeBlockV1(value) {
|
|
1370
|
+
export function SerializeBlockV1(value) {
|
|
1173
1371
|
const buffers = [];
|
|
1174
1372
|
buffers.push(SerializeHeader(value.header));
|
|
1175
1373
|
buffers.push(SerializeUncleBlockVec(value.uncles));
|
|
@@ -1178,8 +1376,7 @@ function SerializeBlockV1(value) {
|
|
|
1178
1376
|
buffers.push(SerializeBytes(value.extension));
|
|
1179
1377
|
return serializeTable(buffers);
|
|
1180
1378
|
}
|
|
1181
|
-
|
|
1182
|
-
class CellbaseWitness {
|
|
1379
|
+
export class CellbaseWitness {
|
|
1183
1380
|
constructor(reader, { validate = true } = {}) {
|
|
1184
1381
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
1185
1382
|
if (validate) {
|
|
@@ -1188,31 +1385,37 @@ class CellbaseWitness {
|
|
|
1188
1385
|
}
|
|
1189
1386
|
validate(compatible = false) {
|
|
1190
1387
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
1191
|
-
new Script(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1192
|
-
|
|
1388
|
+
new Script(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1389
|
+
validate: false,
|
|
1390
|
+
}).validate();
|
|
1391
|
+
new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), {
|
|
1392
|
+
validate: false,
|
|
1393
|
+
}).validate();
|
|
1193
1394
|
}
|
|
1194
1395
|
getLock() {
|
|
1195
1396
|
const start = 4;
|
|
1196
1397
|
const offset = this.view.getUint32(start, true);
|
|
1197
1398
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1198
|
-
return new Script(this.view.buffer.slice(offset, offset_end), {
|
|
1399
|
+
return new Script(this.view.buffer.slice(offset, offset_end), {
|
|
1400
|
+
validate: false,
|
|
1401
|
+
});
|
|
1199
1402
|
}
|
|
1200
1403
|
getMessage() {
|
|
1201
1404
|
const start = 8;
|
|
1202
1405
|
const offset = this.view.getUint32(start, true);
|
|
1203
1406
|
const offset_end = this.view.byteLength;
|
|
1204
|
-
return new Bytes(this.view.buffer.slice(offset, offset_end), {
|
|
1407
|
+
return new Bytes(this.view.buffer.slice(offset, offset_end), {
|
|
1408
|
+
validate: false,
|
|
1409
|
+
});
|
|
1205
1410
|
}
|
|
1206
1411
|
}
|
|
1207
|
-
|
|
1208
|
-
function SerializeCellbaseWitness(value) {
|
|
1412
|
+
export function SerializeCellbaseWitness(value) {
|
|
1209
1413
|
const buffers = [];
|
|
1210
1414
|
buffers.push(SerializeScript(value.lock));
|
|
1211
1415
|
buffers.push(SerializeBytes(value.message));
|
|
1212
1416
|
return serializeTable(buffers);
|
|
1213
1417
|
}
|
|
1214
|
-
|
|
1215
|
-
class WitnessArgs {
|
|
1418
|
+
export class WitnessArgs {
|
|
1216
1419
|
constructor(reader, { validate = true } = {}) {
|
|
1217
1420
|
this.view = new DataView(assertArrayBuffer(reader));
|
|
1218
1421
|
if (validate) {
|
|
@@ -1221,35 +1424,45 @@ class WitnessArgs {
|
|
|
1221
1424
|
}
|
|
1222
1425
|
validate(compatible = false) {
|
|
1223
1426
|
const offsets = verifyAndExtractOffsets(this.view, 0, true);
|
|
1224
|
-
new BytesOpt(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1225
|
-
|
|
1226
|
-
|
|
1427
|
+
new BytesOpt(this.view.buffer.slice(offsets[0], offsets[1]), {
|
|
1428
|
+
validate: false,
|
|
1429
|
+
}).validate();
|
|
1430
|
+
new BytesOpt(this.view.buffer.slice(offsets[1], offsets[2]), {
|
|
1431
|
+
validate: false,
|
|
1432
|
+
}).validate();
|
|
1433
|
+
new BytesOpt(this.view.buffer.slice(offsets[2], offsets[3]), {
|
|
1434
|
+
validate: false,
|
|
1435
|
+
}).validate();
|
|
1227
1436
|
}
|
|
1228
1437
|
getLock() {
|
|
1229
1438
|
const start = 4;
|
|
1230
1439
|
const offset = this.view.getUint32(start, true);
|
|
1231
1440
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1232
|
-
return new BytesOpt(this.view.buffer.slice(offset, offset_end), {
|
|
1441
|
+
return new BytesOpt(this.view.buffer.slice(offset, offset_end), {
|
|
1442
|
+
validate: false,
|
|
1443
|
+
});
|
|
1233
1444
|
}
|
|
1234
1445
|
getInputType() {
|
|
1235
1446
|
const start = 8;
|
|
1236
1447
|
const offset = this.view.getUint32(start, true);
|
|
1237
1448
|
const offset_end = this.view.getUint32(start + 4, true);
|
|
1238
|
-
return new BytesOpt(this.view.buffer.slice(offset, offset_end), {
|
|
1449
|
+
return new BytesOpt(this.view.buffer.slice(offset, offset_end), {
|
|
1450
|
+
validate: false,
|
|
1451
|
+
});
|
|
1239
1452
|
}
|
|
1240
1453
|
getOutputType() {
|
|
1241
1454
|
const start = 12;
|
|
1242
1455
|
const offset = this.view.getUint32(start, true);
|
|
1243
1456
|
const offset_end = this.view.byteLength;
|
|
1244
|
-
return new BytesOpt(this.view.buffer.slice(offset, offset_end), {
|
|
1457
|
+
return new BytesOpt(this.view.buffer.slice(offset, offset_end), {
|
|
1458
|
+
validate: false,
|
|
1459
|
+
});
|
|
1245
1460
|
}
|
|
1246
1461
|
}
|
|
1247
|
-
|
|
1248
|
-
function SerializeWitnessArgs(value) {
|
|
1462
|
+
export function SerializeWitnessArgs(value) {
|
|
1249
1463
|
const buffers = [];
|
|
1250
1464
|
buffers.push(SerializeBytesOpt(value.lock));
|
|
1251
1465
|
buffers.push(SerializeBytesOpt(value.inputType));
|
|
1252
1466
|
buffers.push(SerializeBytesOpt(value.outputType));
|
|
1253
1467
|
return serializeTable(buffers);
|
|
1254
1468
|
}
|
|
1255
|
-
exports.SerializeWitnessArgs = SerializeWitnessArgs;
|