@ckb-ccc/core 1.2.2 → 1.3.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 +22 -0
- package/dist/advancedBarrel.d.ts +1 -0
- package/dist/advancedBarrel.d.ts.map +1 -1
- package/dist/advancedBarrel.js +1 -0
- package/dist/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -0
- package/dist/ckb/script.d.ts +1 -0
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/script.js +1 -0
- package/dist/ckb/transaction.d.ts +3 -1
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +25 -2
- package/dist/client/advanced.d.ts +0 -1
- package/dist/client/advanced.d.ts.map +1 -1
- package/dist/client/advanced.js +0 -1
- package/dist/client/clientPublicMainnet.d.ts +3 -9
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.d.ts +3 -9
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/jsonRpc/client.d.ts +160 -0
- package/dist/client/jsonRpc/client.d.ts.map +1 -0
- package/dist/client/jsonRpc/client.js +220 -0
- package/dist/client/jsonRpc/index.d.ts +1 -182
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +1 -293
- package/dist/jsonRpc/advanced.d.ts +2 -0
- package/dist/jsonRpc/advanced.d.ts.map +1 -0
- package/dist/jsonRpc/advanced.js +1 -0
- package/dist/jsonRpc/index.d.ts +2 -0
- package/dist/jsonRpc/index.d.ts.map +1 -0
- package/dist/jsonRpc/index.js +1 -0
- package/dist/jsonRpc/requestor.d.ts +48 -0
- package/dist/jsonRpc/requestor.d.ts.map +1 -0
- package/dist/jsonRpc/requestor.js +107 -0
- package/dist/jsonRpc/transports/advanced.d.ts +5 -0
- package/dist/jsonRpc/transports/advanced.d.ts.map +1 -0
- package/dist/jsonRpc/transports/advanced.js +4 -0
- package/dist/{client/transports/advanced.d.ts → jsonRpc/transports/factory.d.ts} +1 -4
- package/dist/jsonRpc/transports/factory.d.ts.map +1 -0
- package/dist/{client/transports/advanced.js → jsonRpc/transports/factory.js} +0 -3
- package/dist/jsonRpc/transports/http.d.ts.map +1 -0
- package/dist/jsonRpc/transports/transport.d.ts +18 -0
- package/dist/jsonRpc/transports/transport.d.ts.map +1 -0
- package/dist/jsonRpc/transports/webSocket.d.ts.map +1 -0
- package/dist/molecule/codec.d.ts.map +1 -1
- package/dist/molecule/codec.js +3 -3
- package/dist/molecule/predefined.d.ts +12 -0
- package/dist/molecule/predefined.d.ts.map +1 -1
- package/dist/molecule/predefined.js +28 -0
- package/dist/num/index.d.ts.map +1 -1
- package/dist/num/index.js +10 -2
- package/dist.commonjs/advancedBarrel.d.ts +1 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -1
- package/dist.commonjs/advancedBarrel.js +1 -0
- package/dist.commonjs/barrel.d.ts +1 -0
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +1 -0
- package/dist.commonjs/ckb/script.d.ts +1 -0
- package/dist.commonjs/ckb/script.d.ts.map +1 -1
- package/dist.commonjs/ckb/script.js +2 -1
- package/dist.commonjs/ckb/transaction.d.ts +3 -1
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +25 -2
- package/dist.commonjs/client/advanced.d.ts +0 -1
- package/dist.commonjs/client/advanced.d.ts.map +1 -1
- package/dist.commonjs/client/advanced.js +0 -1
- package/dist.commonjs/client/clientPublicMainnet.d.ts +3 -9
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.d.ts +3 -9
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/client.d.ts +160 -0
- package/dist.commonjs/client/jsonRpc/client.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/client.js +224 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts +1 -182
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +15 -295
- package/dist.commonjs/jsonRpc/advanced.d.ts +2 -0
- package/dist.commonjs/jsonRpc/advanced.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/advanced.js +17 -0
- package/dist.commonjs/jsonRpc/index.d.ts +2 -0
- package/dist.commonjs/jsonRpc/index.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/index.js +17 -0
- package/dist.commonjs/jsonRpc/requestor.d.ts +48 -0
- package/dist.commonjs/jsonRpc/requestor.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/requestor.js +111 -0
- package/dist.commonjs/jsonRpc/transports/advanced.d.ts +5 -0
- package/dist.commonjs/jsonRpc/transports/advanced.d.ts.map +1 -0
- package/dist.commonjs/{client → jsonRpc}/transports/advanced.js +1 -9
- package/dist.commonjs/{client/transports/advanced.d.ts → jsonRpc/transports/factory.d.ts} +1 -4
- package/dist.commonjs/jsonRpc/transports/factory.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/factory.js +11 -0
- package/dist.commonjs/jsonRpc/transports/http.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/transport.d.ts +18 -0
- package/dist.commonjs/jsonRpc/transports/transport.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/webSocket.d.ts.map +1 -0
- package/dist.commonjs/molecule/codec.d.ts.map +1 -1
- package/dist.commonjs/molecule/codec.js +3 -3
- package/dist.commonjs/molecule/predefined.d.ts +12 -0
- package/dist.commonjs/molecule/predefined.d.ts.map +1 -1
- package/dist.commonjs/molecule/predefined.js +30 -1
- package/dist.commonjs/num/index.d.ts.map +1 -1
- package/dist.commonjs/num/index.js +10 -2
- package/package.json +1 -1
- package/src/advancedBarrel.ts +1 -0
- package/src/barrel.ts +1 -0
- package/src/ckb/script.ts +1 -0
- package/src/ckb/transaction.ts +52 -2
- package/src/client/advanced.ts +0 -1
- package/src/client/clientPublicMainnet.ts +2 -8
- package/src/client/clientPublicTestnet.ts +2 -8
- package/src/client/jsonRpc/client.ts +395 -0
- package/src/client/jsonRpc/index.ts +1 -490
- package/src/jsonRpc/advanced.ts +1 -0
- package/src/jsonRpc/index.ts +1 -0
- package/src/jsonRpc/requestor.ts +157 -0
- package/src/jsonRpc/transports/advanced.ts +4 -0
- package/src/{client/transports/advanced.ts → jsonRpc/transports/factory.ts} +0 -4
- package/src/jsonRpc/transports/transport.ts +18 -0
- package/src/molecule/codec.ts +5 -3
- package/src/molecule/predefined.ts +32 -0
- package/src/num/index.ts +12 -2
- package/dist/client/transports/advanced.d.ts.map +0 -1
- package/dist/client/transports/http.d.ts.map +0 -1
- package/dist/client/transports/transport.d.ts +0 -10
- package/dist/client/transports/transport.d.ts.map +0 -1
- package/dist/client/transports/webSocket.d.ts.map +0 -1
- package/dist.commonjs/client/transports/advanced.d.ts.map +0 -1
- package/dist.commonjs/client/transports/http.d.ts.map +0 -1
- package/dist.commonjs/client/transports/transport.d.ts +0 -10
- package/dist.commonjs/client/transports/transport.d.ts.map +0 -1
- package/dist.commonjs/client/transports/webSocket.d.ts.map +0 -1
- package/src/client/transports/transport.ts +0 -10
- /package/dist/{client → jsonRpc}/transports/http.d.ts +0 -0
- /package/dist/{client → jsonRpc}/transports/http.js +0 -0
- /package/dist/{client → jsonRpc}/transports/transport.js +0 -0
- /package/dist/{client → jsonRpc}/transports/webSocket.d.ts +0 -0
- /package/dist/{client → jsonRpc}/transports/webSocket.js +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/http.d.ts +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/http.js +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/transport.js +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/webSocket.d.ts +0 -0
- /package/dist.commonjs/{client → jsonRpc}/transports/webSocket.js +0 -0
- /package/src/{client → jsonRpc}/transports/http.ts +0 -0
- /package/src/{client → jsonRpc}/transports/webSocket.ts +0 -0
|
@@ -254,13 +254,13 @@ function table(codecLayout) {
|
|
|
254
254
|
},
|
|
255
255
|
decode(buffer) {
|
|
256
256
|
const value = (0, index_js_1.bytesFrom)(buffer);
|
|
257
|
+
if (value.byteLength < 4) {
|
|
258
|
+
throw new Error(`table: too short buffer, expected at least 4 bytes, but got ${value.byteLength}`);
|
|
259
|
+
}
|
|
257
260
|
const byteLength = uint32From(value.slice(0, 4));
|
|
258
261
|
if (byteLength !== value.byteLength) {
|
|
259
262
|
throw new Error(`table: invalid buffer size, expected ${byteLength}, but got ${value.byteLength}`);
|
|
260
263
|
}
|
|
261
|
-
if (byteLength <= 4) {
|
|
262
|
-
throw new Error("table: empty buffer");
|
|
263
|
-
}
|
|
264
264
|
const offsets = keys.map((_, index) => uint32From(value.slice(4 + index * 4, 8 + index * 4)));
|
|
265
265
|
offsets.push(byteLength);
|
|
266
266
|
const object = {};
|
|
@@ -36,6 +36,18 @@ export declare const Uint512Vec: Codec<import("../barrel.js").NumLike[], bigint[
|
|
|
36
36
|
export declare const Bytes: Codec<HexLike, Hex>;
|
|
37
37
|
export declare const BytesOpt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
|
|
38
38
|
export declare const BytesVec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
|
|
39
|
+
export declare const Bool: Codec<boolean>;
|
|
40
|
+
export declare const BoolOpt: Codec<boolean | null | undefined, boolean | undefined>;
|
|
41
|
+
export declare const BoolVec: Codec<boolean[], boolean[]>;
|
|
42
|
+
export declare const Byte4: Codec<HexLike, Hex>;
|
|
43
|
+
export declare const Byte4Opt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
|
|
44
|
+
export declare const Byte4Vec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
|
|
45
|
+
export declare const Byte8: Codec<HexLike, Hex>;
|
|
46
|
+
export declare const Byte8Opt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
|
|
47
|
+
export declare const Byte8Vec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
|
|
48
|
+
export declare const Byte16: Codec<HexLike, Hex>;
|
|
49
|
+
export declare const Byte16Opt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
|
|
50
|
+
export declare const Byte16Vec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
|
|
39
51
|
export declare const Byte32: Codec<HexLike, Hex>;
|
|
40
52
|
export declare const Byte32Opt: Codec<import("../bytes/index.js").BytesLike | null | undefined, `0x${string}` | undefined>;
|
|
41
53
|
export declare const Byte32Vec: Codec<import("../bytes/index.js").BytesLike[], `0x${string}`[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predefined.d.ts","sourceRoot":"","sources":["../../src/molecule/predefined.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAW,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAW,KAAK,EAAoC,MAAM,YAAY,CAAC;AAE9E,eAAO,MAAM,KAAK,+CAAsB,CAAC;AACzC,eAAO,MAAM,QAAQ,8EAAgB,CAAC;AACtC,eAAO,MAAM,QAAQ,mDAAgB,CAAC;AAEtC,eAAO,MAAM,QAAQ,+CAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,+CAAgB,CAAC;AACtC,eAAO,MAAM,MAAM,+CAAW,CAAC;AAC/B,eAAO,MAAM,SAAS,8EAAiB,CAAC;AACxC,eAAO,MAAM,SAAS,mDAAiB,CAAC;AAExC,eAAO,MAAM,QAAQ,+CAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,+CAAgB,CAAC;AACtC,eAAO,MAAM,MAAM,+CAAW,CAAC;AAC/B,eAAO,MAAM,SAAS,8EAAiB,CAAC;AACxC,eAAO,MAAM,SAAS,mDAAiB,CAAC;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 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Byte32Opt = exports.Byte32 = exports.Byte16Vec = exports.Byte16Opt = exports.Byte16 = exports.Byte8Vec = exports.Byte8Opt = exports.Byte8 = exports.Byte4Vec = exports.Byte4Opt = exports.Byte4 = exports.BoolVec = exports.BoolOpt = exports.Bool = exports.BytesVec = exports.BytesOpt = exports.Bytes = exports.Uint512Vec = exports.Uint512Opt = exports.Uint512 = exports.Uint512BE = exports.Uint512LE = exports.Uint256Vec = exports.Uint256Opt = exports.Uint256 = exports.Uint256BE = exports.Uint256LE = exports.Uint128Vec = exports.Uint128Opt = exports.Uint128 = exports.Uint128BE = exports.Uint128LE = exports.Uint64Vec = exports.Uint64Opt = exports.Uint64 = exports.Uint64BE = exports.Uint64LE = exports.Uint32Vec = exports.Uint32Opt = exports.Uint32 = exports.Uint32BE = exports.Uint32LE = exports.Uint16Vec = exports.Uint16Opt = exports.Uint16 = exports.Uint16BE = exports.Uint16LE = exports.Uint8Vec = exports.Uint8Opt = exports.Uint8 = void 0;
|
|
4
|
+
exports.StringOpt = exports.StringVec = exports.String = exports.Byte32Vec = void 0;
|
|
4
5
|
const index_js_1 = require("../bytes/index.js");
|
|
5
6
|
const index_js_2 = require("../hex/index.js");
|
|
6
7
|
const codec_js_1 = require("./codec.js");
|
|
@@ -43,6 +44,34 @@ exports.Bytes = (0, codec_js_1.byteVec)({
|
|
|
43
44
|
});
|
|
44
45
|
exports.BytesOpt = (0, codec_js_1.option)(exports.Bytes);
|
|
45
46
|
exports.BytesVec = (0, codec_js_1.vector)(exports.Bytes);
|
|
47
|
+
exports.Bool = codec_js_1.Codec.from({
|
|
48
|
+
byteLength: 1,
|
|
49
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value ? [1] : [0]),
|
|
50
|
+
decode: (buffer) => (0, index_js_1.bytesFrom)(buffer)[0] !== 0,
|
|
51
|
+
});
|
|
52
|
+
exports.BoolOpt = (0, codec_js_1.option)(exports.Bool);
|
|
53
|
+
exports.BoolVec = (0, codec_js_1.vector)(exports.Bool);
|
|
54
|
+
exports.Byte4 = codec_js_1.Codec.from({
|
|
55
|
+
byteLength: 4,
|
|
56
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value),
|
|
57
|
+
decode: (buffer) => (0, index_js_2.hexFrom)(buffer),
|
|
58
|
+
});
|
|
59
|
+
exports.Byte4Opt = (0, codec_js_1.option)(exports.Byte4);
|
|
60
|
+
exports.Byte4Vec = (0, codec_js_1.vector)(exports.Byte4);
|
|
61
|
+
exports.Byte8 = codec_js_1.Codec.from({
|
|
62
|
+
byteLength: 8,
|
|
63
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value),
|
|
64
|
+
decode: (buffer) => (0, index_js_2.hexFrom)(buffer),
|
|
65
|
+
});
|
|
66
|
+
exports.Byte8Opt = (0, codec_js_1.option)(exports.Byte8);
|
|
67
|
+
exports.Byte8Vec = (0, codec_js_1.vector)(exports.Byte8);
|
|
68
|
+
exports.Byte16 = codec_js_1.Codec.from({
|
|
69
|
+
byteLength: 16,
|
|
70
|
+
encode: (value) => (0, index_js_1.bytesFrom)(value),
|
|
71
|
+
decode: (buffer) => (0, index_js_2.hexFrom)(buffer),
|
|
72
|
+
});
|
|
73
|
+
exports.Byte16Opt = (0, codec_js_1.option)(exports.Byte16);
|
|
74
|
+
exports.Byte16Vec = (0, codec_js_1.vector)(exports.Byte16);
|
|
46
75
|
exports.Byte32 = codec_js_1.Codec.from({
|
|
47
76
|
byteLength: 32,
|
|
48
77
|
encode: (value) => (0, index_js_1.bytesFrom)(value),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/num/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,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G,EAAE,OAAO,GAAG,GAAG,CAE1C;AAED;;;;;;;;;;;;GAYG;AAEH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAE9D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAEhE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAOhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAEhD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAQlD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD"}
|
|
@@ -76,7 +76,11 @@ function numFrom(val) {
|
|
|
76
76
|
if (typeof val === "string" || typeof val === "number") {
|
|
77
77
|
return BigInt(val);
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
const hex = (0, index_js_2.hexFrom)(val);
|
|
80
|
+
if (hex === "0x") {
|
|
81
|
+
return BigInt(0);
|
|
82
|
+
}
|
|
83
|
+
return BigInt(hex);
|
|
80
84
|
}
|
|
81
85
|
/**
|
|
82
86
|
* Converts a NumLike value to a hexadecimal string.
|
|
@@ -173,7 +177,11 @@ function numFromBytes(val) {
|
|
|
173
177
|
* ```
|
|
174
178
|
*/
|
|
175
179
|
function numLeFromBytes(val) {
|
|
176
|
-
|
|
180
|
+
// reverse() modifies the original array
|
|
181
|
+
// so we use the map to copy it to avoid this
|
|
182
|
+
return numBeFromBytes((0, index_js_1.bytesFrom)(val)
|
|
183
|
+
.map((v) => v)
|
|
184
|
+
.reverse());
|
|
177
185
|
}
|
|
178
186
|
/**
|
|
179
187
|
* Converts a byte array to a Num (bigint) assuming big-endian order.
|
package/package.json
CHANGED
package/src/advancedBarrel.ts
CHANGED
package/src/barrel.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./client/index.js";
|
|
|
5
5
|
export * from "./fixedPoint/index.js";
|
|
6
6
|
export * from "./hasher/index.js";
|
|
7
7
|
export * from "./hex/index.js";
|
|
8
|
+
export * from "./jsonRpc/index.js";
|
|
8
9
|
export * from "./keystore/index.js";
|
|
9
10
|
export * from "./molecule/index.js";
|
|
10
11
|
export * from "./num/index.js";
|
package/src/ckb/script.ts
CHANGED
package/src/ckb/transaction.ts
CHANGED
|
@@ -1487,8 +1487,13 @@ export class Transaction extends mol.Entity.Base<
|
|
|
1487
1487
|
return addedCount;
|
|
1488
1488
|
}
|
|
1489
1489
|
|
|
1490
|
-
async completeInputsByUdt(
|
|
1491
|
-
|
|
1490
|
+
async completeInputsByUdt(
|
|
1491
|
+
from: Signer,
|
|
1492
|
+
type: ScriptLike,
|
|
1493
|
+
balanceTweak?: NumLike,
|
|
1494
|
+
): Promise<number> {
|
|
1495
|
+
const exceptedBalance =
|
|
1496
|
+
this.getOutputsUdtBalance(type) + numFrom(balanceTweak ?? 0);
|
|
1492
1497
|
const inputsBalance = await this.getInputsUdtBalance(from.client, type);
|
|
1493
1498
|
if (inputsBalance >= exceptedBalance) {
|
|
1494
1499
|
return 0;
|
|
@@ -1517,6 +1522,51 @@ export class Transaction extends mol.Entity.Base<
|
|
|
1517
1522
|
);
|
|
1518
1523
|
}
|
|
1519
1524
|
|
|
1525
|
+
async completeInputsAddOne(
|
|
1526
|
+
from: Signer,
|
|
1527
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1528
|
+
): Promise<number> {
|
|
1529
|
+
for await (const cell of from.findCells(
|
|
1530
|
+
filter ?? {
|
|
1531
|
+
scriptLenRange: [0, 1],
|
|
1532
|
+
outputDataLenRange: [0, 1],
|
|
1533
|
+
},
|
|
1534
|
+
true,
|
|
1535
|
+
undefined,
|
|
1536
|
+
1,
|
|
1537
|
+
)) {
|
|
1538
|
+
if (
|
|
1539
|
+
this.inputs.some(({ previousOutput }) =>
|
|
1540
|
+
previousOutput.eq(cell.outPoint),
|
|
1541
|
+
)
|
|
1542
|
+
) {
|
|
1543
|
+
continue;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
this.inputs.push(
|
|
1547
|
+
CellInput.from({
|
|
1548
|
+
previousOutput: cell.outPoint,
|
|
1549
|
+
outputData: cell.outputData,
|
|
1550
|
+
cellOutput: cell.cellOutput,
|
|
1551
|
+
}),
|
|
1552
|
+
);
|
|
1553
|
+
return 1;
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
throw new Error(`Insufficient CKB, need at least one new cell`);
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
async completeInputsAtLeastOne(
|
|
1560
|
+
from: Signer,
|
|
1561
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1562
|
+
): Promise<number> {
|
|
1563
|
+
if (this.inputs.length > 0) {
|
|
1564
|
+
return 0;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
return this.completeInputsAddOne(from, filter);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1520
1570
|
estimateFee(feeRate: NumLike): Num {
|
|
1521
1571
|
const txSize = this.toBytes().length + 4;
|
|
1522
1572
|
return (numFrom(txSize) * numFrom(feeRate) + numFrom(1000)) / numFrom(1000);
|
package/src/client/advanced.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import WebSocket from "isomorphic-ws";
|
|
2
|
-
import { ClientCache } from "./cache/index.js";
|
|
3
2
|
import { MAINNET_SCRIPTS } from "./clientPublicMainnet.advanced.js";
|
|
4
3
|
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
5
|
-
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
6
|
-
import { Transport } from "./transports/advanced.js";
|
|
4
|
+
import { ClientJsonRpc, ClientJsonRpcConfig } from "./jsonRpc/index.js";
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* @public
|
|
10
8
|
*/
|
|
11
9
|
export class ClientPublicMainnet extends ClientJsonRpc {
|
|
12
10
|
constructor(
|
|
13
|
-
private readonly config?: {
|
|
11
|
+
private readonly config?: ClientJsonRpcConfig & {
|
|
14
12
|
url?: string;
|
|
15
|
-
timeout?: number;
|
|
16
|
-
maxConcurrent?: number;
|
|
17
|
-
transport?: Transport;
|
|
18
13
|
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
19
|
-
cache?: ClientCache;
|
|
20
14
|
},
|
|
21
15
|
) {
|
|
22
16
|
super(
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import WebSocket from "isomorphic-ws";
|
|
2
|
-
import { ClientCache } from "./cache/index.js";
|
|
3
2
|
import { TESTNET_SCRIPTS } from "./clientPublicTestnet.advanced.js";
|
|
4
3
|
import { KnownScript, ScriptInfo, ScriptInfoLike } from "./clientTypes.js";
|
|
5
|
-
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
6
|
-
import { Transport } from "./transports/advanced.js";
|
|
4
|
+
import { ClientJsonRpc, ClientJsonRpcConfig } from "./jsonRpc/index.js";
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* @public
|
|
10
8
|
*/
|
|
11
9
|
export class ClientPublicTestnet extends ClientJsonRpc {
|
|
12
10
|
constructor(
|
|
13
|
-
private readonly config?: {
|
|
11
|
+
private readonly config?: ClientJsonRpcConfig & {
|
|
14
12
|
url?: string;
|
|
15
|
-
timeout?: number;
|
|
16
|
-
maxConcurrent?: number;
|
|
17
|
-
transport?: Transport;
|
|
18
13
|
scripts?: Record<KnownScript, ScriptInfoLike | undefined>;
|
|
19
|
-
cache?: ClientCache;
|
|
20
14
|
},
|
|
21
15
|
) {
|
|
22
16
|
super(
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cell,
|
|
3
|
+
OutPoint,
|
|
4
|
+
OutPointLike,
|
|
5
|
+
TransactionLike,
|
|
6
|
+
} from "../../ckb/index.js";
|
|
7
|
+
import { Hex, HexLike, hexFrom } from "../../hex/index.js";
|
|
8
|
+
import {
|
|
9
|
+
RequestorJsonRpc,
|
|
10
|
+
RequestorJsonRpcConfig,
|
|
11
|
+
} from "../../jsonRpc/requestor.js";
|
|
12
|
+
import { Num, NumLike, numFrom, numToHex } from "../../num/index.js";
|
|
13
|
+
import { apply } from "../../utils/index.js";
|
|
14
|
+
import { ClientCache } from "../cache/index.js";
|
|
15
|
+
import { Client } from "../client.js";
|
|
16
|
+
import {
|
|
17
|
+
ClientFindCellsResponse,
|
|
18
|
+
ClientIndexerSearchKeyLike,
|
|
19
|
+
ClientTransactionResponse,
|
|
20
|
+
ErrorClientBase,
|
|
21
|
+
ErrorClientBaseLike,
|
|
22
|
+
ErrorClientDuplicatedTransaction,
|
|
23
|
+
ErrorClientRBFRejected,
|
|
24
|
+
ErrorClientResolveUnknown,
|
|
25
|
+
ErrorClientVerification,
|
|
26
|
+
OutputsValidator,
|
|
27
|
+
} from "../clientTypes.js";
|
|
28
|
+
import {
|
|
29
|
+
JsonRpcBlock,
|
|
30
|
+
JsonRpcBlockHeader,
|
|
31
|
+
JsonRpcCellOutput,
|
|
32
|
+
JsonRpcTransformers,
|
|
33
|
+
} from "./advanced.js";
|
|
34
|
+
|
|
35
|
+
const ERROR_PARSERS: [
|
|
36
|
+
string,
|
|
37
|
+
(error: ErrorClientBaseLike, match: RegExpMatchArray) => ErrorClientBase,
|
|
38
|
+
][] = [
|
|
39
|
+
[
|
|
40
|
+
"Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)",
|
|
41
|
+
(error, match) =>
|
|
42
|
+
new ErrorClientResolveUnknown(error, OutPoint.fromBytes(match[1])),
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
"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",
|
|
46
|
+
(error, match) =>
|
|
47
|
+
new ErrorClientVerification(
|
|
48
|
+
error,
|
|
49
|
+
match[3] === "Lock"
|
|
50
|
+
? "lock"
|
|
51
|
+
: match[1] === "Inputs"
|
|
52
|
+
? "inputType"
|
|
53
|
+
: "outputType",
|
|
54
|
+
match[2],
|
|
55
|
+
Number(match[4]),
|
|
56
|
+
match[5] === "data" ? "data" : "type",
|
|
57
|
+
match[6],
|
|
58
|
+
),
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
"Duplicated\\(Byte32\\((0x.*)\\)\\)",
|
|
62
|
+
(error, match) => new ErrorClientDuplicatedTransaction(error, match[1]),
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
'RBFRejected\\("Tx\'s current fee is ([0-9]*), expect it to >= ([0-9]*) to replace old txs"\\)',
|
|
66
|
+
(error, match) => new ErrorClientRBFRejected(error, match[1], match[2]),
|
|
67
|
+
],
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
export type ClientJsonRpcConfig = RequestorJsonRpcConfig & {
|
|
71
|
+
cache?: ClientCache;
|
|
72
|
+
requestor?: RequestorJsonRpc;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
|
|
77
|
+
* Provides methods for sending transactions and building JSON-RPC payloads.
|
|
78
|
+
*/
|
|
79
|
+
export abstract class ClientJsonRpc extends Client {
|
|
80
|
+
public readonly requestor: RequestorJsonRpc;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Creates an instance of ClientJsonRpc.
|
|
84
|
+
*
|
|
85
|
+
* @param url_ - The URL of the JSON-RPC server.
|
|
86
|
+
* @param timeout - The timeout for requests in milliseconds
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
constructor(url_: string, config?: ClientJsonRpcConfig) {
|
|
90
|
+
super(config);
|
|
91
|
+
|
|
92
|
+
this.requestor =
|
|
93
|
+
config?.requestor ??
|
|
94
|
+
new RequestorJsonRpc(url_, config, (errAny) => {
|
|
95
|
+
if (
|
|
96
|
+
typeof errAny !== "object" ||
|
|
97
|
+
errAny === null ||
|
|
98
|
+
!("data" in errAny) ||
|
|
99
|
+
typeof errAny.data !== "string"
|
|
100
|
+
) {
|
|
101
|
+
throw errAny;
|
|
102
|
+
}
|
|
103
|
+
const err = errAny as ErrorClientBaseLike;
|
|
104
|
+
|
|
105
|
+
for (const [regexp, builder] of ERROR_PARSERS) {
|
|
106
|
+
const match = err.data.match(regexp);
|
|
107
|
+
if (match) {
|
|
108
|
+
throw builder(err, match);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
throw new ErrorClientBase(err);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns the URL of the JSON-RPC server.
|
|
118
|
+
*
|
|
119
|
+
* @returns The URL of the JSON-RPC server.
|
|
120
|
+
*/
|
|
121
|
+
get url(): string {
|
|
122
|
+
return this.requestor.url;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get fee rate statistics
|
|
127
|
+
*
|
|
128
|
+
* @returns Fee rate statistics
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
getFeeRateStatistics = this.buildSender(
|
|
132
|
+
"get_fee_rate_statistics",
|
|
133
|
+
[(n: NumLike) => apply(numFrom, n)],
|
|
134
|
+
({ mean, median }: { mean: NumLike; median: NumLike }) => ({
|
|
135
|
+
mean: numFrom(mean),
|
|
136
|
+
median: numFrom(median),
|
|
137
|
+
}),
|
|
138
|
+
) as Client["getFeeRateStatistics"];
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Get tip block number
|
|
142
|
+
*
|
|
143
|
+
* @returns Tip block number
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
getTip = this.buildSender(
|
|
147
|
+
"get_tip_block_number",
|
|
148
|
+
[],
|
|
149
|
+
numFrom,
|
|
150
|
+
) as () => Promise<Num>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get tip block header
|
|
154
|
+
*
|
|
155
|
+
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
156
|
+
* @returns BlockHeader
|
|
157
|
+
*/
|
|
158
|
+
getTipHeader = this.buildSender(
|
|
159
|
+
"get_tip_header",
|
|
160
|
+
[],
|
|
161
|
+
(b: JsonRpcBlockHeader) => apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
162
|
+
) as Client["getTipHeader"];
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get block by block number
|
|
166
|
+
*
|
|
167
|
+
* @param blockNumber - The block number.
|
|
168
|
+
* @param verbosity - result format which allows 0 and 2. (Optional, the default is 2.)
|
|
169
|
+
* @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
|
|
170
|
+
* @returns Block
|
|
171
|
+
*/
|
|
172
|
+
getBlockByNumber = this.buildSender(
|
|
173
|
+
"get_block_by_number",
|
|
174
|
+
[(v: NumLike) => numToHex(numFrom(v))],
|
|
175
|
+
(b: JsonRpcBlock) => apply(JsonRpcTransformers.blockTo, b),
|
|
176
|
+
) as Client["getBlockByNumber"];
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get block by block hash
|
|
180
|
+
*
|
|
181
|
+
* @param blockHash - The block hash.
|
|
182
|
+
* @param verbosity - result format which allows 0 and 2. (Optional, the default is 2.)
|
|
183
|
+
* @param withCycles - whether the return cycles of block transactions. (Optional, default false.)
|
|
184
|
+
* @returns Block
|
|
185
|
+
*/
|
|
186
|
+
getBlockByHash = this.buildSender("get_block", [hexFrom], (b: JsonRpcBlock) =>
|
|
187
|
+
apply(JsonRpcTransformers.blockTo, b),
|
|
188
|
+
) as Client["getBlockByHash"];
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Get header by block number
|
|
192
|
+
*
|
|
193
|
+
* @param blockNumber - The block number.
|
|
194
|
+
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
195
|
+
* @returns BlockHeader
|
|
196
|
+
*/
|
|
197
|
+
getHeaderByNumber = this.buildSender(
|
|
198
|
+
"get_header_by_number",
|
|
199
|
+
[(v: NumLike) => numToHex(numFrom(v))],
|
|
200
|
+
(b: JsonRpcBlockHeader) => apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
201
|
+
) as Client["getHeaderByNumber"];
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Get header by block hash
|
|
205
|
+
*
|
|
206
|
+
* @param blockHash - The block hash.
|
|
207
|
+
* @param verbosity - result format which allows 0 and 1. (Optional, the default is 1.)
|
|
208
|
+
* @returns BlockHeader
|
|
209
|
+
*/
|
|
210
|
+
getHeaderByHash = this.buildSender(
|
|
211
|
+
"get_header",
|
|
212
|
+
[hexFrom],
|
|
213
|
+
(b: JsonRpcBlockHeader) => apply(JsonRpcTransformers.blockHeaderTo, b),
|
|
214
|
+
) as Client["getHeaderByHash"];
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Estimate cycles of a transaction.
|
|
218
|
+
*
|
|
219
|
+
* @param transaction - The transaction to estimate.
|
|
220
|
+
* @returns Consumed cycles
|
|
221
|
+
*/
|
|
222
|
+
estimateCycles = this.buildSender(
|
|
223
|
+
"estimate_cycles",
|
|
224
|
+
[JsonRpcTransformers.transactionFrom],
|
|
225
|
+
({ cycles }: { cycles: NumLike }) => numFrom(cycles),
|
|
226
|
+
) as Client["estimateCycles"];
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Test a transaction.
|
|
230
|
+
*
|
|
231
|
+
* @param transaction - The transaction to test.
|
|
232
|
+
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
233
|
+
* @returns Consumed cycles
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
sendTransactionDry = this.buildSender(
|
|
237
|
+
"test_tx_pool_accept",
|
|
238
|
+
[JsonRpcTransformers.transactionFrom],
|
|
239
|
+
({ cycles }: { cycles: NumLike }) => numFrom(cycles),
|
|
240
|
+
) as Client["sendTransactionDry"];
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Send a transaction to node.
|
|
244
|
+
*
|
|
245
|
+
* @param transaction - The transaction to send.
|
|
246
|
+
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
247
|
+
* @returns Transaction hash.
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
sendTransactionNoCache = this.buildSender(
|
|
251
|
+
"send_transaction",
|
|
252
|
+
[JsonRpcTransformers.transactionFrom],
|
|
253
|
+
hexFrom,
|
|
254
|
+
) as (
|
|
255
|
+
transaction: TransactionLike,
|
|
256
|
+
validator?: OutputsValidator | undefined,
|
|
257
|
+
) => Promise<Hex>;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Get a transaction from node.
|
|
261
|
+
*
|
|
262
|
+
* @param txHash - The hash of the transaction.
|
|
263
|
+
* @returns The transaction with status.
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
getTransactionNoCache = this.buildSender(
|
|
267
|
+
"get_transaction",
|
|
268
|
+
[hexFrom],
|
|
269
|
+
JsonRpcTransformers.transactionResponseTo,
|
|
270
|
+
) as (txHash: HexLike) => Promise<ClientTransactionResponse | undefined>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Get a live cell from node.
|
|
274
|
+
*
|
|
275
|
+
* @param outPoint - The out point of the cell.
|
|
276
|
+
* @param withData - Include data in the response.
|
|
277
|
+
* @param includeTxPool - Include cells in the tx pool.
|
|
278
|
+
* @returns The cell
|
|
279
|
+
*/
|
|
280
|
+
getCellLiveNoCache(
|
|
281
|
+
outPoint: OutPointLike,
|
|
282
|
+
withData?: boolean | null,
|
|
283
|
+
includeTxPool?: boolean | null,
|
|
284
|
+
) {
|
|
285
|
+
return this.buildSender(
|
|
286
|
+
"get_live_cell",
|
|
287
|
+
[JsonRpcTransformers.outPointFrom],
|
|
288
|
+
({
|
|
289
|
+
cell,
|
|
290
|
+
}: {
|
|
291
|
+
cell?: {
|
|
292
|
+
output: JsonRpcCellOutput;
|
|
293
|
+
data?: { content: HexLike; hash: HexLike };
|
|
294
|
+
};
|
|
295
|
+
}) =>
|
|
296
|
+
apply(
|
|
297
|
+
({
|
|
298
|
+
output,
|
|
299
|
+
data,
|
|
300
|
+
}: {
|
|
301
|
+
output: JsonRpcCellOutput;
|
|
302
|
+
data?: { content: HexLike; hash: HexLike };
|
|
303
|
+
}) =>
|
|
304
|
+
Cell.from({
|
|
305
|
+
cellOutput: JsonRpcTransformers.cellOutputTo(output),
|
|
306
|
+
outputData: data?.content ?? "0x",
|
|
307
|
+
outPoint,
|
|
308
|
+
}),
|
|
309
|
+
cell,
|
|
310
|
+
),
|
|
311
|
+
)(outPoint, withData ?? true, includeTxPool) as Promise<Cell | undefined>;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* find cells from node.
|
|
316
|
+
*
|
|
317
|
+
* @param key - The search key of cells.
|
|
318
|
+
* @param order - The order of cells.
|
|
319
|
+
* @param limit - The max return size of cells.
|
|
320
|
+
* @param after - Pagination parameter.
|
|
321
|
+
* @returns The found cells.
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
findCellsPagedNoCache = this.buildSender(
|
|
325
|
+
"get_cells",
|
|
326
|
+
[
|
|
327
|
+
JsonRpcTransformers.indexerSearchKeyFrom,
|
|
328
|
+
(order?: "asc" | "desc") => order ?? "asc",
|
|
329
|
+
(limit?: NumLike) => numToHex(limit ?? 10),
|
|
330
|
+
],
|
|
331
|
+
JsonRpcTransformers.findCellsResponseTo,
|
|
332
|
+
) as (
|
|
333
|
+
key: ClientIndexerSearchKeyLike,
|
|
334
|
+
order?: "asc" | "desc",
|
|
335
|
+
limit?: NumLike,
|
|
336
|
+
after?: string,
|
|
337
|
+
) => Promise<ClientFindCellsResponse>;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* find transactions from node.
|
|
341
|
+
*
|
|
342
|
+
* @param key - The search key of transactions.
|
|
343
|
+
* @param order - The order of transactions.
|
|
344
|
+
* @param limit - The max return size of transactions.
|
|
345
|
+
* @param after - Pagination parameter.
|
|
346
|
+
* @returns The found transactions.
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
findTransactionsPaged = this.buildSender(
|
|
350
|
+
"get_transactions",
|
|
351
|
+
[
|
|
352
|
+
JsonRpcTransformers.indexerSearchKeyTransactionFrom,
|
|
353
|
+
(order?: "asc" | "desc") => order ?? "asc",
|
|
354
|
+
(limit?: NumLike) => numToHex(limit ?? 10),
|
|
355
|
+
],
|
|
356
|
+
JsonRpcTransformers.findTransactionsResponseTo,
|
|
357
|
+
) as Client["findTransactionsPaged"];
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* get cells capacity from node.
|
|
361
|
+
*
|
|
362
|
+
* @param key - The search key of cells.
|
|
363
|
+
* @returns The sum of cells capacity.
|
|
364
|
+
*/
|
|
365
|
+
|
|
366
|
+
getCellsCapacity = this.buildSender(
|
|
367
|
+
"get_cells_capacity",
|
|
368
|
+
[JsonRpcTransformers.indexerSearchKeyFrom],
|
|
369
|
+
({ capacity }: { capacity: NumLike }) => numFrom(capacity),
|
|
370
|
+
) as (key: ClientIndexerSearchKeyLike) => Promise<Num>;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Builds a sender function for a JSON-RPC method.
|
|
374
|
+
*
|
|
375
|
+
* @param rpcMethod - The JSON-RPC method.
|
|
376
|
+
* @param inTransformers - An array of input transformers.
|
|
377
|
+
* @param outTransformer - An output transformer function.
|
|
378
|
+
* @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
|
|
379
|
+
*/
|
|
380
|
+
|
|
381
|
+
buildSender(
|
|
382
|
+
rpcMethod: Parameters<RequestorJsonRpc["request"]>[0],
|
|
383
|
+
inTransformers?: Parameters<RequestorJsonRpc["request"]>[2],
|
|
384
|
+
outTransformer?: Parameters<RequestorJsonRpc["request"]>[3],
|
|
385
|
+
): (...req: unknown[]) => Promise<unknown> {
|
|
386
|
+
return async (...req: unknown[]) => {
|
|
387
|
+
return this.requestor.request(
|
|
388
|
+
rpcMethod,
|
|
389
|
+
req,
|
|
390
|
+
inTransformers,
|
|
391
|
+
outTransformer,
|
|
392
|
+
);
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
}
|