Skip to content

Commit 3805f1e

Browse files
committed
Add coin-gated text posts
1 parent bff2ecc commit 3805f1e

9 files changed

Lines changed: 870 additions & 52 deletions

api/dbv1/access.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (q *Queries) GetBulkTrackAccess(
323323
var mint string
324324
var balance int64
325325
if err := rows.Scan(&mint, &balance); err == nil {
326-
walletTokenBalances[mint] = balance
326+
walletTokenBalances[mint] += balance
327327
}
328328
}
329329
return rows.Err()

api/dbv1/full_comments.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type FullComment struct {
4040
Replies []FullComment `json:"replies"`
4141
ParentCommentId pgtype.Int4 `json:"parent_comment_id"`
4242

43-
// this should be omitted
4443
ReplyIds []int32 `db:"reply_ids" json:"-"`
4544
}
4645

@@ -51,12 +50,12 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
5150

5251
sql := `
5352
SELECT
54-
comment_id as id,
55-
parent_comment_id,
56-
entity_type,
57-
entity_id,
58-
user_id,
59-
text as message,
53+
comments.comment_id AS id,
54+
comment_threads.parent_comment_id,
55+
comments.entity_type,
56+
comments.entity_id,
57+
comments.user_id,
58+
comments.text AS message,
6059
6160
(
6261
SELECT json_agg(
@@ -72,7 +71,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
7271
) m
7372
)::jsonb as mentions,
7473
75-
track_timestamp_s,
74+
comments.track_timestamp_s,
7675
7776
(
7877
SELECT count(*)
@@ -90,7 +89,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
9089
AND cc.is_delete = false
9190
) as reply_ids,
9291
93-
is_edited,
92+
comments.is_edited,
9493
9594
EXISTS (
9695
SELECT 1
@@ -104,7 +103,7 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
104103
SELECT 1
105104
FROM comment_reactions
106105
WHERE comment_id = comments.comment_id
107-
AND user_id = tracks.owner_id
106+
AND user_id = COALESCE(tracks.owner_id, comments.entity_id)
108107
AND is_delete = false
109108
) AS is_artist_reacted,
110109
@@ -115,19 +114,22 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
115114
FROM comment_notification_settings mutes
116115
WHERE @my_id > 0
117116
AND mutes.user_id = @my_id
118-
AND mutes.entity_type = entity_type
119-
AND mutes.entity_id = entity_id
117+
AND mutes.entity_type = comments.entity_type
118+
AND mutes.entity_id = comments.entity_id
120119
LIMIT 1
121120
), false) as is_muted,
122121
123122
comments.created_at,
124123
comments.updated_at
125124
126125
FROM comments
127-
JOIN tracks ON entity_id = track_id
126+
LEFT JOIN tracks ON comments.entity_type = 'Track' AND comments.entity_id = tracks.track_id
128127
LEFT JOIN comment_threads USING (comment_id)
129-
WHERE comment_id = ANY(@ids::int[])
130-
AND (@include_unlisted = true OR tracks.is_unlisted = false)
128+
WHERE comments.comment_id = ANY(@ids::int[])
129+
AND (
130+
(comments.entity_type = 'Track' AND (@include_unlisted = true OR COALESCE(tracks.is_unlisted, false) = false))
131+
OR comments.entity_type = 'Coin'
132+
)
131133
ORDER BY comments.created_at DESC
132134
`
133135

@@ -150,7 +152,6 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
150152
commentMap[int32(comment.Id)] = comment
151153
}
152154

153-
// fetch replies
154155
replyIds := []int32{}
155156
for _, comment := range comments {
156157
replyIds = append(replyIds, comment.ReplyIds...)
@@ -170,7 +171,6 @@ func (q *Queries) FullCommentsKeyed(ctx context.Context, arg GetCommentsParams)
170171
comment.Replies = append(comment.Replies, reply)
171172
}
172173
}
173-
// todo: sort replies?
174174
comment.ReplyCount = len(comment.Replies)
175175

176176
if comment.IsDelete {

api/dbv1/parallel.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
)
88

99
type ParallelParams struct {
10-
UserIds []int32
11-
TrackIds []int32
12-
PlaylistIds []int32
13-
MyID int32
14-
AuthedWallet string
10+
UserIds []int32
11+
TrackIds []int32
12+
PlaylistIds []int32
13+
MyID int32
14+
AuthedWallet string
1515
}
1616

1717
type ParallelResult struct {

api/relay.go

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"api.audius.co/trashid"
1212
"connectrpc.com/connect"
1313
v1 "github.com/OpenAudio/go-openaudio/pkg/api/core/v1"
14+
"github.com/OpenAudio/go-openaudio/pkg/sdk"
1415
cconfig "github.com/OpenAudio/go-openaudio/pkg/core/config"
1516
"github.com/OpenAudio/go-openaudio/pkg/core/server"
1617
eth_gen "github.com/OpenAudio/go-openaudio/pkg/eth/contracts/gen"
@@ -259,37 +260,43 @@ func (app *ApiServer) relay(c *fiber.Ctx) error {
259260
})
260261
}
261262

263+
const sosEndpoint = "https://sos.audius.co"
264+
262265
func (app *ApiServer) handleRelay(ctx context.Context, logger *zap.Logger, decodedTx *v1.ManageEntityLegacy) (*v1.Transaction, error) {
263-
allClients := app.openAudioPool.GetAll()
264-
if len(allClients) == 0 {
265-
logger.Error("no OpenAudio clients configured")
266-
return nil, fmt.Errorf("no OpenAudio clients configured")
267-
}
268-
269-
var lastErr error
270-
for i, clientInfo := range allClients {
271-
endpointLogger := logger.With(zap.String("openaudio_endpoint", clientInfo.Endpoint), zap.Int("attempt", i+1))
272-
res, err := clientInfo.Client.Core.SendTransaction(ctx, connect.NewRequest(&v1.SendTransactionRequest{
273-
Transaction: &v1.SignedTransaction{
274-
Transaction: &v1.SignedTransaction_ManageEntity{
275-
ManageEntity: decodedTx,
276-
},
266+
req := &v1.SendTransactionRequest{
267+
Transaction: &v1.SignedTransaction{
268+
Transaction: &v1.SignedTransaction_ManageEntity{
269+
ManageEntity: decodedTx,
277270
},
278-
}))
279-
280-
if err != nil {
281-
lastErr = err
282-
endpointLogger.Warn("transaction failed, trying next", zap.Error(err))
283-
continue
271+
},
272+
}
273+
274+
// mainnet
275+
go func() {
276+
allClients := app.openAudioPool.GetAll()
277+
for i, clientInfo := range allClients {
278+
endpointLogger := logger.With(zap.String("openaudio_endpoint", clientInfo.Endpoint), zap.Int("attempt", i+1))
279+
res, err := clientInfo.Client.Core.SendTransaction(context.Background(), connect.NewRequest(req))
280+
if err != nil {
281+
endpointLogger.Warn("transaction failed, trying next", zap.Error(err))
282+
continue
283+
}
284+
endpointLogger.Info("transaction confirmed", zap.String("hash", res.Msg.Transaction.GetHash()))
285+
return
284286
}
287+
logger.Error("all mainnet endpoints failed")
288+
}()
285289

286-
msg := res.Msg.Transaction
287-
endpointLogger.Info("transaction confirmed", zap.String("hash", msg.GetHash()))
288-
return msg, nil
290+
// sos
291+
sosClient := sdk.NewOpenAudioSDK(sosEndpoint)
292+
sosLogger := logger.With(zap.String("openaudio_endpoint", sosEndpoint))
293+
res, err := sosClient.Core.SendTransaction(ctx, connect.NewRequest(req))
294+
if err != nil {
295+
sosLogger.Warn("sos dual-write failed", zap.Error(err))
296+
return nil, err
289297
}
290-
291-
logger.Error("all OpenAudio endpoints failed", zap.Error(lastErr))
292-
return nil, fmt.Errorf("all endpoints failed, last error: %w", lastErr)
298+
sosLogger.Info("sos dual-write confirmed", zap.String("hash", res.Msg.Transaction.GetHash()))
299+
return res.Msg.Transaction, nil
293300
}
294301

295302
func transactionToReceipt(tx *v1.Transaction, wallet string) map[string]interface{} {

api/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ func NewApiServer(config config.Config) *ApiServer {
507507
g.Post("/tracks/:trackId/downloads", app.requireAuthMiddleware, app.requireWriteScope, app.postV1TrackDownload)
508508
g.Put("/tracks/:trackId", app.requireAuthMiddleware, app.requireWriteScope, app.putV1Track)
509509
g.Delete("/tracks/:trackId", app.requireAuthMiddleware, app.requireWriteScope, app.deleteV1Track)
510+
g.Get("/fan_club/feed", app.v1FanClubFeed)
511+
510512
g.Get("/tracks/:trackId/comments", app.v1TrackComments)
511513
g.Get("/tracks/:trackId/comment_count", app.v1TrackCommentCount)
512514
g.Get("/tracks/:trackId/comment-count", app.v1TrackCommentCount)

api/solana_wallet_middleware.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,14 @@ func (app *ApiServer) solanaWalletMiddleware(c *fiber.Ctx) error {
5252
c.Locals(SolanaWalletCtxKey, wallet)
5353
return c.Next()
5454
}
55+
56+
// tryGetSolanaWallet returns the verified wallet from the request context, or "".
57+
func (app *ApiServer) tryGetSolanaWallet(c *fiber.Ctx) string {
58+
if c == nil {
59+
return ""
60+
}
61+
if w, ok := c.UserContext().Value(SolanaWalletCtxKey).(string); ok {
62+
return w
63+
}
64+
return ""
65+
}

0 commit comments

Comments
 (0)