@onekeyfe/cardano-coin-selection-asmjs 1.1.7 → 1.1.8
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.
|
@@ -33,6 +33,8 @@ const CardanoMessage = __importStar(require("@emurgo/cardano-message-signing-asm
|
|
|
33
33
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
34
34
|
const signTx_1 = require("./signTx");
|
|
35
35
|
const error_1 = require("./error");
|
|
36
|
+
const errors_1 = require("../errors");
|
|
37
|
+
const constants_1 = require("../../constants");
|
|
36
38
|
const types_1 = require("./types");
|
|
37
39
|
const getBalance = async (balances) => {
|
|
38
40
|
const value = await (0, exports.assetsToValue)(balances);
|
|
@@ -177,6 +179,11 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
|
|
|
177
179
|
// outputs txs
|
|
178
180
|
const outputs = [];
|
|
179
181
|
const outputsLen = body.outputs().len();
|
|
182
|
+
// All valid transactions must have at least one output
|
|
183
|
+
// Empty outputs means insufficient funds to cover the transaction
|
|
184
|
+
if (outputsLen === 0) {
|
|
185
|
+
throw new errors_1.CoinSelectionError(constants_1.ERROR.UTXO_BALANCE_INSUFFICIENT);
|
|
186
|
+
}
|
|
180
187
|
for (let i = 0; i < outputsLen; i++) {
|
|
181
188
|
const output = body.outputs().get(i);
|
|
182
189
|
const address = output.address().to_bech32();
|
|
@@ -216,9 +223,7 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
|
|
|
216
223
|
isChange,
|
|
217
224
|
});
|
|
218
225
|
}
|
|
219
|
-
const totalSpent = outputs.
|
|
220
|
-
? bignumber_js_1.default.sum(...outputs.map(o => o.amount)).toFixed()
|
|
221
|
-
: '0';
|
|
226
|
+
const totalSpent = bignumber_js_1.default.sum(...outputs.map(o => o.amount)).toFixed();
|
|
222
227
|
const token = (_b = (_a = outputs
|
|
223
228
|
.filter(o => !addresses.includes(o.address))
|
|
224
229
|
.find(o => o.assets.length > 0)) === null || _a === void 0 ? void 0 : _a.assets) === null || _b === void 0 ? void 0 : _b[0].unit;
|
|
@@ -4,6 +4,8 @@ import * as CardanoMessage from '@emurgo/cardano-message-signing-asmjs/cardano_m
|
|
|
4
4
|
import BigNumber from 'bignumber.js';
|
|
5
5
|
import { getUtxos as getRawUtxos, requestAccountKey } from './signTx';
|
|
6
6
|
import { DataSignError } from './error';
|
|
7
|
+
import { CoinSelectionError } from '../errors';
|
|
8
|
+
import { ERROR } from '../../constants';
|
|
7
9
|
import { CardanoCertificateType, } from './types';
|
|
8
10
|
const getBalance = async (balances) => {
|
|
9
11
|
const value = await assetsToValue(balances);
|
|
@@ -147,6 +149,11 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
|
|
|
147
149
|
// outputs txs
|
|
148
150
|
const outputs = [];
|
|
149
151
|
const outputsLen = body.outputs().len();
|
|
152
|
+
// All valid transactions must have at least one output
|
|
153
|
+
// Empty outputs means insufficient funds to cover the transaction
|
|
154
|
+
if (outputsLen === 0) {
|
|
155
|
+
throw new CoinSelectionError(ERROR.UTXO_BALANCE_INSUFFICIENT);
|
|
156
|
+
}
|
|
150
157
|
for (let i = 0; i < outputsLen; i++) {
|
|
151
158
|
const output = body.outputs().get(i);
|
|
152
159
|
const address = output.address().to_bech32();
|
|
@@ -186,9 +193,7 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
|
|
|
186
193
|
isChange,
|
|
187
194
|
});
|
|
188
195
|
}
|
|
189
|
-
const totalSpent = outputs.
|
|
190
|
-
? BigNumber.sum(...outputs.map(o => o.amount)).toFixed()
|
|
191
|
-
: '0';
|
|
196
|
+
const totalSpent = BigNumber.sum(...outputs.map(o => o.amount)).toFixed();
|
|
192
197
|
const token = (_b = (_a = outputs
|
|
193
198
|
.filter(o => !addresses.includes(o.address))
|
|
194
199
|
.find(o => o.assets.length > 0)) === null || _a === void 0 ? void 0 : _a.assets) === null || _b === void 0 ? void 0 : _b[0].unit;
|