@ckb-ccc/core 0.0.13-alpha.7 → 0.0.13
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 +58 -0
- package/dist/client/cache/cache.d.ts +29 -9
- package/dist/client/cache/cache.d.ts.map +1 -1
- package/dist/client/cache/cache.js +43 -1
- package/dist/client/cache/memory.d.ts +10 -6
- package/dist/client/cache/memory.d.ts.map +1 -1
- package/dist/client/cache/memory.js +49 -39
- package/dist/client/client.d.ts +2 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +7 -0
- package/dist/client/clientTypes.d.ts +24 -2
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/clientTypes.js +25 -1
- package/dist/client/jsonRpc/index.d.ts +10 -1
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +42 -1
- package/dist/fixedPoint/index.d.ts +3 -3
- package/dist/fixedPoint/index.js +3 -3
- package/dist.commonjs/client/cache/cache.d.ts +29 -9
- package/dist.commonjs/client/cache/cache.d.ts.map +1 -1
- package/dist.commonjs/client/cache/cache.js +45 -0
- package/dist.commonjs/client/cache/memory.d.ts +10 -6
- package/dist.commonjs/client/cache/memory.d.ts.map +1 -1
- package/dist.commonjs/client/cache/memory.js +49 -39
- package/dist.commonjs/client/client.d.ts +2 -0
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +7 -0
- package/dist.commonjs/client/clientTypes.d.ts +24 -2
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.js +32 -5
- package/dist.commonjs/client/jsonRpc/index.d.ts +10 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +58 -17
- package/dist.commonjs/fixedPoint/index.d.ts +3 -3
- package/dist.commonjs/fixedPoint/index.js +3 -3
- package/package.json +1 -1
- package/src/client/cache/cache.ts +58 -13
- package/src/client/cache/memory.ts +60 -52
- package/src/client/client.ts +21 -0
- package/src/client/clientTypes.ts +52 -3
- package/src/client/jsonRpc/index.ts +97 -3
- package/src/fixedPoint/index.ts +3 -3
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Cell,
|
|
3
|
+
OutPoint,
|
|
4
|
+
OutPointLike,
|
|
5
|
+
TransactionLike,
|
|
6
|
+
} from "../../ckb/index.js";
|
|
2
7
|
import { Hex, HexLike, hexFrom } from "../../hex/index.js";
|
|
3
8
|
import { Num, NumLike, numFrom, numToHex } from "../../num/index.js";
|
|
4
9
|
import { apply } from "../../utils/index.js";
|
|
@@ -8,6 +13,10 @@ import {
|
|
|
8
13
|
ClientFindCellsResponse,
|
|
9
14
|
ClientIndexerSearchKeyLike,
|
|
10
15
|
ClientTransactionResponse,
|
|
16
|
+
ErrorClientBase,
|
|
17
|
+
ErrorClientBaseLike,
|
|
18
|
+
ErrorClientResolveUnknown,
|
|
19
|
+
ErrorClientVerification,
|
|
11
20
|
OutputsValidator,
|
|
12
21
|
} from "../clientTypes.js";
|
|
13
22
|
import {
|
|
@@ -15,7 +24,7 @@ import {
|
|
|
15
24
|
Transport,
|
|
16
25
|
transportFromUri,
|
|
17
26
|
} from "../transports/advanced.js";
|
|
18
|
-
import { JsonRpcTransformers } from "./advanced.js";
|
|
27
|
+
import { JsonRpcCellOutput, JsonRpcTransformers } from "./advanced.js";
|
|
19
28
|
|
|
20
29
|
/**
|
|
21
30
|
* Applies a transformation function to a value if the transformer is provided.
|
|
@@ -203,6 +212,48 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
203
212
|
JsonRpcTransformers.transactionResponseTo,
|
|
204
213
|
) as (txHash: HexLike) => Promise<ClientTransactionResponse | undefined>;
|
|
205
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Get a live cell from node.
|
|
217
|
+
*
|
|
218
|
+
* @param outPoint - The out point of the cell.
|
|
219
|
+
* @param withData - Include data in the response.
|
|
220
|
+
* @param includeTxPool - Include cells in the tx pool.
|
|
221
|
+
* @returns The cell
|
|
222
|
+
*/
|
|
223
|
+
getCellLiveNoCache(
|
|
224
|
+
outPoint: OutPointLike,
|
|
225
|
+
withData?: boolean | null,
|
|
226
|
+
includeTxPool?: boolean | null,
|
|
227
|
+
) {
|
|
228
|
+
return this.buildSender(
|
|
229
|
+
"get_live_cell",
|
|
230
|
+
[JsonRpcTransformers.outPointFrom],
|
|
231
|
+
({
|
|
232
|
+
cell,
|
|
233
|
+
}: {
|
|
234
|
+
cell?: {
|
|
235
|
+
output: JsonRpcCellOutput;
|
|
236
|
+
data?: { content: HexLike; hash: HexLike };
|
|
237
|
+
};
|
|
238
|
+
}) =>
|
|
239
|
+
apply(
|
|
240
|
+
({
|
|
241
|
+
output,
|
|
242
|
+
data,
|
|
243
|
+
}: {
|
|
244
|
+
output: JsonRpcCellOutput;
|
|
245
|
+
data?: { content: HexLike; hash: HexLike };
|
|
246
|
+
}) =>
|
|
247
|
+
Cell.from({
|
|
248
|
+
cellOutput: JsonRpcTransformers.cellOutputTo(output),
|
|
249
|
+
outputData: data?.content ?? "0x",
|
|
250
|
+
outPoint,
|
|
251
|
+
}),
|
|
252
|
+
cell,
|
|
253
|
+
),
|
|
254
|
+
)(outPoint, withData ?? true, includeTxPool) as Promise<Cell | undefined>;
|
|
255
|
+
}
|
|
256
|
+
|
|
206
257
|
/**
|
|
207
258
|
* find cells from node.
|
|
208
259
|
*
|
|
@@ -289,7 +340,50 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
289
340
|
),
|
|
290
341
|
);
|
|
291
342
|
|
|
292
|
-
|
|
343
|
+
try {
|
|
344
|
+
return transform(await this.send(payload), outTransformer);
|
|
345
|
+
} catch (errAny: unknown) {
|
|
346
|
+
if (
|
|
347
|
+
typeof errAny !== "object" ||
|
|
348
|
+
errAny === null ||
|
|
349
|
+
!("data" in errAny) ||
|
|
350
|
+
typeof errAny.data !== "string"
|
|
351
|
+
) {
|
|
352
|
+
throw errAny;
|
|
353
|
+
}
|
|
354
|
+
const err = errAny as ErrorClientBaseLike;
|
|
355
|
+
|
|
356
|
+
const unknownOutPointMatch = err.data.match(
|
|
357
|
+
new RegExp("Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)"),
|
|
358
|
+
)?.[1];
|
|
359
|
+
if (unknownOutPointMatch) {
|
|
360
|
+
throw new ErrorClientResolveUnknown(
|
|
361
|
+
err,
|
|
362
|
+
OutPoint.fromBytes(unknownOutPointMatch),
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
const verificationFailedMatch = err.data.match(
|
|
366
|
+
new RegExp(
|
|
367
|
+
"Verification\\(Error { kind: Script, inner: TransactionScriptError { source: (Inputs|Outputs)\\[([0-9]*)\\].(Lock|Type), cause: ValidationFailure: see error code (-?[0-9])* on page https://nervosnetwork\\.github\\.io/ckb-script-error-codes/by-(type|data)-hash/(.*)\\.html",
|
|
368
|
+
),
|
|
369
|
+
);
|
|
370
|
+
if (verificationFailedMatch) {
|
|
371
|
+
throw new ErrorClientVerification(
|
|
372
|
+
err,
|
|
373
|
+
verificationFailedMatch[3] === "Lock"
|
|
374
|
+
? "lock"
|
|
375
|
+
: verificationFailedMatch[1] === "Inputs"
|
|
376
|
+
? "inputType"
|
|
377
|
+
: "outputType",
|
|
378
|
+
verificationFailedMatch[2],
|
|
379
|
+
Number(verificationFailedMatch[4]),
|
|
380
|
+
verificationFailedMatch[5] === "data" ? "data" : "type",
|
|
381
|
+
verificationFailedMatch[6],
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
throw new ErrorClientBase(err);
|
|
386
|
+
}
|
|
293
387
|
};
|
|
294
388
|
}
|
|
295
389
|
|
package/src/fixedPoint/index.ts
CHANGED
|
@@ -24,8 +24,8 @@ export type FixedPointLike = bigint | string | number;
|
|
|
24
24
|
* @example
|
|
25
25
|
* ```typescript
|
|
26
26
|
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
27
|
-
* const strFromString = fixedPointToString("
|
|
28
|
-
* const strFromNumber = fixedPointToString(
|
|
27
|
+
* const strFromString = fixedPointToString("1.23456789", 8); // Outputs "1.23456789"
|
|
28
|
+
* const strFromNumber = fixedPointToString(1.23456789, 8); // Outputs "1.23456789"
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
|
|
@@ -54,7 +54,7 @@ export function fixedPointToString(val: FixedPointLike, decimals = 8): string {
|
|
|
54
54
|
*
|
|
55
55
|
* @example
|
|
56
56
|
* ```typescript
|
|
57
|
-
* const fixedPoint = fixedPointFrom(
|
|
57
|
+
* const fixedPoint = fixedPointFrom(123456789n, 8); // Outputs 123456789n
|
|
58
58
|
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
59
59
|
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
60
60
|
* ```
|