Exemplo n.º 1
0
 def process_request(self, request):
     w3 = get_w3()
     try:
         sync_now = w3.eth.syncing
     except Exception as e:
         return HttpResponse('Node disabled', status=503)
     else:
         return sync_now and HttpResponse('Node syncing now', status=503)
Exemplo n.º 2
0
def deploy_new_company(company_id):
    """
    Deploy new company contract
    :param company_id: Company off chain id for deploy
    :return: True in case of successful, false otherwise
    """
    try:
        instance = Company.objects.get(pk=company_id)
    except Company.DoesNotExist:
        logger.error(
            'Company with id {} not found, contract will bot be deployed.'.
            format(company_id))
        return False
    else:
        oracle = OracleHandler()
        w3 = utils.get_w3()
        contract_file = 'dapp/contracts/Company.sol'
        compile_sol = compile_files([
            contract_file,
        ],
                                    output_values=(
                                        "abi",
                                        "ast",
                                        "bin",
                                        "bin-runtime",
                                    ))
        create_abi(compile_sol[contract_file + ':Company']['abi'], 'Company')
        obj = w3.eth.contract(
            abi=compile_sol[contract_file + ':Company']['abi'],
            bytecode=compile_sol[contract_file + ':Company']['bin'],
            bytecode_runtime=compile_sol[contract_file +
                                         ':Company']['bin-runtime'],
        )
        args = [
            settings.VERA_COIN_CONTRACT_ADDRESS,
            settings.VERA_ORACLE_CONTRACT_ADDRESS,
        ]
        logger.info('Try to unlock account: {}.'.format(
            oracle.unlockAccount()))
        try:
            txn_hash = obj.deploy(transaction={'from': oracle.account},
                                  args=args)
        except Exception as e:
            logger.warning(
                'Error while deploy new company contract. Company {}: {}'.
                format(company_id, e))
        else:
            logger.info('Lock account: {}'.format(oracle.lockAccount()))
            save_txn.delay(txn_hash.hex(), 'NewCompany',
                           instance.created_by.id, company_id)
            save_txn_to_history.delay(instance.created_by.id, txn_hash.hex(),
                                      'Creation of a new Company contract')
Exemplo n.º 3
0
 def __init__(self, contract_address, account=None, password=None):
     self.web3 = utils.get_w3()
     self.account = account or settings.WEB_ETH_COINBASE
     self.contract_address = contract_address
     try:
         with open(settings.ABI_PATH + 'Company.abi.json', 'r') as ad:
             self.abi = json.load(ad)
     except FileNotFoundError:
         path = 'dapp/contracts/Company.sol'
         compiled = compile_files([path, ],
                                  output_values=("abi", "ast", "bin", "bin-runtime",))
         with open(settings.ABI_PATH + 'Company.abi.json', 'w+') as ad:
             ad.write(json.dumps(compiled[path + ':Company']['abi']))
             self.abi = compiled[path + ':Company']['abi']
     self.__password = password or settings.COINBASE_PASSWORD_SECRET
     self.contract = self.web3.eth.contract(abi=self.abi, address=self.contract_address)