Esempio n. 1
0
def get_bounty_id_from_web3(issue_url,
                            network,
                            start_bounty_id,
                            direction='up'):
    issue_url = normalize_url(issue_url)

    # iterate through all the bounties
    bounty_enum = start_bounty_id
    more_bounties = True
    while more_bounties:
        try:

            # pull and process each bounty
            print(f'** get_bounty_id_from_web3; looking at {bounty_enum}')
            bounty = get_bounty(bounty_enum, network)
            url = bounty.get('data', {}).get('payload',
                                             {}).get('webReferenceURL', False)
            if url == issue_url:
                return bounty['id']

        except BountyNotFoundException:
            more_bounties = False
        except UnsupportedSchemaException:
            pass
        finally:
            # prepare for next loop
            if direction == 'up':
                bounty_enum += 1
            else:
                bounty_enum -= 1

    return None
Esempio n. 2
0
def get_bounty_id(issue_url, network):
    issue_url = normalize_url(issue_url)
    bounty_id = get_bounty_id_from_db(issue_url, network)
    if bounty_id:
        return bounty_id

    all_known_stdbounties = Bounty.objects.filter(
        web3_type='bounties_network',
        network=network).order_by('-standard_bounties_id')

    try:
        highest_known_bounty_id = get_highest_known_bounty_id(network)
        bounty_id = get_bounty_id_from_web3(issue_url,
                                            network,
                                            highest_known_bounty_id,
                                            direction='down')
    except NoBountiesException:
        last_known_bounty_id = 0
        if all_known_stdbounties.exists():
            last_known_bounty_id = all_known_stdbounties.first(
            ).standard_bounties_id
        bounty_id = get_bounty_id_from_web3(issue_url,
                                            network,
                                            last_known_bounty_id,
                                            direction='up')

    return bounty_id
Esempio n. 3
0
def get_bounty_id_from_db(issue_url, network):
    issue_url = normalize_url(issue_url)
    bounties = Bounty.objects.filter(github_url=issue_url,
                                     network=network,
                                     web3_type='bounties_network')
    if not bounties.exists():
        return None
    return bounties.first().standard_bounties_id
Esempio n. 4
0
File: views.py Progetto: msuess/web
def sync_web3(request):
    """Sync web3 for legacy."""
    # setup
    result = {}
    issue_url = request.POST.get('issueURL', False)
    bountydetails = request.POST.getlist('bountydetails[]', [])
    if issue_url:
        issue_url = normalize_url(issue_url)
        if not bountydetails:
            # create a bounty sync request
            result['status'] = 'OK'
            for existing_bsr in BountySyncRequest.objects.filter(
                    github_url=issue_url, processed=False):
                existing_bsr.processed = True
                existing_bsr.save()
        else:
            # normalize data
            bountydetails[0] = int(bountydetails[0])
            bountydetails[1] = str(bountydetails[1])
            bountydetails[2] = str(bountydetails[2])
            bountydetails[3] = str(bountydetails[3])
            bountydetails[4] = bool(bountydetails[4] == 'true')
            bountydetails[5] = bool(bountydetails[5] == 'true')
            bountydetails[6] = str(bountydetails[6])
            bountydetails[7] = int(bountydetails[7])
            bountydetails[8] = str(bountydetails[8])
            bountydetails[9] = int(bountydetails[9])
            bountydetails[10] = str(bountydetails[10])
            print(bountydetails)
            contract_address = request.POST.get('contract_address')
            network = request.POST.get('network')
            did_change, old_bounty, new_bounty = process_bounty_details(
                bountydetails, issue_url, contract_address, network)
            print(f"LEGACY: {did_change} changed, {issue_url}")
            if did_change:
                print("- processing changes")
                process_bounty_changes(old_bounty, new_bounty)

        BountySyncRequest.objects.create(github_url=issue_url, processed=False)

    return JsonResponse(result)
Esempio n. 5
0
 def test_normalize_url(self):
     """Test the dashboard helper normalize_url method."""
     assert normalize_url('https://gitcoin.co/') == 'https://gitcoin.co'
Esempio n. 6
0
def process_bounty_details(bountydetails, url, contract_address, network):
    """Process legacy bounty details."""
    url = normalize_url(url)

    # extract json
    metadata = None
    try:
        metadata = json.loads(bountydetails[8])
    except Exception as e:
        print(e)
        metadata = {}

    # create new bounty (but only if things have changed)
    did_change = False
    old_bounties = Bounty.objects.none()
    try:
        old_bounties = Bounty.objects.current().filter(
            github_url=url,
            title=metadata.get('issueTitle'),
        ).order_by('-created_on')
        did_change = (bountydetails != old_bounties.first().raw_data)
        if not did_change:
            return (did_change, old_bounties.first(), old_bounties.first())
    except Exception as e:
        print(e)
        did_change = True

    with transaction.atomic():
        new_bounty = Bounty.objects.create(
            title=metadata.get('issueTitle', ''),
            web3_type='legacy_gitcoin',
            web3_created=timezone.datetime.fromtimestamp(bountydetails[7]),
            value_in_token=bountydetails[0],
            token_name=metadata.get('tokenName'),
            token_address=bountydetails[1],
            bounty_type=metadata.get('bountyType'),
            project_length=metadata.get('projectLength'),
            experience_level=metadata.get('experienceLevel'),
            github_url=url,
            bounty_owner_address=bountydetails[2],
            bounty_owner_email=metadata.get('notificationEmail', ''),
            bounty_owner_github_username=metadata.get('githubUsername', ''),
            is_open=bountydetails[4],
            expires_date=timezone.datetime.fromtimestamp(bountydetails[9]),
            raw_data=bountydetails,
            metadata=metadata,
            current_bounty=True,
            contract_address=contract_address,
            network=network,
            issue_description='',
        )
        # only xfr fulfilments to new bounty if new bounty has fulfillments
        if bountydetails[3] != '0x0000000000000000000000000000000000000000':
            for old_bounty in old_bounties:
                if old_bounty.current_bounty:
                    old_num_fulfillments = old_bounty.fulfillments.count()
                    old_bounty.num_fulfillments = old_num_fulfillments
                    old_bounty.fulfillments.update(bounty=new_bounty)
                    if new_bounty.num_fulfillments < old_num_fulfillments or \
                       new_bounty.num_fulfillments < new_bounty.fulfillments.count():
                        new_bounty.num_fulfillments = new_bounty.fulfillments.count()
                        new_bounty.save()
                old_bounty.current_bounty = False
                old_bounty.save()
        new_bounty.fetch_issue_item()
        if not new_bounty.avatar_url:
            new_bounty.avatar_url = new_bounty.get_avatar_url()
        new_bounty.save()

    return (did_change, old_bounties.first(), new_bounty)