-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransactionChain.py
60 lines (44 loc) · 1.39 KB
/
TransactionChain.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
import Transaction
import ccxt
import queue
import copy
class TransactionChain:
def __init__(self, balance):
self.Transactions = queue.Queue()
self.Balance = balance
self.Pending = None
self.Started = False
self.Finished = False
def size(self):
return self.Transactions.qsize()
def set(self, txchain):
self.Transactions = copy.deepcopy(txchain.Transactions)
def start(self):
if self.validate_chain() == False:
raise Exception("Invalid Transaction Chain")
if self.Transactions.qsize() == 0:
self.Finished = True
return
if self.Started:
self.update()
return
self.Started = True
self.Pending = self.Transactions.get()
self.Pending.push_tx()
def update(self):
if not self.Started:
self.start()
return
if self.Finished or not self.Pending.Finished:
return
if self.Pending.Finished:
if self.Transactions.qsize() == 0:
self.Finished = True
return
self.Pending = self.Transactions.get()
self.Pending.push_tx()
def validate_chain(self):
#TODO:
#for tx in transactions
#if cfrom != last.cto or efrom != last.eto or amount > last.amount return false
# else return true