@ckb-ccc/core 0.0.4-alpha.3 → 0.0.4-alpha.5
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/dist/client/advanced.d.ts +1 -0
- package/dist/client/advanced.d.ts.map +1 -1
- package/dist/client/advanced.js +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/jsonRpc/index.js +2 -2
- package/dist/client/jsonRpc/transformers.d.ts +17 -17
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
- package/dist/client/jsonRpc/transformers.js +36 -36
- package/package.json +2 -2
- package/src/client/advanced.ts +1 -0
- package/src/client/index.ts +1 -0
- package/src/client/jsonRpc/index.ts +2 -2
- package/src/client/jsonRpc/transformers.ts +38 -36
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oBAAoB,CAAC"}
|
package/dist/client/advanced.js
CHANGED
package/dist/client/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -43,14 +43,14 @@ export class ClientJsonRpc extends Client {
|
|
|
43
43
|
* @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
|
|
44
44
|
* @returns Transaction hash.
|
|
45
45
|
*/
|
|
46
|
-
this.sendTransaction = this.buildSender("send_transaction", [JsonRpcTransformers.
|
|
46
|
+
this.sendTransaction = this.buildSender("send_transaction", [JsonRpcTransformers.transactionFrom], hexFrom);
|
|
47
47
|
/**
|
|
48
48
|
* Get a transaction from node.
|
|
49
49
|
*
|
|
50
50
|
* @param txHash - The hash of the transaction.
|
|
51
51
|
* @returns The transaction with status.
|
|
52
52
|
*/
|
|
53
|
-
this.getTransaction = this.buildSender("get_transaction", [hexFrom], JsonRpcTransformers.
|
|
53
|
+
this.getTransaction = this.buildSender("get_transaction", [hexFrom], JsonRpcTransformers.transactionResponseTo);
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Returns the URL of the JSON-RPC server.
|
|
@@ -2,23 +2,23 @@ import { CellDep, CellDepLike, CellInput, CellInputLike, CellOutput, CellOutputL
|
|
|
2
2
|
import { ClientTransactionResponse, TransactionStatus } from "../clientTypes";
|
|
3
3
|
import { JsonRpcCellDep, JsonRpcCellInput, JsonRpcCellOutput, JsonRpcDepType, JsonRpcHashType, JsonRpcOutPoint, JsonRpcScript, JsonRpcTransaction } from "./types";
|
|
4
4
|
export declare class JsonRpcTransformers {
|
|
5
|
-
static
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static
|
|
15
|
-
static
|
|
16
|
-
static
|
|
17
|
-
static
|
|
18
|
-
static
|
|
19
|
-
static
|
|
20
|
-
static
|
|
21
|
-
static
|
|
5
|
+
static hashTypeFrom(hashType: HashTypeLike): JsonRpcHashType;
|
|
6
|
+
static hashTypeTo(hashType: JsonRpcHashType): HashType;
|
|
7
|
+
static depTypeFrom(depType: DepTypeLike): JsonRpcDepType;
|
|
8
|
+
static depTypeTo(depType: JsonRpcDepType): DepType;
|
|
9
|
+
static scriptFrom(scriptLike: ScriptLike): JsonRpcScript;
|
|
10
|
+
static scriptTo(script: JsonRpcScript): Script;
|
|
11
|
+
static outPointFrom(outPointLike: OutPointLike): JsonRpcOutPoint;
|
|
12
|
+
static outPointTo(outPoint: JsonRpcOutPoint): OutPoint;
|
|
13
|
+
static cellInputFrom(cellInput: CellInputLike): JsonRpcCellInput;
|
|
14
|
+
static cellInputTo(cellInput: JsonRpcCellInput): CellInput;
|
|
15
|
+
static cellOutputFrom(cellOutput: CellOutputLike): JsonRpcCellOutput;
|
|
16
|
+
static cellOutputTo(cellOutput: JsonRpcCellOutput): CellOutput;
|
|
17
|
+
static cellDepFrom(cellDep: CellDepLike): JsonRpcCellDep;
|
|
18
|
+
static cellDepTo(cellDep: JsonRpcCellDep): CellDep;
|
|
19
|
+
static transactionFrom(txLike: TransactionLike): JsonRpcTransaction;
|
|
20
|
+
static transactionTo(tx: JsonRpcTransaction): Transaction;
|
|
21
|
+
static transactionResponseTo({ tx_status: { status }, transaction, }: {
|
|
22
22
|
tx_status: {
|
|
23
23
|
status: TransactionStatus;
|
|
24
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,UAAU,EACV,WAAW,EACX,eAAe,EAGhB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,EACb,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/transformers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,UAAU,EACV,WAAW,EACX,eAAe,EAGhB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,EACb,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,eAAe;IAG5D,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ;IAGtD,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc;IAQxD,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAQlD,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,aAAa;IAQxD,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;IAO9C,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,eAAe;IAOhE,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,QAAQ;IAMtD,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,GAAG,gBAAgB;IAQhE,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,gBAAgB,GAAG,SAAS;IAM1D,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,cAAc,GAAG,iBAAiB;IAOpE,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,iBAAiB,GAAG,UAAU;IAO9D,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc;IAMxD,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAMlD,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,kBAAkB;IAYnE,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,kBAAkB,GAAG,WAAW;IAWzD,MAAM,CAAC,qBAAqB,CAAC,EAC3B,SAAS,EAAE,EAAE,MAAM,EAAE,EACrB,WAAW,GACZ,EAAE;QACD,SAAS,EAAE;YAAE,MAAM,EAAE,iBAAiB,CAAA;SAAE,CAAC;QACzC,WAAW,EAAE,kBAAkB,CAAC;KACjC,GAAG,yBAAyB;CAM9B"}
|
|
@@ -2,13 +2,13 @@ import { CellDep, CellInput, CellOutput, OutPoint, Script, Transaction, depTypeF
|
|
|
2
2
|
import { numToHex } from "../../num";
|
|
3
3
|
import { apply } from "../../utils";
|
|
4
4
|
export class JsonRpcTransformers {
|
|
5
|
-
static
|
|
5
|
+
static hashTypeFrom(hashType) {
|
|
6
6
|
return hashTypeFrom(hashType);
|
|
7
7
|
}
|
|
8
|
-
static
|
|
8
|
+
static hashTypeTo(hashType) {
|
|
9
9
|
return hashType;
|
|
10
10
|
}
|
|
11
|
-
static
|
|
11
|
+
static depTypeFrom(depType) {
|
|
12
12
|
switch (depTypeFrom(depType)) {
|
|
13
13
|
case "code":
|
|
14
14
|
return "code";
|
|
@@ -16,7 +16,7 @@ export class JsonRpcTransformers {
|
|
|
16
16
|
return "dep_group";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
static
|
|
19
|
+
static depTypeTo(depType) {
|
|
20
20
|
switch (depType) {
|
|
21
21
|
case "code":
|
|
22
22
|
return "code";
|
|
@@ -24,98 +24,98 @@ export class JsonRpcTransformers {
|
|
|
24
24
|
return "depGroup";
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
static
|
|
27
|
+
static scriptFrom(scriptLike) {
|
|
28
28
|
const script = Script.from(scriptLike);
|
|
29
29
|
return {
|
|
30
30
|
code_hash: script.codeHash,
|
|
31
|
-
hash_type: JsonRpcTransformers.
|
|
31
|
+
hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
|
|
32
32
|
args: script.args,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
static
|
|
35
|
+
static scriptTo(script) {
|
|
36
36
|
return Script.from({
|
|
37
37
|
codeHash: script.code_hash,
|
|
38
|
-
hashType: JsonRpcTransformers.
|
|
38
|
+
hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
|
|
39
39
|
args: script.args,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
static
|
|
42
|
+
static outPointFrom(outPointLike) {
|
|
43
43
|
const outPoint = OutPoint.from(outPointLike);
|
|
44
44
|
return {
|
|
45
45
|
index: numToHex(outPoint.index),
|
|
46
46
|
tx_hash: outPoint.txHash,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
static
|
|
49
|
+
static outPointTo(outPoint) {
|
|
50
50
|
return OutPoint.from({
|
|
51
51
|
index: outPoint.index,
|
|
52
52
|
txHash: outPoint.tx_hash,
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
static
|
|
55
|
+
static cellInputFrom(cellInput) {
|
|
56
56
|
return {
|
|
57
|
-
previous_output: JsonRpcTransformers.
|
|
57
|
+
previous_output: JsonRpcTransformers.outPointFrom(cellInput.previousOutput),
|
|
58
58
|
since: numToHex(cellInput.since),
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
static
|
|
61
|
+
static cellInputTo(cellInput) {
|
|
62
62
|
return CellInput.from({
|
|
63
|
-
previousOutput:
|
|
63
|
+
previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
|
|
64
64
|
since: cellInput.since,
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
static
|
|
67
|
+
static cellOutputFrom(cellOutput) {
|
|
68
68
|
return {
|
|
69
69
|
capacity: numToHex(cellOutput.capacity),
|
|
70
|
-
lock: JsonRpcTransformers.
|
|
71
|
-
type: apply(JsonRpcTransformers.
|
|
70
|
+
lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
|
|
71
|
+
type: apply(JsonRpcTransformers.scriptFrom, cellOutput.type),
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
static
|
|
74
|
+
static cellOutputTo(cellOutput) {
|
|
75
75
|
return CellOutput.from({
|
|
76
76
|
capacity: cellOutput.capacity,
|
|
77
|
-
lock: JsonRpcTransformers.
|
|
78
|
-
type: apply(JsonRpcTransformers.
|
|
77
|
+
lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
|
|
78
|
+
type: apply(JsonRpcTransformers.scriptTo, cellOutput.type),
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
static
|
|
81
|
+
static cellDepFrom(cellDep) {
|
|
82
82
|
return {
|
|
83
|
-
out_point: JsonRpcTransformers.
|
|
84
|
-
dep_type: JsonRpcTransformers.
|
|
83
|
+
out_point: JsonRpcTransformers.outPointFrom(cellDep.outPoint),
|
|
84
|
+
dep_type: JsonRpcTransformers.depTypeFrom(cellDep.depType),
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
static
|
|
87
|
+
static cellDepTo(cellDep) {
|
|
88
88
|
return CellDep.from({
|
|
89
|
-
outPoint: JsonRpcTransformers.
|
|
90
|
-
depType: JsonRpcTransformers.
|
|
89
|
+
outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
|
|
90
|
+
depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
static
|
|
93
|
+
static transactionFrom(txLike) {
|
|
94
94
|
const tx = Transaction.from(txLike);
|
|
95
95
|
return {
|
|
96
96
|
version: numToHex(tx.version),
|
|
97
|
-
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.
|
|
97
|
+
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
|
|
98
98
|
header_deps: tx.headerDeps,
|
|
99
|
-
inputs: tx.inputs.map((i) => JsonRpcTransformers.
|
|
100
|
-
outputs: tx.outputs.map((o) => JsonRpcTransformers.
|
|
99
|
+
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
|
|
100
|
+
outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputFrom(o)),
|
|
101
101
|
outputs_data: tx.outputsData,
|
|
102
102
|
witnesses: tx.witnesses,
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
static
|
|
105
|
+
static transactionTo(tx) {
|
|
106
106
|
return Transaction.from({
|
|
107
107
|
version: tx.version,
|
|
108
|
-
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.
|
|
108
|
+
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
|
|
109
109
|
headerDeps: tx.header_deps,
|
|
110
|
-
inputs: tx.inputs.map((i) => JsonRpcTransformers.
|
|
111
|
-
outputs: tx.outputs.map((o) => JsonRpcTransformers.
|
|
110
|
+
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputTo(i)),
|
|
111
|
+
outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputTo(o)),
|
|
112
112
|
outputsData: tx.outputs_data,
|
|
113
113
|
witnesses: tx.witnesses,
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
-
static
|
|
116
|
+
static transactionResponseTo({ tx_status: { status }, transaction, }) {
|
|
117
117
|
return {
|
|
118
|
-
transaction: JsonRpcTransformers.
|
|
118
|
+
transaction: JsonRpcTransformers.transactionTo(transaction),
|
|
119
119
|
status,
|
|
120
120
|
};
|
|
121
121
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.0.4-alpha.
|
|
3
|
+
"version": "0.0.4-alpha.5",
|
|
4
4
|
"description": "Common Chains Connector Core",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"buffer": "^6.0.3",
|
|
48
48
|
"cross-fetch": "^4.0.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "20746c0e9160fbf6eb519d5081897ae55042275a"
|
|
51
51
|
}
|
package/src/client/advanced.ts
CHANGED
package/src/client/index.ts
CHANGED
|
@@ -69,7 +69,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
69
69
|
|
|
70
70
|
sendTransaction = this.buildSender(
|
|
71
71
|
"send_transaction",
|
|
72
|
-
[JsonRpcTransformers.
|
|
72
|
+
[JsonRpcTransformers.transactionFrom],
|
|
73
73
|
hexFrom,
|
|
74
74
|
) as (
|
|
75
75
|
transaction: TransactionLike,
|
|
@@ -86,7 +86,7 @@ export abstract class ClientJsonRpc extends Client {
|
|
|
86
86
|
getTransaction = this.buildSender(
|
|
87
87
|
"get_transaction",
|
|
88
88
|
[hexFrom],
|
|
89
|
-
JsonRpcTransformers.
|
|
89
|
+
JsonRpcTransformers.transactionResponseTo,
|
|
90
90
|
) as (txHash: HexLike) => Promise<ClientTransactionResponse>;
|
|
91
91
|
|
|
92
92
|
/**
|
|
@@ -33,13 +33,13 @@ import {
|
|
|
33
33
|
} from "./types";
|
|
34
34
|
|
|
35
35
|
export class JsonRpcTransformers {
|
|
36
|
-
static
|
|
36
|
+
static hashTypeFrom(hashType: HashTypeLike): JsonRpcHashType {
|
|
37
37
|
return hashTypeFrom(hashType);
|
|
38
38
|
}
|
|
39
|
-
static
|
|
39
|
+
static hashTypeTo(hashType: JsonRpcHashType): HashType {
|
|
40
40
|
return hashType;
|
|
41
41
|
}
|
|
42
|
-
static
|
|
42
|
+
static depTypeFrom(depType: DepTypeLike): JsonRpcDepType {
|
|
43
43
|
switch (depTypeFrom(depType)) {
|
|
44
44
|
case "code":
|
|
45
45
|
return "code";
|
|
@@ -47,7 +47,7 @@ export class JsonRpcTransformers {
|
|
|
47
47
|
return "dep_group";
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
static
|
|
50
|
+
static depTypeTo(depType: JsonRpcDepType): DepType {
|
|
51
51
|
switch (depType) {
|
|
52
52
|
case "code":
|
|
53
53
|
return "code";
|
|
@@ -55,96 +55,98 @@ export class JsonRpcTransformers {
|
|
|
55
55
|
return "depGroup";
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
static
|
|
58
|
+
static scriptFrom(scriptLike: ScriptLike): JsonRpcScript {
|
|
59
59
|
const script = Script.from(scriptLike);
|
|
60
60
|
return {
|
|
61
61
|
code_hash: script.codeHash,
|
|
62
|
-
hash_type: JsonRpcTransformers.
|
|
62
|
+
hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
|
|
63
63
|
args: script.args,
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
static
|
|
66
|
+
static scriptTo(script: JsonRpcScript): Script {
|
|
67
67
|
return Script.from({
|
|
68
68
|
codeHash: script.code_hash,
|
|
69
|
-
hashType: JsonRpcTransformers.
|
|
69
|
+
hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
|
|
70
70
|
args: script.args,
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
static
|
|
73
|
+
static outPointFrom(outPointLike: OutPointLike): JsonRpcOutPoint {
|
|
74
74
|
const outPoint = OutPoint.from(outPointLike);
|
|
75
75
|
return {
|
|
76
76
|
index: numToHex(outPoint.index),
|
|
77
77
|
tx_hash: outPoint.txHash,
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
static
|
|
80
|
+
static outPointTo(outPoint: JsonRpcOutPoint): OutPoint {
|
|
81
81
|
return OutPoint.from({
|
|
82
82
|
index: outPoint.index,
|
|
83
83
|
txHash: outPoint.tx_hash,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
static
|
|
86
|
+
static cellInputFrom(cellInput: CellInputLike): JsonRpcCellInput {
|
|
87
87
|
return {
|
|
88
|
-
previous_output: JsonRpcTransformers.
|
|
88
|
+
previous_output: JsonRpcTransformers.outPointFrom(
|
|
89
|
+
cellInput.previousOutput,
|
|
90
|
+
),
|
|
89
91
|
since: numToHex(cellInput.since),
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
|
-
static
|
|
94
|
+
static cellInputTo(cellInput: JsonRpcCellInput): CellInput {
|
|
93
95
|
return CellInput.from({
|
|
94
|
-
previousOutput:
|
|
96
|
+
previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
|
|
95
97
|
since: cellInput.since,
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
|
-
static
|
|
100
|
+
static cellOutputFrom(cellOutput: CellOutputLike): JsonRpcCellOutput {
|
|
99
101
|
return {
|
|
100
102
|
capacity: numToHex(cellOutput.capacity),
|
|
101
|
-
lock: JsonRpcTransformers.
|
|
102
|
-
type: apply(JsonRpcTransformers.
|
|
103
|
+
lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
|
|
104
|
+
type: apply(JsonRpcTransformers.scriptFrom, cellOutput.type),
|
|
103
105
|
};
|
|
104
106
|
}
|
|
105
|
-
static
|
|
107
|
+
static cellOutputTo(cellOutput: JsonRpcCellOutput): CellOutput {
|
|
106
108
|
return CellOutput.from({
|
|
107
109
|
capacity: cellOutput.capacity,
|
|
108
|
-
lock: JsonRpcTransformers.
|
|
109
|
-
type: apply(JsonRpcTransformers.
|
|
110
|
+
lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
|
|
111
|
+
type: apply(JsonRpcTransformers.scriptTo, cellOutput.type),
|
|
110
112
|
});
|
|
111
113
|
}
|
|
112
|
-
static
|
|
114
|
+
static cellDepFrom(cellDep: CellDepLike): JsonRpcCellDep {
|
|
113
115
|
return {
|
|
114
|
-
out_point: JsonRpcTransformers.
|
|
115
|
-
dep_type: JsonRpcTransformers.
|
|
116
|
+
out_point: JsonRpcTransformers.outPointFrom(cellDep.outPoint),
|
|
117
|
+
dep_type: JsonRpcTransformers.depTypeFrom(cellDep.depType),
|
|
116
118
|
};
|
|
117
119
|
}
|
|
118
|
-
static
|
|
120
|
+
static cellDepTo(cellDep: JsonRpcCellDep): CellDep {
|
|
119
121
|
return CellDep.from({
|
|
120
|
-
outPoint: JsonRpcTransformers.
|
|
121
|
-
depType: JsonRpcTransformers.
|
|
122
|
+
outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
|
|
123
|
+
depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
|
|
122
124
|
});
|
|
123
125
|
}
|
|
124
|
-
static
|
|
126
|
+
static transactionFrom(txLike: TransactionLike): JsonRpcTransaction {
|
|
125
127
|
const tx = Transaction.from(txLike);
|
|
126
128
|
return {
|
|
127
129
|
version: numToHex(tx.version),
|
|
128
|
-
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.
|
|
130
|
+
cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
|
|
129
131
|
header_deps: tx.headerDeps,
|
|
130
|
-
inputs: tx.inputs.map((i) => JsonRpcTransformers.
|
|
131
|
-
outputs: tx.outputs.map((o) => JsonRpcTransformers.
|
|
132
|
+
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
|
|
133
|
+
outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputFrom(o)),
|
|
132
134
|
outputs_data: tx.outputsData,
|
|
133
135
|
witnesses: tx.witnesses,
|
|
134
136
|
};
|
|
135
137
|
}
|
|
136
|
-
static
|
|
138
|
+
static transactionTo(tx: JsonRpcTransaction): Transaction {
|
|
137
139
|
return Transaction.from({
|
|
138
140
|
version: tx.version,
|
|
139
|
-
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.
|
|
141
|
+
cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
|
|
140
142
|
headerDeps: tx.header_deps,
|
|
141
|
-
inputs: tx.inputs.map((i) => JsonRpcTransformers.
|
|
142
|
-
outputs: tx.outputs.map((o) => JsonRpcTransformers.
|
|
143
|
+
inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputTo(i)),
|
|
144
|
+
outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputTo(o)),
|
|
143
145
|
outputsData: tx.outputs_data,
|
|
144
146
|
witnesses: tx.witnesses,
|
|
145
147
|
});
|
|
146
148
|
}
|
|
147
|
-
static
|
|
149
|
+
static transactionResponseTo({
|
|
148
150
|
tx_status: { status },
|
|
149
151
|
transaction,
|
|
150
152
|
}: {
|
|
@@ -152,7 +154,7 @@ export class JsonRpcTransformers {
|
|
|
152
154
|
transaction: JsonRpcTransaction;
|
|
153
155
|
}): ClientTransactionResponse {
|
|
154
156
|
return {
|
|
155
|
-
transaction: JsonRpcTransformers.
|
|
157
|
+
transaction: JsonRpcTransformers.transactionTo(transaction),
|
|
156
158
|
status,
|
|
157
159
|
};
|
|
158
160
|
}
|