Created
December 22, 2017 17:00
-
-
Save dymurray/f4cdca0032e9b57cfe890d246795400a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import urllib2 | |
import json | |
import sys | |
import time | |
import wget | |
import os | |
if len(sys.argv) == 1: | |
address = raw_input('Please enter the receiving address: ') | |
print(address) | |
satoshi_amount = int(raw_input('Please enter sending amount (in satoshi): ')) | |
else: | |
address = sys.argv[1] | |
satoshi_amount = int(sys.argv[2]) | |
amount = satoshi_amount * 0.00000001 | |
os.system("rm /tmp/qr.png") | |
url = "https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl= bitcoincash:%s?amount=%s" % (address, amount) | |
print("Generating QR code.") | |
wget.download(url, out="/tmp/qr.png") | |
print() | |
os.system("xdg-open /tmp/qr.png") | |
response = urllib2.urlopen('https://bch-chain.api.btc.com/v3/address/%s' % address) | |
data = json.load(response) | |
while data['data'] is None: | |
print("This wallet address has no tx activity. Trying again in 5 seconds.") | |
time.sleep(5) | |
response = urllib2.urlopen('https://bch-chain.api.btc.com/v3/address/%s' % address) | |
data = json.load(response) | |
last_tx = data['data']['last_tx'] | |
response = urllib2.urlopen('https://bch-chain.api.btc.com/v3/tx/%s' % last_tx) | |
data = json.load(response) | |
outputs = data['data']['outputs'] | |
total_amount = 0 | |
for output in outputs: | |
for addr in output['addresses']: | |
if addr == address: | |
total_amount += int(output['value']) | |
print("\n") | |
if satoshi_amount > total_amount: | |
print("The last tx did not hold the right amount of satoshi. Expected: %s, Got: %s" % (satoshi_amount, total_amount)) | |
else: | |
print("SUCCESS!! Found the expected satoshi amount. Expected: %s, Got %s" % (satoshi_amount, total_amount)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment