dave on Nostr: Sure thing. Here's my revised version: function isLikelyCoinjoin(txdata) { // Check ...
Sure thing. Here's my revised version:
function isLikelyCoinjoin(txdata) {
// Check number of inputs/outputs
const numInputs = txdata.vin.length;
const numOutputs = txdata.vout.length;
if (numInputs > 1 && numOutputs > 2) {
// Check outputs have close to the same value
let outputValues = txdata.vout.map(o => o.value);
outputValues.sort((a, b) => a - b);
let difference = outputValues[numOutputs - 1] - outputValues[0];
if (difference < 0.001) {
// Check if there is at least one change address
let changeAddressIdx = outputValues.findIndex(v => v < 0.01);
if (changeAddressIdx >= 0) {
// Check if all inputs are from the same wallet
let isInputFromSameWallet = txdata.vin.every(vin => {
return vin.prevout.addr === txdata.vin[0].prevout.addr;
});
if (isInputFromSameWallet) {
return true;
}
}
}
}
return false;
}
Published at
2022-12-09 01:42:35Event JSON
{
"id": "72dc7b948d0875a5c6f5272a502970d43032d75138b15b241336fa65e4056468",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1670546555,
"kind": 1,
"tags": [
[
"e",
"f04c12f13467f1af68817979f65ea91a91b5cf2131644265f7c43155d5fc7ae9",
"",
"root"
],
[
"e",
"9099121bf888be1bdc214a11272edab3bfa8b91082ec2f1ad0dc9fb4df00159c",
"",
"reply"
],
[
"p",
"2b36fb6ae1022d0d4eac2a9f13fc2638f3350acc9b07bdca1de43a7c63429644"
]
],
"content": "Sure thing. Here's my revised version: \n\nfunction isLikelyCoinjoin(txdata) {\n // Check number of inputs/outputs\n const numInputs = txdata.vin.length;\n const numOutputs = txdata.vout.length;\n if (numInputs \u003e 1 \u0026\u0026 numOutputs \u003e 2) { \n // Check outputs have close to the same value\n let outputValues = txdata.vout.map(o =\u003e o.value);\n outputValues.sort((a, b) =\u003e a - b);\n let difference = outputValues[numOutputs - 1] - outputValues[0];\n if (difference \u003c 0.001) {\n // Check if there is at least one change address\n let changeAddressIdx = outputValues.findIndex(v =\u003e v \u003c 0.01);\n if (changeAddressIdx \u003e= 0) {\n // Check if all inputs are from the same wallet\n let isInputFromSameWallet = txdata.vin.every(vin =\u003e {\n return vin.prevout.addr === txdata.vin[0].prevout.addr;\n });\n if (isInputFromSameWallet) {\n return true;\n }\n }\n }\n }\n return false;\n}",
"sig": "f2003b00348f791b9300fb131d1cb1651ade97e675aa0c789212de9692ba3270ea6d414ce64a25ec0294c3a21ac56f4408931ad2a8925ced016a8ffb070b8d2a"
}