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