Skip to content

Commit e3bd7d1

Browse files
committed
Updates
1 parent 03d6f12 commit e3bd7d1

3 files changed

Lines changed: 27 additions & 45 deletions

File tree

api/relay.go

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ 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"
1514
cconfig "github.com/OpenAudio/go-openaudio/pkg/core/config"
1615
"github.com/OpenAudio/go-openaudio/pkg/core/server"
1716
eth_gen "github.com/OpenAudio/go-openaudio/pkg/eth/contracts/gen"
@@ -260,43 +259,37 @@ func (app *ApiServer) relay(c *fiber.Ctx) error {
260259
})
261260
}
262261

263-
const sosEndpoint = "https://sos.audius.co"
264-
265262
func (app *ApiServer) handleRelay(ctx context.Context, logger *zap.Logger, decodedTx *v1.ManageEntityLegacy) (*v1.Transaction, error) {
266-
req := &v1.SendTransactionRequest{
267-
Transaction: &v1.SignedTransaction{
268-
Transaction: &v1.SignedTransaction_ManageEntity{
269-
ManageEntity: decodedTx,
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+
},
270277
},
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
278+
}))
279+
280+
if err != nil {
281+
lastErr = err
282+
endpointLogger.Warn("transaction failed, trying next", zap.Error(err))
283+
continue
286284
}
287-
logger.Error("all mainnet endpoints failed")
288-
}()
289285

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
286+
msg := res.Msg.Transaction
287+
endpointLogger.Info("transaction confirmed", zap.String("hash", msg.GetHash()))
288+
return msg, nil
297289
}
298-
sosLogger.Info("sos dual-write confirmed", zap.String("hash", res.Msg.Transaction.GetHash()))
299-
return res.Msg.Transaction, nil
290+
291+
logger.Error("all OpenAudio endpoints failed", zap.Error(lastErr))
292+
return nil, fmt.Errorf("all endpoints failed, last error: %w", lastErr)
300293
}
301294

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

api/solana_wallet_middleware.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,3 @@ 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-
}

api/v1_fan_club_comments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (app *ApiServer) v1FanClubFeed(c *fiber.Ctx) error {
231231
}
232232

233233
myID := app.getMyId(c)
234-
solWallet := app.tryGetSolanaWallet(c)
234+
solWallet, _ := c.Context().Value(SolanaWalletCtxKey).(string)
235235

236236
revealText, err := app.viewerCanRevealFanClubText(c.Context(), artistUserID, mint, myID, solWallet)
237237
if err != nil {

0 commit comments

Comments
 (0)