- Feb 27, 2017
- 42
- 60
Today I played around with jq and bitcoin-cli and constructed this little bash script:
It checks all new mempool entrants and outputs the parent-vout-child relationship as illustrated below:
call it with watch to have it periodically updated on screen to see new transactions appearing in the mempool on the fly. It is fast enough on testnet but could get slow on mainnet, haven't tested.
Could be useful for double-spend detection. I plan to run a pruned BitcoinXT node to detect double spends with this script without having wallet functionality enabled on the node. So I periodically call this script and check if the parent:vout part of any new mempool entrants is already in use by my main application for some different TX.
Code:
#!/bin/bash
bitcoin-cli getrawmempool | jq -M -r .[] | sort | tee new_mempool | comm -23 - old_mempool | xargs -I % -r -d'\n' -n1 bitcoin-cli getrawtransaction % 1 | jq -M -r '. as $child | .vin[] | "\(.txid):\(.vout):\($child.txid)"' && mv old_mempool tmp_mempool && mv new_mempool old_mempool && mv tmp_mempool new_mempool
Code:
a52c14073dfda3ebc29bf69bee5397f4e5c65754e2d3cc47f1070e418e4ebbe6:1:5a1ebf4c8e6289f0aeff161db52eca0933b820ce367364889caaa678acb03776
29a11bd4e5659f832f2445e76fff4f267413560ccff85262351206c6d181623c:1:766fd108cb13f5b41a79e971e4000af7d29ca271d0b82df0107cca955236073a
ff1d625590a9f73dd83d9d88c53f5476eae2f69f33b1ecc5a20815959dae1cb0:0:766fd108cb13f5b41a79e971e4000af7d29ca271d0b82df0107cca955236073a
c6c8ab740b0bfcd166850a38275e2b1638b28e0b9868a8345baa1811ed1635dd:1:766fd108cb13f5b41a79e971e4000af7d29ca271d0b82df0107cca955236073a
17666e6bfe2ae3866dcf1be9357cc38596b0b5d05094e022c65caa1ec083d746:1:db37511fcdba4699700ed84d17ad6069996770323e44b01264ad9ac25af4d622
7b5e4b0da82efaaea94e3afcfbd7bbb775bbdbc93d6def2f8bf673d24ae0c85e:1:db37511fcdba4699700ed84d17ad6069996770323e44b01264ad9ac25af4d622
814215bfa9c735e0f12de9c441994a4eaa430d303d4627b3718dac4498605d83:1:efdbe6472e81127197c6699c4e59439789f8d0859e22e17ed6c276dee7ceccbf
30722d0b8033d31ee95a2ce1ebfe8c2c0852c723d277d11ce60dab7b0005417e:1:f12ace8a04221c2608a68287ba7b264f948dd3ce050355b207832d03fc43fe65
fb51c7b5b5502a922990471821f4172286cfbc4cb75ac3afb7e7158f2e191e08:0:f5d883a9b0b77994104fcf2b7ca5818045dab083b1d8fc83f3b0d8d8412eedba
Could be useful for double-spend detection. I plan to run a pruned BitcoinXT node to detect double spends with this script without having wallet functionality enabled on the node. So I periodically call this script and check if the parent:vout part of any new mempool entrants is already in use by my main application for some different TX.