Post
Topic
Board Development & Technical Discussion
Re: Useful targeted data
by
mahurovihamilo
on 24/05/2024, 19:29:27 UTC
So after studying this issue for a wile I have concluded that the best data can come for gathering spent only outputs from TX hashes. Now due to limitations on the amount of data allowed by API operators, and lack of detailed info on flags to only download spent outputs of tXS, I decided to write a script to: first download all transactions, then download all UTXOs separately, then using some grep and sed magick, take out the UTXOs from the all transactions file piping only the spent TXs into a final file...most of it works, just the last step is not quite there by mixing grep and sed. I wander if anyone can offer a suggestion on where I am going wrong with grep and sed?

Please see the code:

#!/bin/bash

# first lets get ALL TXs for address

curl -sSL "https://mempool.space/api/address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs" | jq '.' > alltxs.data

# Lets clean up the data and keep just the TX number:

grep "txid" alltxs.data > allhashes.data  # pass the TX Hash into  allhashes.data
sed -i 's/"txid": "//g' allhashes.data    # remove the leadinng "txid" and leave the bare Hash number into  allhashes.data
sed -i 's/",//g' allhashes.data           # remove commas and quotes and leave bare number in  allhashes.data
sed -i 's/^[ \t]*//' allhashes.data       # remove all leading empty space in  allhashes.data


# then lets get just the unspent (utxo) TXs

curl -sSL "https://mempool.space/api/address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/utxo" | jq '.' > allutxos.data

grep "txid" allutxos.data > utxos.data  # pass the TX Hash into  allhashes.data
sed -i 's/"txid": "//g' utxos.data    # remove the leadinng "txid" and leave the bare Hash number into  allhashes.data
sed -i 's/",//g' utxos.data           # remove commas and quotes and leave bare number in  allhashes.data
sed -i 's/^[ \t]*//' utxos.data       # remove all leading empty space in  allhashes.data


# now lets filter out the utxos out so that we are left with the spent outputs only


while IFS= read -r line
do

  #echo "$line"  # Test print to output to see if we are reading lines correctly

  grep $line -n | sed 's/$line/ /' allhashes.data > unspent.data  # <==== not working as it is not removing the linesin utxos.data  from allhashes.data

 


done < utxos.data


Any suggestions welcome !! Thank you!!