@ckb-ccc/core 0.0.4-alpha.4 → 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.
@@ -1,3 +1,4 @@
1
1
  export * from "./clientPublicMainnet.advanced";
2
2
  export * from "./clientPublicTestnet.advanced";
3
+ export * from "./jsonRpc/advanced";
3
4
  //# sourceMappingURL=advanced.d.ts.map
@@ -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"}
@@ -1,2 +1,3 @@
1
1
  export * from "./clientPublicMainnet.advanced";
2
2
  export * from "./clientPublicTestnet.advanced";
3
+ export * from "./jsonRpc/advanced";
@@ -2,4 +2,5 @@ export * from "./client";
2
2
  export * from "./clientPublicMainnet";
3
3
  export * from "./clientPublicTestnet";
4
4
  export * from "./clientTypes";
5
+ export * from "./jsonRpc";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -2,3 +2,4 @@ export * from "./client";
2
2
  export * from "./clientPublicMainnet";
3
3
  export * from "./clientPublicTestnet";
4
4
  export * from "./clientTypes";
5
+ export * from "./jsonRpc";
@@ -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.toTransaction], hexFrom);
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.fromTransactionResponse);
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 toHashType(hashType: HashTypeLike): JsonRpcHashType;
6
- static fromHashType(hashType: JsonRpcHashType): HashType;
7
- static toDepType(depType: DepTypeLike): JsonRpcDepType;
8
- static fromDepType(depType: JsonRpcDepType): DepType;
9
- static toScript(scriptLike: ScriptLike): JsonRpcScript;
10
- static fromScript(script: JsonRpcScript): Script;
11
- static toOutPoint(outPointLike: OutPointLike): JsonRpcOutPoint;
12
- static fromOutPoint(outPoint: JsonRpcOutPoint): OutPoint;
13
- static toCellInput(cellInput: CellInputLike): JsonRpcCellInput;
14
- static fromCellInput(cellInput: JsonRpcCellInput): CellInput;
15
- static toCellOutput(cellOutput: CellOutputLike): JsonRpcCellOutput;
16
- static fromCellOutput(cellOutput: JsonRpcCellOutput): CellOutput;
17
- static toCellDep(cellDep: CellDepLike): JsonRpcCellDep;
18
- static fromCellDep(cellDep: JsonRpcCellDep): CellDep;
19
- static toTransaction(txLike: TransactionLike): JsonRpcTransaction;
20
- static fromTransaction(tx: JsonRpcTransaction): Transaction;
21
- static fromTransactionResponse({ tx_status: { status }, transaction, }: {
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,EAC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AAM;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 toHashType(hashType) {
5
+ static hashTypeFrom(hashType) {
6
6
  return hashTypeFrom(hashType);
7
7
  }
8
- static fromHashType(hashType) {
8
+ static hashTypeTo(hashType) {
9
9
  return hashType;
10
10
  }
11
- static toDepType(depType) {
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 fromDepType(depType) {
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 toScript(scriptLike) {
27
+ static scriptFrom(scriptLike) {
28
28
  const script = Script.from(scriptLike);
29
29
  return {
30
30
  code_hash: script.codeHash,
31
- hash_type: JsonRpcTransformers.toHashType(script.hashType),
31
+ hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
32
32
  args: script.args,
33
33
  };
34
34
  }
35
- static fromScript(script) {
35
+ static scriptTo(script) {
36
36
  return Script.from({
37
37
  codeHash: script.code_hash,
38
- hashType: JsonRpcTransformers.fromHashType(script.hash_type),
38
+ hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
39
39
  args: script.args,
40
40
  });
41
41
  }
42
- static toOutPoint(outPointLike) {
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 fromOutPoint(outPoint) {
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 toCellInput(cellInput) {
55
+ static cellInputFrom(cellInput) {
56
56
  return {
57
- previous_output: JsonRpcTransformers.toOutPoint(cellInput.previousOutput),
57
+ previous_output: JsonRpcTransformers.outPointFrom(cellInput.previousOutput),
58
58
  since: numToHex(cellInput.since),
59
59
  };
60
60
  }
61
- static fromCellInput(cellInput) {
61
+ static cellInputTo(cellInput) {
62
62
  return CellInput.from({
63
- previousOutput: this.fromOutPoint(cellInput.previous_output),
63
+ previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
64
64
  since: cellInput.since,
65
65
  });
66
66
  }
67
- static toCellOutput(cellOutput) {
67
+ static cellOutputFrom(cellOutput) {
68
68
  return {
69
69
  capacity: numToHex(cellOutput.capacity),
70
- lock: JsonRpcTransformers.toScript(cellOutput.lock),
71
- type: apply(JsonRpcTransformers.toScript, cellOutput.type),
70
+ lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
71
+ type: apply(JsonRpcTransformers.scriptFrom, cellOutput.type),
72
72
  };
73
73
  }
74
- static fromCellOutput(cellOutput) {
74
+ static cellOutputTo(cellOutput) {
75
75
  return CellOutput.from({
76
76
  capacity: cellOutput.capacity,
77
- lock: JsonRpcTransformers.fromScript(cellOutput.lock),
78
- type: apply(JsonRpcTransformers.fromScript, cellOutput.type),
77
+ lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
78
+ type: apply(JsonRpcTransformers.scriptTo, cellOutput.type),
79
79
  });
80
80
  }
81
- static toCellDep(cellDep) {
81
+ static cellDepFrom(cellDep) {
82
82
  return {
83
- out_point: JsonRpcTransformers.toOutPoint(cellDep.outPoint),
84
- dep_type: JsonRpcTransformers.toDepType(cellDep.depType),
83
+ out_point: JsonRpcTransformers.outPointFrom(cellDep.outPoint),
84
+ dep_type: JsonRpcTransformers.depTypeFrom(cellDep.depType),
85
85
  };
86
86
  }
87
- static fromCellDep(cellDep) {
87
+ static cellDepTo(cellDep) {
88
88
  return CellDep.from({
89
- outPoint: JsonRpcTransformers.fromOutPoint(cellDep.out_point),
90
- depType: JsonRpcTransformers.fromDepType(cellDep.dep_type),
89
+ outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
90
+ depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
91
91
  });
92
92
  }
93
- static toTransaction(txLike) {
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.toCellDep(c)),
97
+ cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
98
98
  header_deps: tx.headerDeps,
99
- inputs: tx.inputs.map((i) => JsonRpcTransformers.toCellInput(i)),
100
- outputs: tx.outputs.map((o) => JsonRpcTransformers.toCellOutput(o)),
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 fromTransaction(tx) {
105
+ static transactionTo(tx) {
106
106
  return Transaction.from({
107
107
  version: tx.version,
108
- cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.fromCellDep(c)),
108
+ cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
109
109
  headerDeps: tx.header_deps,
110
- inputs: tx.inputs.map((i) => JsonRpcTransformers.fromCellInput(i)),
111
- outputs: tx.outputs.map((o) => JsonRpcTransformers.fromCellOutput(o)),
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 fromTransactionResponse({ tx_status: { status }, transaction, }) {
116
+ static transactionResponseTo({ tx_status: { status }, transaction, }) {
117
117
  return {
118
- transaction: JsonRpcTransformers.fromTransaction(transaction),
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.4",
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": "8ce2ee90a1277c34b76a2ffe69c2cf29e122a4d4"
50
+ "gitHead": "20746c0e9160fbf6eb519d5081897ae55042275a"
51
51
  }
@@ -69,7 +69,7 @@ export abstract class ClientJsonRpc extends Client {
69
69
 
70
70
  sendTransaction = this.buildSender(
71
71
  "send_transaction",
72
- [JsonRpcTransformers.toTransaction],
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.fromTransactionResponse,
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 toHashType(hashType: HashTypeLike): JsonRpcHashType {
36
+ static hashTypeFrom(hashType: HashTypeLike): JsonRpcHashType {
37
37
  return hashTypeFrom(hashType);
38
38
  }
39
- static fromHashType(hashType: JsonRpcHashType): HashType {
39
+ static hashTypeTo(hashType: JsonRpcHashType): HashType {
40
40
  return hashType;
41
41
  }
42
- static toDepType(depType: DepTypeLike): JsonRpcDepType {
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 fromDepType(depType: JsonRpcDepType): DepType {
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 toScript(scriptLike: ScriptLike): JsonRpcScript {
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.toHashType(script.hashType),
62
+ hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
63
63
  args: script.args,
64
64
  };
65
65
  }
66
- static fromScript(script: JsonRpcScript): Script {
66
+ static scriptTo(script: JsonRpcScript): Script {
67
67
  return Script.from({
68
68
  codeHash: script.code_hash,
69
- hashType: JsonRpcTransformers.fromHashType(script.hash_type),
69
+ hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
70
70
  args: script.args,
71
71
  });
72
72
  }
73
- static toOutPoint(outPointLike: OutPointLike): JsonRpcOutPoint {
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 fromOutPoint(outPoint: JsonRpcOutPoint): OutPoint {
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 toCellInput(cellInput: CellInputLike): JsonRpcCellInput {
86
+ static cellInputFrom(cellInput: CellInputLike): JsonRpcCellInput {
87
87
  return {
88
- previous_output: JsonRpcTransformers.toOutPoint(cellInput.previousOutput),
88
+ previous_output: JsonRpcTransformers.outPointFrom(
89
+ cellInput.previousOutput,
90
+ ),
89
91
  since: numToHex(cellInput.since),
90
92
  };
91
93
  }
92
- static fromCellInput(cellInput: JsonRpcCellInput): CellInput {
94
+ static cellInputTo(cellInput: JsonRpcCellInput): CellInput {
93
95
  return CellInput.from({
94
- previousOutput: this.fromOutPoint(cellInput.previous_output),
96
+ previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
95
97
  since: cellInput.since,
96
98
  });
97
99
  }
98
- static toCellOutput(cellOutput: CellOutputLike): JsonRpcCellOutput {
100
+ static cellOutputFrom(cellOutput: CellOutputLike): JsonRpcCellOutput {
99
101
  return {
100
102
  capacity: numToHex(cellOutput.capacity),
101
- lock: JsonRpcTransformers.toScript(cellOutput.lock),
102
- type: apply(JsonRpcTransformers.toScript, cellOutput.type),
103
+ lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
104
+ type: apply(JsonRpcTransformers.scriptFrom, cellOutput.type),
103
105
  };
104
106
  }
105
- static fromCellOutput(cellOutput: JsonRpcCellOutput): CellOutput {
107
+ static cellOutputTo(cellOutput: JsonRpcCellOutput): CellOutput {
106
108
  return CellOutput.from({
107
109
  capacity: cellOutput.capacity,
108
- lock: JsonRpcTransformers.fromScript(cellOutput.lock),
109
- type: apply(JsonRpcTransformers.fromScript, cellOutput.type),
110
+ lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
111
+ type: apply(JsonRpcTransformers.scriptTo, cellOutput.type),
110
112
  });
111
113
  }
112
- static toCellDep(cellDep: CellDepLike): JsonRpcCellDep {
114
+ static cellDepFrom(cellDep: CellDepLike): JsonRpcCellDep {
113
115
  return {
114
- out_point: JsonRpcTransformers.toOutPoint(cellDep.outPoint),
115
- dep_type: JsonRpcTransformers.toDepType(cellDep.depType),
116
+ out_point: JsonRpcTransformers.outPointFrom(cellDep.outPoint),
117
+ dep_type: JsonRpcTransformers.depTypeFrom(cellDep.depType),
116
118
  };
117
119
  }
118
- static fromCellDep(cellDep: JsonRpcCellDep): CellDep {
120
+ static cellDepTo(cellDep: JsonRpcCellDep): CellDep {
119
121
  return CellDep.from({
120
- outPoint: JsonRpcTransformers.fromOutPoint(cellDep.out_point),
121
- depType: JsonRpcTransformers.fromDepType(cellDep.dep_type),
122
+ outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
123
+ depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
122
124
  });
123
125
  }
124
- static toTransaction(txLike: TransactionLike): JsonRpcTransaction {
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.toCellDep(c)),
130
+ cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
129
131
  header_deps: tx.headerDeps,
130
- inputs: tx.inputs.map((i) => JsonRpcTransformers.toCellInput(i)),
131
- outputs: tx.outputs.map((o) => JsonRpcTransformers.toCellOutput(o)),
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 fromTransaction(tx: JsonRpcTransaction): Transaction {
138
+ static transactionTo(tx: JsonRpcTransaction): Transaction {
137
139
  return Transaction.from({
138
140
  version: tx.version,
139
- cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.fromCellDep(c)),
141
+ cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
140
142
  headerDeps: tx.header_deps,
141
- inputs: tx.inputs.map((i) => JsonRpcTransformers.fromCellInput(i)),
142
- outputs: tx.outputs.map((o) => JsonRpcTransformers.fromCellOutput(o)),
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 fromTransactionResponse({
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.fromTransaction(transaction),
157
+ transaction: JsonRpcTransformers.transactionTo(transaction),
156
158
  status,
157
159
  };
158
160
  }