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
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 12 additions & 0 deletions api/swagger/swagger-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions api/v1_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions api/v1_coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
32 changes: 19 additions & 13 deletions api/v1_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
}
Expand All @@ -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",
})
}

Expand Down
4 changes: 4 additions & 0 deletions ddl/migrations/0155_add_artist_coins_logo_description.sql
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 13 additions & 24 deletions sql/01_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from #282


END;
$$;
Expand Down Expand Up @@ -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
);


Expand Down
Loading