@ckb-ccc/core 0.0.7-alpha.2 → 0.0.8-alpha.3
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/README.md +6 -4
- package/dist.commonjs/address/address.advanced.d.ts +29 -24
- package/dist.commonjs/address/address.advanced.js +115 -89
- package/dist.commonjs/address/advanced.d.ts +1 -1
- package/dist.commonjs/address/advanced.js +30 -14
- package/dist.commonjs/address/index.d.ts +51 -44
- package/dist.commonjs/address/index.js +84 -65
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +47 -22
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +30 -14
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +30 -14
- package/dist.commonjs/bytes/advanced.d.ts +11 -2
- package/dist.commonjs/bytes/index.d.ts +9 -3
- package/dist.commonjs/bytes/index.js +28 -26
- package/dist.commonjs/ckb/advanced.d.ts +1 -1
- package/dist.commonjs/ckb/advanced.js +47 -22
- package/dist.commonjs/ckb/index.d.ts +1 -1
- package/dist.commonjs/ckb/index.js +30 -14
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
- package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
- package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
- package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/script.advanced.js +12 -9
- package/dist.commonjs/ckb/script.d.ts +121 -117
- package/dist.commonjs/ckb/script.js +220 -176
- package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/transaction.advanced.js +4 -4
- package/dist.commonjs/ckb/transaction.d.ts +792 -717
- package/dist.commonjs/ckb/transaction.js +1383 -1155
- package/dist.commonjs/client/advanced.d.ts +1 -1
- package/dist.commonjs/client/advanced.js +30 -14
- package/dist.commonjs/client/client.advanced.d.ts +23 -6
- package/dist.commonjs/client/client.advanced.js +89 -61
- package/dist.commonjs/client/client.d.ts +113 -53
- package/dist.commonjs/client/client.js +214 -181
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +8 -4
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +144 -127
- package/dist.commonjs/client/clientPublicMainnet.d.ts +8 -6
- package/dist.commonjs/client/clientPublicMainnet.js +17 -15
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +6 -3
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +204 -179
- package/dist.commonjs/client/clientPublicTestnet.d.ts +8 -6
- package/dist.commonjs/client/clientPublicTestnet.js +13 -13
- package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
- package/dist.commonjs/client/clientTypes.advanced.js +1 -1
- package/dist.commonjs/client/clientTypes.d.ts +51 -26
- package/dist.commonjs/client/clientTypes.js +56 -22
- package/dist.commonjs/client/index.d.ts +1 -1
- package/dist.commonjs/client/index.js +30 -14
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
- package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
- package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
- package/dist.commonjs/client/jsonRpc/index.js +135 -108
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -36
- package/dist.commonjs/client/jsonRpc/transformers.js +174 -152
- package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
- package/dist.commonjs/fixedPoint/index.d.ts +9 -3
- package/dist.commonjs/fixedPoint/index.js +26 -20
- package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
- package/dist.commonjs/fixedPoint/index.test.js +42 -36
- package/dist.commonjs/hasher/advanced.d.ts +1 -1
- package/dist.commonjs/hasher/index.d.ts +36 -36
- package/dist.commonjs/hasher/index.js +54 -47
- package/dist.commonjs/hex/index.d.ts +1 -1
- package/dist.commonjs/hex/index.js +1 -1
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +47 -22
- package/dist.commonjs/num/index.d.ts +1 -1
- package/dist.commonjs/num/index.js +39 -27
- package/dist.commonjs/signer/btc/index.d.ts +1 -1
- package/dist.commonjs/signer/btc/index.js +30 -14
- package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
- package/dist.commonjs/signer/btc/signerBtc.js +89 -66
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
- package/dist.commonjs/signer/btc/verify.d.ts +6 -2
- package/dist.commonjs/signer/btc/verify.js +10 -3
- package/dist.commonjs/signer/ckb/index.d.ts +1 -1
- package/dist.commonjs/signer/ckb/index.js +30 -14
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
- package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
- package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
- package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
- package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
- package/dist.commonjs/signer/dummy/dummy.js +16 -16
- package/dist.commonjs/signer/dummy/index.d.ts +1 -1
- package/dist.commonjs/signer/dummy/index.js +30 -14
- package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
- package/dist.commonjs/signer/dummy/openLink.js +7 -7
- package/dist.commonjs/signer/evm/index.d.ts +1 -1
- package/dist.commonjs/signer/evm/index.js +30 -14
- package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
- package/dist.commonjs/signer/evm/signerEvm.js +105 -70
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
- package/dist.commonjs/signer/evm/verify.d.ts +6 -2
- package/dist.commonjs/signer/evm/verify.js +7 -2
- package/dist.commonjs/signer/index.d.ts +1 -1
- package/dist.commonjs/signer/index.js +30 -14
- package/dist.commonjs/signer/nostr/index.d.ts +1 -1
- package/dist.commonjs/signer/nostr/index.js +30 -14
- package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
- package/dist.commonjs/signer/nostr/signerNostr.js +100 -71
- package/dist.commonjs/signer/nostr/verify.d.ts +9 -3
- package/dist.commonjs/signer/nostr/verify.js +50 -39
- package/dist.commonjs/signer/signer/index.d.ts +156 -150
- package/dist.commonjs/signer/signer/index.js +208 -181
- package/dist.commonjs/utils/index.d.ts +38 -8
- package/dist.commonjs/utils/index.js +18 -12
- package/package.json +2 -2
|
@@ -6,30 +6,64 @@ const hex_1 = require("../hex");
|
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const clientTypes_advanced_1 = require("./clientTypes.advanced");
|
|
8
8
|
class ClientIndexerSearchKeyFilter {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
constructor(
|
|
10
|
+
script,
|
|
11
|
+
scriptLenRange,
|
|
12
|
+
outputData,
|
|
13
|
+
outputDataSearchMode,
|
|
14
|
+
outputDataLenRange,
|
|
15
|
+
outputCapacityRange,
|
|
16
|
+
blockRange,
|
|
17
|
+
) {
|
|
18
|
+
this.script = script;
|
|
19
|
+
this.scriptLenRange = scriptLenRange;
|
|
20
|
+
this.outputData = outputData;
|
|
21
|
+
this.outputDataSearchMode = outputDataSearchMode;
|
|
22
|
+
this.outputDataLenRange = outputDataLenRange;
|
|
23
|
+
this.outputCapacityRange = outputCapacityRange;
|
|
24
|
+
this.blockRange = blockRange;
|
|
25
|
+
}
|
|
26
|
+
static from(filterLike) {
|
|
27
|
+
return new ClientIndexerSearchKeyFilter(
|
|
28
|
+
(0, utils_1.apply)(ckb_1.Script.from, filterLike.script),
|
|
29
|
+
(0, utils_1.apply)(
|
|
30
|
+
clientTypes_advanced_1.clientSearchKeyRangeFrom,
|
|
31
|
+
filterLike.scriptLenRange,
|
|
32
|
+
),
|
|
33
|
+
(0, utils_1.apply)(hex_1.hexFrom, filterLike.outputData),
|
|
34
|
+
filterLike.outputDataSearchMode,
|
|
35
|
+
(0, utils_1.apply)(
|
|
36
|
+
clientTypes_advanced_1.clientSearchKeyRangeFrom,
|
|
37
|
+
filterLike.outputDataLenRange,
|
|
38
|
+
),
|
|
39
|
+
(0, utils_1.apply)(
|
|
40
|
+
clientTypes_advanced_1.clientSearchKeyRangeFrom,
|
|
41
|
+
filterLike.outputCapacityRange,
|
|
42
|
+
),
|
|
43
|
+
(0, utils_1.apply)(
|
|
44
|
+
clientTypes_advanced_1.clientSearchKeyRangeFrom,
|
|
45
|
+
filterLike.blockRange,
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
21
49
|
}
|
|
22
50
|
exports.ClientIndexerSearchKeyFilter = ClientIndexerSearchKeyFilter;
|
|
23
51
|
class ClientIndexerSearchKey {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
constructor(script, scriptType, scriptSearchMode, filter, withData) {
|
|
53
|
+
this.script = script;
|
|
54
|
+
this.scriptType = scriptType;
|
|
55
|
+
this.scriptSearchMode = scriptSearchMode;
|
|
56
|
+
this.filter = filter;
|
|
57
|
+
this.withData = withData;
|
|
58
|
+
}
|
|
59
|
+
static from(keyLike) {
|
|
60
|
+
return new ClientIndexerSearchKey(
|
|
61
|
+
ckb_1.Script.from(keyLike.script),
|
|
62
|
+
keyLike.scriptType,
|
|
63
|
+
keyLike.scriptSearchMode,
|
|
64
|
+
(0, utils_1.apply)(ClientIndexerSearchKeyFilter.from, keyLike.filter),
|
|
65
|
+
keyLike.withData,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
34
68
|
}
|
|
35
69
|
exports.ClientIndexerSearchKey = ClientIndexerSearchKey;
|
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __exportStar =
|
|
26
|
+
(this && this.__exportStar) ||
|
|
27
|
+
function (m, exports) {
|
|
28
|
+
for (var p in m)
|
|
29
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
+
__createBinding(exports, m, p);
|
|
31
|
+
};
|
|
16
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
33
|
__exportStar(require("./client"), exports);
|
|
18
34
|
__exportStar(require("./clientPublicMainnet"), exports);
|
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __exportStar =
|
|
26
|
+
(this && this.__exportStar) ||
|
|
27
|
+
function (m, exports) {
|
|
28
|
+
for (var p in m)
|
|
29
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
+
__createBinding(exports, m, p);
|
|
31
|
+
};
|
|
16
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
33
|
__exportStar(require("./transformers"), exports);
|
|
18
34
|
__exportStar(require("./types"), exports);
|
|
@@ -2,85 +2,104 @@ import { TransactionLike } from "../../ckb";
|
|
|
2
2
|
import { Hex, HexLike } from "../../hex";
|
|
3
3
|
import { Num, NumLike } from "../../num";
|
|
4
4
|
import { Client } from "../client";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ClientFindCellsResponse,
|
|
7
|
+
ClientIndexerSearchKeyLike,
|
|
8
|
+
ClientTransactionResponse,
|
|
9
|
+
OutputsValidator,
|
|
10
|
+
} from "../clientTypes";
|
|
6
11
|
import { JsonRpcPayload } from "./advanced";
|
|
7
12
|
/**
|
|
8
13
|
* An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
|
|
9
14
|
* Provides methods for sending transactions and building JSON-RPC payloads.
|
|
10
15
|
*/
|
|
11
16
|
export declare abstract class ClientJsonRpc extends Client {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
17
|
+
private readonly url_;
|
|
18
|
+
private readonly timeout;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of ClientJsonRpc.
|
|
21
|
+
*
|
|
22
|
+
* @param url - The URL of the JSON-RPC server.
|
|
23
|
+
* @param timeout - The timeout for requests in milliseconds, default is 30000.
|
|
24
|
+
*/
|
|
25
|
+
constructor(url_: string, timeout?: number);
|
|
26
|
+
/**
|
|
27
|
+
* Returns the URL of the JSON-RPC server.
|
|
28
|
+
*
|
|
29
|
+
* @returns The URL of the JSON-RPC server.
|
|
30
|
+
*/
|
|
31
|
+
get url(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Send a transaction to node.
|
|
34
|
+
*
|
|
35
|
+
* @param transaction - The transaction to send.
|
|
36
|
+
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
37
|
+
* @returns Transaction hash.
|
|
38
|
+
*/
|
|
39
|
+
sendTransactionNoCache: (
|
|
40
|
+
transaction: TransactionLike,
|
|
41
|
+
validator?: OutputsValidator | undefined,
|
|
42
|
+
) => Promise<Hex>;
|
|
43
|
+
/**
|
|
44
|
+
* Get a transaction from node.
|
|
45
|
+
*
|
|
46
|
+
* @param txHash - The hash of the transaction.
|
|
47
|
+
* @returns The transaction with status.
|
|
48
|
+
*/
|
|
49
|
+
getTransactionNoCache: (
|
|
50
|
+
txHash: HexLike,
|
|
51
|
+
) => Promise<ClientTransactionResponse | null>;
|
|
52
|
+
/**
|
|
53
|
+
* find cells from node.
|
|
54
|
+
*
|
|
55
|
+
* @param key - The search key of cells.
|
|
56
|
+
* @param order - The order of cells.
|
|
57
|
+
* @param limit - The max return size of cells.
|
|
58
|
+
* @param after - Pagination parameter.
|
|
59
|
+
* @returns The found cells.
|
|
60
|
+
*/
|
|
61
|
+
findCellsPagedNoCache: (
|
|
62
|
+
key: ClientIndexerSearchKeyLike,
|
|
63
|
+
order?: "asc" | "desc",
|
|
64
|
+
limit?: NumLike,
|
|
65
|
+
after?: string,
|
|
66
|
+
) => Promise<ClientFindCellsResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* get cells capacity from node.
|
|
69
|
+
*
|
|
70
|
+
* @param key - The search key of cells.
|
|
71
|
+
* @returns The sum of cells capacity.
|
|
72
|
+
*/
|
|
73
|
+
getCellsCapacity: (key: ClientIndexerSearchKeyLike) => Promise<Num>;
|
|
74
|
+
/**
|
|
75
|
+
* Builds a sender function for a JSON-RPC method.
|
|
76
|
+
*
|
|
77
|
+
* @param rpcMethod - The JSON-RPC method.
|
|
78
|
+
* @param inTransformers - An array of input transformers.
|
|
79
|
+
* @param outTransformer - An output transformer function.
|
|
80
|
+
* @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
|
|
81
|
+
*/
|
|
82
|
+
buildSender(
|
|
83
|
+
rpcMethod: string,
|
|
84
|
+
inTransformers: (((_: any) => unknown) | undefined)[],
|
|
85
|
+
outTransformer?: (_: any) => unknown,
|
|
86
|
+
): (...req: unknown[]) => Promise<unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* Sends a JSON-RPC request to the server.
|
|
89
|
+
*
|
|
90
|
+
* @param payload - The JSON-RPC payload to send.
|
|
91
|
+
* @returns The result of the JSON-RPC request.
|
|
92
|
+
*
|
|
93
|
+
* @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
|
|
94
|
+
*/
|
|
95
|
+
send(payload: JsonRpcPayload): Promise<unknown>;
|
|
96
|
+
/**
|
|
97
|
+
* Builds a JSON-RPC payload for the given method and parameters.
|
|
98
|
+
*
|
|
99
|
+
* @param method - The JSON-RPC method name.
|
|
100
|
+
* @param req - The parameters for the JSON-RPC method.
|
|
101
|
+
* @returns The JSON-RPC payload.
|
|
102
|
+
*/
|
|
103
|
+
static buildPayload(method: string, req: unknown[]): JsonRpcPayload;
|
|
85
104
|
}
|
|
86
|
-
//# sourceMappingURL=index.d.ts.map
|
|
105
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
5
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
8
|
exports.ClientJsonRpc = void 0;
|
|
7
9
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
@@ -23,130 +25,155 @@ const advanced_1 = require("./advanced");
|
|
|
23
25
|
* ```
|
|
24
26
|
*/
|
|
25
27
|
async function transform(value, transformer) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (transformer) {
|
|
29
|
+
return transformer(value);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
34
|
* An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
|
|
33
35
|
* Provides methods for sending transactions and building JSON-RPC payloads.
|
|
34
36
|
*/
|
|
35
37
|
class ClientJsonRpc extends client_1.Client {
|
|
38
|
+
/**
|
|
39
|
+
* Creates an instance of ClientJsonRpc.
|
|
40
|
+
*
|
|
41
|
+
* @param url - The URL of the JSON-RPC server.
|
|
42
|
+
* @param timeout - The timeout for requests in milliseconds, default is 30000.
|
|
43
|
+
*/
|
|
44
|
+
constructor(url_, timeout = 30000) {
|
|
45
|
+
super();
|
|
46
|
+
this.url_ = url_;
|
|
47
|
+
this.timeout = timeout;
|
|
36
48
|
/**
|
|
37
|
-
*
|
|
49
|
+
* Send a transaction to node.
|
|
38
50
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
51
|
+
* @param transaction - The transaction to send.
|
|
52
|
+
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
53
|
+
* @returns Transaction hash.
|
|
41
54
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* Send a transaction to node.
|
|
48
|
-
*
|
|
49
|
-
* @param transaction - The transaction to send.
|
|
50
|
-
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
51
|
-
* @returns Transaction hash.
|
|
52
|
-
*/
|
|
53
|
-
this.sendTransactionNoCache = this.buildSender("send_transaction", [advanced_1.JsonRpcTransformers.transactionFrom], hex_1.hexFrom);
|
|
54
|
-
/**
|
|
55
|
-
* Get a transaction from node.
|
|
56
|
-
*
|
|
57
|
-
* @param txHash - The hash of the transaction.
|
|
58
|
-
* @returns The transaction with status.
|
|
59
|
-
*/
|
|
60
|
-
this.getTransactionNoCache = this.buildSender("get_transaction", [hex_1.hexFrom], advanced_1.JsonRpcTransformers.transactionResponseTo);
|
|
61
|
-
/**
|
|
62
|
-
* find cells from node.
|
|
63
|
-
*
|
|
64
|
-
* @param key - The search key of cells.
|
|
65
|
-
* @param order - The order of cells.
|
|
66
|
-
* @param limit - The max return size of cells.
|
|
67
|
-
* @param after - Pagination parameter.
|
|
68
|
-
* @returns The found cells.
|
|
69
|
-
*/
|
|
70
|
-
this.findCellsPagedNoCache = this.buildSender("get_cells", [
|
|
71
|
-
advanced_1.JsonRpcTransformers.indexerSearchKeyFrom,
|
|
72
|
-
(order) => order ?? "asc",
|
|
73
|
-
(limit) => (0, num_1.numToHex)(limit ?? 10),
|
|
74
|
-
], advanced_1.JsonRpcTransformers.findCellsResponseTo);
|
|
75
|
-
/**
|
|
76
|
-
* get cells capacity from node.
|
|
77
|
-
*
|
|
78
|
-
* @param key - The search key of cells.
|
|
79
|
-
* @returns The sum of cells capacity.
|
|
80
|
-
*/
|
|
81
|
-
this.getCellsCapacity = this.buildSender("get_cells_capacity", [advanced_1.JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => (0, num_1.numFrom)(capacity));
|
|
82
|
-
}
|
|
55
|
+
this.sendTransactionNoCache = this.buildSender(
|
|
56
|
+
"send_transaction",
|
|
57
|
+
[advanced_1.JsonRpcTransformers.transactionFrom],
|
|
58
|
+
hex_1.hexFrom,
|
|
59
|
+
);
|
|
83
60
|
/**
|
|
84
|
-
*
|
|
61
|
+
* Get a transaction from node.
|
|
85
62
|
*
|
|
86
|
-
* @
|
|
63
|
+
* @param txHash - The hash of the transaction.
|
|
64
|
+
* @returns The transaction with status.
|
|
87
65
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
66
|
+
this.getTransactionNoCache = this.buildSender(
|
|
67
|
+
"get_transaction",
|
|
68
|
+
[hex_1.hexFrom],
|
|
69
|
+
advanced_1.JsonRpcTransformers.transactionResponseTo,
|
|
70
|
+
);
|
|
91
71
|
/**
|
|
92
|
-
*
|
|
72
|
+
* find cells from node.
|
|
93
73
|
*
|
|
94
|
-
* @param
|
|
95
|
-
* @param
|
|
96
|
-
* @param
|
|
97
|
-
* @
|
|
74
|
+
* @param key - The search key of cells.
|
|
75
|
+
* @param order - The order of cells.
|
|
76
|
+
* @param limit - The max return size of cells.
|
|
77
|
+
* @param after - Pagination parameter.
|
|
78
|
+
* @returns The found cells.
|
|
98
79
|
*/
|
|
99
|
-
buildSender(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
80
|
+
this.findCellsPagedNoCache = this.buildSender(
|
|
81
|
+
"get_cells",
|
|
82
|
+
[
|
|
83
|
+
advanced_1.JsonRpcTransformers.indexerSearchKeyFrom,
|
|
84
|
+
(order) => order ?? "asc",
|
|
85
|
+
(limit) => (0, num_1.numToHex)(limit ?? 10),
|
|
86
|
+
],
|
|
87
|
+
advanced_1.JsonRpcTransformers.findCellsResponseTo,
|
|
88
|
+
);
|
|
107
89
|
/**
|
|
108
|
-
*
|
|
90
|
+
* get cells capacity from node.
|
|
109
91
|
*
|
|
110
|
-
* @param
|
|
111
|
-
* @returns The
|
|
112
|
-
*
|
|
113
|
-
* @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
|
|
92
|
+
* @param key - The search key of cells.
|
|
93
|
+
* @returns The sum of cells capacity.
|
|
114
94
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
95
|
+
this.getCellsCapacity = this.buildSender(
|
|
96
|
+
"get_cells_capacity",
|
|
97
|
+
[advanced_1.JsonRpcTransformers.indexerSearchKeyFrom],
|
|
98
|
+
({ capacity }) => (0, num_1.numFrom)(capacity),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns the URL of the JSON-RPC server.
|
|
103
|
+
*
|
|
104
|
+
* @returns The URL of the JSON-RPC server.
|
|
105
|
+
*/
|
|
106
|
+
get url() {
|
|
107
|
+
return this.url_;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Builds a sender function for a JSON-RPC method.
|
|
111
|
+
*
|
|
112
|
+
* @param rpcMethod - The JSON-RPC method.
|
|
113
|
+
* @param inTransformers - An array of input transformers.
|
|
114
|
+
* @param outTransformer - An output transformer function.
|
|
115
|
+
* @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
|
|
116
|
+
*/
|
|
117
|
+
buildSender(rpcMethod, inTransformers, outTransformer) {
|
|
118
|
+
return async (...req) => {
|
|
119
|
+
const payload = ClientJsonRpc.buildPayload(
|
|
120
|
+
rpcMethod,
|
|
121
|
+
await Promise.all(
|
|
122
|
+
req
|
|
123
|
+
.concat(
|
|
124
|
+
Array.from(
|
|
125
|
+
new Array(Math.max(inTransformers.length - req.length, 0)),
|
|
126
|
+
),
|
|
127
|
+
)
|
|
128
|
+
.map((v, i) => transform(v, inTransformers[i])),
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
return transform(await this.send(payload), outTransformer);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Sends a JSON-RPC request to the server.
|
|
136
|
+
*
|
|
137
|
+
* @param payload - The JSON-RPC payload to send.
|
|
138
|
+
* @returns The result of the JSON-RPC request.
|
|
139
|
+
*
|
|
140
|
+
* @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
|
|
141
|
+
*/
|
|
142
|
+
async send(payload) {
|
|
143
|
+
const aborter = new AbortController();
|
|
144
|
+
const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
|
|
145
|
+
const raw = await (0, cross_fetch_1.default)(this.url, {
|
|
146
|
+
method: "POST",
|
|
147
|
+
headers: {
|
|
148
|
+
"content-type": "application/json",
|
|
149
|
+
},
|
|
150
|
+
body: JSON.stringify(payload),
|
|
151
|
+
signal: aborter.signal,
|
|
152
|
+
});
|
|
153
|
+
clearTimeout(abortTimer);
|
|
154
|
+
const res = await raw.json();
|
|
155
|
+
if (res.id !== payload.id) {
|
|
156
|
+
throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
|
|
135
157
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*
|
|
139
|
-
* @param method - The JSON-RPC method name.
|
|
140
|
-
* @param req - The parameters for the JSON-RPC method.
|
|
141
|
-
* @returns The JSON-RPC payload.
|
|
142
|
-
*/
|
|
143
|
-
static buildPayload(method, req) {
|
|
144
|
-
return {
|
|
145
|
-
id: Math.round(Math.random() * 10000),
|
|
146
|
-
method,
|
|
147
|
-
params: req,
|
|
148
|
-
jsonrpc: "2.0",
|
|
149
|
-
};
|
|
158
|
+
if (res.error) {
|
|
159
|
+
throw res.error;
|
|
150
160
|
}
|
|
161
|
+
return res.result;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Builds a JSON-RPC payload for the given method and parameters.
|
|
165
|
+
*
|
|
166
|
+
* @param method - The JSON-RPC method name.
|
|
167
|
+
* @param req - The parameters for the JSON-RPC method.
|
|
168
|
+
* @returns The JSON-RPC payload.
|
|
169
|
+
*/
|
|
170
|
+
static buildPayload(method, req) {
|
|
171
|
+
return {
|
|
172
|
+
id: Math.round(Math.random() * 10000),
|
|
173
|
+
method,
|
|
174
|
+
params: req,
|
|
175
|
+
jsonrpc: "2.0",
|
|
176
|
+
};
|
|
177
|
+
}
|
|
151
178
|
}
|
|
152
179
|
exports.ClientJsonRpc = ClientJsonRpc;
|