@ckb-ccc/core 1.22.1 → 1.23.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 +61 -0
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.mjs +1 -1
- package/dist/{advancedBarrel-Daj_LJkz.d.mts → advancedBarrel-BBbQZ2OW.d.mts} +480 -379
- package/dist/advancedBarrel-BBbQZ2OW.d.mts.map +1 -0
- package/dist/advancedBarrel.d.mts +1 -1
- package/dist/advancedBarrel.mjs +1 -1
- package/dist/barrel-Dz1WLXRX.mjs +7 -0
- package/dist/barrel-Dz1WLXRX.mjs.map +1 -0
- package/dist/barrel.d.mts +2 -2
- package/dist/barrel.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/transformers-BHt442Nd.mjs +2 -0
- package/dist/transformers-BHt442Nd.mjs.map +1 -0
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +1 -1
- package/dist.commonjs/{advancedBarrel-CJL3rfuW.d.ts → advancedBarrel-BS4zFcFI.d.ts} +480 -379
- package/dist.commonjs/advancedBarrel-BS4zFcFI.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +1 -1
- package/dist.commonjs/{barrel--PaV2IZx.js → barrel-CZYID7jh.js} +10 -10
- package/dist.commonjs/barrel-CZYID7jh.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +2 -2
- package/dist.commonjs/barrel.js +1 -1
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -1
- package/dist.commonjs/transformers-CYUULrnt.js +2 -0
- package/dist.commonjs/transformers-CYUULrnt.js.map +1 -0
- package/package.json +1 -1
- package/src/address/index.ts +32 -4
- package/src/ckb/transaction.ts +59 -27
- package/src/client/cache/memory.advanced.ts +18 -3
- package/src/client/client.ts +41 -2
- package/src/client/clientPublicMainnet.ts +9 -2
- package/src/client/clientPublicTestnet.ts +9 -2
- package/src/client/jsonRpc/client.ts +7 -7
- package/src/codec/codec.ts +51 -27
- package/src/codec/entity.ts +26 -16
- package/src/molecule/codec.ts +437 -202
- package/dist/advancedBarrel-Daj_LJkz.d.mts.map +0 -1
- package/dist/barrel-pRBtHOAW.mjs +0 -7
- package/dist/barrel-pRBtHOAW.mjs.map +0 -1
- package/dist/transformers-lavDTtAW.mjs +0 -2
- package/dist/transformers-lavDTtAW.mjs.map +0 -1
- package/dist.commonjs/advancedBarrel-CJL3rfuW.d.ts.map +0 -1
- package/dist.commonjs/barrel--PaV2IZx.js.map +0 -1
- package/dist.commonjs/transformers-VBXQGQKe.js +0 -2
- package/dist.commonjs/transformers-VBXQGQKe.js.map +0 -1
package/src/codec/entity.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { hashCkb } from "../hasher/index.js";
|
|
|
3
3
|
import { Hex, hexFrom } from "../hex/index.js";
|
|
4
4
|
import type { UnionDecoded, UnionMatchHandlers } from "../molecule/codec.js";
|
|
5
5
|
import { Constructor } from "../utils/index.js";
|
|
6
|
-
import type { CodecLike, DecodedType } from "./codec.js";
|
|
6
|
+
import type { CodecLike, ContextType, DecodedType } from "./codec.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The base class of CCC to create a serializable instance. This should be used with the {@link codec} decorator.
|
|
@@ -15,7 +15,12 @@ export abstract class Entity {
|
|
|
15
15
|
* This should be used with the {@link codec} decorator.
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
|
-
static Base<
|
|
18
|
+
static Base<
|
|
19
|
+
SubTypeLike,
|
|
20
|
+
SubType = SubTypeLike,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
Context = any,
|
|
23
|
+
>() {
|
|
19
24
|
abstract class Impl extends Entity {
|
|
20
25
|
/**
|
|
21
26
|
* The bytes length of the entity, if it is fixed, otherwise undefined
|
|
@@ -41,10 +46,11 @@ export abstract class Entity {
|
|
|
41
46
|
* @public
|
|
42
47
|
* @static
|
|
43
48
|
* @param _ - The bytes to decode
|
|
49
|
+
* @param _context - Optional context passed to the codec
|
|
44
50
|
* @returns The decoded entity
|
|
45
51
|
* @throws Will throw an error if the entity is not serializable
|
|
46
52
|
*/
|
|
47
|
-
static decode(_: BytesLike): SubType {
|
|
53
|
+
static decode(_: BytesLike, _context?: Context): SubType {
|
|
48
54
|
throw new Error(
|
|
49
55
|
"decode not implemented, use @ccc.codec to decorate your type",
|
|
50
56
|
);
|
|
@@ -55,10 +61,11 @@ export abstract class Entity {
|
|
|
55
61
|
* @public
|
|
56
62
|
* @static
|
|
57
63
|
* @param _ - The bytes to create the entity from
|
|
64
|
+
* @param _context - Optional context passed to the codec
|
|
58
65
|
* @returns The created entity
|
|
59
66
|
* @throws Will throw an error if the entity is not serializable
|
|
60
67
|
*/
|
|
61
|
-
static fromBytes(_bytes: BytesLike): SubType {
|
|
68
|
+
static fromBytes(_bytes: BytesLike, _context?: Context): SubType {
|
|
62
69
|
throw new Error(
|
|
63
70
|
"fromBytes not implemented, use @ccc.codec to decorate your type",
|
|
64
71
|
);
|
|
@@ -181,14 +188,18 @@ export abstract class Entity {
|
|
|
181
188
|
*/
|
|
182
189
|
static BaseUnion<
|
|
183
190
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
-
CodecType extends CodecLike<any, UnionDecoded<any, any
|
|
191
|
+
CodecType extends CodecLike<any, UnionDecoded<any, any>, any>,
|
|
185
192
|
SubTypeLike,
|
|
186
193
|
SubType = SubTypeLike,
|
|
187
194
|
>() {
|
|
188
195
|
type Handlers<Result> = UnionMatchHandlers<CodecType, Result>;
|
|
189
196
|
type Decoded = DecodedType<CodecType>;
|
|
190
197
|
|
|
191
|
-
abstract class Impl extends Entity.Base<
|
|
198
|
+
abstract class Impl extends Entity.Base<
|
|
199
|
+
SubTypeLike,
|
|
200
|
+
SubType,
|
|
201
|
+
ContextType<CodecType>
|
|
202
|
+
>() {
|
|
192
203
|
/**
|
|
193
204
|
* The inner decoded object representing the union value.
|
|
194
205
|
* @public
|
|
@@ -263,12 +274,11 @@ export function codec<
|
|
|
263
274
|
Encodable,
|
|
264
275
|
TypeLike extends Encodable,
|
|
265
276
|
Decoded extends TypeLike,
|
|
277
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
278
|
+
Context = any,
|
|
266
279
|
>(codec: {
|
|
267
280
|
encode: (encodable: Encodable) => Bytes;
|
|
268
|
-
decode: (
|
|
269
|
-
decodable: Bytes,
|
|
270
|
-
config?: { isExtraFieldIgnored?: boolean },
|
|
271
|
-
) => Decoded;
|
|
281
|
+
decode: (decodable: Bytes, context?: Context) => Decoded;
|
|
272
282
|
byteLength?: number;
|
|
273
283
|
}) {
|
|
274
284
|
return function <
|
|
@@ -277,8 +287,8 @@ export function codec<
|
|
|
277
287
|
from(decoded: TypeLike): Type;
|
|
278
288
|
byteLength?: number;
|
|
279
289
|
encode(encodable: TypeLike): Bytes;
|
|
280
|
-
decode(bytesLike: BytesLike): Type;
|
|
281
|
-
fromBytes(bytes: BytesLike): Type;
|
|
290
|
+
decode(bytesLike: BytesLike, context?: Context): Type;
|
|
291
|
+
fromBytes(bytes: BytesLike, context?: Context): Type;
|
|
282
292
|
},
|
|
283
293
|
>(Constructor: ConstructorType, ..._: unknown[]) {
|
|
284
294
|
Constructor.byteLength = codec.byteLength;
|
|
@@ -288,13 +298,13 @@ export function codec<
|
|
|
288
298
|
};
|
|
289
299
|
}
|
|
290
300
|
if (Constructor.decode === undefined) {
|
|
291
|
-
Constructor.decode = function (bytesLike: BytesLike) {
|
|
292
|
-
return Constructor.from(codec.decode(bytesFrom(bytesLike)));
|
|
301
|
+
Constructor.decode = function (bytesLike: BytesLike, context?: Context) {
|
|
302
|
+
return Constructor.from(codec.decode(bytesFrom(bytesLike), context));
|
|
293
303
|
};
|
|
294
304
|
}
|
|
295
305
|
if (Constructor.fromBytes === undefined) {
|
|
296
|
-
Constructor.fromBytes = function (bytes: BytesLike) {
|
|
297
|
-
return Constructor.from(codec.decode(bytesFrom(bytes)));
|
|
306
|
+
Constructor.fromBytes = function (bytes: BytesLike, context?: Context) {
|
|
307
|
+
return Constructor.from(codec.decode(bytesFrom(bytes), context));
|
|
298
308
|
};
|
|
299
309
|
}
|
|
300
310
|
|