Example #1
0
    async def record_transactions(self,
                                  buf_len=0,
                                  delay=True,
                                  check_table_len=False):
        """This function records the transaction records into the ledger

        """

        if check_table_len:
            table_len = db_utils.get_table_len(self.__db['path'],
                                               self.__db['table'])
            if table_len < self.transactions_count:
                return False

        if delay and buf_len:
            delay = buf_len / 100
            ts = datetime.datetime.now().timestamp()
            if ts - self.__transaction_last_record_time < delay:
                return False

        transactions_len = len(self.__transactions)
        if transactions_len < buf_len:
            return False

        transactions = self.__transactions[:transactions_len]
        asyncio.create_task(
            db_utils.dump_data(transactions, self.__db['path'],
                               self.__db['table']))

        self.__transaction_last_record_time = datetime.datetime.now(
        ).timestamp()
        del self.__transactions[:transactions_len]
        self.transactions_count += transactions_len
        return True
Example #2
0
 async def __ensure_transactions_complete(self):
     table_len = db_utils.get_table_len(self.__db['path'],
                                        self.__db['table'])
     if table_len < self.transactions_count:
         raise Exception
     return True