def new_member_instance(user_id): try: Member.objects.get(pk=user_id) except Member.DoesNotExist: logger.error('Member with id {} not found, contract will not be deployed.'.format(user_id)) else: oracle = OracleHandler() w3 = utils.get_w3() contract_file = 'dapp/contracts/Member.sol' compile_sol = compile_files([contract_file, ], output_values=("abi", "ast", "bin", "bin-runtime",)) create_abi(compile_sol[contract_file + ':Member']['abi'], 'Member') obj = w3.eth.contract( abi=compile_sol[contract_file + ':Member']['abi'], bytecode=compile_sol[contract_file + ':Member']['bin'], bytecode_runtime=compile_sol[contract_file + ':Member']['bin-runtime'], ) args = [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 member contract. User {}: {}'.format(user_id, e)) return False else: logger.info('Lock account: {}'.format(oracle.lockAccount())) save_txn.delay(txn_hash.hex(), 'NewMember', user_id, user_id) save_txn_to_history.delay(user_id, txn_hash.hex(), 'Creation of a new Member contract')
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')