Exemplo n.º 1
0
 def approve_money(self, amount):
     tnx_hash = self.employer_h.approve_money(amount=int(amount) * 10**18)
     user_id = self.request.role_object.user.id
     save_txn.delay(tnx_hash.hex(), 'tokenApprove', user_id,
                    self.request.role_object.id)
     save_txn_to_history.delay(user_id, tnx_hash.hex(),
                               'Money approved for oracle')
Exemplo n.º 2
0
def set_member_role(company_address, sender_id, member_id, role):
    try:
        sender = Member.objects.get(pk=sender_id)
        member = Member.objects.get(pk=member_id)
    except Member.DoesNotExist:
        logger.warning('Member not found and will not be added to company.')
    else:
        mi = MemberInterface(sender.contract_address)
        try:
            if role == 'owner':
                txn_hash = mi.new_company_owner(company_address,
                                                member.contract_address)
            elif role == 'collaborator':
                txn_hash = mi.new_company_collaborator(company_address,
                                                       member.contract_address)
            else:
                txn_hash = mi.new_company_member(company_address,
                                                 member.contract_address)
        except Exception as e:
            logger.error(
                'Error while add member to company {} {} {} {}'.format(
                    company_address, member_id, sender_id, e))
        else:
            save_txn.delay(txn_hash.hex(), 'AddCompanyMember', sender_id,
                           member_id)
            save_txn_to_history.delay(
                sender_id, txn_hash.hex(),
                'Add {} as company member'.format(member.full_name))
            return True
Exemplo n.º 3
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.º 4
0
def action_with_candidate(vacancy_id, candidate_id, action, sender_id):
    try:
        sender = Member.objects.get(pk=sender_id)
    except Member.DoesNotExist:
        logger.warning('Sender {} not found, candidate {} will not '
                       'be level up or reset on vacancy {}'.format(
                           sender_id, candidate_id, vacancy_id))
        return False
    try:
        vacancy = Vacancy.objects.get(pk=vacancy_id)
    except Vacancy.DoesNotExist:
        logger.warning(
            'Vacancy {} not found, action with candidate {} will not be provided'
            .format(vacancy_id, candidate_id))
        return False
    else:
        try:
            candidate = Member.objects.get(pk=candidate_id)
        except Member.DoesNotExist:
            logger.warning(
                'Candidate {} do not found, action with vacancy {} will not be provided'
                .format(candidate_id, vacancy_id))
            return False
        else:
            mi = MemberInterface(contract_address=sender.contract_address)
            if action == 'approve':
                method = getattr(mi, 'approve_level_up')
            else:
                method = getattr(mi, 'reset_candidate_action')
            try:
                txn_hash = method(vacancy.company.contract_address,
                                  vacancy.uuid, candidate.contract_address)
            except Exception as e:
                logger.error('Error {} member on vacancy {}: {}'.format(
                    action, vacancy_id, e))
            else:
                save_txn.delay(txn_hash.hex(), 'CandidateActionUpDown',
                               sender_id, candidate_id, vacancy_id)
                save_txn_to_history.delay(
                    sender_id, txn_hash.hex(),
                    'Member {} {} on vacancy {}.'.format(
                        candidate.full_name, action == 'approve' and 'approved'
                        or 'revoked', vacancy.title))
                save_txn_to_history.delay(
                    candidate_id, txn_hash.hex(),
                    '{} on vacancy {}.'.format(action.capitalize(),
                                               vacancy.title))
                return True
Exemplo n.º 5
0
def change_member_role(company_address, member_id, sender_id, role):
    try:
        sender = Member.objects.get(pk=sender_id)
        member = Member.objects.get(pk=member_id)
    except Member.DoesNotExist:
        logger.warning('Member not found and will not be added to company.')
    else:
        mi = MemberInterface(sender.contract_address)
        c_role = company_member_role(company_address, member.contract_address)
        if role == c_role:
            logger.info('Member already {} in company {}'.format(
                role, company_address))
            return False

        if c_role == 'owner':
            try:
                mi.del_owner_member(company_address, member.contract_address)
            except Exception as e:
                logger.warning('Cant delete owner member role: {} {}'.format(
                    member_id, e))
        elif c_role == 'collaborator':
            try:
                mi.del_collaborator_member(company_address,
                                           member.contract_address)
            except Exception as e:
                logger.warning(
                    'Cant delete collaborator member role: {} {}'.format(
                        member_id, e))

        method = getattr(mi, 'new_company_{}'.format(role))
        try:
            txn_hash = method(company_address, member.contract_address)
        except Exception as e:
            logger.warning('Cant add {} member role: {} {}'.format(
                role, member_id, e))
        else:
            save_txn.delay(txn_hash.hex(), 'ChangeCompanyMember', sender_id,
                           member_id)
            save_txn_to_history.delay(
                sender_id, txn_hash.hex(),
                'Change {} as company {}'.format(member.full_name, role))
            return True
Exemplo n.º 6
0
def change_member_status(member_id, status):
    try:
        member = Member.objects.get(pk=member_id)
    except Member.DoesNotExist:
        logger.warning('Member {} not found. Status will not be changed.')
        return False
    else:
        mi = MemberInterface(contract_address=member.contract_address)
        try:
            txn_hash = mi.change_status(status)
        except Exception as e:
            logger.error('Error while change member {} status: {}'.format(
                member_id, e))
            return False
        else:
            save_txn.delay(txn_hash.hex(), 'ChangeStatus', member_id,
                           member_id)
            save_txn_to_history.delay(
                member_id, txn_hash.hex(), 'Status changed to {}'.format(
                    OracleHandler().statuses[int(status)]))
        return True
Exemplo n.º 7
0
def new_fact_confirmation(sender_address, member_address, fact_uuid):
    try:
        sender = Member.objects.get(contract_address=sender_address)
    except Member.DoesNotExist:
        logger.warning(
            'Member with address {} not found, confirmation will not be added'.
            format(sender_address))
        return False
    else:
        mi = MemberInterface(sender_address)
        try:
            txn_hash = mi.verify_fact(member_address, fact_uuid)
        except Exception as e:
            logger.error("Cannot verify fact, e: {}".format(e))
            return False
        else:
            save_txn.delay(txn_hash.hex(), 'NewFactConfirmation', sender.id,
                           fact_uuid)
            save_txn_to_history.delay(
                sender.id, txn_hash.hex(),
                'Added fact confirmation for fact {}'.format(fact_uuid))
        return True
Exemplo n.º 8
0
def new_member_fact(fact, sender_address, about_address):
    try:
        member = Member.objects.get(contract_address=sender_address)
    except Member.DoesNotExist:
        logger.warning(
            'Cant find member with address {}, fact will not be added'.format(
                sender_address))
        return False
    else:
        mi = MemberInterface(sender_address)
        try:
            txn_hash = mi.new_fact(about_address, fact,
                                   Web3.toHex(os.urandom(32)))
        except Exception as e:
            logger.error('Cant add new member fact: about: {}, e: {}'.format(
                about_address, e))
            return False
        else:
            save_txn.delay(txn_hash.hex(), 'AddNewFact', member.id, member.id)
            save_txn_to_history.delay(
                member.id, txn_hash.hex(), 'Added new fact about {}'.format(
                    about_address == sender_address and 'yourself'
                    or about_address))
    return True