Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Update main_function.js
Browse files Browse the repository at this point in the history
  • Loading branch information
22388o authored Jan 31, 2024
1 parent 5f7302e commit 694bd36
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/coinjoin/main_function.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,40 @@ class CXJT {
});
}
}
class mktx {
this.build_ins_from_template();
this.build_outs_from_template();

if (!(this.ins.length && this.outs.length)) {
throw new Error("Invalid inputs or outputs");
}

this.base_form = btc.mktx(this.ins.map(x => x[0]), this.outs);
const dtx = btc.deserialize(this.base_form);

if (this.locktime) {
dtx["ins"][0]["sequence"] = 0;
dtx["locktime"] = this.locktime;
}

for (let i = 0; i < dtx["ins"].length; i++) {
const inp = dtx["ins"][i];
const sti = this.template.ins[i];

if (sti.spk_type === "p2sh-p2wpkh") {
inp["script"] = "16" + btc.pubkey_to_p2tr_script(
this.keys["ins"][i][sti.counterparty]
);
} else if (sti.spk_type === "NN") {
inp["script"] = "";
}
}

this.txid = btc.txhash(btc.serialize(dtx));

for (const to of this.template.outs) {
to.txid = this.txid;
}

// Function to calculate dynamic fee
function calculateDynamicFee() {
Expand Down

0 comments on commit 694bd36

Please sign in to comment.