Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- '''
- attempt to send myself the Bitcoin from `unusual` scripts
- my project jcomeauictx/blockparse/python/script.py has a search
- for `unusual` scripts in it, and it found a bunch of
- ['IFDUP', 'IF', '2SWAP', 'VERIFY', '2OVER', 'DEPTH'] scripts... which,
- when compiled, spell exactly the word 'script'.
- this shouldn't even run, because an unterminated `IF` should fail. but
- it's worth a shot.
- '''
- from __future__ import print_function, division
- import sys, os, re, logging
- from bitcoin import *
- from binascii import b2a_hex
- from ast import literal_eval
- logging.basicConfig(level=logging.DEBUG if __debug__ else logging.INFO)
- MY_ADDR = '16eEr7P3wtozVB96D4CXXdf9hhWTCJXYGM' # Coinomi wallet
- SATOSHIS_PER_BYTE = 240 # currently recommended by bitcoinfees.earn.com
- SCRIPT = b2a_hex('QQQQQ') # ['TRUE'] * 5, should avoid stack underflows
- def harvest(really_send=False):
- '''
- harvest the idle funds. it's not theft because the sender[s] didn't
- code a correct script to send them to anybody.
- '''
- with open('/tmp/unusual.log') as infile:
- logs = infile.readlines()
- outputs = [literal_eval(line)['unusual'] for line in logs]
- for output in list(outputs):
- if output['script'][:1] == ['IFDUP']:
- output['script'] = SCRIPT
- output.pop('height')
- else:
- outputs.remove(output)
- assert len(outputs) == 182
- logging.debug(outputs)
- total = sum([output['value'] for output in outputs])
- logging.debug('number of inputs: %d', len(outputs))
- value = total - 1000000 # .01BTC for miners, first draft
- to_me = [{'value': value, 'address': MY_ADDR}]
- transaction = mktx(outputs, to_me)
- bytecount = len(transaction) // 2
- fee = SATOSHIS_PER_BYTE * bytecount
- value = total - fee
- logging.info('updated fee for %d bytes: %.8f, to me: %.8f',
- bytecount,
- fee / 100000000,
- value / 100000000)
- to_me = [{'value': value, 'address': MY_ADDR}] # rebuild output
- transaction = mktx(outputs, to_me)
- if really_send:
- pushtx(transaction)
- return transaction
- if __name__ == '__main__':
- print(harvest(bool(sys.argv[1:])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement