From 78b6cc3b24351ec4606e2b59e79e91e1f2ea98d1 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 15 Aug 2024 01:27:25 -0600 Subject: [PATCH] f: can send collateral now --- public/wallet-app.js | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/public/wallet-app.js b/public/wallet-app.js index f93bed3..9564d7e 100644 --- a/public/wallet-app.js +++ b/public/wallet-app.js @@ -354,10 +354,17 @@ let dust = Math.floor(dustF); let utxos = getAllUtxos(); - let memo = { satoshis: dust, memo: '\0' }; - let draftTx = await draftWalletTx(utxos, null, memo); - draftTx.outputs[0].satoshis = 0; - draftTx.feeTarget += dust; + let memo = { satoshis: dust, memo: '' }; + let draft = await draftWalletTx(utxos, null, memo); + console.log('draftTx'); + console.log(draft); + draft.tx.outputs[0].satoshis = 0; + draft.tx.feeTarget += dust; + + draft.tx.inputs.sort(DashTx.sortInputs); + draft.tx.outputs.sort(DashTx.sortOutputs); + let signedTx = await dashTx.legacy.finalizePresorted(draft.tx); + console.log(signedTx); }; async function draftWalletTx(utxos, inputs, output) { @@ -387,17 +394,20 @@ output.satoshis = 0; continue; } - if (!output.address && typeof output.memo !== 'string') { - let err = new Error(`output is missing 'address' and 'pubKeyHash'`); - window.alert(err.message); - throw err; + if (!output.address) { + if (typeof output.memo !== 'string') { + let err = new Error(`output is missing 'address' and 'pubKeyHash'`); + window.alert(err.message); + throw err; + } + } else { + let pkhBytes = await DashKeys.addrToPkh(output.address, { + version: network, + }); + Object.assign(output, { + pubKeyHash: DashKeys.utils.bytesToHex(pkhBytes), + }); } - let pkhBytes = await DashKeys.addrToPkh(output.address, { - version: network, - }); - Object.assign(output, { - pubKeyHash: DashKeys.utils.bytesToHex(pkhBytes), - }); } draftTx.inputs.sort(DashTx.sortInputs); @@ -769,7 +779,7 @@ } let utxos = getAllUtxos(); - let coins = DashWallet.selectOptimalUtxos(utxos, slot.denom); + let coins = DashTx.selectOptimalUtxos(utxos, slot.denom); let sats = DashTx.sum(coins); if (sats < slot.denom) { console.log(`not enough coins for ${slot.denom}`);