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