def sync_web3(request): """ Sync up web3 with the database. This function has a few different uses. It is typically called from the front end using the javascript `sync_web3` function. The `issueURL` is passed in first, followed optionally by a `bountydetails` argument. """ # setup result = { 'status': '400', 'msg': "bad request" } issue_url = request.POST.get('url') txid = request.POST.get('txid') network = request.POST.get('network') if issue_url and txid and network: # confirm txid has mined print('* confirming tx has mined') if not has_tx_mined(txid, network): result = { 'status': '400', 'msg': 'tx has not mined yet' } else: # get bounty id print('* getting bounty id') bounty_id = get_bounty_id(issue_url, network) if not bounty_id: result = { 'status': '400', 'msg': 'could not find bounty id' } else: # get/process bounty print('* getting bounty') bounty = get_bounty(bounty_id, network) print('* processing bounty') did_change = False max_tries_attempted = False counter = 0 url = None while not did_change and not max_tries_attempted: did_change, _, new_bounty = web3_process_bounty(bounty) if not did_change: print("RETRYING") time.sleep(3) counter += 1 max_tries_attempted = counter > 3 if new_bounty: url = new_bounty.url result = { 'status': '200', 'msg': "success", 'did_change': did_change, 'url': url, } return JsonResponse(result, status=result['status'])
def handle(self, *args, **options): # config network = options['network'] hour = datetime.datetime.now().hour day = datetime.datetime.now().day month = datetime.datetime.now().month start_id = get_bounty_id(options['start_id'], network) end_id = get_bounty_id(options['end_id'], network) # iterate through all the bounties bounty_enum = int(start_id) print(f"syncing from {start_id} to {end_id}") more_bounties = True while more_bounties: try: # pull and process each bounty print( f"[{month}/{day} {hour}:00] Getting bounty {bounty_enum}") bounty = get_bounty(bounty_enum, network) print( f"[{month}/{day} {hour}:00] Processing bounty {bounty_enum}" ) web3_process_bounty(bounty) except BountyNotFoundException: more_bounties = False except UnsupportedSchemaException as e: logger.info(f"* Unsupported Schema => {e}") except Exception as e: extra_data = { 'bounty_enum': bounty_enum, 'more_bounties': more_bounties, 'network': network } logger.error('Failed to fetch github username', exc_info=True, extra=extra_data) logger.error(f"* Exception in sync_geth => {e}") finally: # prepare for next loop bounty_enum += 1 if bounty_enum > int(end_id): more_bounties = False
def sync_web3(request): """ Sync up web3 with the database. This function has a few different uses. It is typically called from the front end using the javascript `sync_web3` function. The `issueURL` is passed in first, followed optionally by a `bountydetails` argument. """ # setup result = { 'status': '400', 'msg': "bad request" } issueURL = request.POST.get('url') txid = request.POST.get('txid') network = request.POST.get('network') if issueURL and txid and network: # confirm txid has mined print('* confirming tx has mined') if not has_tx_mined(txid, network): result = { 'status': '400', 'msg': 'tx has not mined yet' } else: # get bounty id print('* getting bounty id') bounty_id = getBountyID(issueURL, network) if not bounty_id: result = { 'status': '400', 'msg': 'could not find bounty id' } else: # get/process bounty print('* getting bounty') bounty = get_bounty(bounty_id, network) print('* processing bounty') did_change, _, _ = web3_process_bounty(bounty) result = { 'status': '200', 'msg': "success", 'did_change': did_change } return JsonResponse(result, status=result['status'])
def process_bounty(bounty_id, network): bounty = get_bounty(bounty_id, network) return web3_process_bounty(bounty)