예제 #1
0
def update(address, contract_name):
    file_name = "challenges/" + contract_name + ".py"
    if not os.path.exists(file_name) or not os.path.isfile(file_name):
        print("Challenge validator not found for contract: " + contract_name)
        return redirect(
            url_for('view',
                    _external=True,
                    _scheme='https',
                    address=address,
                    contract=contract))

    status_blob = util.get_status(address,
                                  util.get_contract_number(contract_name))
    contract_addr = status_blob[2].strip()
    status = status_blob[0].lower()
    if "unfinished" in status:
        return render_template('grade.html',
                               address=address,
                               contract_name=contract_name)
    else:
        return redirect(
            url_for('dashboard',
                    _external=True,
                    _scheme='https',
                    address=address))
    def _grade_challenge(self, contract_name, user_address, contract_address, timeout=180):
        """
        Deploys solidity contract
        :param contract_name: name of the challenge / the contract we're going to deploy
        :param user_address:  end-user address that asked for this challenge
        :param timeout: how long to wait for things to happen on-chain - in seconds
        :return: contract_address - address of this newly spawned contract
        """
        with self._lock:
            self._status = "started"
        contract_number = util.get_contract_number(contract_name)
        with self._lock:
            self._status = "in-progress"
            self._deployed_address = contract_address
        util.mark_grading(user_address, contract_number)

        if (util.contract_exists(contract_name)):
            contract_helper = util.get_icontract(user_address, contract_name, contract_address=contract_address)
            hacked = contract_helper.has_been_hacked()
            if hacked:
                util.mark_finished(user_address, contract_name)
            else:
                util.mark_in_progress(user_address, contract_number)

        with self._lock:
            self._status = "graded"

        return contract_address
예제 #3
0
def redeploy(address, contract_name):
    print("Redeploying {}, {}".format(address, contract_name))
    util.erase_challenge_deployed_address_from_db(
        address, util.get_contract_number(contract_name))
    return redirect(url_for('deploy',
                            _external=True,
                            _scheme='https',
                            _method="POST",
                            address=address,
                            contract=contract_name),
                    code=307)
예제 #4
0
def get_grade_thread_status(address, contract_name):
    global graders
    grade_key = (address, contract_name)
    if not grade_key in graders:
        web3_instance = easyweb3.EasyWeb3()
        graders[grade_key] = web3_instance
        contract_addr = util.get_deployed_contract_address_for_challenge(
            address, util.get_contract_number(contract_name))
        web3_instance.grade_challenge(contract_name, address, contract_addr)
    else:
        web3_instance = graders[grade_key]
    return web3_instance.deploy_status()
예제 #5
0
def deploy(address, contract):
    status = util.get_status(address, util.get_contract_number(contract))
    if "not started" in status[0].lower():
        return render_template('deploy.html',
                               deployed=False,
                               address=address,
                               contract=contract)
    else:
        return redirect(
            url_for('view',
                    _external=True,
                    _scheme='https',
                    address=address,
                    contract=contract))
예제 #6
0
def done(address, contract):
    print("deploying:\t{} {}".format(address, contract))
    status = get_deploy_thread_status(address, contract)

    if status[1] is not None and status[0] == "deployed":
        print("Status is not none: " + str(status))
        global deployers
        deploy_key = (address, contract)
        del deployers[deploy_key]  # TODO race condition?
        util.write_address(address, util.get_contract_number(contract),
                           status[1])
    if status[0]:
        return status[0]
    else:
        return "Starting deployment process"
예제 #7
0
def view(address, contract):
    status = util.get_status(address, util.get_contract_number(contract))
    if "not started" in status[0].lower():
        return "Not started!"
    contract_code = open("challenges/" + contract + ".sol").read().strip()
    contract_desc = json.loads(
        open("challenges/" + contract + ".json").read().strip())["description"]
    return render_template('view.html',
                           deployed=True,
                           done=("done" in status[0].lower()),
                           status=status,
                           address=address,
                           contract=contract,
                           contract_code=contract_code,
                           contract_desc=contract_desc)