diff --git a/Makefile b/Makefile index e62e8f81..07426679 100644 --- a/Makefile +++ b/Makefile @@ -30,3 +30,13 @@ setup:: apidiff:: open http://localhost:1323/apidiff.html + +test-schema:: + @set -a; \ + . .env; \ + if [ -z "$$writeDbUrl" ]; then \ + echo "writeDbUrl is not set in .env"; \ + exit 1; \ + fi; \ + adjustedUrl=$$(echo "$$writeDbUrl" | sed 's/localhost/host.docker.internal/g'); \ + docker compose exec db bash -c "pg_dump '$$adjustedUrl' --schema-only --no-owner --no-acl > ./sql/01_schema.sql" \ No newline at end of file diff --git a/api/swagger/swagger-v1.yaml b/api/swagger/swagger-v1.yaml index 3923641f..0c75a718 100644 --- a/api/swagger/swagger-v1.yaml +++ b/api/swagger/swagger-v1.yaml @@ -4997,6 +4997,18 @@ components: type: string description: The ID of the user associated with the coin example: "7eP5n" + logo_uri: + type: string + description: URL to the coin's logo image + example: "https://arweave.net/hQiPZOsRZXGXBJd_82PhVdlM_hACsT_q6wqwf5cSY7I" + description: + type: string + description: A longform description about the coin + example: "The Official Bonk Inu token\nLorem ipsum dolor sit amet, consectetur adipiscing elit." + website: + type: string + description: The official website for the coin + example: "https://www.bonkcoin.com/" created_at: type: string description: The date and time when the coin was added to Audius. diff --git a/api/v1_coin.go b/api/v1_coin.go index d760342a..92d03251 100644 --- a/api/v1_coin.go +++ b/api/v1_coin.go @@ -19,6 +19,9 @@ func (app *ApiServer) v1Coin(c *fiber.Ctx) error { artist_coins.mint, artist_coins.decimals, artist_coins.user_id, + artist_coins.logo_uri, + artist_coins.description, + artist_coins.website, artist_coins.created_at FROM artist_coins WHERE artist_coins.mint = @mint diff --git a/api/v1_coins.go b/api/v1_coins.go index 34ddb54a..63250f06 100644 --- a/api/v1_coins.go +++ b/api/v1_coins.go @@ -17,11 +17,14 @@ type GetArtistCoinsQueryParams struct { } type ArtistCoin struct { - Ticker string `json:"ticker"` - Mint string `json:"mint"` - Decimals int `json:"decimals"` - OwnerId trashid.HashId `db:"user_id" json:"owner_id"` - CreatedAt time.Time `json:"created_at"` + Ticker string `json:"ticker"` + Mint string `json:"mint"` + Decimals int `json:"decimals"` + OwnerId trashid.HashId `db:"user_id" json:"owner_id"` + LogoUri *string `json:"logo_uri,omitempty"` + Description *string `json:"description,omitempty"` + Website *string `json:"website,omitempty"` + CreatedAt time.Time `json:"created_at"` } func (app *ApiServer) v1Coins(c *fiber.Ctx) error { @@ -49,6 +52,9 @@ func (app *ApiServer) v1Coins(c *fiber.Ctx) error { artist_coins.mint, artist_coins.decimals, artist_coins.user_id, + artist_coins.logo_uri, + artist_coins.description, + artist_coins.website, artist_coins.created_at FROM artist_coins WHERE 1=1 diff --git a/api/v1_coins_test.go b/api/v1_coins_test.go index 70c84b66..29dc2874 100644 --- a/api/v1_coins_test.go +++ b/api/v1_coins_test.go @@ -22,11 +22,14 @@ func TestGetCoins(t *testing.T) { "created_at": time.Now().Add(-time.Second), }, { - "ticker": "$USDC", - "decimals": 6, - "user_id": 2, - "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", - "created_at": time.Now(), + "ticker": "$USDC", + "decimals": 6, + "user_id": 2, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "logo_uri": "https://example.com/usdc-logo.png", + "description": "USDC is a stablecoin pegged to the US dollar.", + "website": "https://www.circle.com/en/usdc", + "created_at": time.Now(), }, }, } @@ -41,14 +44,17 @@ func TestGetCoins(t *testing.T) { assert.Equal(t, 200, status) jsonAssert(t, body, map[string]any{ - "data.0.ticker": "$AUDIO", - "data.0.mint": "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM", - "data.0.decimals": 8, - "data.0.owner_id": trashid.MustEncodeHashID(1), - "data.1.ticker": "$USDC", - "data.1.mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", - "data.1.decimals": 6, - "data.1.owner_id": trashid.MustEncodeHashID(2), + "data.0.ticker": "$AUDIO", + "data.0.mint": "9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM", + "data.0.decimals": 8, + "data.0.owner_id": trashid.MustEncodeHashID(1), + "data.1.ticker": "$USDC", + "data.1.mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "data.1.decimals": 6, + "data.1.owner_id": trashid.MustEncodeHashID(2), + "data.1.logo_uri": "https://example.com/usdc-logo.png", + "data.1.description": "USDC is a stablecoin pegged to the US dollar.", + "data.1.website": "https://www.circle.com/en/usdc", }) } diff --git a/ddl/migrations/0155_add_artist_coins_logo_description.sql b/ddl/migrations/0155_add_artist_coins_logo_description.sql new file mode 100644 index 00000000..4c34a115 --- /dev/null +++ b/ddl/migrations/0155_add_artist_coins_logo_description.sql @@ -0,0 +1,4 @@ +ALTER TABLE IF EXISTS artist_coins +ADD COLUMN IF NOT EXISTS logo_uri TEXT, +ADD COLUMN IF NOT EXISTS description TEXT, +ADD COLUMN IF NOT EXISTS website TEXT; \ No newline at end of file diff --git a/sql/01_schema.sql b/sql/01_schema.sql index e19285d7..95359973 100644 --- a/sql/01_schema.sql +++ b/sql/01_schema.sql @@ -1174,29 +1174,15 @@ BEGIN UNION -- coin_holder_audience - -- Case 1: userbank ie. sol_claimable_accounts - SELECT chat_blast.blast_id, u.user_id AS to_user_id - FROM artist_coins ac - JOIN chat_blast ON chat_blast.blast_id = blast_id_param - AND chat_blast.audience = 'coin_holder_audience' - AND ac.user_id = chat_blast.from_user_id - JOIN sol_claimable_accounts sca ON sca.mint = ac.mint - JOIN sol_token_account_balances stab ON stab.account = sca.account - JOIN users u ON u.wallet = sca.ethereum_address - WHERE stab.balance > 0 - - UNION - - -- Case 2: associated_wallets - SELECT chat_blast.blast_id, u.user_id AS to_user_id - FROM artist_coins ac - JOIN chat_blast ON chat_blast.blast_id = blast_id_param - AND chat_blast.audience = 'coin_holder_audience' - AND ac.user_id = chat_blast.from_user_id - JOIN sol_token_account_balances stab ON stab.mint = ac.mint - JOIN associated_wallets aw ON aw.wallet = stab.owner - JOIN users u ON u.user_id = aw.user_id - WHERE stab.balance > 0; + SELECT chat_blast.blast_id, sol_user_balances.user_id AS to_user_id + FROM chat_blast + JOIN artist_coins + ON artist_coins.user_id = chat_blast.from_user_id + JOIN sol_user_balances + ON sol_user_balances.mint = artist_coins.mint + AND sol_user_balances.balance > 0 + WHERE chat_blast.blast_id = blast_id_param + AND chat_blast.audience = 'coin_holder_audience'; END; $$; @@ -5768,7 +5754,10 @@ CREATE TABLE public.artist_coins ( ticker character varying NOT NULL, user_id integer NOT NULL, decimals integer NOT NULL, - created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL + created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, + logo_uri text, + description text, + website text );