Skip to content
Merged
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
27 changes: 27 additions & 0 deletions api/dbv1/full_connected_wallets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dbv1

import "context"

type FullConnectedWallets struct {
ErcWallets []string `json:"erc_wallets"`
SplWallets []string `json:"spl_wallets"`
}

func (q *Queries) FullConnectedWallets(ctx context.Context, userId int32) (*FullConnectedWallets, error) {
rows, err := q.GetUserConnectedWallets(ctx, userId)
if err != nil {
return nil, err
}

fullConnectedWallets := FullConnectedWallets{}
for _, row := range rows {
if row.Chain == WalletChainEth {
fullConnectedWallets.ErcWallets = append(fullConnectedWallets.ErcWallets, row.Wallet)
}
if row.Chain == WalletChainSol {
fullConnectedWallets.SplWallets = append(fullConnectedWallets.SplWallets, row.Wallet)
}
}

return &fullConnectedWallets, nil
}
43 changes: 43 additions & 0 deletions api/dbv1/get_connected_wallets.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/dbv1/queries/get_connected_wallets.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- name: GetUserConnectedWallets :many
SELECT chain, wallet
FROM associated_wallets
WHERE is_current = true
AND is_delete = false
AND user_id = @user_id;
11 changes: 11 additions & 0 deletions api/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ var (
"updated_at": time.Now(),
"image_url": nil,
}

connectedWalletsBaseRow = map[string]any{
"id": nil,
"user_id": nil,
"wallet": nil,
"blockhash": "block_abc123",
"blocknumber": 101,
"is_current": true,
"is_delete": false,
"chain": nil,
}
)

func insertFixtures(table string, baseRow map[string]any, csvFile string) {
Expand Down
1 change: 1 addition & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func NewApiServer(config Config) *ApiServer {
g.Get("/users/:userId/supporting", app.v1UsersSupporting)
g.Get("/users/:userId/tracks", app.v1UserTracks)
g.Get("/users/:userId/feed", app.v1UsersFeed)
g.Get("/users/:userId/connected_wallets", app.v1UsersConnectedWallets)

// Tracks
g.Get("/tracks", app.v1Tracks)
Expand Down
1 change: 1 addition & 0 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestMain(m *testing.M) {
insertFixtures("follows", followBaseRow, "testdata/follow_fixtures.csv")
insertFixtures("reposts", repostBaseRow, "testdata/repost_fixtures.csv")
insertFixtures("developer_apps", developerAppBaseRow, "testdata/developer_app_fixtures.csv")
insertFixtures("associated_wallets", connectedWalletsBaseRow, "testdata/connected_wallets_fixtures.csv")

// index to es / os

Expand Down
10 changes: 10 additions & 0 deletions api/testdata/connected_wallets_fixtures.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"id","user_id","wallet","blockhash","blocknumber","is_current","is_delete","chain"
2338,1,"sol11111111111111111111111111111111111111111","",101,TRUE,FALSE,"sol"
2344,1,"sol22222222222222222222222222222222222222222","",101,TRUE,FALSE,"sol"
2339,2,"sol33333333333333333333333333333333333333333","",101,TRUE,TRUE,"sol"
2476,2,"0x1111111111111111111111111111111111111111","",101,TRUE,FALSE,"eth"
2475,2,"0x2222222222222222222222222222222222222222","",101,TRUE,FALSE,"eth"
2487,2,"0x3333333333333333333333333333333333333333","",101,TRUE,TRUE,"eth"
2483,2,"sol44444444444444444444444444444444444444444","",101,TRUE,FALSE,"sol"
2484,2,"sol55555555555555555555555555555555555555555","",101,TRUE,FALSE,"sol"
2485,3,"0x4444444444444444444444444444444444444444","",101,TRUE,FALSE,"eth"
18 changes: 18 additions & 0 deletions api/v1_users_connected_wallets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package api

import (
"github.com/gofiber/fiber/v2"
)

func (app *ApiServer) v1UsersConnectedWallets(c *fiber.Ctx) error {
userId := c.Locals("userId").(int)

wallets, err := app.queries.FullConnectedWallets(c.Context(), int32(userId))
if err != nil {
return err
}

return c.JSON(fiber.Map{
"data": wallets,
})
}
29 changes: 29 additions & 0 deletions api/v1_users_connected_wallets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package api

import (
"strings"
"testing"

"bridgerton.audius.co/trashid"
"github.com/stretchr/testify/assert"
)

func TestGetUserConnectedWalletsQuery(t *testing.T) {
connectedWallets, err := app.queries.FullConnectedWallets(t.Context(), 2)
assert.NoError(t, err)
assert.Len(t, connectedWallets.ErcWallets, 2)
assert.Len(t, connectedWallets.SplWallets, 2)
assert.Contains(t, connectedWallets.ErcWallets, "0x1111111111111111111111111111111111111111")
assert.Contains(t, connectedWallets.ErcWallets, "0x2222222222222222222222222222222222222222")
assert.NotContains(t, connectedWallets.ErcWallets, "0x3333333333333333333333333333333333333333")
assert.NotContains(t, connectedWallets.SplWallets, "sol33333333333333333333333333333333333333333")
assert.Contains(t, connectedWallets.SplWallets, "sol44444444444444444444444444444444444444444")
assert.Contains(t, connectedWallets.SplWallets, "sol55555555555555555555555555555555555555555")
}

func TestGetUserConnectedWallets(t *testing.T) {
status, body := testGet(t, "/v1/users/"+trashid.MustEncodeHashID(2)+"/connected_wallets")
assert.Equal(t, 200, status)
assert.True(t, strings.Contains(string(body), `spl_wallets`))
assert.True(t, strings.Contains(string(body), `erc_wallets`))
}
1 change: 1 addition & 0 deletions static/apidiff.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<script type="module">
const testPaths = [
"/v1/users/PWgX8NR/connected_wallets",
"/v1/full/playlists?id=K99x4MB&id=Akkz9wv&id=kKdggMN&id=k2J9Na3&id=NVr4gVN&id=1E87V7Q&user_id=aNzoj",
"/v1/full/playlists/P5abMZp/favorites?limit=15&offset=0&user_id=aNzoj",
"/v1/full/playlists/P5abMZp/reposts?limit=15&offset=0&user_id=aNzoj",
Expand Down
Loading