4
4
import pendulum
5
5
from mongoengine import (
6
6
Document , ReferenceField ,
7
- FloatField , DateTimeField , StringField )
7
+ FloatField , DateTimeField , StringField ,
8
+ BooleanField , IntField )
8
9
9
10
from bot .messages import TX_ID_ERROR
10
11
from db .observer import Observer
@@ -103,12 +104,15 @@ class Ticket(Document):
103
104
tx_id = StringField (max_length = 64 , required = True )
104
105
_status = ReferenceField (Status )
105
106
vote_id = StringField (max_length = 64 )
107
+ vote_block = IntField ()
108
+ spendable = BooleanField (default = False )
106
109
107
110
def __str__ (self ):
108
111
message = f"tx { self .tx_id } \n " \
109
112
f"status: { self .status } "
110
113
if self .vote_id :
111
114
message += f"\n vote: { self .vote_id } "
115
+ message += f"\n spendable: { self .spendable } "
112
116
return message
113
117
114
118
@property
@@ -117,6 +121,7 @@ def html(self):
117
121
f"<b>status</b>: { self .status } "
118
122
if self .vote_id :
119
123
message += f"\n <b>vote</b>: { self .vote_link } "
124
+ message += f"\n <b>spendable</b>: { self .spendable } "
120
125
return message
121
126
122
127
def is_same_status (self , new_status_name ):
@@ -162,7 +167,24 @@ def fetch(self):
162
167
self .status = status
163
168
if self .status == Status .voted ():
164
169
self .vote_id = data .get ('vote' )
170
+ logger .debug (f"fetching vote { self } " )
171
+ data = request_dcr_data (f"tx/{ self .vote_id } /vinfo" )
172
+ self .vote_block = data .get ('block_validation' ).get ('height' )
165
173
166
174
self .save ()
167
175
self .notify ()
168
176
return True
177
+
178
+ def change_spendable (self , new_block ):
179
+ if (new_block - self .vote_block ) >= 256 :
180
+ self .spendable = True
181
+ self .save ()
182
+ self .notify ()
183
+
184
+ @classmethod
185
+ def voted (cls ):
186
+ return cls .objects .filter (_status = Status .voted ())
187
+
188
+ @classmethod
189
+ def voted_and_spendable (cls ):
190
+ return cls .voted ().filter (spendable = True )
0 commit comments