-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Milestone
Description
From AIP61 Main issue:
validator: sentry: will have an authenticated POST to modify/submit campaigns
- check if
campaign.budget >= campaignSpent
; update a key in Redis for the remaining spendable amount- get the last approved NewState from the DB and set
totalSpent = lastApprovedNewState.spenders[user]
- set
totalDeposited
to total from the Spendable DB entry for this(channelId, spender)
- make sure
sum(campaigns.map(getRemaining)) <= totalDeposited - totalSpent
when updating campaigns; by doing that we ensure that advertisers can't spend more than they have- please note that we can't assume
totalSpent
equals the sum of all campaign spendings, because a spending can occur outside of campaign (cases like v4 CLOSE or PAY); so we must always compare remaining funds based ontotalDeposited - lastApprovedNewState.spenders[user]
- to close a campaign, just set it's budget to what it's spent so far (so that
remaining == 0
)
### To-Dos:
Logic:
- Retrieve
campaignSpent
from Redis - Check if we have reached the budget
- Calculate the remaining spendable amount for the campaign and update it on Redis
- Retrieve the latest new state
- Retrieve the latest Spendable entry from the DB
- Calculate the total remaining amount for the channel
-
??? Does the totalRemaining need to be stored in Redis?no - Compare the remaining amount for all campaigns on this channel with totalDeposited - totalSpent and update the campaign on Postgres
API:
- Create an authenticated POST route for modifying campaigns
/campaign/{id}/
- Create a middleware for checking if a campaign with this ID exists in Postgres
- Track changes in budget, possibly with a struct that includes all of the editable fields.
- Create an authenticated POST route for creating campaigns `/campaign/
- Deserialize CreateCampaign struct from the request
- Check if there is enough remaining deposit (through spendable) for the campaign budget
- Return a campaign with a randomly generated ID and insert it to Postgres
Testing:
- Refactor business logic to make it easily testable
- Additional test cases for creating & modifying campaign
- Test Postgres update functions
- Test
sentry::routes::campaign::update_campaign::get_delta_budget
Additional Tasks:
- Implement pagination for
get_campaigns_by_channel(...)
- Very important - when modifying a Campaign make sure to Authenticate the caller AND validate that he can perform the modification (
AuthRequired
& check if Auth.uid = campaign.creator - could be middleware as well) - Update Spendable entry as stated in AIP 61
we'll also update the document from the adapter before a user tries to mutate (add/update) campaigns
- Campaign creation was updated in Channel v5 table #432
- Campaign modification Issue #409 update spendable on modify campaign #434
Metadata
Metadata
Assignees
Labels
No labels