예제 #1
0
    def issue_bounty(self, bounty_id, inputs, event_timestamp):
        data_hash = inputs.get('data', 'invalid')
        event_date = datetime.datetime.fromtimestamp(int(event_timestamp))
        ipfs_data = map_bounty_data(data_hash, bounty_id)
        token_data = map_token_data(inputs.get('paysTokens'),
                                    inputs.get('tokenContract'),
                                    inputs.get('fulfillmentAmount'))

        plucked_inputs = {
            key: inputs.get(key)
            for key in issue_bounty_input_keys
        }

        bounty_data = {
            'id': bounty_id,
            'bounty_id': bounty_id,
            'issuer': inputs.get('issuer', '').lower(),
            'deadline': getDateTimeFromTimestamp(inputs.get('deadline', None)),
            'bountyStage': DRAFT_STAGE,
            'bounty_created': event_date,
        }

        bounty_serializer = BountySerializer(data={
            **bounty_data,
            **plucked_inputs,
            **ipfs_data,
            **token_data
        })
        bounty_serializer.is_valid(raise_exception=True)
        saved_bounty = bounty_serializer.save()
        saved_bounty.save_and_clear_categories(
            ipfs_data.get('data_categories'))
        saved_bounty.record_bounty_state(event_date)
        return saved_bounty
예제 #2
0
    def change_data(self, bounty, **kwargs):
        updated_data = {}

        updated_data = map_bounty_data(kwargs.get('data'), bounty.bounty_id)

        bounty_serializer = BountySerializer(bounty,
                                             data=updated_data,
                                             partial=True)
        bounty_serializer.is_valid(raise_exception=True)
        saved_bounty = bounty_serializer.save()

        saved_bounty.save_and_clear_categories(
            updated_data.get('data_categories'))

        return saved_bounty
예제 #3
0
    def change_data(self, bounty, **kwargs):
        updated_data = {}

        updated_data = map_bounty_data(kwargs.get('data'), bounty.bounty_id,
                                       bounty.contract_version)

        bounty_serializer = BountySerializer(bounty,
                                             data=updated_data,
                                             partial=True)
        bounty_serializer.is_valid(raise_exception=True)
        saved_bounty = bounty_serializer.save()
        saved_bounty.save_and_clear_categories(
            updated_data.get('data_categories'))

        saved_bounty.usd_price = get_token_pricing(
            saved_bounty.token_symbol, saved_bounty.token_decimals,
            saved_bounty.fulfillment_amount)[0]
        saved_bounty.save()

        return saved_bounty
예제 #4
0
    def change_bounty(self, bounty, inputs, **kwargs):
        updated_data = {}
        data_hash = inputs.get('newData', None) or inputs.get('data', None)
        deadline = inputs.get('newDeadline', None)
        fulfillmentAmount = inputs.get('newFulfillmentAmount', None)
        arbiter = inputs.get('newArbiter', None)

        if data_hash:
            updated_data = map_bounty_data(data_hash, bounty.bounty_id)

        if deadline:
            updated_data['deadline'] = datetime.datetime.fromtimestamp(
                int(deadline))

        if fulfillmentAmount:
            updated_data['fulfillmentAmount'] = Decimal(fulfillmentAmount)

        if arbiter:
            updated_data['arbiter'] = arbiter

        bounty_serializer = BountySerializer(bounty,
                                             data=updated_data,
                                             partial=True)
        bounty_serializer.is_valid(raise_exception=True)
        saved_bounty = bounty_serializer.save()

        if data_hash:
            saved_bounty.save_and_clear_categories(
                updated_data.get('data_categories'))

        if fulfillmentAmount:
            usd_price = get_token_pricing(saved_bounty.tokenSymbol,
                                          saved_bounty.tokenDecimals,
                                          fulfillmentAmount)[0]
            saved_bounty.usd_price = usd_price
            saved_bounty.save()

        return saved_bounty
예제 #5
0
    def issue_bounty(self, bounty_id, contract_version, **kwargs):
        event_date = datetime.datetime.fromtimestamp(
            int(kwargs.get('event_timestamp')))

        ipfs_data = map_bounty_data(kwargs.get('data', ''), bounty_id)
        token_data = map_token_data(kwargs.get('token_version'),
                                    kwargs.get('token'), 0)

        # TODO what happens if issuers or approvers is actually blank?
        contract_state = {'issuers': {}, 'approvers': {}}
        issuers = []
        for index, issuer in enumerate(kwargs.get('issuers', [])):
            user = User.objects.get_or_create(public_address=issuer.lower())[0]
            issuers.append(user.pk)
            contract_state['issuers'].update({issuer.lower(): index})

        approvers = []
        for index, approver in enumerate(kwargs.get('approvers', [])):
            user = User.objects.get_or_create(
                public_address=approver.lower())[0]
            approvers.append(user.pk)
            contract_state['approvers'].update({approver.lower(): index})

        bounty_data = {
            'bounty_id': bounty_id,
            'contract_version': contract_version,

            # legacy for stb 1.0
            'user': issuers[0],
            'issuer': kwargs.get('issuers')[0].lower(),
            ###
            'issuers': issuers,
            'approvers': approvers,
            'contract_state': json.dumps(contract_state),
            'deadline': getDateTimeFromTimestamp(kwargs.get('deadline', None)),
            'bounty_stage': DEAD_STAGE,
            'bounty_created': event_date,
        }
        print('contract version')
        print(contract_version)
        print('fulfillment amount')
        print(ipfs_data.get('fulfillmentAmount'))

        if contract_version == STANDARD_BOUNTIES_V1:
            bounty_data.update(
                {'fulfillment_amount': kwargs.get('fulfillment_amount')})
        else:
            bounty_data.update(
                {'fulfillment_amount': ipfs_data.get('fulfillmentAmount')})

        bounty_serializer = BountySerializer(data={
            **bounty_data,
            **ipfs_data,
            **token_data
        })

        bounty_serializer.is_valid(raise_exception=True)

        saved_bounty = bounty_serializer.save()
        saved_bounty.save_and_clear_categories(
            ipfs_data.get('data_categories'))
        saved_bounty.bounty_stage = ACTIVE_STAGE
        saved_bounty.record_bounty_state(event_date)

        uid = saved_bounty.uid

        if uid:
            DraftBounty.objects.filter(uid=uid).update(on_chain=True)

        return saved_bounty