Exemple #1
0
    def anti_spamming_tx(self):
        # protect against spam attacks of an address having UTXOs.
        while True:
            rpc_antispam = crypto.get_rpc()

            bot_logger.logger.info('Make clean of tx')
            # get list of account
            list_account = user_function.get_users()
            for account, address in list_account.items():
                # don't flood rpc daemon
                time.sleep(1)
                list_tx = rpc_antispam.listunspent(1, 99999999999, [address])

                if len(list_tx) > int(config.spam_limit):
                    unspent_amounts = []
                    for i in range(0, len(list_tx), 1):
                        unspent_amounts.append(list_tx[i]['amount'])
                        # limits to 200 transaction to not explode timeout rpc
                        if i > 200:
                            break

                    bot_logger.logger.info('Consolidate %s account !' % account)
                    crypto.send_to(rpc_antispam, address, address, sum(unspent_amounts), True)

            # wait a bit before re-scan account
            time.sleep(240)
Exemple #2
0
    def import_address(self):
        rpc = crypto.get_rpc()
        rpc.importprivkey(self.private_key,
                          "reddit-vanity-" + self.user.username, False)

        # on import success clean key from memory
        self.private_key = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
        self.private_key = None
Exemple #3
0
def withdraw_user(msg, failover_time):
    rpc = crypto.get_rpc()
    split_message = msg.body.strip().split()

    user = models.User(msg.author.name)
    if user.is_registered():

        if utils.check_amount_valid(
                split_message[1]) and split_message[4] != user.address:
            amount = float(split_message[1])
            amount = round(amount - 0.5)

            user_balance = user.get_balance_confirmed()
            user_spendable_balance = crypto.get_user_spendable_balance(
                msg.author.name)

            if amount >= float(user_balance) + float(user_spendable_balance):
                bot_logger.logger.info(
                    'user %s not have enough to withdraw this amount (%s), balance = %s'
                    % (msg.author.name, amount, user_balance))
                msg.reply(
                    Template(lang.message_balance_low_withdraw).render(
                        username=msg.author.name,
                        user_balance=str(user_balance),
                        amount=str(amount)) + lang.message_footer)
            else:
                receiver_address = split_message[4]

                history.add_to_history(msg.author.name, user.username,
                                       receiver_address, amount, "withdraw")

                send = crypto.tip_user(user.address, receiver_address, amount,
                                       None, failover_time)

                if send:
                    history.add_to_history(msg.author.name, user.username,
                                           receiver_address, amount,
                                           "withdraw", True, send)
                    value_usd = utils.get_coin_value(amount)
                    msg.reply(
                        Template(lang.message_withdraw +
                                 lang.message_footer).render(
                                     username=msg.author.name,
                                     receiver_address=receiver_address,
                                     amount=str(amount),
                                     value_usd=str(value_usd)))

        elif split_message[4] == user.address:
            msg.reply(lang.message_withdraw_to_self + lang.message_footer)
        else:
            bot_logger.logger.info(lang.message_invalid_amount)
            msg.reply(lang.message_invalid_amount + lang.message_footer)
    else:
        msg.reply(
            Template(lang.message_need_register +
                     lang.message_footer).render(username=msg.author.name))
Exemple #4
0
def register_user(msg, reddit):
    rpc = crypto.get_rpc()

    user = models.User(msg.author.name)
    if not user.is_registered():
        user.get_new_address()
        if user.address:
            content_reply = Template(lang.message_register_success +
                                     lang.message_footer).render(
                                         username=user.username,
                                         address=user.address)
            tittle_reply = 'you are registered'

            user_function.add_user(msg.author.name, user.address)

            history.add_to_history(msg.author.name, "", "", "", "register")

            # create a backup of wallet
            crypto.backup_wallet()
        else:
            bot_logger.logger.warning('Error during register !')
    else:
        bot_logger.logger.info('%s are already registered ' % msg.author.name)

        balance = user.get_balance_confirmed()
        pending_balance = user.get_balance_unconfirmed()
        spendable_balance = crypto.get_user_spendable_balance(
            msg.author.name) + balance
        pending_value_usd = utils.get_coin_value(pending_balance)
        spendable_value_usd = utils.get_coin_value(spendable_balance)
        content_reply = Template(
            lang.message_already_registered + lang.message_account_details +
            lang.message_footer).render(
                username=msg.author.name,
                address=user.address,
                pending_balance=str(pending_balance),
                pending_value_usd=str(pending_value_usd),
                spendable_balance=str(spendable_balance),
                spendable_value_usd=str(spendable_value_usd))
        tittle_reply = 'you are already registered'

    # send PM so just reply
    if type(msg) is Message:
        msg.reply(content_reply)

    # we have just comment so send info in PM
    if type(msg) is Comment:
        reddit.redditor(msg.author.name).message(tittle_reply, content_reply)
