Skip to content

Commit

Permalink
f: can send collateral now
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Aug 15, 2024
1 parent 5ac05a7 commit 78b6cc3
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions public/wallet-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit 78b6cc3

Please sign in to comment.