What is Nostr?
dave /
npub1tsg…htk4
2022-12-09 00:38:55
in reply to nevent1q…fn34

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;
}
Author Public Key
npub1tsgw6pncspg4d5u778hk63s3pls70evs4czfsmx0fzap9xwt203qtkhtk4