#!/usr/bin/python3 # # File insertion tool for Bitcoin # Requires git://github.com/jgarzik/python-bitcoinrpc.git # # (c) 2013 Satoshi Nakamoto All Rights Reserved # # UNAUTHORIZED DUPLICATION AND/OR USAGE OF THIS PROGRAM IS PROHIBITED BY US AND INTERNATIONAL COPYRIGHT LAW import io import jsonrpc import os import random import struct import sys from binascii import crc32,hexlify,unhexlify from decimal import Decimal if len(sys.argv) < 5: print(\ """\ Usage: %s {} Set BTCRPCURL=http://user:pass@localhost:portnum""" % sys.argv[0], file=sys.stderr) sys.exit() COIN = 100000000 def unhexstr(str): return unhexlify(str.encode('utf8')) proxy = jsonrpc.ServiceProxy(os.environ['BTCRPCURL']) def select_txins(value): unspent = list(proxy.listunspent()) random.shuffle(unspent) r = [] total = 0 for tx in unspent: total += tx['amount'] r.append(tx) if total >= value: break if total < value: return None else: return (r, total) def varint(n): if n < 0xfd: return bytes([n]) elif n < 0xffff: return b'\xfd' + struct.pack('