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)
def withdraw_user(rpc, msg): split_message = msg.body.strip().split() if user_function.user_exist(msg.author.name): sender_address = user_function.get_user_address(msg.author.name) amount = split_message[1] user_balance = crypto.get_user_balance(rpc, msg.author.name) if int(amount) >= user_balance: print( 'user %s not have enough to withdraw this amount (%s), balance = %s' % (msg.author.name, amount, user_balance)) msg.reply('+/u/%s your balance is too low for this withdraw ' % msg.author.name) else: if utils.check_amount_valid(amount): receiver_address = split_message[4] try: if crypto.send_to(rpc, sender_address, receiver_address, amount, True): user_function.add_to_history(msg.author.name, sender_address, receiver_address, amount, "withdraw") msg.reply('Withdraw : ' + str(amount) + ' to ' + receiver_address) except: traceback.print_exc() else: print('You must use valid amount') msg.reply('You must use valid amount') else: msg.reply('You need %s before' % linkRegister)
def withdraw_user(rpc, msg, failover_time): split_message = msg.body.strip().split() if user_function.user_exist(msg.author.name): sender_address = user_function.get_user_address(msg.author.name) amount = float(split_message[1]) amount = round(amount - 0.5) print(amount) user_balance = crypto.get_user_confirmed_balance(rpc, msg.author.name) user_spendable_balance = crypto.get_user_spendable_balance( rpc, msg.author.name) if utils.check_amount_valid( amount) and split_message[4] != sender_address: 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] if time.time() > int(failover_time.value) + 86400: send = crypto.send_to(rpc, sender_address, receiver_address, amount) else: send = crypto.send_to_failover(rpc, sender_address, receiver_address, amount) if send: user_function.add_to_history(msg.author.name, sender_address, receiver_address, amount, "withdraw") 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] == sender_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))
def vanity(msg): if config.vanity_enabled is True: user = models.User(msg.author.name) if user.is_registered(): v = models.VanityGenRequest(user) v.parse_message(msg.body.lower().strip()) if len(v.pattern) not in config.vanitygen_price.keys(): user.send_private_message( "Vanity Request : Error", "Your request can't be process, pattern too long or too short" ) else: if v.save_resquest(): # send money to vanity account amount = config.vanitygen_price[len( v.pattern )] - 2 # reduce fee to move funds after generation crypto.send_to(None, user.address, config.vanitygen_address, amount) # send message user.send_private_message( "Vanity Request : Received", "Your request will be process in few time") else: # send error message user.send_private_message( "Vanity Request : Error", "Your request can't be process, check your pattern is a valid base58 string, and start with D" ) else: bot_logger.logger.info( 'user %s not registered (command : vanity) ' % user.username) msg.reply( Template(lang.message_need_register + lang.message_footer).render(username=user.username))