Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/comms/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func getNewBlasts(tx dbv1.DBTX, ctx context.Context, arg getNewBlastsParams) ([]
OR from_user_id IN (
-- customer_audience
SELECT seller_user_id
FROM usdc_purchases p
FROM v_usdc_purchases p
WHERE blast.audience = 'customer_audience'
AND p.seller_user_id = blast.from_user_id
AND p.buyer_user_id = @user_id
Expand Down
12 changes: 2 additions & 10 deletions api/comms/chat_blast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,16 +773,8 @@ func TestChatBlastPurchasers(t *testing.T) {
"owner_id": 1,
},
},
"usdc_purchases": {
{
"buyer_user_id": 203,
"seller_user_id": 1,
"content_type": "track",
"content_id": 1,
"amount": 5990000, // 5.99USDC in micro-units
"signature": "purchase_sig_123",
"slot": 101,
},
"sol_purchases": {
{"signature": "purchase_sig_123", "instruction_index": 0, "buyer_user_id": 203, "content_type": "track", "content_id": 1, "amount": 5990000, "slot": 101, "is_valid": true},
},
})

Expand Down
2 changes: 1 addition & 1 deletion api/comms/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func hasNewBlastFromUser(pool *dbv1.DBPools, ctx context.Context, userID int32,
-- customer_audience
(blast.audience = 'customer_audience' and exists (
SELECT 1
FROM usdc_purchases p
FROM v_usdc_purchases p
WHERE p.seller_user_id = blast.from_user_id
AND p.buyer_user_id = $1
AND (
Expand Down
2 changes: 1 addition & 1 deletion api/comms_blasts.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (app *ApiServer) getNewBlasts(c *fiber.Ctx) error {
OR from_user_id IN (
-- customer_audience
SELECT seller_user_id
FROM usdc_purchases p
FROM v_usdc_purchases p
WHERE blast.audience = 'customer_audience'
AND p.seller_user_id = blast.from_user_id
AND p.buyer_user_id = @user_id
Expand Down
48 changes: 6 additions & 42 deletions api/comms_blasts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,37 +97,10 @@ func TestGetNewBlasts(t *testing.T) {
"child_track_id": 2,
},
},
"usdc_purchases": {
{
"buyer_user_id": 2,
"seller_user_id": 1,
"content_type": "track",
"content_id": 1,
"amount": 1000000, // 1 USDC in micro-units
"created_at": now.Add(-time.Hour * 2), // Purchase before blast
"signature": "purchase_sig_123",
"slot": 101,
},
{
"buyer_user_id": 2,
"seller_user_id": 1,
"content_type": "track",
"content_id": 2,
"amount": 2000000, // 2 USDC in micro-units
"created_at": now.Add(-time.Hour * 2), // Purchase before blast
"signature": "purchase_sig_456",
"slot": 102,
},
{
"buyer_user_id": 3,
"seller_user_id": 1,
"content_type": "track",
"content_id": 1, // User 3 only bought track 1, not track 2
"amount": 500000, // 0.5 USDC in micro-units
"created_at": now.Add(-time.Hour * 2), // Purchase before blast
"signature": "purchase_sig_789",
"slot": 103,
},
"sol_purchases": {
{"signature": "purchase_sig_123", "instruction_index": 0, "buyer_user_id": 2, "content_type": "track", "content_id": 1, "amount": 1000000, "created_at": now.Add(-time.Hour * 2), "slot": 101, "is_valid": true},
{"signature": "purchase_sig_456", "instruction_index": 0, "buyer_user_id": 2, "content_type": "track", "content_id": 2, "amount": 2000000, "created_at": now.Add(-time.Hour * 2), "slot": 102, "is_valid": true},
{"signature": "purchase_sig_789", "instruction_index": 0, "buyer_user_id": 3, "content_type": "track", "content_id": 1, "amount": 500000, "created_at": now.Add(-time.Hour * 2), "slot": 103, "is_valid": true},
},
"artist_coins": {
{
Expand Down Expand Up @@ -665,17 +638,8 @@ func TestGetNewBlastsAudienceSpecificFiltering(t *testing.T) {
"updated_at": now.Add(-time.Hour),
},
},
"usdc_purchases": {
{
"buyer_user_id": 2,
"seller_user_id": 1,
"content_type": "track",
"content_id": 1, // User only bought track 1
"amount": 1000000,
"created_at": now.Add(-time.Hour),
"signature": "purchase_sig_123",
"slot": 101,
},
"sol_purchases": {
{"signature": "purchase_sig_123", "instruction_index": 0, "buyer_user_id": 2, "content_type": "track", "content_id": 1, "amount": 1000000, "created_at": now.Add(-time.Hour), "slot": 101, "is_valid": true},
},
"chat_blast": {
{
Expand Down
8 changes: 4 additions & 4 deletions api/dbv1/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (q *Queries) GetPlaylistAccess(
err := q.db.QueryRow(ctx, `
SELECT EXISTS (
SELECT 1
FROM usdc_purchases
FROM v_usdc_purchases
WHERE buyer_user_id = $1
AND content_id = $2
AND content_type = 'album'
Expand Down Expand Up @@ -261,7 +261,7 @@ func (q *Queries) GetBulkTrackAccess(
g.Go(func() error {
rows, err := q.db.Query(ctx, `
SELECT content_id
FROM usdc_purchases
FROM v_usdc_purchases
WHERE buyer_user_id = $1
AND content_id = ANY($2)
AND content_type = 'track'
Expand Down Expand Up @@ -357,7 +357,7 @@ func (q *Queries) GetBulkTrackAccess(
g.Go(func() error {
rows, err := q.db.Query(ctx, `
SELECT content_id
FROM usdc_purchases
FROM v_usdc_purchases
WHERE buyer_user_id = $1
AND content_id = ANY($2)
AND content_type = 'album'
Expand Down Expand Up @@ -390,7 +390,7 @@ func (q *Queries) GetBulkTrackAccess(
g.Go(func() error {
rows, err := q.db.Query(ctx, `
SELECT up.content_id
FROM usdc_purchases up
FROM v_usdc_purchases up
JOIN jsonb_each_text($2) AS prev_playlists(playlist_id, removal_time)
ON up.content_id = prev_playlists.playlist_id::integer
WHERE up.buyer_user_id = $1
Expand Down
3 changes: 2 additions & 1 deletion api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func testAppWithFixtures(t *testing.T) *ApiServer {
database.SeedTable(app.pool.Replicas[0], "track_trending_scores", testdata.TrackTrendingScoresFixtures)
database.SeedTable(app.pool.Replicas[0], "trending_results", testdata.TrendingResultsFixtures)
database.SeedTable(app.pool.Replicas[0], "track_routes", testdata.TrackRoutesFixtures)
database.SeedTable(app.pool.Replicas[0], "usdc_purchases", testdata.UsdcPurchasesFixtures)
database.SeedTable(app.pool.Replicas[0], "sol_purchases", testdata.SolPurchasesFixtures)
database.SeedTable(app.pool.Replicas[0], "sol_payments", testdata.SolPaymentsFixtures)
database.SeedTable(app.pool.Replicas[0], "usdc_transactions_history", testdata.UsdcTransactionsHistoryFixtures)
database.SeedTable(app.pool.Replicas[0], "user_bank_accounts", testdata.UserBankAccountsFixtures)
database.SeedTable(app.pool.Replicas[0], "user_challenges", testdata.UserChallengesFixtures)
Expand Down
54 changes: 22 additions & 32 deletions api/testdata/usdc_purchases_fixtures.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
package testdata

var UsdcPurchasesFixtures = []map[string]any{
// SolPurchasesFixtures + SolPaymentsFixtures populate the new tables backing
// v_usdc_purchases. Maintained alongside the legacy UsdcPurchasesFixtures
// during the purchases-cutover transition.
var SolPurchasesFixtures = []map[string]any{
{
"signature": "a",
"buyer_user_id": 11,
"seller_user_id": 3,
"content_id": 303,
"content_type": "track",
"amount": 135,
"splits": []map[string]any{
{
"amount": 135000000,
"user_id": 3,
"eth_wallet": "0x123",
"percentage": 100,
},
},
"signature": "a",
"instruction_index": 0,
"buyer_user_id": 11,
"content_id": 303,
"content_type": "track",
"amount": 135,
"is_valid": true,
},
{
"signature": "b",
"buyer_user_id": 11,
"seller_user_id": 3,
"content_id": 4,
"content_type": "album",
"amount": 135,
"splits": []map[string]any{
{
"amount": 135000000,
"user_id": 3,
"eth_wallet": "0x123",
"percentage": 100,
},
},
"signature": "b",
"instruction_index": 0,
"buyer_user_id": 11,
"content_id": 4,
"content_type": "album",
"amount": 135,
"is_valid": true,
},
}

// signature,buyer_user_id,seller_user_id,content_id,content_type,amount,splits
// a,11,3,303,track,135,"[{""amount"": 135000000, ""user_id"": 3, ""eth_wallet"": ""0x123"", ""percentage"": 100}]"
// b,11,3,4,album,135,"[{""amount"": 135000000, ""user_id"": 3, ""eth_wallet"": ""0x123"", ""percentage"": 100}]"
var SolPaymentsFixtures = []map[string]any{
{"signature": "a", "instruction_index": 0, "route_index": 0, "to_account": "0x123", "amount": 135000000, "slot": 101},
{"signature": "b", "instruction_index": 0, "route_index": 0, "to_account": "0x123", "amount": 135000000, "slot": 101},
}
2 changes: 1 addition & 1 deletion api/v1_explore_best_selling.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (app *ApiServer) v1ExploreBestSelling(c *fiber.Ctx) error {
sql := `
WITH ranked_sales AS (
SELECT content_id, content_type, COUNT(*) AS sales_count
FROM usdc_purchases
FROM v_usdc_purchases
WHERE ` + strings.Join(filters, " AND ") + `
GROUP BY content_id, content_type
),
Expand Down
Loading
Loading