示例#1
0
def replay_remove_pending_tip(reddit, tx_queue, failover_time):
    # check if user have pending tips
    list_tips = user_function.get_unregistered_tip()

    if list_tips:
        for arr_tip in list_tips:
            tip = models.Tip().create_from_array(arr_tip)

            bot_logger.logger.info("replay tipping check for %s" % str(tip.id))

            # check if it's not too old & replay tipping
            if not tip.is_expired():
                if tip.receiver.is_registered():
                    bot_logger.logger.info(
                        "replay tipping %s - %s send %s to %s  " %
                        (str(tip.id), tip.sender.username, tip.amount,
                         tip.receiver.username))

                    tip.tx_id = crypto.tip_user(tip.sender.address,
                                                tip.receiver.address,
                                                tip.amount, tx_queue,
                                                failover_time)
                    if tip.tx_id:
                        tip.finish = True

                        user_function.remove_pending_tip(tip.id)

                        if tip.message_fullname is not None:
                            msg_id = re.sub(r't\d+_(?P<id>\w+)', r'\g<id>',
                                            tip.message_fullname)
                            msg = Comment(reddit, msg_id)
                            msg.reply(
                                Template(lang.message_tip).render(
                                    sender=tip.sender.username,
                                    receiver=tip.receiver.username,
                                    amount=str(tip.amount),
                                    value_usd=str(tip.get_value_usd()),
                                    txid=tip.tx_id))

                else:
                    tip.status = "waiting registration of receiver"
                    bot_logger.logger.info(
                        "replay check for %s - user %s not registered " %
                        (str(tip.id), tip.receiver.username))

            else:
                tip.status = "receiver not registered in time"
                tip.finish = ""
                bot_logger.logger.info(
                    "delete old tipping - %s send %s to %s  " %
                    (tip.sender.username, tip.amount, tip.receiver.username))
                user_function.remove_pending_tip(tip.id)

            # update tip status
            history.update_tip(tip.sender.username, tip)
            history.update_tip(tip.receiver.username, tip)
    else:
        bot_logger.logger.info("no pending tipping")
示例#2
0
    def test_create_from_array(self):
        list_tips = user_function.get_unregistered_tip()

        # make a copy for tests :)
        list_tips_edit = copy.deepcopy(list_tips)

        tip = models.Tip().create_from_array(list_tips_edit[1])
        self.assertEqual(list_tips[1]['amount'], tip.amount)
        self.assertEqual(list_tips[1]['sender'], tip.sender.username)
        self.assertEqual(list_tips[1]['receiver'], tip.receiver.username)
        self.assertEqual(list_tips[1]['message_fullname'],
                         tip.message_fullname)
        self.assertEqual(list_tips[1]['time'], tip.time)
        self.assertEqual(list_tips[1]['id'], tip.id)
示例#3
0
def replay_remove_pending_tip(rpc, reddit, tx_queue, failover_time):
    # check if it's not too old & replay tipping
    limit_date = datetime.datetime.now() - datetime.timedelta(days=3)

    # check if user have pending tips
    list_tips = user_function.get_unregistered_tip()

    if list_tips:
        for tip in list_tips:
            bot_logger.logger.info("replay tipping check for %s" %
                                   str(tip['id']))
            if (datetime.datetime.strptime(tip['time'], '%Y-%m-%dT%H:%M:%S.%f')
                    > limit_date):
                if (user_function.user_exist(tip['receiver'])):
                    bot_logger.logger.info(
                        "replay tipping %s - %s send %s to %s  " %
                        (str(tip['id']), tip['sender'], tip['amount'],
                         tip['receiver']))
                    txid = crypto.tip_user(rpc, tip['sender'], tip['receiver'],
                                           tip['amount'], tx_queue,
                                           failover_time)
                    user_function.remove_pending_tip(tip['id'])

                    value_usd = utils.get_coin_value(tip['amount'])

                    if 'message_fullname' in tip.keys():
                        msg_id = re.sub(r't\d+_(?P<id>\w+)', r'\g<id>',
                                        tip['message_fullname'])
                        msg = Comment(reddit, msg_id)
                        msg.reply(
                            Template(lang.message_tip).render(
                                sender=tip['sender'],
                                receiver=tip['receiver'],
                                amount=str(tip['amount']),
                                value_usd=str(value_usd),
                                txid=txid))

                else:
                    bot_logger.logger.info(
                        "replay check for %s - user %s not registered " %
                        (str(tip['id']), tip['receiver']))
            else:
                bot_logger.logger.info(
                    "delete old tipping - %s send %s for %s  " %
                    (tip['sender'], tip['amount'], tip['receiver']))
                user_function.remove_pending_tip(tip['id'])
    else:
        bot_logger.logger.info("no pending tipping")
示例#4
0
def get_user_balance(rpc, user):
    pending_tips = []
    unspent_amounts = []

    address = user_function.get_user_address(user)
    list_unspent = rpc.listunspent(0, 99999999999, [address])
    for i in range(0, len(list_unspent), 1):
        unspent_amounts.append(list_unspent[i]['amount'])

    # check if user have pending tips
    list_tip_unregistered = user_function.get_unregistered_tip()
    for list_tip in list_tip_unregistered.values():
        for tip in list_tip:
            if tip['sender'] == user:
                pending_tips.append(int(tip['amount']))

    return int(sum(unspent_amounts) - sum(pending_tips))
示例#5
0
    def test_tip_unregistered(self):
        list_tips = user_function.get_unregistered_tip()

        tip = models.Tip().create_from_array(list_tips[2])
        self.assertEqual(True, tip.is_expired())