Exemple #5
0
def info_user(msg):
    rpc = crypto.get_rpc()

    user = models.User(msg.author.name)
    if user.is_registered():
        balance = user.get_balance_confirmed()

        # pending_tips is balance of tip send to unregistered users
        pending_tips = user.get_balance_unregistered_tip()

        pending_balance = user.get_balance_unconfirmed()
        spendable_balance = crypto.get_user_spendable_balance(
            msg.author.name) + balance

        bot_logger.logger.info('user %s balance = %s' %
                               (msg.author.name, balance))
        bot_logger.logger.info('user %s spendable_balance = %s' %
                               (msg.author.name, spendable_balance))

        pending_value_usd = utils.get_coin_value(pending_balance)
        spendable_value_usd = utils.get_coin_value(spendable_balance)
        pending_tips_value_usd = utils.get_coin_value(pending_tips)

        msg.reply(
            Template(lang.message_account_details +
                     lang.message_footer).render(
                         username=msg.author.name,
                         spendable_balance=str(spendable_balance),
                         spendable_value_usd=str(spendable_value_usd),
                         pending_balance=str(pending_balance),
                         pending_value_usd=str(pending_value_usd),
                         pending_tips=str(pending_tips),
                         pending_tips_value_usd=str(pending_tips_value_usd),
                         address=user.address))

        history.add_to_history(msg.author.name, "", "", spendable_balance,
                               "info")
    else:
        bot_logger.logger.info('user %s not registered (command : info) ' %
                               msg.author.name)
        msg.reply(
            Template(lang.message_need_register +
                     lang.message_footer).render(username=msg.author.name))
Exemple #6
0
    def parse_message(self, message_to_parse, rpc=None):
        if rpc is None:
            # init rpc to validate address
            rpc = crypto.get_rpc()

        p = re.compile(
            '(\+?\/?u\/' + config.bot_name + ')\s?(@?[0-9a-zA-Z-_\/\+]+)?\s+(\d+|[0-9a-zA-Z,.]+)\s(doge)\s?(verify)?',
            re.IGNORECASE)
        m = p.search(message_to_parse.strip())
        # Group 1 is +/u/sodogetiptest
        # Group 2 is either blank(tip to the commentor), an address, or a user
        self.receiver = m.group(2)
        # Group 3 is the tip amount in integers(ex.  100) or a word(ex.roll)
        self.amount = m.group(3).replace(',', '.')
        # Group 4 is doge
        self.currency = m.group(4)
        # Group 5 is either blank(no verify message) or verify(verify message)
        self.verify = True if (m.group(5) == "verify") else False

        if self.receiver is not None:
            # to support send tip to username
            if '+/u/' in self.receiver:
                self.receiver = User(self.receiver[4:])
            elif '/u/' in self.receiver:
                self.receiver = User(self.receiver[3:])
            elif 'u/' in self.receiver:
                self.receiver = User(self.receiver[2:])
            elif '@' in self.receiver:
                self.receiver = User(self.receiver[1:])
            # to support send tip to an address
            elif len(self.receiver) == 34 and rpc.validateaddress(self.receiver)['isvalid']:
                address = self.receiver
                bot_logger.logger.info("Send an tip to address")
                self.receiver = User("address-" + address)
                self.receiver.username = ("address-" + address)
                self.receiver.address = address

        # to support any type of randomXXX amount
        if 'random' in self.amount and utils.check_amount_valid(self.amount[6:]):
            self.amount = random.randint(1, int(self.amount[6:]))

        # here amount is numeric, make magic to support not whole tips
        if utils.check_amount_valid(self.amount):
            self.amount = round(float(self.amount) - 0.5)

        # if amount is all, get balance
        if self.amount == 'all':
            # get user balance
            self.amount = self.sender.get_balance()

        bot_logger.logger.debug("isinstance self.amount = %s" % str(isinstance(self.amount, str)))
        bot_logger.logger.debug("type self.amount = %s" % str(type(self.amount)))

        if type(self.amount) is unicode or type(self.amount) is str:
            bot_logger.logger.debug("self.amount is str")
            if self.amount == "roll":
                self.amount = random.randint(1, 6)

            elif self.amount == "flip":
                self.amount = random.randint(1, 2)

            elif self.amount in config.tip_keyword.keys():
                self.amount = config.tip_keyword[self.amount]

        bot_logger.logger.debug("self.amount = %s" % str(self.amount))

        # if tip is over 1000 doge set verify
        if float(self.amount) >= float(1000):
            self.verify = True
Exemple #7
0
 def get_new_address(self, rpc=None):
     # create a new simple address
     if rpc is None:
         rpc = crypto.get_rpc()
     self.address = rpc.getnewaddress("reddit-%s" % self.username)
Exemple #8
0
 def get_new_address(self):
     # create a new simple address
     rpc = crypto.get_rpc()
     self.address = rpc.getnewaddress("reddit-%s" % self.username)