@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.
- package/dist/ckb/script.js +2 -2
- package/dist/ckb/transaction.js +2 -2
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +1 -0
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +35 -1
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +20 -0
- package/dist/hasher/index.d.ts +17 -2
- package/dist/hasher/index.d.ts.map +1 -1
- package/dist/hasher/index.js +19 -2
- package/dist/signer/nostr/signerNostr.js +2 -2
- package/dist.commonjs/address/address.advanced.d.ts +24 -29
- package/dist.commonjs/address/address.advanced.js +89 -115
- package/dist.commonjs/address/advanced.d.ts +1 -1
- package/dist.commonjs/address/advanced.js +14 -30
- package/dist.commonjs/address/index.d.ts +44 -51
- package/dist.commonjs/address/index.js +65 -84
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +22 -47
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +14 -30
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +14 -30
- package/dist.commonjs/bytes/advanced.d.ts +2 -11
- package/dist.commonjs/bytes/index.d.ts +3 -9
- package/dist.commonjs/bytes/index.js +26 -28
- package/dist.commonjs/ckb/advanced.d.ts +1 -1
- package/dist.commonjs/ckb/advanced.js +22 -47
- package/dist.commonjs/ckb/index.d.ts +1 -1
- package/dist.commonjs/ckb/index.js +14 -30
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +260 -420
- package/dist.commonjs/ckb/molecule.advanced/generated.js +1332 -1536
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
- package/dist.commonjs/ckb/molecule.advanced/index.js +18 -34
- package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/script.advanced.js +9 -12
- package/dist.commonjs/ckb/script.d.ts +117 -121
- package/dist.commonjs/ckb/script.js +176 -220
- package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/transaction.advanced.js +4 -4
- package/dist.commonjs/ckb/transaction.d.ts +717 -792
- package/dist.commonjs/ckb/transaction.js +1155 -1383
- package/dist.commonjs/client/advanced.d.ts +1 -1
- package/dist.commonjs/client/advanced.js +14 -30
- package/dist.commonjs/client/client.advanced.d.ts +6 -23
- package/dist.commonjs/client/client.advanced.js +61 -89
- package/dist.commonjs/client/client.d.ts +54 -113
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +182 -214
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -8
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +161 -144
- package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -8
- package/dist.commonjs/client/clientPublicMainnet.js +15 -17
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +3 -6
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +199 -204
- package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -8
- package/dist.commonjs/client/clientPublicTestnet.js +13 -13
- package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
- package/dist.commonjs/client/clientTypes.advanced.js +1 -1
- package/dist.commonjs/client/clientTypes.d.ts +26 -51
- package/dist.commonjs/client/clientTypes.js +22 -56
- package/dist.commonjs/client/index.d.ts +1 -1
- package/dist.commonjs/client/index.js +14 -30
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
- package/dist.commonjs/client/jsonRpc/advanced.js +14 -30
- package/dist.commonjs/client/jsonRpc/index.d.ts +75 -94
- package/dist.commonjs/client/jsonRpc/index.js +108 -135
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +36 -76
- package/dist.commonjs/client/jsonRpc/transformers.js +152 -174
- package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
- package/dist.commonjs/fixedPoint/index.d.ts +3 -9
- package/dist.commonjs/fixedPoint/index.js +20 -26
- package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
- package/dist.commonjs/fixedPoint/index.test.js +36 -42
- package/dist.commonjs/hasher/advanced.d.ts +1 -1
- package/dist.commonjs/hasher/index.d.ts +53 -38
- package/dist.commonjs/hasher/index.d.ts.map +1 -1
- package/dist.commonjs/hasher/index.js +69 -58
- package/dist.commonjs/hex/index.d.ts +1 -1
- package/dist.commonjs/hex/index.js +1 -1
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +22 -47
- package/dist.commonjs/num/index.d.ts +1 -1
- package/dist.commonjs/num/index.js +27 -39
- package/dist.commonjs/signer/btc/index.d.ts +1 -1
- package/dist.commonjs/signer/btc/index.js +14 -30
- package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
- package/dist.commonjs/signer/btc/signerBtc.js +66 -89
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
- package/dist.commonjs/signer/btc/verify.d.ts +2 -6
- package/dist.commonjs/signer/btc/verify.js +3 -10
- package/dist.commonjs/signer/ckb/index.d.ts +1 -1
- package/dist.commonjs/signer/ckb/index.js +14 -30
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +2 -6
- package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -11
- package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
- package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
- package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
- package/dist.commonjs/signer/dummy/dummy.js +16 -16
- package/dist.commonjs/signer/dummy/index.d.ts +1 -1
- package/dist.commonjs/signer/dummy/index.js +14 -30
- package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
- package/dist.commonjs/signer/dummy/openLink.js +7 -7
- package/dist.commonjs/signer/evm/index.d.ts +1 -1
- package/dist.commonjs/signer/evm/index.js +14 -30
- package/dist.commonjs/signer/evm/signerEvm.d.ts +38 -42
- package/dist.commonjs/signer/evm/signerEvm.js +70 -105
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
- package/dist.commonjs/signer/evm/verify.d.ts +2 -6
- package/dist.commonjs/signer/evm/verify.js +2 -7
- package/dist.commonjs/signer/index.d.ts +1 -1
- package/dist.commonjs/signer/index.js +14 -30
- package/dist.commonjs/signer/nostr/index.d.ts +1 -1
- package/dist.commonjs/signer/nostr/index.js +14 -30
- package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
- package/dist.commonjs/signer/nostr/signerNostr.js +71 -100
- package/dist.commonjs/signer/nostr/verify.d.ts +3 -9
- package/dist.commonjs/signer/nostr/verify.js +39 -50
- package/dist.commonjs/signer/signer/index.d.ts +150 -156
- package/dist.commonjs/signer/signer/index.js +181 -208
- package/dist.commonjs/utils/index.d.ts +8 -38
- package/dist.commonjs/utils/index.js +12 -18
- package/package.json +3 -3
- package/src/ckb/script.ts +2 -2
- package/src/ckb/transaction.ts +2 -2
- package/src/client/client.ts +1 -0
- package/src/client/clientPublicMainnet.advanced.ts +40 -1
- package/src/client/clientPublicTestnet.advanced.ts +23 -0
- package/src/hasher/index.ts +27 -2
- package/src/signer/nostr/signerNostr.ts +2 -2
|
@@ -1,61 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}
|
|
21
|
-
: function (o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
});
|
|
25
|
-
var __setModuleDefault =
|
|
26
|
-
(this && this.__setModuleDefault) ||
|
|
27
|
-
(Object.create
|
|
28
|
-
? function (o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}
|
|
31
|
-
: function (o, v) {
|
|
32
|
-
o["default"] = v;
|
|
33
|
-
});
|
|
34
|
-
var __importStar =
|
|
35
|
-
(this && this.__importStar) ||
|
|
36
|
-
function (mod) {
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
37
19
|
if (mod && mod.__esModule) return mod;
|
|
38
20
|
var result = {};
|
|
39
|
-
if (mod != null)
|
|
40
|
-
for (var k in mod)
|
|
41
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
-
__createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
43
22
|
__setModuleDefault(result, mod);
|
|
44
23
|
return result;
|
|
45
|
-
|
|
24
|
+
};
|
|
46
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.Transaction =
|
|
48
|
-
exports.udtBalanceFrom =
|
|
49
|
-
exports.WitnessArgs =
|
|
50
|
-
exports.CellDep =
|
|
51
|
-
exports.CellInput =
|
|
52
|
-
exports.Cell =
|
|
53
|
-
exports.CellOutput =
|
|
54
|
-
exports.OutPoint =
|
|
55
|
-
exports.depTypeFromBytes =
|
|
56
|
-
exports.depTypeToBytes =
|
|
57
|
-
exports.depTypeFrom =
|
|
58
|
-
void 0;
|
|
26
|
+
exports.Transaction = exports.udtBalanceFrom = exports.WitnessArgs = exports.CellDep = exports.CellInput = exports.Cell = exports.CellOutput = exports.OutPoint = exports.depTypeFromBytes = exports.depTypeToBytes = exports.depTypeFrom = void 0;
|
|
59
27
|
const bytes_1 = require("../bytes");
|
|
60
28
|
const fixedPoint_1 = require("../fixedPoint");
|
|
61
29
|
const hasher_1 = require("../hasher");
|
|
@@ -80,19 +48,19 @@ const transaction_advanced_1 = require("./transaction.advanced");
|
|
|
80
48
|
* ```
|
|
81
49
|
*/
|
|
82
50
|
function depTypeFrom(val) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
51
|
+
const depType = (() => {
|
|
52
|
+
if (typeof val === "number") {
|
|
53
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[val];
|
|
54
|
+
}
|
|
55
|
+
if (typeof val === "bigint") {
|
|
56
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[Number(val)];
|
|
57
|
+
}
|
|
58
|
+
return val;
|
|
59
|
+
})();
|
|
60
|
+
if (depType === undefined) {
|
|
61
|
+
throw new Error(`Invalid dep type ${val}`);
|
|
62
|
+
}
|
|
63
|
+
return depType;
|
|
96
64
|
}
|
|
97
65
|
exports.depTypeFrom = depTypeFrom;
|
|
98
66
|
/**
|
|
@@ -107,9 +75,7 @@ exports.depTypeFrom = depTypeFrom;
|
|
|
107
75
|
* ```
|
|
108
76
|
*/
|
|
109
77
|
function depTypeToBytes(depType) {
|
|
110
|
-
|
|
111
|
-
transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)],
|
|
112
|
-
]);
|
|
78
|
+
return (0, bytes_1.bytesFrom)([transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
|
|
113
79
|
}
|
|
114
80
|
exports.depTypeToBytes = depTypeToBytes;
|
|
115
81
|
/**
|
|
@@ -126,1357 +92,1163 @@ exports.depTypeToBytes = depTypeToBytes;
|
|
|
126
92
|
* ```
|
|
127
93
|
*/
|
|
128
94
|
function depTypeFromBytes(bytes) {
|
|
129
|
-
|
|
130
|
-
(0, bytes_1.bytesFrom)(bytes)[0]
|
|
131
|
-
];
|
|
95
|
+
return transaction_advanced_1.NUM_TO_DEP_TYPE[(0, bytes_1.bytesFrom)(bytes)[0]];
|
|
132
96
|
}
|
|
133
97
|
exports.depTypeFromBytes = depTypeFromBytes;
|
|
134
98
|
class OutPoint {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
* const isEqual = outPoint.eq(anotherOutPoint);
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
eq(val) {
|
|
235
|
-
const outPoint = OutPoint.from(val);
|
|
236
|
-
return this.txHash === outPoint.txHash && this.index === outPoint.index;
|
|
237
|
-
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates an instance of OutPoint.
|
|
101
|
+
*
|
|
102
|
+
* @param txHash - The transaction hash.
|
|
103
|
+
* @param index - The index of the output in the transaction.
|
|
104
|
+
*/
|
|
105
|
+
constructor(txHash, index) {
|
|
106
|
+
this.txHash = txHash;
|
|
107
|
+
this.index = index;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Clone an OutPoint.
|
|
111
|
+
*
|
|
112
|
+
* @returns A cloned OutPoint instance.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const outPoint1 = outPoint0.clone();
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
clone() {
|
|
120
|
+
return new OutPoint(this.txHash, this.index);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Creates an OutPoint instance from an OutPointLike object.
|
|
124
|
+
*
|
|
125
|
+
* @param outPoint - An OutPointLike object or an instance of OutPoint.
|
|
126
|
+
* @returns An OutPoint instance.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
static from(outPoint) {
|
|
134
|
+
if (outPoint instanceof OutPoint) {
|
|
135
|
+
return outPoint;
|
|
136
|
+
}
|
|
137
|
+
return new OutPoint((0, hex_1.hexFrom)(outPoint.txHash), (0, num_1.numFrom)(outPoint.index));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Converts the OutPoint instance to molecule data format.
|
|
141
|
+
*
|
|
142
|
+
* @returns An object representing the outpoint in molecule data format.
|
|
143
|
+
*/
|
|
144
|
+
_toMolData() {
|
|
145
|
+
return {
|
|
146
|
+
txHash: (0, bytes_1.bytesFrom)(this.txHash),
|
|
147
|
+
index: (0, num_1.numToBytes)(this.index, 4),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Converts the OutPoint instance to bytes.
|
|
152
|
+
*
|
|
153
|
+
* @returns A Uint8Array containing the outpoint bytes.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const outPointBytes = outPoint.toBytes();
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
toBytes() {
|
|
161
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeOutPoint(this._toMolData()));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates an OutPoint instance from a byte-like value or molecule OutPoint.
|
|
165
|
+
*
|
|
166
|
+
* @param bytes - The byte-like value or molecule OutPoint to convert.
|
|
167
|
+
* @returns An OutPoint instance.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
static fromBytes(bytes) {
|
|
175
|
+
const view = bytes instanceof mol.OutPoint
|
|
176
|
+
? bytes
|
|
177
|
+
: new mol.OutPoint((0, bytes_1.bytesFrom)(bytes));
|
|
178
|
+
return new OutPoint((0, hex_1.hexFrom)(view.getTxHash().raw()), (0, num_1.numFromBytes)(view.getIndex().raw()));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Compares the current OutPoint instance with another OutPointLike object for equality.
|
|
182
|
+
*
|
|
183
|
+
* @param val - The OutPointLike object to compare with.
|
|
184
|
+
* @returns True if the out points are equal, otherwise false.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const isEqual = outPoint.eq(anotherOutPoint);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
eq(val) {
|
|
192
|
+
const outPoint = OutPoint.from(val);
|
|
193
|
+
return this.txHash === outPoint.txHash && this.index === outPoint.index;
|
|
194
|
+
}
|
|
238
195
|
}
|
|
239
196
|
exports.OutPoint = OutPoint;
|
|
240
197
|
class CellOutput {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
bytes instanceof mol.CellOutput
|
|
333
|
-
? bytes
|
|
334
|
-
: new mol.CellOutput((0, bytes_1.bytesFrom)(bytes));
|
|
335
|
-
return new CellOutput(
|
|
336
|
-
(0, num_1.numFromBytes)(view.getCapacity().raw()),
|
|
337
|
-
script_1.Script.fromBytes(view.getLock()),
|
|
338
|
-
(0, utils_1.apply)(
|
|
339
|
-
script_1.Script.fromBytes,
|
|
340
|
-
mol.molOptional(view.getType()),
|
|
341
|
-
),
|
|
342
|
-
);
|
|
343
|
-
}
|
|
198
|
+
/**
|
|
199
|
+
* Creates an instance of CellOutput.
|
|
200
|
+
*
|
|
201
|
+
* @param capacity - The capacity of the cell.
|
|
202
|
+
* @param lock - The lock script of the cell.
|
|
203
|
+
* @param type - The optional type script of the cell.
|
|
204
|
+
*/
|
|
205
|
+
constructor(capacity, lock, type) {
|
|
206
|
+
this.capacity = capacity;
|
|
207
|
+
this.lock = lock;
|
|
208
|
+
this.type = type;
|
|
209
|
+
}
|
|
210
|
+
get occupiedSize() {
|
|
211
|
+
return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Clone a CellOutput.
|
|
215
|
+
*
|
|
216
|
+
* @returns A cloned CellOutput instance.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const cellOutput1 = cellOutput0.clone();
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
clone() {
|
|
224
|
+
return new CellOutput(this.capacity, this.lock.clone(), this.type?.clone());
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Creates a CellOutput instance from a CellOutputLike object.
|
|
228
|
+
*
|
|
229
|
+
* @param cellOutput - A CellOutputLike object or an instance of CellOutput.
|
|
230
|
+
* @returns A CellOutput instance.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const cellOutput = CellOutput.from({
|
|
235
|
+
* capacity: 1000n,
|
|
236
|
+
* lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
|
|
237
|
+
* type: { codeHash: "0x...", hashType: "type", args: "0x..." }
|
|
238
|
+
* });
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
static from(cellOutput) {
|
|
242
|
+
if (cellOutput instanceof CellOutput) {
|
|
243
|
+
return cellOutput;
|
|
244
|
+
}
|
|
245
|
+
return new CellOutput((0, num_1.numFrom)(cellOutput.capacity), script_1.Script.from(cellOutput.lock), (0, utils_1.apply)(script_1.Script.from, cellOutput.type));
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Converts the CellOutput instance to molecule data format.
|
|
249
|
+
*
|
|
250
|
+
* @returns An object representing the cell output in molecule data format.
|
|
251
|
+
*/
|
|
252
|
+
_toMolData() {
|
|
253
|
+
return {
|
|
254
|
+
capacity: (0, num_1.numToBytes)(this.capacity, 8),
|
|
255
|
+
lock: this.lock._toMolData(),
|
|
256
|
+
type: this.type?._toMolData(),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Converts the CellOutput instance to bytes.
|
|
261
|
+
*
|
|
262
|
+
* @returns A Uint8Array containing the cell output bytes.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const cellOutputBytes = cellOutput.toBytes();
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
toBytes() {
|
|
270
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellOutput(this._toMolData()));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Creates a CellOutput instance from a byte-like value or molecule CellOutput.
|
|
274
|
+
*
|
|
275
|
+
* @param bytes - The byte-like value or molecule CellOutput to convert.
|
|
276
|
+
* @returns A CellOutput instance.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
static fromBytes(bytes) {
|
|
284
|
+
const view = bytes instanceof mol.CellOutput
|
|
285
|
+
? bytes
|
|
286
|
+
: new mol.CellOutput((0, bytes_1.bytesFrom)(bytes));
|
|
287
|
+
return new CellOutput((0, num_1.numFromBytes)(view.getCapacity().raw()), script_1.Script.fromBytes(view.getLock()), (0, utils_1.apply)(script_1.Script.fromBytes, mol.molOptional(view.getType())));
|
|
288
|
+
}
|
|
344
289
|
}
|
|
345
290
|
exports.CellOutput = CellOutput;
|
|
346
291
|
class Cell {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
*/
|
|
385
|
-
clone() {
|
|
386
|
-
return new Cell(
|
|
387
|
-
this.outPoint.clone(),
|
|
388
|
-
this.cellOutput.clone(),
|
|
389
|
-
this.outputData,
|
|
390
|
-
);
|
|
391
|
-
}
|
|
292
|
+
/**
|
|
293
|
+
* Creates an instance of Cell.
|
|
294
|
+
*
|
|
295
|
+
* @param outPoint - The output point of the cell.
|
|
296
|
+
* @param cellOutput - The cell output of the cell.
|
|
297
|
+
* @param outputData - The output data of the cell.
|
|
298
|
+
*/
|
|
299
|
+
constructor(outPoint, cellOutput, outputData) {
|
|
300
|
+
this.outPoint = outPoint;
|
|
301
|
+
this.cellOutput = cellOutput;
|
|
302
|
+
this.outputData = outputData;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Creates a Cell instance from a CellLike object.
|
|
306
|
+
*
|
|
307
|
+
* @param cell - A CellLike object or an instance of Cell.
|
|
308
|
+
* @returns A Cell instance.
|
|
309
|
+
*/
|
|
310
|
+
static from(cell) {
|
|
311
|
+
if (cell instanceof Cell) {
|
|
312
|
+
return cell;
|
|
313
|
+
}
|
|
314
|
+
return new Cell(OutPoint.from(cell.outPoint), CellOutput.from(cell.cellOutput), (0, hex_1.hexFrom)(cell.outputData));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Clone a Cell
|
|
318
|
+
*
|
|
319
|
+
* @returns A cloned Cell instance.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* const cell1 = cell0.clone();
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
clone() {
|
|
327
|
+
return new Cell(this.outPoint.clone(), this.cellOutput.clone(), this.outputData);
|
|
328
|
+
}
|
|
392
329
|
}
|
|
393
330
|
exports.Cell = Cell;
|
|
394
331
|
class CellInput {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
* ```typescript
|
|
505
|
-
* const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
|
|
506
|
-
* ```
|
|
507
|
-
*/
|
|
508
|
-
static fromBytes(bytes) {
|
|
509
|
-
const view =
|
|
510
|
-
bytes instanceof mol.CellInput
|
|
511
|
-
? bytes
|
|
512
|
-
: new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
|
|
513
|
-
return new CellInput(
|
|
514
|
-
OutPoint.fromBytes(view.getPreviousOutput()),
|
|
515
|
-
(0, num_1.numFromBytes)(view.getSince().raw()),
|
|
516
|
-
);
|
|
517
|
-
}
|
|
332
|
+
/**
|
|
333
|
+
* Creates an instance of CellInput.
|
|
334
|
+
*
|
|
335
|
+
* @param previousOutput - The previous outpoint of the cell.
|
|
336
|
+
* @param since - The since value of the cell input.
|
|
337
|
+
* @param cellOutput - The optional cell output associated with the cell input.
|
|
338
|
+
* @param outputData - The optional output data associated with the cell input.
|
|
339
|
+
*/
|
|
340
|
+
constructor(previousOutput, since, cellOutput, outputData) {
|
|
341
|
+
this.previousOutput = previousOutput;
|
|
342
|
+
this.since = since;
|
|
343
|
+
this.cellOutput = cellOutput;
|
|
344
|
+
this.outputData = outputData;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Clone a CellInput.
|
|
348
|
+
*
|
|
349
|
+
* @returns A cloned CellInput instance.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* const cellInput1 = cellInput0.clone();
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
clone() {
|
|
357
|
+
return new CellInput(this.previousOutput.clone(), this.since, this.cellOutput?.clone(), this.outputData);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Creates a CellInput instance from a CellInputLike object.
|
|
361
|
+
*
|
|
362
|
+
* @param cellInput - A CellInputLike object or an instance of CellInput.
|
|
363
|
+
* @returns A CellInput instance.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const cellInput = CellInput.from({
|
|
368
|
+
* previousOutput: { txHash: "0x...", index: 0 },
|
|
369
|
+
* since: 0n
|
|
370
|
+
* });
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
static from(cellInput) {
|
|
374
|
+
if (cellInput instanceof CellInput) {
|
|
375
|
+
return cellInput;
|
|
376
|
+
}
|
|
377
|
+
return new CellInput(OutPoint.from(cellInput.previousOutput), (0, num_1.numFrom)(cellInput.since ?? 0), (0, utils_1.apply)(CellOutput.from, cellInput.cellOutput), (0, utils_1.apply)(hex_1.hexFrom, cellInput.outputData));
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Complete extra infos in the input. Like the output of the out point.
|
|
381
|
+
* The instance will be modified.
|
|
382
|
+
*
|
|
383
|
+
* @returns true if succeed.
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* await cellInput.completeExtraInfos();
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
async completeExtraInfos(client) {
|
|
390
|
+
if (this.cellOutput && this.outputData) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const cell = await client.getCell(this.previousOutput);
|
|
394
|
+
if (!cell) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
this.cellOutput = cell.cellOutput;
|
|
398
|
+
this.outputData = cell.outputData;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Converts the CellInput instance to molecule data format.
|
|
402
|
+
*
|
|
403
|
+
* @returns An object representing the cell input in molecule data format.
|
|
404
|
+
*/
|
|
405
|
+
_toMolData() {
|
|
406
|
+
return {
|
|
407
|
+
previousOutput: this.previousOutput._toMolData(),
|
|
408
|
+
since: (0, num_1.numToBytes)(this.since, 8),
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Converts the CellInput instance to bytes.
|
|
413
|
+
*
|
|
414
|
+
* @returns A Uint8Array containing the cell input bytes.
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* const cellInputBytes = cellInput.toBytes();
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
toBytes() {
|
|
422
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Creates a CellInput instance from a byte-like value or molecule CellInput.
|
|
426
|
+
*
|
|
427
|
+
* @param bytes - The byte-like value or molecule CellInput to convert.
|
|
428
|
+
* @returns A CellInput instance.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```typescript
|
|
432
|
+
* const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
static fromBytes(bytes) {
|
|
436
|
+
const view = bytes instanceof mol.CellInput
|
|
437
|
+
? bytes
|
|
438
|
+
: new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
|
|
439
|
+
return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), (0, num_1.numFromBytes)(view.getSince().raw()));
|
|
440
|
+
}
|
|
518
441
|
}
|
|
519
442
|
exports.CellInput = CellInput;
|
|
520
443
|
class CellDep {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
* @example
|
|
619
|
-
* ```typescript
|
|
620
|
-
* const isEqual = cellDep.eq(anotherCellDep);
|
|
621
|
-
* ```
|
|
622
|
-
*/
|
|
623
|
-
eq(val) {
|
|
624
|
-
const cellDep = CellDep.from(val);
|
|
625
|
-
return (
|
|
626
|
-
this.outPoint.eq(cellDep.outPoint) && this.depType === cellDep.depType
|
|
627
|
-
);
|
|
628
|
-
}
|
|
444
|
+
/**
|
|
445
|
+
* Creates an instance of CellDep.
|
|
446
|
+
*
|
|
447
|
+
* @param outPoint - The outpoint of the cell dependency.
|
|
448
|
+
* @param depType - The dependency type.
|
|
449
|
+
*/
|
|
450
|
+
constructor(outPoint, depType) {
|
|
451
|
+
this.outPoint = outPoint;
|
|
452
|
+
this.depType = depType;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Clone a CellDep.
|
|
456
|
+
*
|
|
457
|
+
* @returns A cloned CellDep instance.
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ```typescript
|
|
461
|
+
* const cellDep1 = cellDep0.clone();
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
clone() {
|
|
465
|
+
return new CellDep(this.outPoint.clone(), this.depType);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Creates a CellDep instance from a CellDepLike object.
|
|
469
|
+
*
|
|
470
|
+
* @param cellDep - A CellDepLike object or an instance of CellDep.
|
|
471
|
+
* @returns A CellDep instance.
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* const cellDep = CellDep.from({
|
|
476
|
+
* outPoint: { txHash: "0x...", index: 0 },
|
|
477
|
+
* depType: "depGroup"
|
|
478
|
+
* });
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
static from(cellDep) {
|
|
482
|
+
if (cellDep instanceof CellDep) {
|
|
483
|
+
return cellDep;
|
|
484
|
+
}
|
|
485
|
+
return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Converts the CellDep instance to molecule data format.
|
|
489
|
+
*
|
|
490
|
+
* @returns An object representing the cell dependency in molecule data format.
|
|
491
|
+
*/
|
|
492
|
+
_toMolData() {
|
|
493
|
+
return {
|
|
494
|
+
outPoint: this.outPoint._toMolData(),
|
|
495
|
+
depType: depTypeToBytes(this.depType),
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Converts the CellDep instance to bytes.
|
|
500
|
+
*
|
|
501
|
+
* @returns A Uint8Array containing the cell dependency bytes.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```typescript
|
|
505
|
+
* const cellDepBytes = cellDep.toBytes();
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
toBytes() {
|
|
509
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Creates a CellDep instance from a byte-like value or molecule CellDep.
|
|
513
|
+
*
|
|
514
|
+
* @param bytes - The byte-like value or molecule CellDep to convert.
|
|
515
|
+
* @returns A CellDep instance.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
fromBytes(bytes) {
|
|
523
|
+
const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
|
|
524
|
+
return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Compares the current CellDep instance with another CellDepLike object for equality.
|
|
528
|
+
*
|
|
529
|
+
* @param val - The CellDepLike object to compare with.
|
|
530
|
+
* @returns True if the cell deps are equal, otherwise false.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```typescript
|
|
534
|
+
* const isEqual = cellDep.eq(anotherCellDep);
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
eq(val) {
|
|
538
|
+
const cellDep = CellDep.from(val);
|
|
539
|
+
return (this.outPoint.eq(cellDep.outPoint) && this.depType === cellDep.depType);
|
|
540
|
+
}
|
|
629
541
|
}
|
|
630
542
|
exports.CellDep = CellDep;
|
|
631
543
|
class WitnessArgs {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
bytes instanceof mol.WitnessArgs
|
|
708
|
-
? bytes
|
|
709
|
-
: new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
|
|
710
|
-
return new WitnessArgs(
|
|
711
|
-
(0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getLock())?.raw()),
|
|
712
|
-
(0, utils_1.apply)(
|
|
713
|
-
hex_1.hexFrom,
|
|
714
|
-
mol.molOptional(view.getInputType())?.raw(),
|
|
715
|
-
),
|
|
716
|
-
(0, utils_1.apply)(
|
|
717
|
-
hex_1.hexFrom,
|
|
718
|
-
mol.molOptional(view.getOutputType())?.raw(),
|
|
719
|
-
),
|
|
720
|
-
);
|
|
721
|
-
}
|
|
544
|
+
/**
|
|
545
|
+
* Creates an instance of WitnessArgs.
|
|
546
|
+
*
|
|
547
|
+
* @param lock - The optional lock field of the witness.
|
|
548
|
+
* @param inputType - The optional input type field of the witness.
|
|
549
|
+
* @param outputType - The optional output type field of the witness.
|
|
550
|
+
*/
|
|
551
|
+
constructor(lock, inputType, outputType) {
|
|
552
|
+
this.lock = lock;
|
|
553
|
+
this.inputType = inputType;
|
|
554
|
+
this.outputType = outputType;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Creates a WitnessArgs instance from a WitnessArgsLike object.
|
|
558
|
+
*
|
|
559
|
+
* @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
|
|
560
|
+
* @returns A WitnessArgs instance.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```typescript
|
|
564
|
+
* const witnessArgs = WitnessArgs.from({
|
|
565
|
+
* lock: "0x...",
|
|
566
|
+
* inputType: "0x...",
|
|
567
|
+
* outputType: "0x..."
|
|
568
|
+
* });
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
static from(witnessArgs) {
|
|
572
|
+
if (witnessArgs instanceof WitnessArgs) {
|
|
573
|
+
return witnessArgs;
|
|
574
|
+
}
|
|
575
|
+
return new WitnessArgs((0, utils_1.apply)(hex_1.hexFrom, witnessArgs.lock), (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.inputType), (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.outputType));
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Converts the WitnessArgs instance to molecule data format.
|
|
579
|
+
*
|
|
580
|
+
* @returns An object representing the witness arguments in molecule data format.
|
|
581
|
+
*/
|
|
582
|
+
_toMolData() {
|
|
583
|
+
return {
|
|
584
|
+
lock: (0, utils_1.apply)(bytes_1.bytesFrom, this.lock),
|
|
585
|
+
inputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.inputType),
|
|
586
|
+
outputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.outputType),
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Converts the WitnessArgs instance to bytes.
|
|
591
|
+
*
|
|
592
|
+
* @returns A Uint8Array containing the witness arguments bytes.
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* ```typescript
|
|
596
|
+
* const witnessArgsBytes = witnessArgs.toBytes();
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
toBytes() {
|
|
600
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
|
|
604
|
+
*
|
|
605
|
+
* @param bytes - The byte-like value or molecule WitnessArgs to convert.
|
|
606
|
+
* @returns A WitnessArgs instance.
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
static fromBytes(bytes) {
|
|
614
|
+
const view = bytes instanceof mol.WitnessArgs
|
|
615
|
+
? bytes
|
|
616
|
+
: new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
|
|
617
|
+
return new WitnessArgs((0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getLock())?.raw()), (0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getInputType())?.raw()), (0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getOutputType())?.raw()));
|
|
618
|
+
}
|
|
722
619
|
}
|
|
723
620
|
exports.WitnessArgs = WitnessArgs;
|
|
724
621
|
function udtBalanceFrom(dataLike) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
622
|
+
const data = (0, bytes_1.bytesFrom)(dataLike).slice(0, 16);
|
|
623
|
+
if (data.length !== 16) {
|
|
624
|
+
throw new Error("Invalid UDT cell data");
|
|
625
|
+
}
|
|
626
|
+
return (0, num_1.numFromBytes)(data);
|
|
730
627
|
}
|
|
731
628
|
exports.udtBalanceFrom = udtBalanceFrom;
|
|
732
629
|
class Transaction {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
* @example
|
|
820
|
-
* ```typescript
|
|
821
|
-
* const transaction = Transaction.from({
|
|
822
|
-
* version: 0,
|
|
823
|
-
* cellDeps: [],
|
|
824
|
-
* headerDeps: [],
|
|
825
|
-
* inputs: [],
|
|
826
|
-
* outputs: [],
|
|
827
|
-
* outputsData: [],
|
|
828
|
-
* witnesses: []
|
|
829
|
-
* });
|
|
830
|
-
* ```
|
|
831
|
-
*/
|
|
832
|
-
static from(tx) {
|
|
833
|
-
if (tx instanceof Transaction) {
|
|
834
|
-
return tx;
|
|
835
|
-
}
|
|
836
|
-
const outputs =
|
|
837
|
-
tx.outputs?.map((output, i) => {
|
|
838
|
-
const o = CellOutput.from({
|
|
839
|
-
...output,
|
|
840
|
-
capacity: output.capacity ?? 0,
|
|
841
|
-
});
|
|
842
|
-
if (o.capacity === fixedPoint_1.Zero) {
|
|
843
|
-
o.capacity = (0, fixedPoint_1.fixedPointFrom)(
|
|
844
|
-
o.occupiedSize +
|
|
845
|
-
((0, utils_1.apply)(bytes_1.bytesFrom, tx.outputsData?.[i])
|
|
846
|
-
?.length ?? 0),
|
|
847
|
-
);
|
|
630
|
+
/**
|
|
631
|
+
* Creates an instance of Transaction.
|
|
632
|
+
*
|
|
633
|
+
* @param version - The version of the transaction.
|
|
634
|
+
* @param cellDeps - The cell dependencies of the transaction.
|
|
635
|
+
* @param headerDeps - The header dependencies of the transaction.
|
|
636
|
+
* @param inputs - The inputs of the transaction.
|
|
637
|
+
* @param outputs - The outputs of the transaction.
|
|
638
|
+
* @param outputsData - The data associated with the outputs.
|
|
639
|
+
* @param witnesses - The witnesses of the transaction.
|
|
640
|
+
*/
|
|
641
|
+
constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
|
|
642
|
+
this.version = version;
|
|
643
|
+
this.cellDeps = cellDeps;
|
|
644
|
+
this.headerDeps = headerDeps;
|
|
645
|
+
this.inputs = inputs;
|
|
646
|
+
this.outputs = outputs;
|
|
647
|
+
this.outputsData = outputsData;
|
|
648
|
+
this.witnesses = witnesses;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Creates a default Transaction instance with empty fields.
|
|
652
|
+
*
|
|
653
|
+
* @returns A default Transaction instance.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```typescript
|
|
657
|
+
* const defaultTx = Transaction.default();
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
static default() {
|
|
661
|
+
return new Transaction(0n, [], [], [], [], [], []);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Copy every properties from another transaction.
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
* ```typescript
|
|
668
|
+
* this.copy(Transaction.default());
|
|
669
|
+
* ```
|
|
670
|
+
*/
|
|
671
|
+
copy(txLike) {
|
|
672
|
+
const tx = Transaction.from(txLike);
|
|
673
|
+
this.version = tx.version;
|
|
674
|
+
this.cellDeps = tx.cellDeps;
|
|
675
|
+
this.headerDeps = tx.headerDeps;
|
|
676
|
+
this.inputs = tx.inputs;
|
|
677
|
+
this.outputs = tx.outputs;
|
|
678
|
+
this.outputsData = tx.outputsData;
|
|
679
|
+
this.witnesses = tx.witnesses;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Clone a Transaction.
|
|
683
|
+
*
|
|
684
|
+
* @returns A cloned instance
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* ```typescript
|
|
688
|
+
* const tx1 = tx0.clone();
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
691
|
+
clone() {
|
|
692
|
+
return new Transaction(0n, this.cellDeps.map((c) => c.clone()), [...this.headerDeps], this.inputs.map((i) => i.clone()), this.outputs.map((o) => o.clone()), [...this.outputsData], [...this.witnesses]);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Creates a Transaction instance from a TransactionLike object.
|
|
696
|
+
*
|
|
697
|
+
* @param tx - A TransactionLike object or an instance of Transaction.
|
|
698
|
+
* @returns A Transaction instance.
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* ```typescript
|
|
702
|
+
* const transaction = Transaction.from({
|
|
703
|
+
* version: 0,
|
|
704
|
+
* cellDeps: [],
|
|
705
|
+
* headerDeps: [],
|
|
706
|
+
* inputs: [],
|
|
707
|
+
* outputs: [],
|
|
708
|
+
* outputsData: [],
|
|
709
|
+
* witnesses: []
|
|
710
|
+
* });
|
|
711
|
+
* ```
|
|
712
|
+
*/
|
|
713
|
+
static from(tx) {
|
|
714
|
+
if (tx instanceof Transaction) {
|
|
715
|
+
return tx;
|
|
848
716
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
return new Transaction(
|
|
865
|
-
(0, num_1.numFrom)(tx.version ?? 0),
|
|
866
|
-
tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [],
|
|
867
|
-
tx.headerDeps?.map(hex_1.hexFrom) ?? [],
|
|
868
|
-
tx.inputs?.map((input) => CellInput.from(input)) ?? [],
|
|
869
|
-
outputs,
|
|
870
|
-
outputsData,
|
|
871
|
-
tx.witnesses?.map(hex_1.hexFrom) ?? [],
|
|
872
|
-
);
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* Creates a Transaction instance from a Lumos skeleton.
|
|
876
|
-
*
|
|
877
|
-
* @param skeleton - The Lumos transaction skeleton.
|
|
878
|
-
* @returns A Transaction instance.
|
|
879
|
-
*
|
|
880
|
-
* @throws Will throw an error if an input's outPoint is missing.
|
|
881
|
-
*
|
|
882
|
-
* @example
|
|
883
|
-
* ```typescript
|
|
884
|
-
* const transaction = Transaction.fromLumosSkeleton(skeleton);
|
|
885
|
-
* ```
|
|
886
|
-
*/
|
|
887
|
-
static fromLumosSkeleton(skeleton) {
|
|
888
|
-
return Transaction.from({
|
|
889
|
-
version: 0n,
|
|
890
|
-
cellDeps: skeleton.cellDeps.toArray(),
|
|
891
|
-
headerDeps: skeleton.headerDeps.toArray(),
|
|
892
|
-
inputs: skeleton.inputs.toArray().map((input, i) => {
|
|
893
|
-
if (!input.outPoint) {
|
|
894
|
-
throw new Error("outPoint is required in input");
|
|
717
|
+
const outputs = tx.outputs?.map((output, i) => {
|
|
718
|
+
const o = CellOutput.from({
|
|
719
|
+
...output,
|
|
720
|
+
capacity: output.capacity ?? 0,
|
|
721
|
+
});
|
|
722
|
+
if (o.capacity === fixedPoint_1.Zero) {
|
|
723
|
+
o.capacity = (0, fixedPoint_1.fixedPointFrom)(o.occupiedSize +
|
|
724
|
+
((0, utils_1.apply)(bytes_1.bytesFrom, tx.outputsData?.[i])?.length ?? 0));
|
|
725
|
+
}
|
|
726
|
+
return o;
|
|
727
|
+
}) ?? [];
|
|
728
|
+
const outputsData = outputs.map((_, i) => (0, hex_1.hexFrom)(tx.outputsData?.[i] ?? "0x"));
|
|
729
|
+
if (tx.outputsData !== undefined &&
|
|
730
|
+
outputsData.length < tx.outputsData.length) {
|
|
731
|
+
outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => (0, hex_1.hexFrom)(d)));
|
|
895
732
|
}
|
|
896
|
-
return CellInput.from(
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
733
|
+
return new Transaction((0, num_1.numFrom)(tx.version ?? 0), tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [], tx.headerDeps?.map(hex_1.hexFrom) ?? [], tx.inputs?.map((input) => CellInput.from(input)) ?? [], outputs, outputsData, tx.witnesses?.map(hex_1.hexFrom) ?? []);
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Creates a Transaction instance from a Lumos skeleton.
|
|
737
|
+
*
|
|
738
|
+
* @param skeleton - The Lumos transaction skeleton.
|
|
739
|
+
* @returns A Transaction instance.
|
|
740
|
+
*
|
|
741
|
+
* @throws Will throw an error if an input's outPoint is missing.
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* ```typescript
|
|
745
|
+
* const transaction = Transaction.fromLumosSkeleton(skeleton);
|
|
746
|
+
* ```
|
|
747
|
+
*/
|
|
748
|
+
static fromLumosSkeleton(skeleton) {
|
|
749
|
+
return Transaction.from({
|
|
750
|
+
version: 0n,
|
|
751
|
+
cellDeps: skeleton.cellDeps.toArray(),
|
|
752
|
+
headerDeps: skeleton.headerDeps.toArray(),
|
|
753
|
+
inputs: skeleton.inputs.toArray().map((input, i) => {
|
|
754
|
+
if (!input.outPoint) {
|
|
755
|
+
throw new Error("outPoint is required in input");
|
|
756
|
+
}
|
|
757
|
+
return CellInput.from({
|
|
758
|
+
previousOutput: input.outPoint,
|
|
759
|
+
since: skeleton.inputSinces.get(i, "0x0"),
|
|
760
|
+
cellOutput: input.cellOutput,
|
|
761
|
+
outputData: input.data,
|
|
762
|
+
});
|
|
763
|
+
}),
|
|
764
|
+
outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
|
|
765
|
+
outputsData: skeleton.outputs.toArray().map((output) => output.data),
|
|
766
|
+
witnesses: skeleton.witnesses.toArray(),
|
|
901
767
|
});
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
hasher.update(this.hash());
|
|
1024
|
-
for (let i = 0; i < this.witnesses.length; i += 1) {
|
|
1025
|
-
const input = this.inputs[i];
|
|
1026
|
-
if (input) {
|
|
1027
|
-
await input.completeExtraInfos(client);
|
|
1028
|
-
if (!input.cellOutput) {
|
|
1029
|
-
throw new Error("Unable to complete input");
|
|
1030
|
-
}
|
|
1031
|
-
if (!script.eq(input.cellOutput.lock)) {
|
|
1032
|
-
continue;
|
|
768
|
+
}
|
|
769
|
+
stringify() {
|
|
770
|
+
return JSON.stringify(this, (_, value) => {
|
|
771
|
+
if (typeof value === "bigint") {
|
|
772
|
+
return (0, num_1.numToHex)(value);
|
|
773
|
+
}
|
|
774
|
+
return value;
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Converts the raw transaction data to bytes.
|
|
779
|
+
*
|
|
780
|
+
* @returns A Uint8Array containing the raw transaction bytes.
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* const rawTxBytes = transaction.rawToBytes();
|
|
785
|
+
* ```
|
|
786
|
+
*/
|
|
787
|
+
rawToBytes() {
|
|
788
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeRawTransaction({
|
|
789
|
+
version: (0, num_1.numToBytes)(this.version, 4),
|
|
790
|
+
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
791
|
+
headerDeps: this.headerDeps.map((header) => (0, bytes_1.bytesFrom)(header)),
|
|
792
|
+
inputs: this.inputs.map((i) => i._toMolData()),
|
|
793
|
+
outputs: this.outputs.map((o) => o._toMolData()),
|
|
794
|
+
outputsData: this.outputsData.map((header) => (0, bytes_1.bytesFrom)(header)),
|
|
795
|
+
}));
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Converts the whole transaction data to bytes.
|
|
799
|
+
*
|
|
800
|
+
* @returns A Uint8Array containing the full transaction bytes.
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* ```typescript
|
|
804
|
+
* const txBytes = transaction.toBytes();
|
|
805
|
+
* ```
|
|
806
|
+
*/
|
|
807
|
+
toBytes() {
|
|
808
|
+
return (0, bytes_1.bytesFrom)(mol.SerializeTransaction({
|
|
809
|
+
raw: {
|
|
810
|
+
version: (0, num_1.numToBytes)(this.version, 4),
|
|
811
|
+
cellDeps: this.cellDeps.map((d) => d._toMolData()),
|
|
812
|
+
headerDeps: this.headerDeps.map((header) => (0, bytes_1.bytesFrom)(header)),
|
|
813
|
+
inputs: this.inputs.map((i) => i._toMolData()),
|
|
814
|
+
outputs: this.outputs.map((o) => o._toMolData()),
|
|
815
|
+
outputsData: this.outputsData.map((header) => (0, bytes_1.bytesFrom)(header)),
|
|
816
|
+
},
|
|
817
|
+
witnesses: this.witnesses.map((witness) => (0, bytes_1.bytesFrom)(witness)),
|
|
818
|
+
}));
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Calculates the hash of the transaction.
|
|
822
|
+
*
|
|
823
|
+
* @returns The hash of the transaction.
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* ```typescript
|
|
827
|
+
* const txHash = transaction.hash();
|
|
828
|
+
* ```
|
|
829
|
+
*/
|
|
830
|
+
hash() {
|
|
831
|
+
return (0, hasher_1.hashCkb)(this.rawToBytes());
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Hashes a witness and updates the hasher.
|
|
835
|
+
*
|
|
836
|
+
* @param witness - The witness to hash.
|
|
837
|
+
* @param hasher - The hasher instance to update.
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```typescript
|
|
841
|
+
* Transaction.hashWitnessToHasher("0x...", hasher);
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
static hashWitnessToHasher(witness, hasher) {
|
|
845
|
+
const raw = (0, bytes_1.bytesFrom)((0, hex_1.hexFrom)(witness));
|
|
846
|
+
hasher.update((0, num_1.numToBytes)(raw.length, 8));
|
|
847
|
+
hasher.update(raw);
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Computes the signing hash information for a given script.
|
|
851
|
+
*
|
|
852
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
853
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
854
|
+
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
855
|
+
* or undefined if no matching input is found.
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* ```typescript
|
|
859
|
+
* const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
|
|
860
|
+
* if (signHashInfo) {
|
|
861
|
+
* console.log(signHashInfo.message); // Outputs the signing message
|
|
862
|
+
* console.log(signHashInfo.position); // Outputs the witness position
|
|
863
|
+
* }
|
|
864
|
+
* ```
|
|
865
|
+
*/
|
|
866
|
+
async getSignHashInfo(scriptLike, client) {
|
|
867
|
+
const script = script_1.Script.from(scriptLike);
|
|
868
|
+
let position = -1;
|
|
869
|
+
const hasher = new hasher_1.Hasher();
|
|
870
|
+
hasher.update(this.hash());
|
|
871
|
+
for (let i = 0; i < this.witnesses.length; i += 1) {
|
|
872
|
+
const input = this.inputs[i];
|
|
873
|
+
if (input) {
|
|
874
|
+
await input.completeExtraInfos(client);
|
|
875
|
+
if (!input.cellOutput) {
|
|
876
|
+
throw new Error("Unable to complete input");
|
|
877
|
+
}
|
|
878
|
+
if (!script.eq(input.cellOutput.lock)) {
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
if (position === -1) {
|
|
882
|
+
position = i;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (position === -1) {
|
|
886
|
+
return undefined;
|
|
887
|
+
}
|
|
888
|
+
Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
|
|
1033
889
|
}
|
|
1034
890
|
if (position === -1) {
|
|
1035
|
-
|
|
891
|
+
return undefined;
|
|
1036
892
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
1066
|
-
const input = this.inputs[i];
|
|
1067
|
-
await input.completeExtraInfos(client);
|
|
1068
|
-
if (!input.cellOutput) {
|
|
1069
|
-
throw new Error("Unable to complete input");
|
|
1070
|
-
}
|
|
1071
|
-
if (script.eq(input.cellOutput.lock)) {
|
|
1072
|
-
return i;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
/**
|
|
1077
|
-
* Find the last occurrence of a input with the specified lock
|
|
1078
|
-
*
|
|
1079
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
1080
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
1081
|
-
* @returns A promise that resolves to the prepared transaction
|
|
1082
|
-
*
|
|
1083
|
-
* @example
|
|
1084
|
-
* ```typescript
|
|
1085
|
-
* const index = await tx.findLastInputIndexByLock(scriptLike, client);
|
|
1086
|
-
* ```
|
|
1087
|
-
*/
|
|
1088
|
-
async findLastInputIndexByLock(scriptLike, client) {
|
|
1089
|
-
const script = script_1.Script.from(scriptLike);
|
|
1090
|
-
for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
|
|
1091
|
-
const input = this.inputs[i];
|
|
1092
|
-
await input.completeExtraInfos(client);
|
|
1093
|
-
if (!input.cellOutput) {
|
|
1094
|
-
throw new Error("Unable to complete input");
|
|
1095
|
-
}
|
|
1096
|
-
if (script.eq(input.cellOutput.lock)) {
|
|
1097
|
-
return i;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
* Add cell deps if they are not existed
|
|
1103
|
-
*
|
|
1104
|
-
* @param cellDepLikes - The cell deps to add
|
|
1105
|
-
*
|
|
1106
|
-
* @example
|
|
1107
|
-
* ```typescript
|
|
1108
|
-
* tx.addCellDeps(cellDep);
|
|
1109
|
-
* ```
|
|
1110
|
-
*/
|
|
1111
|
-
addCellDeps(...cellDepsLike) {
|
|
1112
|
-
cellDepsLike.flat().forEach((cellDepLike) => {
|
|
1113
|
-
const cellDep = CellDep.from(cellDepLike);
|
|
1114
|
-
if (this.cellDeps.some((c) => c.eq(cellDep))) {
|
|
1115
|
-
return;
|
|
1116
|
-
}
|
|
1117
|
-
this.cellDeps.push(cellDep);
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Add cell dep from infos if they are not existed
|
|
1122
|
-
*
|
|
1123
|
-
* @param client - A client for searching cell deps
|
|
1124
|
-
* @param cellDepLikes - The cell dep infos to add
|
|
1125
|
-
*
|
|
1126
|
-
* @example
|
|
1127
|
-
* ```typescript
|
|
1128
|
-
* tx.addCellDepInfos(client, cellDepInfos);
|
|
1129
|
-
* ```
|
|
1130
|
-
*/
|
|
1131
|
-
async addCellDepInfos(client, ...cellDepInfosLike) {
|
|
1132
|
-
this.addCellDeps(await client.getCellDeps(...cellDepInfosLike));
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Add cell deps from known script
|
|
1136
|
-
*
|
|
1137
|
-
* @param client - The client for searching known script and cell deps
|
|
1138
|
-
* @param scripts - The known scripts to add
|
|
1139
|
-
*
|
|
1140
|
-
* @example
|
|
1141
|
-
* ```typescript
|
|
1142
|
-
* tx.addCellDepsOfKnownScripts(client, KnownScript.OmniLock);
|
|
1143
|
-
* ```
|
|
1144
|
-
*/
|
|
1145
|
-
async addCellDepsOfKnownScripts(client, ...scripts) {
|
|
1146
|
-
await Promise.all(
|
|
1147
|
-
scripts
|
|
1148
|
-
.flat()
|
|
1149
|
-
.map(async (script) =>
|
|
1150
|
-
this.addCellDepInfos(
|
|
1151
|
-
client,
|
|
1152
|
-
(await client.getKnownScript(script)).cellDeps,
|
|
1153
|
-
),
|
|
1154
|
-
),
|
|
1155
|
-
);
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Set output data at index.
|
|
1159
|
-
*
|
|
1160
|
-
* @param index - The index of the output data.
|
|
1161
|
-
* @param witness - The data to set.
|
|
1162
|
-
*
|
|
1163
|
-
* @example
|
|
1164
|
-
* ```typescript
|
|
1165
|
-
* await tx.setOutputData(0, "0x00");
|
|
1166
|
-
* ```
|
|
1167
|
-
*/
|
|
1168
|
-
setOutputDataAt(index, data) {
|
|
1169
|
-
if (this.outputsData.length < index) {
|
|
1170
|
-
this.outputsData.push(
|
|
1171
|
-
...Array.from(new Array(index - this.outputsData.length), () => "0x"),
|
|
1172
|
-
);
|
|
1173
|
-
}
|
|
1174
|
-
this.outputsData[index] = (0, hex_1.hexFrom)(data);
|
|
1175
|
-
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Add output
|
|
1178
|
-
*
|
|
1179
|
-
* @param output - The cell output to add
|
|
1180
|
-
* @param data - optional output data
|
|
1181
|
-
*
|
|
1182
|
-
* @example
|
|
1183
|
-
* ```typescript
|
|
1184
|
-
* await tx.addOutput(cellOutput, "0xabcd");
|
|
1185
|
-
* ```
|
|
1186
|
-
*/
|
|
1187
|
-
addOutput(outputLike, outputData = "0x") {
|
|
1188
|
-
const output = CellOutput.from({
|
|
1189
|
-
...outputLike,
|
|
1190
|
-
capacity: outputLike.capacity ?? 0,
|
|
1191
|
-
});
|
|
1192
|
-
if (output.capacity === fixedPoint_1.Zero) {
|
|
1193
|
-
output.capacity = (0, fixedPoint_1.fixedPointFrom)(
|
|
1194
|
-
output.occupiedSize + (0, bytes_1.bytesFrom)(outputData).length,
|
|
1195
|
-
);
|
|
1196
|
-
}
|
|
1197
|
-
const i = this.outputs.push(output) - 1;
|
|
1198
|
-
this.setOutputDataAt(i, outputData);
|
|
1199
|
-
}
|
|
1200
|
-
/**
|
|
1201
|
-
* Get witness at index as WitnessArgs
|
|
1202
|
-
*
|
|
1203
|
-
* @param index - The index of the witness.
|
|
1204
|
-
* @returns The witness parsed as WitnessArgs.
|
|
1205
|
-
*
|
|
1206
|
-
* @example
|
|
1207
|
-
* ```typescript
|
|
1208
|
-
* const witnessArgs = await tx.getWitnessArgsAt(0);
|
|
1209
|
-
* ```
|
|
1210
|
-
*/
|
|
1211
|
-
getWitnessArgsAt(index) {
|
|
1212
|
-
const rawWitness = this.witnesses[index];
|
|
1213
|
-
return (rawWitness ?? "0x") !== "0x"
|
|
1214
|
-
? WitnessArgs.fromBytes(rawWitness)
|
|
1215
|
-
: undefined;
|
|
1216
|
-
}
|
|
1217
|
-
/**
|
|
1218
|
-
* Set witness at index by WitnessArgs
|
|
1219
|
-
*
|
|
1220
|
-
* @param index - The index of the witness.
|
|
1221
|
-
* @param witness - The WitnessArgs to set.
|
|
1222
|
-
*
|
|
1223
|
-
* @example
|
|
1224
|
-
* ```typescript
|
|
1225
|
-
* await tx.setWitnessArgsAt(0, witnessArgs);
|
|
1226
|
-
* ```
|
|
1227
|
-
*/
|
|
1228
|
-
setWitnessArgsAt(index, witness) {
|
|
1229
|
-
if (this.witnesses.length < index) {
|
|
1230
|
-
this.witnesses.push(
|
|
1231
|
-
...Array.from(new Array(index - this.witnesses.length), () => "0x"),
|
|
1232
|
-
);
|
|
1233
|
-
}
|
|
1234
|
-
this.witnesses[index] = (0, hex_1.hexFrom)(witness.toBytes());
|
|
1235
|
-
}
|
|
1236
|
-
/**
|
|
1237
|
-
* Prepare dummy witness for sighash all method
|
|
1238
|
-
*
|
|
1239
|
-
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
1240
|
-
* @param lockLen - The length of dummy lock bytes.
|
|
1241
|
-
* @param client - The client for complete extra infos in the transaction.
|
|
1242
|
-
* @returns A promise that resolves to the prepared transaction
|
|
1243
|
-
*
|
|
1244
|
-
* @example
|
|
1245
|
-
* ```typescript
|
|
1246
|
-
* await tx.prepareSighashAllWitness(scriptLike, 85, client);
|
|
1247
|
-
* ```
|
|
1248
|
-
*/
|
|
1249
|
-
async prepareSighashAllWitness(scriptLike, lockLen, client) {
|
|
1250
|
-
const position = await this.findInputIndexByLock(scriptLike, client);
|
|
1251
|
-
if (position === undefined) {
|
|
1252
|
-
return;
|
|
1253
|
-
}
|
|
1254
|
-
const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
|
|
1255
|
-
witness.lock = (0, hex_1.hexFrom)(Array.from(new Array(lockLen), () => 0));
|
|
1256
|
-
this.setWitnessArgsAt(position, witness);
|
|
1257
|
-
}
|
|
1258
|
-
async getInputsCapacity(client) {
|
|
1259
|
-
return (0, utils_1.reduceAsync)(
|
|
1260
|
-
this.inputs,
|
|
1261
|
-
async (acc, input) => {
|
|
1262
|
-
await input.completeExtraInfos(client);
|
|
1263
|
-
if (!input.cellOutput) {
|
|
1264
|
-
throw new Error("Unable to complete input");
|
|
893
|
+
return {
|
|
894
|
+
message: hasher.digest(),
|
|
895
|
+
position,
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Find the first occurrence of a input with the specified lock
|
|
900
|
+
*
|
|
901
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
902
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
903
|
+
* @returns A promise that resolves to the prepared transaction
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* ```typescript
|
|
907
|
+
* const index = await tx.findInputIndexByLock(scriptLike, client);
|
|
908
|
+
* ```
|
|
909
|
+
*/
|
|
910
|
+
async findInputIndexByLock(scriptLike, client) {
|
|
911
|
+
const script = script_1.Script.from(scriptLike);
|
|
912
|
+
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
913
|
+
const input = this.inputs[i];
|
|
914
|
+
await input.completeExtraInfos(client);
|
|
915
|
+
if (!input.cellOutput) {
|
|
916
|
+
throw new Error("Unable to complete input");
|
|
917
|
+
}
|
|
918
|
+
if (script.eq(input.cellOutput.lock)) {
|
|
919
|
+
return i;
|
|
920
|
+
}
|
|
1265
921
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Find the last occurrence of a input with the specified lock
|
|
925
|
+
*
|
|
926
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
927
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
928
|
+
* @returns A promise that resolves to the prepared transaction
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* ```typescript
|
|
932
|
+
* const index = await tx.findLastInputIndexByLock(scriptLike, client);
|
|
933
|
+
* ```
|
|
934
|
+
*/
|
|
935
|
+
async findLastInputIndexByLock(scriptLike, client) {
|
|
936
|
+
const script = script_1.Script.from(scriptLike);
|
|
937
|
+
for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
|
|
938
|
+
const input = this.inputs[i];
|
|
939
|
+
await input.completeExtraInfos(client);
|
|
940
|
+
if (!input.cellOutput) {
|
|
941
|
+
throw new Error("Unable to complete input");
|
|
942
|
+
}
|
|
943
|
+
if (script.eq(input.cellOutput.lock)) {
|
|
944
|
+
return i;
|
|
945
|
+
}
|
|
1284
946
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Add cell deps if they are not existed
|
|
950
|
+
*
|
|
951
|
+
* @param cellDepLikes - The cell deps to add
|
|
952
|
+
*
|
|
953
|
+
* @example
|
|
954
|
+
* ```typescript
|
|
955
|
+
* tx.addCellDeps(cellDep);
|
|
956
|
+
* ```
|
|
957
|
+
*/
|
|
958
|
+
addCellDeps(...cellDepsLike) {
|
|
959
|
+
cellDepsLike.flat().forEach((cellDepLike) => {
|
|
960
|
+
const cellDep = CellDep.from(cellDepLike);
|
|
961
|
+
if (this.cellDeps.some((c) => c.eq(cellDep))) {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
this.cellDeps.push(cellDep);
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Add cell dep from infos if they are not existed
|
|
969
|
+
*
|
|
970
|
+
* @param client - A client for searching cell deps
|
|
971
|
+
* @param cellDepLikes - The cell dep infos to add
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```typescript
|
|
975
|
+
* tx.addCellDepInfos(client, cellDepInfos);
|
|
976
|
+
* ```
|
|
977
|
+
*/
|
|
978
|
+
async addCellDepInfos(client, ...cellDepInfosLike) {
|
|
979
|
+
this.addCellDeps(await client.getCellDeps(...cellDepInfosLike));
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Add cell deps from known script
|
|
983
|
+
*
|
|
984
|
+
* @param client - The client for searching known script and cell deps
|
|
985
|
+
* @param scripts - The known scripts to add
|
|
986
|
+
*
|
|
987
|
+
* @example
|
|
988
|
+
* ```typescript
|
|
989
|
+
* tx.addCellDepsOfKnownScripts(client, KnownScript.OmniLock);
|
|
990
|
+
* ```
|
|
991
|
+
*/
|
|
992
|
+
async addCellDepsOfKnownScripts(client, ...scripts) {
|
|
993
|
+
await Promise.all(scripts
|
|
994
|
+
.flat()
|
|
995
|
+
.map(async (script) => this.addCellDepInfos(client, (await client.getKnownScript(script)).cellDeps)));
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Set output data at index.
|
|
999
|
+
*
|
|
1000
|
+
* @param index - The index of the output data.
|
|
1001
|
+
* @param witness - The data to set.
|
|
1002
|
+
*
|
|
1003
|
+
* @example
|
|
1004
|
+
* ```typescript
|
|
1005
|
+
* await tx.setOutputData(0, "0x00");
|
|
1006
|
+
* ```
|
|
1007
|
+
*/
|
|
1008
|
+
setOutputDataAt(index, data) {
|
|
1009
|
+
if (this.outputsData.length < index) {
|
|
1010
|
+
this.outputsData.push(...Array.from(new Array(index - this.outputsData.length), () => "0x"));
|
|
1287
1011
|
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1012
|
+
this.outputsData[index] = (0, hex_1.hexFrom)(data);
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Add output
|
|
1016
|
+
*
|
|
1017
|
+
* @param output - The cell output to add
|
|
1018
|
+
* @param data - optional output data
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```typescript
|
|
1022
|
+
* await tx.addOutput(cellOutput, "0xabcd");
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
addOutput(outputLike, outputData = "0x") {
|
|
1026
|
+
const output = CellOutput.from({
|
|
1027
|
+
...outputLike,
|
|
1028
|
+
capacity: outputLike.capacity ?? 0,
|
|
1029
|
+
});
|
|
1030
|
+
if (output.capacity === fixedPoint_1.Zero) {
|
|
1031
|
+
output.capacity = (0, fixedPoint_1.fixedPointFrom)(output.occupiedSize + (0, bytes_1.bytesFrom)(outputData).length);
|
|
1298
1032
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1033
|
+
const i = this.outputs.push(output) - 1;
|
|
1034
|
+
this.setOutputDataAt(i, outputData);
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Get witness at index as WitnessArgs
|
|
1038
|
+
*
|
|
1039
|
+
* @param index - The index of the witness.
|
|
1040
|
+
* @returns The witness parsed as WitnessArgs.
|
|
1041
|
+
*
|
|
1042
|
+
* @example
|
|
1043
|
+
* ```typescript
|
|
1044
|
+
* const witnessArgs = await tx.getWitnessArgsAt(0);
|
|
1045
|
+
* ```
|
|
1046
|
+
*/
|
|
1047
|
+
getWitnessArgsAt(index) {
|
|
1048
|
+
const rawWitness = this.witnesses[index];
|
|
1049
|
+
return (rawWitness ?? "0x") !== "0x"
|
|
1050
|
+
? WitnessArgs.fromBytes(rawWitness)
|
|
1051
|
+
: undefined;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Set witness at index by WitnessArgs
|
|
1055
|
+
*
|
|
1056
|
+
* @param index - The index of the witness.
|
|
1057
|
+
* @param witness - The WitnessArgs to set.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* ```typescript
|
|
1061
|
+
* await tx.setWitnessArgsAt(0, witnessArgs);
|
|
1062
|
+
* ```
|
|
1063
|
+
*/
|
|
1064
|
+
setWitnessArgsAt(index, witness) {
|
|
1065
|
+
if (this.witnesses.length < index) {
|
|
1066
|
+
this.witnesses.push(...Array.from(new Array(index - this.witnesses.length), () => "0x"));
|
|
1322
1067
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1068
|
+
this.witnesses[index] = (0, hex_1.hexFrom)(witness.toBytes());
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Prepare dummy witness for sighash all method
|
|
1072
|
+
*
|
|
1073
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
1074
|
+
* @param lockLen - The length of dummy lock bytes.
|
|
1075
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
1076
|
+
* @returns A promise that resolves to the prepared transaction
|
|
1077
|
+
*
|
|
1078
|
+
* @example
|
|
1079
|
+
* ```typescript
|
|
1080
|
+
* await tx.prepareSighashAllWitness(scriptLike, 85, client);
|
|
1081
|
+
* ```
|
|
1082
|
+
*/
|
|
1083
|
+
async prepareSighashAllWitness(scriptLike, lockLen, client) {
|
|
1084
|
+
const position = await this.findInputIndexByLock(scriptLike, client);
|
|
1085
|
+
if (position === undefined) {
|
|
1086
|
+
return;
|
|
1339
1087
|
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
const
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
);
|
|
1405
|
-
const extraCapacity =
|
|
1406
|
-
(await prepared.getInputsCapacity(from.client)) -
|
|
1407
|
-
prepared.getOutputsCapacity();
|
|
1408
|
-
// The extra capacity paid the fee without a change
|
|
1409
|
-
if (extraCapacity === leastFee) {
|
|
1410
|
-
this.copy(prepared);
|
|
1411
|
-
return [collected, false];
|
|
1412
|
-
}
|
|
1413
|
-
let changed = prepared.clone();
|
|
1414
|
-
const needed = (0, num_1.numFrom)(
|
|
1415
|
-
await Promise.resolve(change(changed, extraCapacity - leastFee)),
|
|
1416
|
-
);
|
|
1417
|
-
// No enough extra capacity to create new cells for change
|
|
1418
|
-
if (needed > fixedPoint_1.Zero) {
|
|
1419
|
-
leastExtraCapacity = needed;
|
|
1420
|
-
continue;
|
|
1421
|
-
}
|
|
1422
|
-
if (
|
|
1423
|
-
(await changed.getInputsCapacity(from.client)) -
|
|
1424
|
-
changed.getOutputsCapacity() !==
|
|
1425
|
-
leastFee
|
|
1426
|
-
) {
|
|
1427
|
-
throw new Error(
|
|
1428
|
-
"The change function doesn't use all available capacity",
|
|
1429
|
-
);
|
|
1430
|
-
}
|
|
1431
|
-
// New change cells created, update the fee
|
|
1432
|
-
await from.prepareTransaction(changed);
|
|
1433
|
-
const changedFee = changed.estimateFee(feeRate);
|
|
1434
|
-
if (leastFee > changedFee) {
|
|
1435
|
-
throw new Error("The change function removed existed transaction data");
|
|
1436
|
-
}
|
|
1437
|
-
// The fee has been paid
|
|
1438
|
-
if (leastFee === changedFee) {
|
|
1439
|
-
this.copy(changed);
|
|
1440
|
-
return [collected, true];
|
|
1441
|
-
}
|
|
1442
|
-
// The fee after changing is more than the original fee
|
|
1443
|
-
leastFee = changedFee;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
completeFeeChangeToLock(from, change, feeRate, filter) {
|
|
1447
|
-
const script = script_1.Script.from(change);
|
|
1448
|
-
return this.completeFee(
|
|
1449
|
-
from,
|
|
1450
|
-
(tx, capacity) => {
|
|
1451
|
-
const changeCell = CellOutput.from({ capacity: 0, lock: script });
|
|
1452
|
-
const occupiedCapacity = (0, fixedPoint_1.fixedPointFrom)(
|
|
1453
|
-
changeCell.occupiedSize,
|
|
1454
|
-
);
|
|
1455
|
-
if (capacity < occupiedCapacity) {
|
|
1456
|
-
return occupiedCapacity;
|
|
1088
|
+
const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
|
|
1089
|
+
witness.lock = (0, hex_1.hexFrom)(Array.from(new Array(lockLen), () => 0));
|
|
1090
|
+
this.setWitnessArgsAt(position, witness);
|
|
1091
|
+
}
|
|
1092
|
+
async getInputsCapacity(client) {
|
|
1093
|
+
return (0, utils_1.reduceAsync)(this.inputs, async (acc, input) => {
|
|
1094
|
+
await input.completeExtraInfos(client);
|
|
1095
|
+
if (!input.cellOutput) {
|
|
1096
|
+
throw new Error("Unable to complete input");
|
|
1097
|
+
}
|
|
1098
|
+
return acc + input.cellOutput.capacity;
|
|
1099
|
+
}, (0, num_1.numFrom)(0));
|
|
1100
|
+
}
|
|
1101
|
+
getOutputsCapacity() {
|
|
1102
|
+
return this.outputs.reduce((acc, { capacity }) => acc + capacity, (0, num_1.numFrom)(0));
|
|
1103
|
+
}
|
|
1104
|
+
async getInputsUdtBalance(client, type) {
|
|
1105
|
+
return (0, utils_1.reduceAsync)(this.inputs, async (acc, input) => {
|
|
1106
|
+
await input.completeExtraInfos(client);
|
|
1107
|
+
if (!input.cellOutput || !input.outputData) {
|
|
1108
|
+
throw new Error("Unable to complete input");
|
|
1109
|
+
}
|
|
1110
|
+
if (!input.cellOutput.type?.eq(type)) {
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
return acc + udtBalanceFrom(input.outputData);
|
|
1114
|
+
}, (0, num_1.numFrom)(0));
|
|
1115
|
+
}
|
|
1116
|
+
getOutputsUdtBalance(type) {
|
|
1117
|
+
return this.outputs.reduce((acc, output, i) => {
|
|
1118
|
+
if (!output.type?.eq(type)) {
|
|
1119
|
+
return acc;
|
|
1120
|
+
}
|
|
1121
|
+
return acc + udtBalanceFrom(this.outputsData[i]);
|
|
1122
|
+
}, (0, num_1.numFrom)(0));
|
|
1123
|
+
}
|
|
1124
|
+
async completeInputs(from, filter, accumulator, init) {
|
|
1125
|
+
const scripts = (await from.getAddressObjs()).map(({ script }) => script);
|
|
1126
|
+
const collectedCells = [];
|
|
1127
|
+
let acc = init;
|
|
1128
|
+
for (const script of scripts) {
|
|
1129
|
+
for await (const cell of from.client.findCellsByCollectableSearchKey({
|
|
1130
|
+
script,
|
|
1131
|
+
scriptType: "lock",
|
|
1132
|
+
filter,
|
|
1133
|
+
scriptSearchMode: "exact",
|
|
1134
|
+
withData: true,
|
|
1135
|
+
})) {
|
|
1136
|
+
if (this.inputs.some(({ previousOutput }) => previousOutput.eq(cell.outPoint))) {
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
const i = collectedCells.push(cell);
|
|
1140
|
+
const next = await Promise.resolve(accumulator(acc, cell, i - 1, collectedCells));
|
|
1141
|
+
if (next === undefined) {
|
|
1142
|
+
this.inputs.push(...collectedCells.map(({ outPoint, outputData, cellOutput }) => CellInput.from({
|
|
1143
|
+
previousOutput: outPoint,
|
|
1144
|
+
since: 0,
|
|
1145
|
+
outputData,
|
|
1146
|
+
cellOutput,
|
|
1147
|
+
})));
|
|
1148
|
+
return collectedCells.length;
|
|
1149
|
+
}
|
|
1150
|
+
acc = next;
|
|
1151
|
+
}
|
|
1457
1152
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1153
|
+
throw new Error("Failed to find enough cells for input");
|
|
1154
|
+
}
|
|
1155
|
+
async completeInputsByCapacity(from, capacityTweak, filter) {
|
|
1156
|
+
const exceptedCapacity = this.getOutputsCapacity() + (0, num_1.numFrom)(capacityTweak ?? 0);
|
|
1157
|
+
const inputsCapacity = await this.getInputsCapacity(from.client);
|
|
1158
|
+
if (inputsCapacity >= exceptedCapacity) {
|
|
1159
|
+
return 0;
|
|
1160
|
+
}
|
|
1161
|
+
return this.completeInputs(from, filter ?? {
|
|
1162
|
+
scriptLenRange: [0, 1],
|
|
1163
|
+
outputDataLenRange: [0, 1],
|
|
1164
|
+
}, (acc, { cellOutput: { capacity } }) => {
|
|
1165
|
+
const sum = acc + capacity;
|
|
1166
|
+
return sum > exceptedCapacity ? undefined : sum;
|
|
1167
|
+
}, inputsCapacity);
|
|
1168
|
+
}
|
|
1169
|
+
async completeInputsByUdt(from, type) {
|
|
1170
|
+
const exceptedBalance = this.getOutputsUdtBalance(type);
|
|
1171
|
+
const inputsBalance = await this.getInputsUdtBalance(from.client, type);
|
|
1172
|
+
if (inputsBalance >= exceptedBalance) {
|
|
1173
|
+
return 0;
|
|
1174
|
+
}
|
|
1175
|
+
return this.completeInputs(from, {
|
|
1176
|
+
script: type,
|
|
1177
|
+
outputDataLenRange: [16, (0, num_1.numFrom)("0xffffffff")],
|
|
1178
|
+
}, (acc, { outputData }) => {
|
|
1179
|
+
const balance = udtBalanceFrom(outputData);
|
|
1180
|
+
const sum = acc + balance;
|
|
1181
|
+
return sum > exceptedBalance ? undefined : sum;
|
|
1182
|
+
}, inputsBalance);
|
|
1183
|
+
}
|
|
1184
|
+
estimateFee(feeRate) {
|
|
1185
|
+
const txSize = this.toBytes().length + 4;
|
|
1186
|
+
return ((0, num_1.numFrom)(txSize) * (0, num_1.numFrom)(feeRate) + (0, num_1.numFrom)(1000)) / (0, num_1.numFrom)(1000);
|
|
1187
|
+
}
|
|
1188
|
+
async completeFee(from, change, feeRate, filter) {
|
|
1189
|
+
// Complete all inputs extra infos for cache
|
|
1190
|
+
await this.getInputsCapacity(from.client);
|
|
1191
|
+
let leastFee = this.estimateFee(feeRate);
|
|
1192
|
+
let leastExtraCapacity = fixedPoint_1.Zero;
|
|
1193
|
+
while (true) {
|
|
1194
|
+
const prepared = await from.prepareTransaction(this.clone());
|
|
1195
|
+
const collected = await prepared.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
|
|
1196
|
+
const extraCapacity = (await prepared.getInputsCapacity(from.client)) -
|
|
1197
|
+
prepared.getOutputsCapacity();
|
|
1198
|
+
// The extra capacity paid the fee without a change
|
|
1199
|
+
if (extraCapacity === leastFee) {
|
|
1200
|
+
this.copy(prepared);
|
|
1201
|
+
return [collected, false];
|
|
1202
|
+
}
|
|
1203
|
+
let changed = prepared.clone();
|
|
1204
|
+
const needed = (0, num_1.numFrom)(await Promise.resolve(change(changed, extraCapacity - leastFee)));
|
|
1205
|
+
// No enough extra capacity to create new cells for change
|
|
1206
|
+
if (needed > fixedPoint_1.Zero) {
|
|
1207
|
+
leastExtraCapacity = needed;
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
if ((await changed.getInputsCapacity(from.client)) -
|
|
1211
|
+
changed.getOutputsCapacity() !==
|
|
1212
|
+
leastFee) {
|
|
1213
|
+
throw new Error("The change function doesn't use all available capacity");
|
|
1214
|
+
}
|
|
1215
|
+
// New change cells created, update the fee
|
|
1216
|
+
await from.prepareTransaction(changed);
|
|
1217
|
+
const changedFee = changed.estimateFee(feeRate);
|
|
1218
|
+
if (leastFee > changedFee) {
|
|
1219
|
+
throw new Error("The change function removed existed transaction data");
|
|
1220
|
+
}
|
|
1221
|
+
// The fee has been paid
|
|
1222
|
+
if (leastFee === changedFee) {
|
|
1223
|
+
this.copy(changed);
|
|
1224
|
+
return [collected, true];
|
|
1225
|
+
}
|
|
1226
|
+
// The fee after changing is more than the original fee
|
|
1227
|
+
leastFee = changedFee;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
completeFeeChangeToLock(from, change, feeRate, filter) {
|
|
1231
|
+
const script = script_1.Script.from(change);
|
|
1232
|
+
return this.completeFee(from, (tx, capacity) => {
|
|
1233
|
+
const changeCell = CellOutput.from({ capacity: 0, lock: script });
|
|
1234
|
+
const occupiedCapacity = (0, fixedPoint_1.fixedPointFrom)(changeCell.occupiedSize);
|
|
1235
|
+
if (capacity < occupiedCapacity) {
|
|
1236
|
+
return occupiedCapacity;
|
|
1237
|
+
}
|
|
1238
|
+
changeCell.capacity = capacity;
|
|
1239
|
+
tx.addOutput(changeCell);
|
|
1240
|
+
return 0;
|
|
1241
|
+
}, feeRate, filter);
|
|
1242
|
+
}
|
|
1243
|
+
completeFeeChangeToOutput(from, index, feeRate, filter) {
|
|
1244
|
+
const change = Number((0, num_1.numFrom)(index));
|
|
1245
|
+
if (!this.outputs[change]) {
|
|
1246
|
+
throw new Error("Non-existed output to change");
|
|
1247
|
+
}
|
|
1248
|
+
return this.completeFee(from, (tx, capacity) => {
|
|
1249
|
+
tx.outputs[change].capacity += capacity;
|
|
1250
|
+
return 0;
|
|
1251
|
+
}, feeRate, filter);
|
|
1252
|
+
}
|
|
1481
1253
|
}
|
|
1482
1254
|
exports.Transaction = Transaction;
|