@ckb-ccc/core 0.0.8-alpha.3 → 0.0.8-alpha.4

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.
Files changed (138) hide show
  1. package/dist/ckb/script.js +2 -2
  2. package/dist/ckb/transaction.js +2 -2
  3. package/dist/client/client.d.ts +1 -0
  4. package/dist/client/client.d.ts.map +1 -1
  5. package/dist/client/client.js +1 -0
  6. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  7. package/dist/client/clientPublicMainnet.advanced.js +35 -1
  8. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  9. package/dist/client/clientPublicTestnet.advanced.js +20 -0
  10. package/dist/hasher/index.d.ts +17 -2
  11. package/dist/hasher/index.d.ts.map +1 -1
  12. package/dist/hasher/index.js +19 -2
  13. package/dist/signer/nostr/signerNostr.js +2 -2
  14. package/dist.commonjs/address/address.advanced.d.ts +24 -29
  15. package/dist.commonjs/address/address.advanced.js +89 -115
  16. package/dist.commonjs/address/advanced.d.ts +1 -1
  17. package/dist.commonjs/address/advanced.js +14 -30
  18. package/dist.commonjs/address/index.d.ts +44 -51
  19. package/dist.commonjs/address/index.js +65 -84
  20. package/dist.commonjs/advanced.d.ts +1 -1
  21. package/dist.commonjs/advanced.js +22 -47
  22. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  23. package/dist.commonjs/advancedBarrel.js +14 -30
  24. package/dist.commonjs/barrel.d.ts +1 -1
  25. package/dist.commonjs/barrel.js +14 -30
  26. package/dist.commonjs/bytes/advanced.d.ts +2 -11
  27. package/dist.commonjs/bytes/index.d.ts +3 -9
  28. package/dist.commonjs/bytes/index.js +26 -28
  29. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  30. package/dist.commonjs/ckb/advanced.js +22 -47
  31. package/dist.commonjs/ckb/index.d.ts +1 -1
  32. package/dist.commonjs/ckb/index.js +14 -30
  33. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +260 -420
  34. package/dist.commonjs/ckb/molecule.advanced/generated.js +1332 -1536
  35. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  36. package/dist.commonjs/ckb/molecule.advanced/index.js +18 -34
  37. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  38. package/dist.commonjs/ckb/script.advanced.js +9 -12
  39. package/dist.commonjs/ckb/script.d.ts +117 -121
  40. package/dist.commonjs/ckb/script.js +176 -220
  41. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  42. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  43. package/dist.commonjs/ckb/transaction.d.ts +717 -792
  44. package/dist.commonjs/ckb/transaction.js +1155 -1383
  45. package/dist.commonjs/client/advanced.d.ts +1 -1
  46. package/dist.commonjs/client/advanced.js +14 -30
  47. package/dist.commonjs/client/client.advanced.d.ts +6 -23
  48. package/dist.commonjs/client/client.advanced.js +61 -89
  49. package/dist.commonjs/client/client.d.ts +54 -113
  50. package/dist.commonjs/client/client.d.ts.map +1 -1
  51. package/dist.commonjs/client/client.js +182 -214
  52. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -8
  53. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  54. package/dist.commonjs/client/clientPublicMainnet.advanced.js +161 -144
  55. package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -8
  56. package/dist.commonjs/client/clientPublicMainnet.js +15 -17
  57. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +3 -6
  58. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  59. package/dist.commonjs/client/clientPublicTestnet.advanced.js +199 -204
  60. package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -8
  61. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  62. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  63. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  64. package/dist.commonjs/client/clientTypes.d.ts +26 -51
  65. package/dist.commonjs/client/clientTypes.js +22 -56
  66. package/dist.commonjs/client/index.d.ts +1 -1
  67. package/dist.commonjs/client/index.js +14 -30
  68. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  69. package/dist.commonjs/client/jsonRpc/advanced.js +14 -30
  70. package/dist.commonjs/client/jsonRpc/index.d.ts +75 -94
  71. package/dist.commonjs/client/jsonRpc/index.js +108 -135
  72. package/dist.commonjs/client/jsonRpc/transformers.d.ts +36 -76
  73. package/dist.commonjs/client/jsonRpc/transformers.js +152 -174
  74. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  75. package/dist.commonjs/fixedPoint/index.d.ts +3 -9
  76. package/dist.commonjs/fixedPoint/index.js +20 -26
  77. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  78. package/dist.commonjs/fixedPoint/index.test.js +36 -42
  79. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  80. package/dist.commonjs/hasher/index.d.ts +53 -38
  81. package/dist.commonjs/hasher/index.d.ts.map +1 -1
  82. package/dist.commonjs/hasher/index.js +69 -58
  83. package/dist.commonjs/hex/index.d.ts +1 -1
  84. package/dist.commonjs/hex/index.js +1 -1
  85. package/dist.commonjs/index.d.ts +1 -1
  86. package/dist.commonjs/index.js +22 -47
  87. package/dist.commonjs/num/index.d.ts +1 -1
  88. package/dist.commonjs/num/index.js +27 -39
  89. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  90. package/dist.commonjs/signer/btc/index.js +14 -30
  91. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  92. package/dist.commonjs/signer/btc/signerBtc.js +66 -89
  93. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  94. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  95. package/dist.commonjs/signer/btc/verify.d.ts +2 -6
  96. package/dist.commonjs/signer/btc/verify.js +3 -10
  97. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  98. package/dist.commonjs/signer/ckb/index.js +14 -30
  99. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  100. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  101. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +2 -6
  102. package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -11
  103. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  104. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  105. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  106. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  107. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  108. package/dist.commonjs/signer/dummy/index.js +14 -30
  109. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  110. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  111. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  112. package/dist.commonjs/signer/evm/index.js +14 -30
  113. package/dist.commonjs/signer/evm/signerEvm.d.ts +38 -42
  114. package/dist.commonjs/signer/evm/signerEvm.js +70 -105
  115. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  116. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  117. package/dist.commonjs/signer/evm/verify.d.ts +2 -6
  118. package/dist.commonjs/signer/evm/verify.js +2 -7
  119. package/dist.commonjs/signer/index.d.ts +1 -1
  120. package/dist.commonjs/signer/index.js +14 -30
  121. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  122. package/dist.commonjs/signer/nostr/index.js +14 -30
  123. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  124. package/dist.commonjs/signer/nostr/signerNostr.js +71 -100
  125. package/dist.commonjs/signer/nostr/verify.d.ts +3 -9
  126. package/dist.commonjs/signer/nostr/verify.js +39 -50
  127. package/dist.commonjs/signer/signer/index.d.ts +150 -156
  128. package/dist.commonjs/signer/signer/index.js +181 -208
  129. package/dist.commonjs/utils/index.d.ts +8 -38
  130. package/dist.commonjs/utils/index.js +12 -18
  131. package/package.json +3 -3
  132. package/src/ckb/script.ts +2 -2
  133. package/src/ckb/transaction.ts +2 -2
  134. package/src/client/client.ts +1 -0
  135. package/src/client/clientPublicMainnet.advanced.ts +40 -1
  136. package/src/client/clientPublicTestnet.advanced.ts +23 -0
  137. package/src/hasher/index.ts +27 -2
  138. package/src/signer/nostr/signerNostr.ts +2 -2
