Skip to content

Instantly share code, notes, and snippets.

@JburkeRSAC
Created November 1, 2016 22:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JburkeRSAC/6f3c1fcf9714d67d93ffb6103f48c134 to your computer and use it in GitHub Desktop.
Save JburkeRSAC/6f3c1fcf9714d67d93ffb6103f48c134 to your computer and use it in GitHub Desktop.
decode bitcoin OP_RETURN
import sys
import pycurl
import struct
from binascii import unhexlify, crc32
import urllib2
transaction = str(sys.argv[1])
data = urllib2.urlopen("https://blockchain.info/tx/"+transaction+"?show_adv=true")
dataout = b''
atoutput = False
for line in data:
if 'Output Scripts' in line:
atoutput = True
if '</table>' in line:
atoutput = False
if atoutput:
if len(line) > 100:
chunks = line.split(' ')
for c in chunks:
if 'O' not in c and '\n' not in c and '>' not in c and '<' not in c:
dataout += unhexlify(c.encode('utf8'))
length = struct.unpack('<L', dataout[0:4])[0]
checksum = struct.unpack('<L', dataout[4:8])[0]
dataout = dataout[8:8+length]
print dataout
@ty-everett
Copy link

Thanks, this was really useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment