import { bitcoinQuery } from '@subsquid/pipes/bitcoin'
export const taprootSpends = bitcoinQuery()
.addFields({
block: { number: true, timestamp: true },
transaction: { transactionIndex: true, txid: true },
input: {
transactionIndex: true,
inputIndex: true,
prevoutValue: true,
prevoutScriptPubKeyAddress: true,
prevoutScriptPubKeyType: true,
},
})
.addInputRequest({
range: { from: 880_000, to: 880_000 },
request: {
prevoutScriptPubKeyType: ['witness_v1_taproot'],
transaction: true,
},
})
.build()
.pipe((blocks) =>
blocks.flatMap((block) => {
const transactions = new Map(
block.transactions.map((tx) => [tx.transactionIndex, tx]),
)
return block.inputs.map((input) => ({
block: block.header.number,
spendingTxid: transactions.get(input.transactionIndex)?.txid,
inputIndex: input.inputIndex,
spentAddress: input.prevoutScriptPubKeyAddress,
spentValueBtc: input.prevoutValue,
}))
}),
)