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