Skip to content

Instantly share code, notes, and snippets.

@wizardofozzie
Forked from brianddk/0_Readme.md
Last active September 9, 2015 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizardofozzie/dbc1bdba38d645429e28 to your computer and use it in GitHub Desktop.
Save wizardofozzie/dbc1bdba38d645429e28 to your computer and use it in GitHub Desktop.
Use PyBitcoinTools to make CPFP transaction with tip to bounty

More later...

# [rights] Copyright Dan B. (brianddk) 2015 https://github.com/brianddk
# [license] Licensed under Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0
# [repo] https://gist.github.com/brianddk/579df081ca42ec956506
# [version] 0.2
# [tips] 18MDTTiqPM8ZEo29Cig1wfGdkLNtvyorW5
import requests
import argparse
from bitcoin import *
import pprint
def main():
tip_addr = args.tipadr
tip_fee = args.tip
miner_fee = args.fee
unc_addr = args.uncadr
if args.testnet:
(inp, amt) = get_inputs_tbtc(unc_addr)
else:
(inp, amt) = get_inputs_bci(unc_addr)
outp = ['%s:%d' % (unc_addr, amt - tip_fee)]
outp += ['%s:%d' % (tip_addr, tip_fee - miner_fee)]
tx = mktx(inp,outp)
if args.debug:
pp = pprint.PrettyPrinter(indent=4)
txo = deserialize(tx)
pp.pprint(txo)
print tx
def get_inputs_bci(unc_addr):
unc_txn = args.unctx
url = 'https://blockchain.info/rawtx/%s?format=json' % unc_txn
req = requests.get(url)
txn = req.json()
for o in txn['out']:
if o['addr'] != unc_addr: continue
if o['spent']: continue
inp = ['%s:%d' % (unc_txn, o['n'])]
amt = o['value']
return (inp, amt)
def get_inputs_tbtc(unc_addr):
satoshis = 100000000
unc_txn = args.unctx
url = 'http://tbtc.blockr.io/api/v1/tx/info/%s' % unc_txn
req = requests.get(url)
txn = req.json()
for o in txn['data']['vouts']:
if o['address'] != unc_addr: continue
if o['is_spent']: continue
inp = ['%s:%d' % (unc_txn, o['n'])]
amt = int(float(o['amount']) * satoshis)
return (inp, amt)
def parse_args():
parser=argparse.ArgumentParser()
parser.add_argument("-unctx", metavar='<hex>', help="Unconfirmed Transaction to recover",
action="store", type=str)
parser.add_argument("-uncadr", metavar='<btc_adr>', help="Bitcoin address to hook to pull TXN out of pool",
action="store", type=str)
parser.add_argument("-fee", metavar='<satoshis>', help="Number of satoshis to pay miners (TxFee)",
action="store", type=int, default=80000)
parser.add_argument("-tipadr", metavar='<btc_adr>', help="Bitcoin address to send the tip too",
action="store", type=str, default='3FEUByMeaxrNmBCVYjvsnhyAjiUdat5i7M')
parser.add_argument("-tip", metavar='<satoshis>', help="Number of satoshis to tip",
action="store", type=int, default=300000)
parser.add_argument("-testnet", help="Run this on the testnet",
action="store_true")
parser.add_argument("-debug", help="Debug run of the script",
action="store_true")
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
main()
#Future Feature Sign and Send.
#curl "http://eligius.st/~wizkid057/newstats/pushtxn.php" -H "Host: eligius.st"^
# -H "User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"^
# -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"^
# -H "Accept-Language: en-US,en;q=0.5" --compressed^
# -H "Referer: http://eligius.st/~wizkid057/newstats/pushtxn.php" ^
#-H "Connection: keep-alive" --data "transaction=test&send=Push"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment