Exemple #1
0
 def __init__(self, repo):
     self.request_dao = RequestDAO(repo=repo)
     self.vote_dao = VoteDAO(repo=repo)
     self.solution_dao = SolutionDAO(repo=repo)
     self.stake_dao = StakeDAO(repo=repo)
     self.foundation_member_dao = FoundationMemberDAO(repo=repo)
     self.rfai_request_dao = RFAIRequestRepository(repo=repo)
Exemple #2
0
class RFAIClaimBackRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _request_dao = RequestDAO(_connection)
    _stake_dao = StakeDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        event_data = self._get_event_data(event)
        request_id = event_data['requestId']
        [
            found, request_id, requester, total_fund, document_uri, expiration,
            end_submission, end_evaluation, status, stake_members, submitters
        ] = self._get_rfai_service_request_by_id(request_id)
        claim_back_amount = event_data["amount"]
        request_data = self._request_dao.get_request_data_for_given_requester_and_status(
            filter_parameter={"request_id": request_id})
        self._connection.begin_transaction()
        try:
            self._request_dao.update_request_for_given_request_id(
                request_id=request_id,
                update_parameters={"fund_total": total_fund})
            self._stake_dao.update_stake_for_given_request_id(
                request_id=request_id,
                update_parameters={"claim_back_amount": 0})
            self._connection.commit_transaction()
        except Exception as e:
            logger.info(
                f"Transaction Rollback for event {event}. Error::{repr(e)}")
            self._connection.rollback_transaction()
            raise e
Exemple #3
0
class RFAIApproveRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _request_dao = RequestDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        # need to change this whenever we clean up it should nto be tied with db column name
        event_data = self._get_event_data(event)

        request_id = event_data['requestId']
        approver = event_data['approver']
        end_submission = event_data['endSubmission']
        end_evaluation = event_data['endEvaluation']
        expiration = event_data['expiration']

        filter_params = {
            "status": RFAIStatusCodes.APPROVED.value,
            "request_actor": approver,
            "end_submission": end_submission,
            "end_evaluation": end_evaluation,
            "expiration": expiration
        }
        self._request_dao.update_request_for_given_request_id(
            request_id, filter_params)
Exemple #4
0
class RFAICloseRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _request_dao = RequestDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        event_data = self._get_event_data(event)
        request_id = event_data['requestId']
        [
            found, request_id, requester, total_fund, document_uri, expiration,
            end_submission, end_evaluation, status, stake_members, submitters
        ] = self._get_rfai_service_request_by_id(request_id)
        self._update_rfai_request_status_and_actor(
            request_id=request_id,
            status=RFAIStatusCodes.CLOSED.value,
            request_actor=event_data["actor"])

    def _update_rfai_request_status_and_actor(self, request_id, status,
                                              request_actor):
        self._request_dao.update_request_for_given_request_id(
            request_id=request_id,
            update_parameters={
                "status": status,
                "request_actor": request_actor
            })
class RFAIFundRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _rfai_request_repository = RequestDAO(_connection)
    _stake_dao_repository = StakeDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        event_data = self._get_event_data(event)

        request_id = event_data['requestId']
        staker = event_data['staker']
        amount = event_data['amount']
        [
            found, request_id, requester, total_fund, document_uri, expiration,
            end_submission, end_evaluation, status, stake_members, submitters
        ] = self._get_rfai_service_request_by_id(request_id)

        metadata_hash = self._get_metadata_hash(document_uri)
        rfai_metadata = eval(self._get_rfai_metadata_from_ipfs(metadata_hash))
        created_at = rfai_metadata['created']

        # from where we will get claim back amount

        self._stake_dao_repository.create_stake(
            request_id, staker, amount, 0, event["data"]["transactionHash"],
            created_at)
Exemple #6
0
class RFAIFundRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _request_dao = RequestDAO(_connection)
    _stake_dao = StakeDAO(_connection)
    _fund_request_trxn_dao = FundRequestTransactionDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        created_at_in_epoch = self._blockchain_util.get_created_at_for_block(
            block_no=event["data"]["block_no"]).get("timestamp", None)
        if created_at_in_epoch is not None:
            created_at = time.strftime('%Y-%m-%d %H:%M:%S',
                                       time.localtime(created_at_in_epoch))
        event_data = self._get_event_data(event)
        request_id = event_data['requestId']
        staker = event_data['staker']
        funded_amount = event_data['amount']
        [
            found, request_id, requester, total_fund, document_uri, expiration,
            end_submission, end_evaluation, status, stake_members, submitters
        ] = self._get_rfai_service_request_by_id(request_id)
        found, stake_amount = self._get_stake_by_id(request_id=request_id,
                                                    staker=staker)
        if not found:
            stake_amount = 0
        request_fund = self._request_dao.get_request_data_for_given_requester_and_status(
            filter_parameter={"request_id": request_id
                              })[0]["request_fund"] + funded_amount
        self._connection.begin_transaction()
        try:
            self._stake_dao.create_or_update_stake(
                request_id=request_id,
                stake_member=staker,
                stake_amount=0,
                claim_back_amount=stake_amount,
                created_at=created_at)
            self._stake_dao.add_stake_amount(request_id=request_id,
                                             stake_member=staker,
                                             stake_amount=funded_amount)

            self._fund_request_trxn_dao.persist_transaction(
                stake_member=requester,
                transaction_hash=event["data"]["transactionHash"],
                created_at=created_at)
            self._request_dao.update_request_for_given_request_id(
                request_id=request_id,
                update_parameters={
                    "request_fund": request_fund,
                    "fund_total": total_fund
                })
            self._connection.commit_transaction()
        except Exception as e:
            logger.info(
                f"Transaction Rollback for event {event}. Error::{repr(e)}")
            self._connection.rollback_transaction()
            raise e
class RFAIClaimBackRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _rfai_request_repository = RequestDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        event_data = self._get_event_data(event)
        request_id = event_data['requestId']
        [
            found, request_id, requester, total_fund, document_uri, expiration,
            end_submission, end_evaluation, status, stake_members, submitters
        ] = self._get_rfai_service_request_by_id(request_id)
        print("reached")
Exemple #8
0
class RFAIExtendRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _request_dao = RequestDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        # need to change this whenever we clean up it should nto be tied with db column name
        event_data = self._get_event_data(event)

        expiration = event_data['expiration']
        requester = event_data['requester']
        request_id = event_data['requestId']
        filter_params = {"expiration": expiration}
        self._request_dao.update_request_for_given_request_id(
            request_id, filter_params)
class RFAICreateRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _rfai_request_repository = RequestDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        event_data = self._get_event_data(event)
        request_id = event_data['requestId']
        requester = event_data['requester']
        expiration = event_data['expiration']
        amount = event_data['amount']
        metadata_hash = self._get_metadata_hash(event_data['documentURI'])

        self._process_create_request_event(request_id, requester, expiration,
                                           amount, metadata_hash)
        self._stake_dao_repository.create_stake(
            request_id, requester, amount, 0, event["data"]["transactionHash"],
            dt.utcnow())

    def _process_create_request_event(self, request_id, requester, expiration,
                                      amount, metadata_hash):
        [
            found, request_id, requester, total_fund, document_uri, expiration,
            end_submission, end_evaluation, status, stake_members, submitters
        ] = self._get_rfai_service_request_by_id(request_id)
        rfai_metadata = eval(self._get_rfai_metadata_from_ipfs(metadata_hash))

        title = rfai_metadata['title']
        requester_name = requester
        description = rfai_metadata['description']
        git_hub_link = ''
        training_data_set_uri = rfai_metadata['training-dataset']
        acceptance_criteria = rfai_metadata['acceptance-criteria']
        request_actor = ''
        created_at = rfai_metadata['created']

        self._rfai_request_repository.create_request(
            request_id, requester, total_fund, metadata_hash, expiration,
            end_submission, end_evaluation, status, title, requester_name,
            description, git_hub_link, training_data_set_uri,
            acceptance_criteria, request_actor, created_at)
Exemple #10
0
class RFAICreateRequestEventConsumer(RFAIEventConsumer):
    _connection = Repository(NETWORKS=NETWORK)
    _request_dao = RequestDAO(_connection)
    _stake_dao = StakeDAO(_connection)
    _fund_request_trxn_dao = FundRequestTransactionDAO(_connection)

    def __init__(self, net_id, ws_provider, ipfs_url, ipfs_port):
        super().__init__(net_id, ws_provider, ipfs_url, ipfs_port)

    def on_event(self, event):
        created_at_in_epoch = self._blockchain_util.get_created_at_for_block(
            block_no=event["data"]["block_no"]).get("timestamp", None)
        if created_at_in_epoch is not None:
            created_at = time.strftime('%Y-%m-%d %H:%M:%S',
                                       time.localtime(created_at_in_epoch))
        event_data = self._get_event_data(event)
        request_id = event_data['requestId']
        requester = event_data['requester']
        expiration = event_data['expiration']
        amount = event_data['amount']
        metadata_hash = self._get_metadata_hash(event_data['documentURI'])
        self._process_create_request_event(request_id, requester, expiration,
                                           amount, metadata_hash, created_at,
                                           event)

    def _process_create_request_event(self, request_id, requester, expiration,
                                      amount, metadata_hash, created_at,
                                      event):
        [
            found, request_id, requester, total_fund, document_uri, expiration,
            end_submission, end_evaluation, status, stake_members, submitters
        ] = self._get_rfai_service_request_by_id(request_id)
        rfai_metadata = eval(self._get_rfai_metadata_from_ipfs(metadata_hash))

        title = rfai_metadata['title']
        requester_name = requester
        description = rfai_metadata['description']
        git_hub_link = rfai_metadata['documentURI']
        training_data_set_uri = rfai_metadata['training-dataset']
        acceptance_criteria = rfai_metadata['acceptance-criteria']
        request_actor = ''

        self._connection.begin_transaction()
        try:
            self._request_dao.create_request(
                request_id=request_id,
                requester=requester,
                request_fund=amount,
                fund_total=total_fund,
                document_uri=metadata_hash,
                expiration=expiration,
                end_submission=end_submission,
                end_evaluation=end_evaluation,
                status=status,
                request_title=title,
                requester_name=requester_name,
                description=description,
                git_hub_link=git_hub_link,
                training_data_set_uri=training_data_set_uri,
                acceptance_criteria=acceptance_criteria,
                request_actor=request_actor,
                created_at=created_at)
            self._stake_dao.create_stake(request_id=request_id,
                                         stake_member=requester,
                                         stake_amount=amount,
                                         claim_back_amount=amount,
                                         created_at=created_at)
            self._fund_request_trxn_dao.persist_transaction(
                stake_member=requester,
                transaction_hash=event["data"]["transactionHash"],
                created_at=created_at)
            self._connection.commit_transaction()
        except Exception as e:
            logger.info(
                f"Transaction Rollback for event {event}. Error::{repr(e)}")
            self._connection.rollback_transaction()
            raise e