-
Notifications
You must be signed in to change notification settings - Fork 5
/
faucet.py
131 lines (96 loc) · 2.84 KB
/
faucet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""#!/usr/bin/env python3"""
import bit
import config
import pyqrcode
from bit import Key
from bit.network import get_fee
import os
import guizero
from guizero import App, Text
from threading import Thread
import scanner
# For images
filepath = os.getcwd() + "/images/"
class Faucet:
"""Initializes and controls dedicated btc faucet wallet"""
def __init__(self):
self.key = Key(config.private_key)
self.address = self.key.address
self.balance = self.key.get_balance("btc")
self.fee = get_fee(fast=False)
def send(self, wallet_address):
# minimum amount that can be sent is .00000546 satoshi's
return self.key.send([(wallet_address, 0.00000546, "btc")])
def generate_qr_hash(self, hash):
latest_transaction = pyqrcode.create("https://blockstream.info/tx/" + hash)
latest_transaction.png(filepath + "latest_transaction.png", scale=5.5)
class Picture(guizero.Picture):
def start_animation(self):
self.image = self.value.replace(".png", ".gif")
def stop_animation(self):
self.image = self.value.replace(".gif", ".png")
def swap_animation(self):
if self.value.endswith(".png"):
self.start_animation()
else:
self.stop_animation()
def timed_stop(self, ms):
self.after(ms, self.stop_animation)
def transition(img, func=None, time=None, click=False):
icon.image = filepath + img
if click:
icon.when_clicked = func
if time:
icon.timed_stop(time)
elif func:
icon.after(time, func)
app.update()
def boot():
transition("boot.gif", start, 2600, click=True)
def start():
transition("start.gif", wait_for_code, 3600)
def wait_for_code():
def scanning_run():
if scanning.code:
app.cancel(scanning_run)
scanned(scanning.code)
transition("start.png")
scanning = scanner.App()
scanning.run()
app.repeat(200, scanning_run)
def scanned(wallet_code):
def send_satoshis():
faucet = Faucet()
hash = faucet.send(wallet_code)
faucet.generate_qr_hash(hash)
satoshis = Thread(target=send_satoshis)
satoshis.start()
transition("scanned.gif", complete, 9000)
def complete():
transition("complete.gif", show_transaction, 3000)
def show_transaction():
icon.hide()
message.show()
transaction.image = filepath + "latest_transaction.png"
transaction.show()
app.update()
def restart():
message.hide()
transaction.hide()
icon.show()
boot()
app = App(bg="white")
app.set_full_screen()
icon = Picture(app)
message = Text(
app,
size=26,
font="Quicksand Medium",
color="green",
text="Satoshi's are on the way!",
visible=False,
)
transaction = Picture(app, align="bottom", visible=False)
transaction.when_clicked = restart
boot()
app.display()