def increase_payout(self, bounty_id, inputs): bounty = Bounty.objects.get(bounty_id=bounty_id) value = inputs.get('value') fulfillment_amount = inputs.get('newFulfillmentAmount') if value: bounty.balance = bounty.balance + Decimal(value) usd_price = get_token_pricing(bounty.tokenSymbol, bounty.tokenDecimals, fulfillment_amount)[0] bounty.fulfillmentAmount = Decimal(fulfillment_amount) bounty.usd_price = usd_price bounty.save()
def test_get_token_pricing_for_nonexistent_token(self): token_symbol = 'NEX' token_decimals = 5 value = 100 expected_token_model = None expected_usd_price = 0 usd_price, token_model = get_token_pricing(token_symbol, token_decimals, value) self.assertEqual(token_model, expected_token_model) self.assertEqual(usd_price, expected_usd_price)
def increase_payout(self, bounty, inputs, **kwargs): value = inputs.get('value') fulfillment_amount = inputs.get('newFulfillmentAmount') if value: bounty.balance = bounty.balance + Decimal(value) usd_price = get_token_pricing(bounty.tokenSymbol, bounty.tokenDecimals, fulfillment_amount)[0] bounty.fulfillmentAmount = Decimal(fulfillment_amount) bounty.usd_price = usd_price bounty.save() return bounty
def increase_payout(self, bounty, **kwargs): fulfillment_amount = kwargs.get('fulfillment_amount') usd_price = get_token_pricing(bounty.token_symbol, bounty.token_decimals, fulfillment_amount)[0] bounty.fulfillment_amount = Decimal(fulfillment_amount) bounty.usd_price = usd_price bounty.save() return bounty
def change_bounty(self, bounty, **kwargs): bounty = self.change_data(bounty, **kwargs) bounty = self.change_deadline(bounty, **kwargs) bounty = self.update_bounty_issuers(bounty, **kwargs) bounty = self.update_bounty_approvers(bounty, **kwargs) usd_price = get_token_pricing(bounty.token_symbol, bounty.token_decimals, bounty.fulfillment_amount)[0] bounty.usd_price = usd_price return bounty
def add_contribution(self, bounty, inputs, event_timestamp, **kwargs): event_date = datetime.datetime.fromtimestamp(int(event_timestamp)) bounty.balance = Decimal(bounty.balance) + Decimal(inputs.get('value')) if bounty.balance >= bounty.fulfillmentAmount and bounty.bountyStage == EXPIRED_STAGE: bounty.bountyStage = ACTIVE_STAGE bounty.record_bounty_state(event_date) if bounty.balance >= bounty.fulfillmentAmount and bounty.bountyStage == COMPLETED_STAGE: bounty.bountyStage = ACTIVE_STAGE bounty.record_bounty_state(event_date) usd_price = get_token_pricing(bounty.tokenSymbol, bounty.tokenDecimals, bounty.fulfillmentAmount)[0] bounty.usd_price = usd_price bounty.save() return bounty
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
def add_contribution(self, bounty, **kwargs): event_date = datetime.datetime.fromtimestamp( int(kwargs.get('event_timestamp'))) bounty.balance = Decimal(bounty.balance) + Decimal( kwargs.get('value', kwargs.get('amount'))) # not sure about this ... what if the bounty expired because the deadline passed? if bounty.balance >= bounty.fulfillment_amount and bounty.bounty_stage == EXPIRED_STAGE: bounty.bounty_stage = ACTIVE_STAGE bounty.record_bounty_state(event_date) if bounty.balance >= bounty.fulfillment_amount and ( bounty.bounty_stage == COMPLETED_STAGE or bounty.bounty_stage == DEAD_STAGE): bounty.bounty_stage = ACTIVE_STAGE bounty.record_bounty_state(event_date) bounty.usd_price = get_token_pricing(bounty.token_symbol, bounty.token_decimals, bounty.fulfillment_amount)[0] bounty.save() contribution_serializer = ContributionSerializer( data={ 'contributor': User.objects.get_or_create( public_address=kwargs.get('contributor').lower())[0].pk, 'bounty': bounty.pk, 'contribution_id': kwargs.get('contribution_id'), 'amount': kwargs.get('amount'), # 'raw_event_data': json.dumps(kwargs), }) contribution_serializer.is_valid(raise_exception=True) contribution = contribution_serializer.save() return contribution
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