@@ -10,227 +10,195 @@ const client_advanced_1 = require("./client.advanced");
10
10
  const clientTypes_1 = require("./clientTypes");
11
11
  var KnownScript;
12
12
  (function (KnownScript) {
13
- KnownScript["Secp256k1Blake160"] = "Secp256k1Blake160";
14
- KnownScript["Secp256k1Multisig"] = "Secp256k1Multisig";
15
- KnownScript["AnyoneCanPay"] = "AnyoneCanPay";
16
- KnownScript["TypeId"] = "TypeId";
17
- KnownScript["XUdt"] = "XUdt";
18
- KnownScript["JoyId"] = "JoyId";
19
- KnownScript["COTA"] = "COTA";
20
- KnownScript["OmniLock"] = "OmniLock";
21
- KnownScript["NostrLock"] = "NostrLock";
22
- KnownScript["SingleUseLock"] = "SingleUseLock";
23
- KnownScript["OutputTypeProxyLock"] = "OutputTypeProxyLock";
13
+ KnownScript["Secp256k1Blake160"] = "Secp256k1Blake160";
14
+ KnownScript["Secp256k1Multisig"] = "Secp256k1Multisig";
15
+ KnownScript["AnyoneCanPay"] = "AnyoneCanPay";
16
+ KnownScript["TypeId"] = "TypeId";
17
+ KnownScript["XUdt"] = "XUdt";
18
+ KnownScript["JoyId"] = "JoyId";
19
+ KnownScript["COTA"] = "COTA";
20
+ KnownScript["OmniLock"] = "OmniLock";
21
+ KnownScript["NostrLock"] = "NostrLock";
22
+ KnownScript["UniqueType"] = "UniqueType";
23
+ KnownScript["SingleUseLock"] = "SingleUseLock";
24
+ KnownScript["OutputTypeProxyLock"] = "OutputTypeProxyLock";
24
25
  })(KnownScript || (exports.KnownScript = KnownScript = {}));
