Skip to content

Commit 78b6cc3

Browse files
committed
f: can send collateral now
1 parent 5ac05a7 commit 78b6cc3

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

public/wallet-app.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,17 @@
354354

355355
let dust = Math.floor(dustF);
356356
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);
361368
};
362369

363370
async function draftWalletTx(utxos, inputs, output) {
@@ -387,17 +394,20 @@
387394
output.satoshis = 0;
388395
continue;
389396
}
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+
});
394410
}
395-
let pkhBytes = await DashKeys.addrToPkh(output.address, {
396-
version: network,
397-
});
398-
Object.assign(output, {
399-
pubKeyHash: DashKeys.utils.bytesToHex(pkhBytes),
400-
});
401411
}
402412

403413
draftTx.inputs.sort(DashTx.sortInputs);
@@ -769,7 +779,7 @@
769779
}
770780

771781
let utxos = getAllUtxos();
772-
let coins = DashWallet.selectOptimalUtxos(utxos, slot.denom);
782+
let coins = DashTx.selectOptimalUtxos(utxos, slot.denom);
773783
let sats = DashTx.sum(coins);
774784
if (sats < slot.denom) {
775785
console.log(`not enough coins for ${slot.denom}`);

0 commit comments

Comments
 (0)