def vote(self, voter: User, amount_staked: float, for_against: bool): if for_against: self._for_map[voter.get_address()] = amount_staked self._for_staked += amount_staked self._for_count += 1 self._for_rep += voter.get_rep() else: self._against_map[voter.get_address()] = amount_staked self._against_staked += amount_staked self._against_count += 1 self._against_rep += voter.get_rep()
def __init__(self, creator: User, data: Database, stock_ticker: str = '', sign: int = 0, margin: float = 0.0, amount_staked: float = 0.0, seconds: int = 0): # initializing our own ADTs self._creator = creator self._key = data.make_bet_key() data.bets()[self._key] = self # initializing our arguments self._stock_ticker = stock_ticker self._sign = sign self._margin = margin self._amount_staked = amount_staked # initializing initial and target stock price with some data reader stuff, edit initial price self._initial_price = self.get_current_price() self._target_price = self._initial_price * (1 + self._sign * self._margin) # creating necessary data structures self._for_map = {creator.get_address(): amount_staked} self._against_map = {} self._for_count = 1 self._against_count = 0 self._for_rep = creator.get_rep() self._against_rep = 0.0 self._for_staked = amount_staked self._against_staked = 0.0 # timing the bet, adjust back for longer time frames after testing # current_time = datetime.utcnow() # tz = timezone.utc # set_time = datetime(year, month, day, 20, 0, 1, 0, tz) # timedelta = set_time - current_time # self._total_seconds = timedelta.total_seconds() self._total_seconds = seconds # starting the timer for the voting duration once the bet is initialized voting_period = self.voting_period() timer = Timer(voting_period, self.timed_payout) timer.start()