예제 #1
0
def process_merges():
    projects = Project.objects.filter()
    compiler = ContractCompiler()
    w3 = deploy.get_w3()

    for project in projects:
        if project.is_mycro_dao:
            continue
        if project.blockchain_state != BlockchainState.COMPLETED:
            continue
        logger.info(f"Looking for PRs for project {project.dao_address}")

        merge_contract = get_merge_module_instance(project, compiler, w3)

        logger.info(f"Found PRs: {merge_contract.functions.pullRequestsToMerge().call()}")
        for pr_id in merge_contract.functions.pullRequestsToMerge().call():
            logger.info(f"DAO {project.dao_address} with name {project.repo_name} wants to merge {pr_id}")

            # TODO get rid of this try catch
            # We can do this when we use get_new_entries but need this for now because we reattempt to merge PRs even
            # after they've been merged which results in an exception
            try:
                github.merge_pr(project.repo_name, pr_id, organization=settings.github_organization())
            except Exception as e:
                logger.warning(
                    f'PR {pr_id} for project {project.repo_name} could not be merged, probably because it already has been')
                logger.warning(e)
예제 #2
0
    def resolve_pull_requests(self: Project,
                              info) -> List[PullRequestType] or None:
        if self is None:
            return None

        if self.is_mycro_dao:
            return None

        pull_requests = []
        for pull_request in github.get_pull_requests(
                self.repo_name,
                settings.github_organization(),
                settings.github_token(),
                state='all'):
            pull_requests.append(
                PullRequestType(
                    additions=pull_request.additions,
                    body=pull_request.body,
                    changed_files=pull_request.changed_files,
                    closed_at=pull_request.closed_at,
                    comments=pull_request.comments,
                    comments_url=pull_request.comments_url,
                    commits=pull_request.commits,
                    commits_url=pull_request.commits_url,
                    created_at=pull_request.created_at,
                    deletions=pull_request.deletions,
                    diff_url=pull_request.diff_url,
                    html_url=pull_request.html_url,
                    id=pull_request.id,
                    issue_url=pull_request.issue_url,
                    merge_commit_sha=pull_request.merge_commit_sha,
                    mergeable=pull_request.mergeable,
                    mergeable_state=pull_request.mergeable_state,
                    merged=pull_request.merged,
                    merged_at=pull_request.merged_at,
                    number=pull_request.number,
                    patch_url=pull_request.patch_url,
                    review_comment_url=pull_request.review_comment_url,
                    review_comments=pull_request.review_comments,
                    review_comments_url=pull_request.review_comments_url,
                    state=pull_request.state,
                    title=pull_request.title,
                    updated_at=pull_request.updated_at,
                    url=pull_request.url))

        return pull_requests
예제 #3
0
    def _validate_asc_creation(project: Project, pr_id: int):
        # first check to see if the project already has an ASC open or closed for this pr
        for asc in project.asc_set.all():
            if asc.pr_id == pr_id:
                raise ASCError(
                    f'ASC at address `{asc.address} already exists for pr {pr_id}'
                )

        # next make sure the project has an OPEN pr with this ID
        for pull_request in github.get_pull_requests(
                project.repo_name,
                settings.github_organization(),
                settings.github_token(),
                state='open'):
            if pull_request.number == pr_id:
                # There's an open PR with this ID
                return

        raise ASCError(
            f'Could not find an open PR with number {pr_id} on project {project.repo_name}'
        )
예제 #4
0
def create_project(self, project_id: int) -> None:
    # TODO add mechanism to retry if anything in here fails
    # TODO there's lots of opportunity for failure in this function, we should be
    # more resilient

    logger.info(f'Attempting to get lock to create project {project_id}')

    # TODO extend to support locking based on wallets
    with REDIS_CLIENT.lock('create-project'):
        logger.info(f'Acquired lock to create project {project_id}')
        project = Project.objects.get(pk=project_id)

        project.blockchain_state = BlockchainState.STARTED.value
        project.save()

        compiler = ContractCompiler()
        mycro_project = Project.get_mycro_dao()

        w3 = deploy.get_w3()

        contract_interface = compiler.get_contract_interface('mycro.sol',
                                                             'MycroCoin')
        mycro_contract = w3.eth.contract(abi=contract_interface['abi'],
                                         address=mycro_project.dao_address)

        base_dao_interface = compiler.get_contract_interface('base_dao.sol',
                                                             'BaseDao')
        merge_module_interface = compiler.get_contract_interface(
            'merge_module.sol', 'MergeModule')

        creators = []
        creator_balances = []
        logger.info(f'Project balances are {project.initial_balances}')
        for creator, balance in project.initial_balances.items():
            creators.append(creator)
            creator_balances.append(balance)

        total_supply = sum(creator_balances)

        # TODO add validation of project properties
        w3, dao_contract, dao_address, _ = deploy.deploy(base_dao_interface,
                                                         project.symbol,
                                                         project.repo_name,
                                                         project.decimals,
                                                         total_supply,
                                                         creators,
                                                         creator_balances,
                                                         private_key=Wallet.objects.first().private_key)

        _, _, merge_module_address, _ = deploy.deploy(merge_module_interface,
                                                      private_key=Wallet.objects.first().private_key)

        deploy.call_contract_function(
            dao_contract.functions.registerModule,
            merge_module_address,
            private_key=Wallet.objects.first().private_key)
        deploy.call_contract_function(
            mycro_contract.functions.registerProject,
            dao_address,
            private_key=Wallet.objects.first().private_key)


        project.blockchain_state = BlockchainState.COMPLETED.value
        project.dao_address = dao_address
        project.merge_module_address = merge_module_address
        project.save()

        github.create_repo(repo_name=project.repo_name,
                           organization=settings.github_organization())

    logger.info(f'Finished creating project {project_id}')