-
Notifications
You must be signed in to change notification settings - Fork 52
/
pngcoin.py
53 lines (41 loc) · 1.2 KB
/
pngcoin.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
import io
import pickle
from PIL import Image
###########
# Helpers #
###########
def handle_user_input(user_input):
if user_input.lower() == "y":
return True
elif user_input.lower() == "n":
return False
else:
user_input = input('Please enter "y" or "n"')
return handle_user_input(user_input)
############
# PNG Coin #
############
class PNGCoin:
def __init__(self, transfers):
self.transfers = transfers # PIL.Image instances
def serialize(self):
return pickle.dumps(self)
@classmethod
def deserialize(cls, serialized):
return pickle.loads(serialized)
def to_disk(self, filename):
serialized = self.serialize()
with open(filename, "wb") as f:
f.write(serialized)
@classmethod
def from_disk(cls, filename):
with open(filename, "rb") as f:
serialized = f.read()
return cls.deserialize(serialized)
def validate(self):
for transfer in self.transfers:
transfer.show()
user_input = input("Is this a valid minting signature? (y/n)")
if not handle_user_input(user_input):
return False
return True