25
26
  class CellDepInfo {
26
- constructor(cellDep, type) {
27
- this.cellDep = cellDep;
28
- this.type = type;
29
- }
30
- static from(cellDepInfoLike) {
31
- return new CellDepInfo(
32
- ckb_1.CellDep.from(cellDepInfoLike.cellDep),
33
- (0, utils_1.apply)(ckb_1.Script.from, cellDepInfoLike.type),
34
- );
35
- }
27
+ constructor(cellDep, type) {
28
+ this.cellDep = cellDep;
29
+ this.type = type;
30
+ }
31
+ static from(cellDepInfoLike) {
32
+ return new CellDepInfo(ckb_1.CellDep.from(cellDepInfoLike.cellDep), (0, utils_1.apply)(ckb_1.Script.from, cellDepInfoLike.type));
33
+ }
36
34
  }
37
35
  exports.CellDepInfo = CellDepInfo;
38
36
  class Client {
39
- constructor() {
40
- this.cachedTransactions = [];
41
- this.unusableOutPoints = [];
42
- this.usableCells = [];
43
- this.knownCells = [];
44
- }
45
- async markUsable(cellLike) {
46
- const cell = ckb_1.Cell.from(cellLike).clone();
47
- this.usableCells.push(cell);
48
- this.knownCells.push(cell);
49
- const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
50
- if (index !== -1) {
51
- this.unusableOutPoints.splice(index, 1);
52
- }
53
- }
54
- async markUnusable(outPointLike) {
55
- const outPoint = ckb_1.OutPoint.from(outPointLike);
56
- this.unusableOutPoints.push(outPoint.clone());
57
- const index = this.usableCells.findIndex((c) => c.outPoint.eq(outPoint));
58
- if (index !== -1) {
59
- this.usableCells.splice(index, 1);
60
- }
61
- }
62
- async getCell(outPointLike) {
63
- const outPoint = ckb_1.OutPoint.from(outPointLike);
64
- const cached = this.knownCells.find((cell) => cell.outPoint.eq(outPoint));
65
- if (cached) {
66
- return cached.clone();
67
- }
68
- const transaction = await this.getTransactionNoCache(outPoint.txHash);
69
- if (!transaction) {
70
- return null;
71
- }
72
- const index = Number((0, num_1.numFrom)(outPoint.index));
73
- if (index >= transaction.transaction.outputs.length) {
74
- return null;
75
- }
76
- const cell = ckb_1.Cell.from({
77
- outPoint,
78
- cellOutput: transaction.transaction.outputs[index],
79
- outputData: transaction.transaction.outputsData[index] ?? "0x",
80
- });
81
- this.knownCells.push(cell);
82
- return cell.clone();
83
- }
84
- async findCellsPaged(key, order, limit, after) {
85
- const res = await this.findCellsPagedNoCache(key, order, limit, after);
86
- this.knownCells.push(...res.cells);
87
- return res;
88
- }
89
- async *findCells(key, order, limit = 10) {
90
- let last = undefined;
91
- while (true) {
92
- const { cells, lastCursor } = await this.findCellsPaged(
93
- key,
94
- order,
95
- limit,
96
- last,
97
- );
98
- for (const cell of cells) {
99
- yield cell;
100
- }
101
- if (cells.length === 0 || cells.length < limit) {
102
- return;
103
- }
104
- last = lastCursor;
105
- }
106
- }
107
- /**
108
- * Find cells by search key designed for collectable cells.
109
- *
110
- * @param key - The search key.
111
- * @returns A async generator for yielding cells.
112
- */
113
- async *findCellsByCollectableSearchKey(keyLike, order, limit = 10) {
114
- const key = clientTypes_1.ClientIndexerSearchKey.from(keyLike);
115
- for (const cell of this.usableCells) {
116
- if ((0, client_advanced_1.filterCell)(key, cell)) {
117
- yield cell;
118
- }
119
- }
120
- for await (const cell of this.findCells(key, order, limit)) {
121
- if (!this.unusableOutPoints.some((o) => o.eq(cell.outPoint))) {
122
- yield cell;
123
- }
124
- }
125
- }
126
- findCellsByLockAndType(lock, type, withData = true, order, limit = 10) {
127
- return this.findCellsByCollectableSearchKey(
128
- {
129
- script: lock,
130
- scriptType: "lock",
131
- scriptSearchMode: "exact",
132
- filter: {
133
- script: type,
134
- },
135
- withData,
136
- },
137
- order,
138
- limit,
139
- );
140
- }
141
- findCellsByType(type, withData = true, order, limit = 10) {
142
- return this.findCellsByCollectableSearchKey(
143
- {
144
- script: type,
145
- scriptType: "type",
146
- scriptSearchMode: "exact",
147
- withData,
148
- },
149
- order,
150
- limit,
151
- );
152
- }
153
- async findSingletonCellByType(type, withData = false) {
154
- for await (const cell of this.findCellsByType(
155
- type,
156
- withData,
157
- undefined,
158
- 1,
159
- )) {
160
- return cell;
161
- }
162
- }
163
- async getCellDeps(...cellDepsInfoLike) {
164
- return Promise.all(
165
- cellDepsInfoLike.flat().map(async (infoLike) => {
166
- const { cellDep, type } = CellDepInfo.from(infoLike);
167
- if (type === undefined) {
168
- return cellDep;
37
+ constructor() {
38
+ this.cachedTransactions = [];
39
+ this.unusableOutPoints = [];
40
+ this.usableCells = [];
41
+ this.knownCells = [];
42
+ }
43
+ async markUsable(cellLike) {
44
+ const cell = ckb_1.Cell.from(cellLike).clone();
45
+ this.usableCells.push(cell);
46
+ this.knownCells.push(cell);
47
+ const index = this.unusableOutPoints.findIndex((o) => cell.outPoint.eq(o));
48
+ if (index !== -1) {
49
+ this.unusableOutPoints.splice(index, 1);
50
+ }
51
+ }
52
+ async markUnusable(outPointLike) {
53
+ const outPoint = ckb_1.OutPoint.from(outPointLike);
54
+ this.unusableOutPoints.push(outPoint.clone());
55
+ const index = this.usableCells.findIndex((c) => c.outPoint.eq(outPoint));
56
+ if (index !== -1) {
57
+ this.usableCells.splice(index, 1);
58
+ }
59
+ }
60
+ async getCell(outPointLike) {
61
+ const outPoint = ckb_1.OutPoint.from(outPointLike);
62
+ const cached = this.knownCells.find((cell) => cell.outPoint.eq(outPoint));
63
+ if (cached) {
64
+ return cached.clone();
169
65
  }
170
- const found = await this.findSingletonCellByType(type);
171
- if (!found) {
172
- return cellDep;
66
+ const transaction = await this.getTransactionNoCache(outPoint.txHash);
67
+ if (!transaction) {
68
+ return null;
173
69
  }
174
- return ckb_1.CellDep.from({
175
- outPoint: found.outPoint,
176
- depType: cellDep.depType,
70
+ const index = Number((0, num_1.numFrom)(outPoint.index));
71
+ if (index >= transaction.transaction.outputs.length) {
72
+ return null;
73
+ }
74
+ const cell = ckb_1.Cell.from({
75
+ outPoint,
76
+ cellOutput: transaction.transaction.outputs[index],
77
+ outputData: transaction.transaction.outputsData[index] ?? "0x",
177
78
  });
178
- }),
179
- );
180
- }
181
- async getBalanceSingle(lock) {
182
- return this.getCellsCapacity({
183
- script: lock,
184
- scriptType: "lock",
185
- scriptSearchMode: "exact",
186
- filter: {
187
- scriptLenRange: [0, 1],
188
- outputDataLenRange: [0, 1],
189
- },
190
- });
191
- }
192
- async getBalance(locks) {
193
- return (0, utils_1.reduceAsync)(
194
- locks,
195
- async (acc, lock) => acc + (await this.getBalanceSingle(lock)),
196
- fixedPoint_1.Zero,
197
- );
198
- }
199
- async sendTransaction(transaction, validator) {
200
- const tx = ckb_1.Transaction.from(transaction);
201
- const txHash = await this.sendTransactionNoCache(tx, validator);
202
- this.cachedTransactions.push(tx.clone());
203
- await Promise.all(
204
- tx.inputs.map((i) => this.markUnusable(i.previousOutput)),
205
- );
206
- await Promise.all(
207
- tx.outputs.map((o, i) =>
208
- this.markUsable({
209
- cellOutput: o,
210
- outputData: tx.outputsData[i],
211
- outPoint: {
212
- txHash,
213
- index: i,
214
- },
215
- }),
216
- ),
217
- );
218
- return txHash;
219
- }
220
- async getTransaction(txHashLike) {
221
- const txHash = (0, hex_1.hexFrom)(txHashLike);
222
- const res = await this.getTransactionNoCache(txHash);
223
- if (res !== null) {
224
- return res;
225
- }
226
- const tx = this.cachedTransactions.find((t) => t.hash() === txHash);
227
- if (!tx) {
228
- return null;
229
- }
230
- return {
231
- transaction: tx,
232
- status: "proposed",
233
- };
234
- }
79
+ this.knownCells.push(cell);
80
+ return cell.clone();
81
+ }
82
+ async findCellsPaged(key, order, limit, after) {
83
+ const res = await this.findCellsPagedNoCache(key, order, limit, after);
84
+ this.knownCells.push(...res.cells);
85
+ return res;
86
+ }
87
+ async *findCells(key, order, limit = 10) {
88
+ let last = undefined;
89
+ while (true) {
90
+ const { cells, lastCursor } = await this.findCellsPaged(key, order, limit, last);
91
+ for (const cell of cells) {
92
+ yield cell;
93
+ }
94
+ if (cells.length === 0 || cells.length < limit) {
95
+ return;
96
+ }
97
+ last = lastCursor;
98
+ }
99
+ }
100
+ /**
101
+ * Find cells by search key designed for collectable cells.
102
+ *
103
+ * @param key - The search key.
104
+ * @returns A async generator for yielding cells.
105
+ */
106
+ async *findCellsByCollectableSearchKey(keyLike, order, limit = 10) {
107
+ const key = clientTypes_1.ClientIndexerSearchKey.from(keyLike);
108
+ for (const cell of this.usableCells) {
109
+ if ((0, client_advanced_1.filterCell)(key, cell)) {
110
+ yield cell;
111
+ }
112
+ }
113
+ for await (const cell of this.findCells(key, order, limit)) {
114
+ if (!this.unusableOutPoints.some((o) => o.eq(cell.outPoint))) {
115
+ yield cell;
116
+ }
117
+ }
118
+ }
119
+ findCellsByLockAndType(lock, type, withData = true, order, limit = 10) {
120
+ return this.findCellsByCollectableSearchKey({
121
+ script: lock,
122
+ scriptType: "lock",
123
+ scriptSearchMode: "exact",
124
+ filter: {
125
+ script: type,
126
+ },
127
+ withData,
128
+ }, order, limit);
129
+ }
130
+ findCellsByType(type, withData = true, order, limit = 10) {
131
+ return this.findCellsByCollectableSearchKey({
132
+ script: type,
133
+ scriptType: "type",
134
+ scriptSearchMode: "exact",
135
+ withData,
136
+ }, order, limit);
137
+ }
138
+ async findSingletonCellByType(type, withData = false) {
139
+ for await (const cell of this.findCellsByType(type, withData, undefined, 1)) {
140
+ return cell;
141
+ }
142
+ }
143
+ async getCellDeps(...cellDepsInfoLike) {
144
+ return Promise.all(cellDepsInfoLike.flat().map(async (infoLike) => {
145
+ const { cellDep, type } = CellDepInfo.from(infoLike);
146
+ if (type === undefined) {
147
+ return cellDep;
148
+ }
149
+ const found = await this.findSingletonCellByType(type);
150
+ if (!found) {
151
+ return cellDep;
152
+ }
153
+ return ckb_1.CellDep.from({
154
+ outPoint: found.outPoint,
155
+ depType: cellDep.depType,
156
+ });
157
+ }));
158
+ }
159
+ async getBalanceSingle(lock) {
160
+ return this.getCellsCapacity({
161
+ script: lock,
162
+ scriptType: "lock",
163
+ scriptSearchMode: "exact",
164
+ filter: {
165
+ scriptLenRange: [0, 1],
166
+ outputDataLenRange: [0, 1],
167
+ },
168
+ });
169
+ }
170
+ async getBalance(locks) {
171
+ return (0, utils_1.reduceAsync)(locks, async (acc, lock) => acc + (await this.getBalanceSingle(lock)), fixedPoint_1.Zero);
172
+ }
173
+ async sendTransaction(transaction, validator) {
174
+ const tx = ckb_1.Transaction.from(transaction);
175
+ const txHash = await this.sendTransactionNoCache(tx, validator);
176
+ this.cachedTransactions.push(tx.clone());
177
+ await Promise.all(tx.inputs.map((i) => this.markUnusable(i.previousOutput)));
178
+ await Promise.all(tx.outputs.map((o, i) => this.markUsable({
179
+ cellOutput: o,
180
+ outputData: tx.outputsData[i],
181
+ outPoint: {
182
+ txHash,
183
+ index: i,
184
+ },
185
+ })));
186
+ return txHash;
187
+ }
188
+ async getTransaction(txHashLike) {
189
+ const txHash = (0, hex_1.hexFrom)(txHashLike);
190
+ const res = await this.getTransactionNoCache(txHash);
191
+ if (res !== null) {
192
+ return res;
193
+ }
194
+ const tx = this.cachedTransactions.find((t) => t.hash() === txHash);
195
+ if (!tx) {
196
+ return null;
197
+ }
198
+ return {
199
+ transaction: tx,
200
+ status: "proposed",
201
+ };
202
+ }
235
203
  }
236
204
  exports.Client = Client;
@@ -1,10 +1,6 @@
1
1
  import { Script } from "../ckb";
2
2
  import { CellDepInfoLike, KnownScript } from "./client";
3
- export declare const MAINNET_SCRIPTS: Record<
4
- KnownScript,
5
- | (Pick<Script, "codeHash" | "hashType"> & {
6
- cellDeps: CellDepInfoLike[];
7
- })
8
- | undefined
9
- >;
10
- //# sourceMappingURL=clientPublicMainnet.advanced.d.ts.map
3
+ export declare const MAINNET_SCRIPTS: Record<KnownScript, (Pick<Script, "codeHash" | "hashType"> & {
4
+ cellDeps: CellDepInfoLike[];
5
+ }) | undefined>;
6
+ //# sourceMappingURL=clientPublicMainnet.advanced.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,WAAW,EACT,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,GAAG;IAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC,GACzE,SAAS,CAkJZ,CAAC"}
1
+ {"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,WAAW,EACT,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,GAAG;IAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC,GACzE,SAAS,CAyLZ,CAAC"}