Skip to content

Instantly share code, notes, and snippets.

@cvasqxz
Last active December 12, 2018 04:37
Show Gist options
  • Save cvasqxz/326d1bf1691440acc120bb84bf890fd4 to your computer and use it in GitHub Desktop.
Save cvasqxz/326d1bf1691440acc120bb84bf890fd4 to your computer and use it in GitHub Desktop.
Generación de transaction puzzle
# https://en.bitcoin.it/wiki/Script#Transaction_puzzle
from argparse import ArgumentParser
from binascii import b2a_hex
from hashlib import new
# Opcodes
OP_HASH256 = 'aa'
OP_EQUAL = '87'
# Arguments
p = ArgumentParser(description='Transaction puzzle (OP_SHA256)')
p.add_argument('solution', help='Puzzle solution')
args = p.parse_args()
def getScriptPubKey(s):
hash = new('sha256', new('sha256', s.encode()).digest()).hexdigest()
lenHash = '{:02x}'.format(int(len(hash)/2))
return OP_HASH256 + lenHash + hash + OP_EQUAL
def main():
s = args.solution
print('> Puzzle solution: %s' % s)
print('> ScriptPubKey: %s' % getScriptPubKey(s))
print('> SigScript: %s' % b2a_hex(s.encode()).decode('utf-8'))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment