Advertisement
jcomeau_ictx

harvest.py

Jan 27th, 2018
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. #!/usr/bin/python
  2. '''
  3. attempt to send myself the Bitcoin from `unusual` scripts
  4.  
  5. my project jcomeauictx/blockparse/python/script.py has a search
  6. for `unusual` scripts in it, and it found a bunch of
  7. ['IFDUP', 'IF', '2SWAP', 'VERIFY', '2OVER', 'DEPTH'] scripts... which,
  8. when compiled, spell exactly the word 'script'.
  9.  
  10. this shouldn't even run, because an unterminated `IF` should fail. but
  11. it's worth a shot.
  12. '''
  13. from __future__ import print_function, division
  14. import sys, os, re, logging
  15. from bitcoin import *
  16. from binascii import b2a_hex
  17. from ast import literal_eval
  18. logging.basicConfig(level=logging.DEBUG if __debug__ else logging.INFO)
  19.  
  20. MY_ADDR = '16eEr7P3wtozVB96D4CXXdf9hhWTCJXYGM'  # Coinomi wallet
  21. SATOSHIS_PER_BYTE = 240  # currently recommended by bitcoinfees.earn.com
  22. SCRIPT = b2a_hex('QQQQQ')  # ['TRUE'] * 5, should avoid stack underflows
  23.  
  24. def harvest(really_send=False):
  25.     '''
  26.    harvest the idle funds. it's not theft because the sender[s] didn't
  27.    code a correct script to send them to anybody.
  28.    '''
  29.     with open('/tmp/unusual.log') as infile:
  30.         logs = infile.readlines()
  31.     outputs = [literal_eval(line)['unusual'] for line in logs]
  32.     for output in list(outputs):
  33.         if output['script'][:1] == ['IFDUP']:
  34.             output['script'] = SCRIPT
  35.             output.pop('height')
  36.         else:
  37.             outputs.remove(output)
  38.     assert len(outputs) == 182
  39.     logging.debug(outputs)
  40.     total = sum([output['value'] for output in outputs])
  41.     logging.debug('number of inputs: %d', len(outputs))
  42.     value = total - 1000000  # .01BTC for miners, first draft
  43.     to_me = [{'value': value, 'address': MY_ADDR}]
  44.     transaction = mktx(outputs, to_me)
  45.     bytecount = len(transaction) // 2
  46.     fee = SATOSHIS_PER_BYTE * bytecount
  47.     value = total - fee
  48.     logging.info('updated fee for %d bytes: %.8f, to me: %.8f',
  49.                  bytecount,
  50.                  fee / 100000000,
  51.                  value / 100000000)
  52.     to_me = [{'value': value, 'address': MY_ADDR}]  # rebuild output
  53.     transaction = mktx(outputs, to_me)
  54.     if really_send:
  55.         pushtx(transaction)
  56.     return transaction
  57.  
  58. if __name__ == '__main__':
  59.     print(harvest(bool(sys.argv[1:])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement