Skip to content

Instantly share code, notes, and snippets.

@moocowmoo
Last active July 11, 2017 13:13
Show Gist options
  • Save moocowmoo/8080187f02360e4a3cc1323e0b2c781d to your computer and use it in GitHub Desktop.
Save moocowmoo/8080187f02360e4a3cc1323e0b2c781d to your computer and use it in GitHub Desktop.
block-a-doodle-chain - scan dash core bdb files for P2PK graffiti
#!/usr/bin/env python
# tagchain-list - scan dash core bdb files for P2PK graffiti
from __future__ import print_function
import re
import os
from collections import OrderedDict
from itertools import izip, repeat
# only show entries longer than
MINLEN = 6
# only scan recent n block files
LASTBLOCKS = 2
# location of blockfiles to scan
blockdir = '/home/ubuntu/.dashcore/blocks/'
# voodoo, prepare a blood sacrifice
pat = re.compile(r'\x19\x76\xa9\x14([\x20-\x7f]+)\x00*\x88')
# how much mega would a mega byte bite if a mega byte could bite wood?
MB = 1024 * 1024
if __name__ == '__main__':
blockpaths = sorted(
[blockdir + fn for fn in os.listdir(blockdir) if fn.startswith('blk')])[-LASTBLOCKS:]
m = []
for blockfile in blockpaths:
print("scanning %s" % blockfile)
with open(blockfile, 'rb') as f:
megs = b''
while True:
meg = f.read(MB)
if not meg:
break
megs += meg
m.extend(pat.findall(megs))
megs = megs[-(MB / 2):]
matches = list(
OrderedDict(izip([n for n in m if len(n) > MINLEN], repeat(None))))
print()
for match in list(matches):
print(match)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment