def verify_address_run(): ark_node.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) ark_node.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) cursor = ark_node.DbCursor() qry = cursor.execute_and_fetchall(""" SELECT transactions"vendorField", transactions."senderId" FROM transactions WHERE transactions."recipientId" = '{0}' ORDER BY transactions."timestamp" ASC; """.format(config.DELEGATE['ADDRESS'])) for i in qry: try: vendor_field = i[0] sender_id = i[1] user = console.models.UserProfile.objects.get( main_ark_wallet=sender_id) rawtoken = settings.VERIFICATION_KEY + str(user) + 'ark' token = hashlib.sha256(rawtoken.encode()).hexdigest() if token in vendor_field: user.receiving_ark_address_verified = True if 'CANCEL VERIFICATION' in vendor_field: user.receiving_ark_address_verified = False except Exception: pass
def update_arknode(): ark_node.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) ark_node.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) logger.info('starting updaterun dutchdelegate info') for i in range(5): try: arky.api.use('ark') dutchdelegatestatus = utils.api_call(arky.api.Delegate.getDelegate, 'dutchdelegate') if not dutchdelegatestatus['success']: logger.fatal( 'unable to update the status of dutchdelegate node after 5 tries: response: {}' .format(dutchdelegatestatus)) return data = ark_delegate_manager.models.DutchDelegateStatus.objects.get_or_create( id='main')[0] data.rank = int(dutchdelegatestatus['delegate']['rate']) data.ark_votes = int( dutchdelegatestatus['delegate']['vote']) / info.ARK data.voters = len(ark_node.Delegate.voters()) data.productivity = float( dutchdelegatestatus['delegate']['productivity']) data.save() except Exception: logger.exception('error in update_arknode')
def gen_balance_report(wallet): res = {} arktool.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) arktool.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) balance_over_time = arktool.Address.balance_over_time(wallet) balances = [] for balance in balance_over_time: balances.append({ 'timestamp': balance.timestamp, 'balance': balance.amount }) stake_amount = 0 payouts = arktool.Address.payout(wallet) for i in payouts: stake_amount += i.amount res.update({ 'success': True, 'wallet': wallet, 'total_stake_reward': stake_amount, 'balance_over_time': balances, }) return res
def do(self): ''' update delegate statistics and save in DB ''' try: api.use('ark') ark_node.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) ark_node.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) all_delegates = utils.api_call( api.Delegate.getDelegates)['delegates'] for delegate in all_delegates: delegate_obj = ark_delegate_manager.models.ArkDelegates.objects.get_or_create( pubkey=delegate['publicKey'])[0] delegate_obj.username = delegate['username'] delegate_obj.address = delegate['address'] delegate_obj.ark_votes = delegate['vote'] delegate_obj.producedblocks = delegate['producedblocks'] delegate_obj.missedblocks = delegate['missedblocks'] delegate_obj.productivity = delegate['productivity'] delegate_obj.rank = delegate['rate'] delegate_obj.voters = len( ark_node.Delegate.voters(delegate['address'])) + 1 delegate_obj.save() except Exception: logger.exception('Error during UpdateDelegates')
def set_params(): ark.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], secret=config.DELEGATE['SECRET'], ) logger.info('setting delegate: {0}, {1}'.format(config.DELEGATE['ADDRESS'], config.DELEGATE['PUBKEY'])) ark.set_calculation(blacklist=config.BLACKLIST) ark.set_sender(payoutsender_test=config.PAYOUTSENDER_TEST)
def do(self): ''' add voters to our record of all voters and calculate their balances ''' try: logger.info('starting share calculation') ark_node.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) ark_node.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) if not ark_node.Node.check_node(51) and settings.DEBUG == False: logger.fatal('Node is more than 51 blocks behind') return try: payouts, timestamp = ark_node.Delegate.trueshare() except Exception: logger.exception('failed to calculate payouts') return for address in payouts: voter, created = VotePool.objects.update_or_create( ark_address=address) if voter.status == "Non-Dutchdelegate Voter": continue if payouts[address][ 'vote_timestamp'] < constants.CUT_OFF_EARLY_ADOPTER: voter.status = "Early adopter" voter.share = 0.96 else: voter.status = "Regular Voter" voter.share = 0.95 voter.payout_amount = (payouts[address]['share'] * voter.share) voter.save() except Exception: logger.exception('error in UpdateVotePool')
def roi_report(request, ark_address): arktool.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) arktool.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) context = sidebar_context(request) res = ark_analytics.analytic_functions.gen_roi_report(ark_address) context.update(res) data_list = [['date', 'Balance']] for i in context['payout']: i['ROI'] = round(100 * i['ROI'], 3) i['payout_amount'] /= arkinfo.ARK i['balance_at_payout'] /= arkinfo.ARK data_list.append([i['date'].strftime('%d/%m/%Y'), i['ROI']]) # incase no payouts have occured yet, this will render an empty graph if len(data_list) == 1: data_list.append([datetime.datetime.today(), 0]) data = SimpleDataSource(data=data_list) chart = LineChart(data, options={'title': 'Balance History'}) context.update({ 'chart': chart, }) context['error'] = False return render(request, 'console/console_roi_report.html', context)
def balance_report(request, ark_address): arktool.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) arktool.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) context = sidebar_context(request) context['error'] = False res = ark_analytics.analytic_functions.gen_balance_report(ark_address) context.update(res) # generate a chart and format balances with appropriate units data_list = [['date', 'Balance']] for i in context['balance_over_time']: i['time'] = arktool.utils.arkt_to_datetime(i['timestamp']) i['balance'] = i['balance'] / arkinfo.ARK data_list.append([i['time'].strftime('%d/%m/%Y'), i['balance']]) # incase no payouts have occured yet, this will render an empty graph if len(data_list) == 1: data_list.append([datetime.datetime.today(), 0]) context['balance_over_time'].reverse() context['total_stake_reward'] = context['total_stake_reward'] / arkinfo.ARK data = SimpleDataSource(data=data_list) chart = LineChart(data, options={'title': 'Balance History'}) context.update({ 'chart': chart, }) return render(request, 'console/console_wallet_balance.html', context)
def payment_run(): logger.critical('starting payment run') ark_node.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) ark_node.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) # if we are in test mode we don't care about our node status if not ark_node.Node.check_node(51) and not settings.DEBUG: logger.fatal('Node is more than 51 blocks behind') return payouts, current_timestamp = ark_node.Delegate.trueshare() arky.api.use(network='ark') custom_exceptions = ark_delegate_manager.models.CustomAddressExceptions.objects.all( ) for voter in payouts: share = 0.95 preferred_day = 8 frequency = 2 vote_timestamp = payouts[voter]['vote_timestamp'] # this was part of our Early Adopter bonus, where early voters permanently received a 96% share if vote_timestamp < constants.CUT_OFF_EARLY_ADOPTER: share = 0.96 try: # we can also designate a custom share share = custom_exceptions.get( new_ark_address=voter).share_RANGE_IS_0_TO_1 # a share if 0 means they are blacklisted, so we continue to the next voter if share == 0: continue user_settings = console.models.UserProfile.objects.get( main_ark_wallet=voter) frequency = user_settings.payout_frequency preferred_day = int(user_settings.preferred_day) except Exception: pass send_destination = ark_delegate_manager.models.PayoutTable.objects.get_or_create( address=voter)[0] send_destination.amount = payouts[voter]['share'] send_destination.vote_timestamp = vote_timestamp send_destination.status = payouts[voter]['status'] send_destination.last_payout_blockchain_side = payouts[voter][ 'last_payout'] send_destination.share = share send_destination.preferred_day = preferred_day send_destination.frequency = frequency send_destination.save() # and now on to actually sending the payouts failed_transactions = 0 failed_amount = 0 succesful_transactions = 0 succesful_amount = 0 vendorfield = ark_delegate_manager.models.Setting.objects.get( id='main').vendorfield weekday = datetime.datetime.today().weekday() # we now iterate over the previously generated table. for send_destination in ark_delegate_manager.models.PayoutTable.objects.all( ): address = send_destination.address share_ratio = send_destination.share pure_amount = send_destination.amount frequency = send_destination.frequency status = send_destination.status last_payout = send_destination.last_payout_blockchain_side last_payout_server_side = send_destination.last_payout_server_side #preferred day of 8 translated to no preference preferred_day = 8 correctday = True if current_timestamp < last_payout_server_side: logger.fatal('double payment run occuring') raise ConcurrencyError( 'double payment run occuring, lock needs to be manually removed' ) if current_timestamp - last_payout_server_side < 15 * constants.HOUR: logger.fatal( 'Time between payouts less than 15 hours according to server.') raise ConcurrencyError( 'double payment run occuring, lock needs to be manually removed' ) # preferred day of 8 if preferred_day == 8: correctday = True elif preferred_day != weekday: correctday = False delegate_share = 0 amount = pure_amount * share_ratio if status and correctday: if frequency == 1 and last_payout < current_timestamp - ( constants.DAY - 3 * constants.HOUR): if amount > constants.MIN_AMOUNT_DAILY: amount -= info.TX_FEE res = send_tx(address=address, amount=amount, vendor_field=vendorfield) if res['success']: delegate_share = pure_amount - amount succesful_transactions += 1 succesful_amount += amount logger.info('sent {0} to {1} res: {2}'.format( amount, send_destination, res)) send_destination.last_payout_server_side = last_payout send_destination.save() user_settings.send_email_about_payout = True user_settings.tx_id = res['transactionIds'][0] user_settings.save() else: failed_transactions += 1 failed_amount += amount logger.warning('failed tx {}'.format(res)) if frequency == 2 and last_payout < current_timestamp - ( constants.WEEK - 5 * constants.HOUR): if amount > constants.MIN_AMOUNT_WEEKY: res = send_tx(address=address, amount=amount, vendor_field=vendorfield) if res['success']: delegate_share = pure_amount - (amount + info.TX_FEE) succesful_transactions += 1 succesful_amount += amount logger.info('sent {0} to {1} res: {2}'.format( amount, send_destination, res)) send_destination.last_payout_server_side = last_payout send_destination.save() user_settings.send_email_about_payout = True user_settings.tx_id = res['transactionIds'][0] user_settings.save() else: failed_transactions += 1 failed_amount += amount logger.warning('failed tx {}'.format(res)) if frequency == 3 and last_payout < ( current_timestamp - constants.MONTH - 5 * constants.HOUR): if amount > constants.MIN_AMOUNT_MONTHLY: amount += 1.5 * info.TX_FEE res = send_tx(address=address, amount=amount, vendor_field=vendorfield) if res['success']: delegate_share = pure_amount - (amount + info.TX_FEE) succesful_transactions += 1 succesful_amount += amount send_destination.last_payout_server_side = last_payout send_destination.save() user_settings.send_email_about_payout = True user_settings.tx_id = res['transactionIds'][0] user_settings.save() else: failed_transactions += 1 failed_amount += amount logger.warning('failed tx {}'.format(res)) dutchdelegate = ark_delegate_manager.models.DutchDelegateStatus.objects.get_or_create( id='main')[0] dutchdelegate.reward += delegate_share dutchdelegate.save() if failed_transactions: logger.critical( 'sent {0} transactions, failed {1} transactions'.format( succesful_transactions, failed_transactions)) logger.critical('amout successful: {0}, failed amount: {1}'.format( succesful_amount / info.ARK, failed_amount / info.ARK)) return True
def gen_payout_report(wallet): res = {} arktool.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) arktool.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) balance = arktool.Address.balance(wallet) payout_history = arktool.Address.payout(wallet) delegates = ark_delegate_manager.models.ArkDelegates.objects.all() height = arktool.Node.height() try: last_vote = arktool.Address.votes(wallet)[0] if last_vote.direction: delegate = delegates.get(pubkey=last_vote.delegate).username vote_timestamp = last_vote.timestamp else: delegate = None vote_timestamp = None except IndexError: vote_timestamp = None delegate = None # initialize some variables total_reward = 0 payout_result = [] share_ratio = None custom_share = None try: voter = ark_delegate_manager.models.VotePool.objects.get( ark_address=wallet) custom_share = ark_delegate_manager.models.CustomAddressExceptions.objects.get( new_ark_address=wallet).share_RANGE_IS_0_TO_1 except Exception: pass for tx in payout_history: total_reward += tx.amount # this is a fast try, as in 99% of the cases tx.senderId is in the database try: delegate = delegates.get(address=tx.senderId) sender_delegate = delegate.username # if a new delegate arrives, or we haven't entered the data yet, this will lead to random errors. try: historic_share_percentages = delegate.share_percentages.json() for x in historic_share_percentages: if tx.timestamp > x: share_ratio = historic_share_percentages[x] except Exception: share_ratio = 'N.A.' except Exception: sender_delegate = 'N.A.' # for dutchdelegate voters' if sender_delegate == 'dutchdelegate' and vote_timestamp: if tx.timestamp < 16247647: share_ratio = 1 elif vote_timestamp < 16247647: share_ratio = 0.96 elif custom_share: share_ratio = custom_share else: share_ratio = 0.95 payout_result.append({ 'amount': tx.amount, 'timestamp': tx.timestamp, 'id': tx.id, 'share': share_ratio, 'delegate': sender_delegate, }) res.update({ 'succes': True, 'height': height, 'wallet': wallet, 'current_delegate': delegate, 'last_vote_timestamp': vote_timestamp, 'balance': balance, 'payout_history': payout_result, 'total_stake_reward': total_reward }) return res