dave on Nostr: function fetchCoinjoins() { // Fetch all TXIDs in the mempool const url = ''; ...
function fetchCoinjoins() {
// Fetch all TXIDs in the mempool
const url = '
https://blockstream.info/api/mempool';;
fetch(url)
.then(res => res.json())
.then(data => {
const txids = data.txids;
// Iterate over every TXID and fetch the full transaction data
txids.forEach(txid => {
const txurl = `
https://blockstream.info/api/tx/${txid}`;
fetch(txurl)
.then(res => res.json())
.then(txdata => {
// Determine if the transaction is likely a coinjoin
if (isLikelyCoinjoin(txdata)) {
console.log(txdata);
}
})
})
});
}
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) {
return true;
}
}
return false;
}
Published at
2022-12-09 00:38:55Event JSON
{
"id": "779c3a3bd4fccbb24e002dbab7806291c647023955d6f897c3bc0b9dc03917fc",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1670546335,
"kind": 1,
"tags": [
[
"e",
"f04c12f13467f1af68817979f65ea91a91b5cf2131644265f7c43155d5fc7ae9",
"",
"root"
],
[
"e",
"70b7351b197655c8d6380496dd38565d646ee857d0e372a9104cc75a6d15e287",
"",
"reply"
],
[
"p",
"2b36fb6ae1022d0d4eac2a9f13fc2638f3350acc9b07bdca1de43a7c63429644"
]
],
"content": "function fetchCoinjoins() {\n // Fetch all TXIDs in the mempool\n const url = 'https://blockstream.info/api/mempool';\n fetch(url)\n .then(res =\u003e res.json())\n .then(data =\u003e {\n const txids = data.txids; \n\n // Iterate over every TXID and fetch the full transaction data\n txids.forEach(txid =\u003e {\n const txurl = `https://blockstream.info/api/tx/${txid}`;\n fetch(txurl)\n .then(res =\u003e res.json())\n .then(txdata =\u003e {\n // Determine if the transaction is likely a coinjoin\n if (isLikelyCoinjoin(txdata)) {\n console.log(txdata);\n }\n })\n })\n });\n}\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 \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 return true;\n }\n }\n return false;\n}",
"sig": "8706d30345b337dd85f8c3c35438ec83f9fe2e98824507527cb5c4c233811b206faa83101dc4e2a0d207569f8cf485c0420ca8304b4b4298571c594493780fa9"
}