|
354 | 354 |
|
355 | 355 | let dust = Math.floor(dustF);
|
356 | 356 | let utxos = getAllUtxos();
|
357 |
| - let memo = { satoshis: dust, memo: '\0' }; |
358 |
| - let draftTx = await draftWalletTx(utxos, null, memo); |
359 |
| - draftTx.outputs[0].satoshis = 0; |
360 |
| - draftTx.feeTarget += dust; |
| 357 | + let memo = { satoshis: dust, memo: '' }; |
| 358 | + let draft = await draftWalletTx(utxos, null, memo); |
| 359 | + console.log('draftTx'); |
| 360 | + console.log(draft); |
| 361 | + draft.tx.outputs[0].satoshis = 0; |
| 362 | + draft.tx.feeTarget += dust; |
| 363 | + |
| 364 | + draft.tx.inputs.sort(DashTx.sortInputs); |
| 365 | + draft.tx.outputs.sort(DashTx.sortOutputs); |
| 366 | + let signedTx = await dashTx.legacy.finalizePresorted(draft.tx); |
| 367 | + console.log(signedTx); |
361 | 368 | };
|
362 | 369 |
|
363 | 370 | async function draftWalletTx(utxos, inputs, output) {
|
|
387 | 394 | output.satoshis = 0;
|
388 | 395 | continue;
|
389 | 396 | }
|
390 |
| - if (!output.address && typeof output.memo !== 'string') { |
391 |
| - let err = new Error(`output is missing 'address' and 'pubKeyHash'`); |
392 |
| - window.alert(err.message); |
393 |
| - throw err; |
| 397 | + if (!output.address) { |
| 398 | + if (typeof output.memo !== 'string') { |
| 399 | + let err = new Error(`output is missing 'address' and 'pubKeyHash'`); |
| 400 | + window.alert(err.message); |
| 401 | + throw err; |
| 402 | + } |
| 403 | + } else { |
| 404 | + let pkhBytes = await DashKeys.addrToPkh(output.address, { |
| 405 | + version: network, |
| 406 | + }); |
| 407 | + Object.assign(output, { |
| 408 | + pubKeyHash: DashKeys.utils.bytesToHex(pkhBytes), |
| 409 | + }); |
394 | 410 | }
|
395 |
| - let pkhBytes = await DashKeys.addrToPkh(output.address, { |
396 |
| - version: network, |
397 |
| - }); |
398 |
| - Object.assign(output, { |
399 |
| - pubKeyHash: DashKeys.utils.bytesToHex(pkhBytes), |
400 |
| - }); |
401 | 411 | }
|
402 | 412 |
|
403 | 413 | draftTx.inputs.sort(DashTx.sortInputs);
|
|
769 | 779 | }
|
770 | 780 |
|
771 | 781 | let utxos = getAllUtxos();
|
772 |
| - let coins = DashWallet.selectOptimalUtxos(utxos, slot.denom); |
| 782 | + let coins = DashTx.selectOptimalUtxos(utxos, slot.denom); |
773 | 783 | let sats = DashTx.sum(coins);
|
774 | 784 | if (sats < slot.denom) {
|
775 | 785 | console.log(`not enough coins for ${slot.denom}`);
|
|
0 commit comments