From b2f89eb23a24692a03e25855b3564a6454b0b6c0 Mon Sep 17 00:00:00 2001 From: jeffyanta Date: Tue, 10 Feb 2026 13:24:50 -0500 Subject: [PATCH] Support currency social links --- ocp/data/currency/model.go | 20 +++++++++++-- ocp/data/currency/postgres/model.go | 38 +++++++++++++++++++----- ocp/data/currency/postgres/store_test.go | 1 + ocp/data/currency/tests/tests.go | 7 ++++- ocp/rpc/currency/server.go | 17 +++++++++++ 5 files changed, 73 insertions(+), 10 deletions(-) diff --git a/ocp/data/currency/model.go b/ocp/data/currency/model.go index 51e50ab..95d7755 100644 --- a/ocp/data/currency/model.go +++ b/ocp/data/currency/model.go @@ -7,6 +7,19 @@ import ( "github.com/code-payments/ocp-server/solana/currencycreator" ) +type SocialLinkType uint8 + +const ( + SocialLinkTypeUnknown SocialLinkType = iota + SocialLinkTypeWebsite + SocialLinkTypeX +) + +type SocialLink struct { + Type SocialLinkType `json:"type"` + Value string `json:"value"` +} + type ExchangeRateRecord struct { Id uint64 Time time.Time @@ -26,7 +39,8 @@ type MetadataRecord struct { Symbol string Description string ImageUrl string - BillColors []string + BillColors []string + SocialLinks []SocialLink Seed string @@ -156,7 +170,8 @@ func (m *MetadataRecord) Clone() *MetadataRecord { Symbol: m.Symbol, Description: m.Description, ImageUrl: m.ImageUrl, - BillColors: append([]string(nil), m.BillColors...), + BillColors: append([]string(nil), m.BillColors...), + SocialLinks: append([]SocialLink(nil), m.SocialLinks...), Seed: m.Seed, @@ -195,6 +210,7 @@ func (m *MetadataRecord) CopyTo(dst *MetadataRecord) { dst.Description = m.Description dst.ImageUrl = m.ImageUrl dst.BillColors = append([]string(nil), m.BillColors...) + dst.SocialLinks = append([]SocialLink(nil), m.SocialLinks...) dst.Seed = m.Seed diff --git a/ocp/data/currency/postgres/model.go b/ocp/data/currency/postgres/model.go index 35a172d..833f254 100644 --- a/ocp/data/currency/postgres/model.go +++ b/ocp/data/currency/postgres/model.go @@ -3,6 +3,8 @@ package postgres import ( "context" "database/sql" + "encoding/json" + "fmt" "strings" "time" @@ -56,7 +58,8 @@ type metadataModel struct { Symbol string `db:"symbol"` Description string `db:"description"` ImageUrl string `db:"image_url"` - BillColors string `db:"bill_colors"` + BillColors string `db:"bill_colors"` + SocialLinks string `db:"social_links"` Seed string `db:"seed"` @@ -98,7 +101,8 @@ func toMetadataModel(obj *currency.MetadataRecord) (*metadataModel, error) { Symbol: obj.Symbol, Description: obj.Description, ImageUrl: obj.ImageUrl, - BillColors: strings.Join(obj.BillColors, ","), + BillColors: strings.Join(obj.BillColors, ","), + SocialLinks: marshalSocialLinks(obj.SocialLinks), Seed: obj.Seed, @@ -142,7 +146,8 @@ func fromMetadataModel(obj *metadataModel) *currency.MetadataRecord { Symbol: obj.Symbol, Description: obj.Description, ImageUrl: obj.ImageUrl, - BillColors: billColors, + BillColors: billColors, + SocialLinks: unmarshalSocialLinks(obj.SocialLinks), Seed: obj.Seed, @@ -204,6 +209,24 @@ func fromReserveModel(obj *reserveModel) *currency.ReserveRecord { } } +func marshalSocialLinks(links []currency.SocialLink) string { + if len(links) == 0 { + return "[]" + } + data, _ := json.Marshal(links) + fmt.Println(string(data)) + return string(data) +} + +func unmarshalSocialLinks(data string) []currency.SocialLink { + if data == "" || data == "[]" { + return nil + } + var links []currency.SocialLink + _ = json.Unmarshal([]byte(data), &links) + return links +} + func makeTimeBasedSelectQuery(table, condition string, ordering q.Ordering) string { return `SELECT * FROM ` + table + ` WHERE ` + condition + ` ORDER BY for_timestamp ` + q.FromOrderingWithFallback(ordering, "asc") } @@ -252,14 +275,15 @@ func (m *metadataModel) dbSave(ctx context.Context, db *sqlx.DB) error { return pgutil.ExecuteInTx(ctx, db, sql.LevelDefault, func(tx *sqlx.Tx) error { err := tx.QueryRowxContext(ctx, `INSERT INTO `+metadataTableName+` - (name, symbol, description, image_url, bill_colors, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22) - RETURNING id, name, symbol, description, image_url, bill_colors, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at`, + (name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23) + RETURNING id, name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at`, m.Name, m.Symbol, m.Description, m.ImageUrl, m.BillColors, + m.SocialLinks, m.Seed, m.Authority, m.Mint, @@ -353,7 +377,7 @@ func dbGetAllExchangeRatesForRange(ctx context.Context, db *sqlx.DB, symbol stri func dbGetMetadataByMint(ctx context.Context, db *sqlx.DB, mint string) (*metadataModel, error) { res := &metadataModel{} err := db.GetContext(ctx, res, - `SELECT id, name, symbol, description, image_url, bill_colors, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at + `SELECT id, name, symbol, description, image_url, bill_colors, social_links, seed, authority, mint, mint_bump, decimals, currency_config, currency_config_bump, liquidity_pool, liquidity_pool_bump, vault_mint, vault_mint_bump, vault_core, vault_core_bump, sell_fee_bps, alt, created_by, created_at FROM `+metadataTableName+` WHERE mint = $1`, mint, diff --git a/ocp/data/currency/postgres/store_test.go b/ocp/data/currency/postgres/store_test.go index f4631b7..859ca41 100644 --- a/ocp/data/currency/postgres/store_test.go +++ b/ocp/data/currency/postgres/store_test.go @@ -38,6 +38,7 @@ const ( description TEXT NOT NULL, image_url TEXT NOT NULL, bill_colors TEXT NOT NULL DEFAULT '', + social_links TEXT NOT NULL DEFAULT '[]', seed TEXT UNIQUE NOT NULL, diff --git a/ocp/data/currency/tests/tests.go b/ocp/data/currency/tests/tests.go index 43075ca..342a547 100644 --- a/ocp/data/currency/tests/tests.go +++ b/ocp/data/currency/tests/tests.go @@ -142,7 +142,11 @@ func testMetadataRoundTrip(t *testing.T, s currency.Store) { Symbol: "JFY", Description: "A test currency for Flipcash created by Jeff Yanta so we can eat our own dog food as we build out the platform. Pun intended", ImageUrl: "https://flipcash-currency-assets.s3.us-east-1.amazonaws.com/52MNGpgvydSwCtC2H4qeiZXZ1TxEuRVCRGa8LAfk2kSj/icon.png", - BillColors: []string{"#19191A", "#FFFFFF"}, + BillColors: []string{"#19191A", "#FFFFFF"}, + SocialLinks: []currency.SocialLink{ + {Type: currency.SocialLinkTypeWebsite, Value: "https://flipcash.com"}, + {Type: currency.SocialLinkTypeX, Value: "jeffycurrency"}, + }, Seed: "H7WNaHtCa5h2k7AwZ8DbdLfM6bU2bi2jmWiUkFqgeBYk", @@ -284,6 +288,7 @@ func assertEquivalentMetadataRecords(t *testing.T, obj1, obj2 *currency.Metadata assert.Equal(t, obj1.Description, obj2.Description) assert.Equal(t, obj1.ImageUrl, obj2.ImageUrl) assert.Equal(t, obj1.BillColors, obj2.BillColors) + assert.Equal(t, obj1.SocialLinks, obj2.SocialLinks) assert.Equal(t, obj1.Seed, obj2.Seed) assert.Equal(t, obj1.Authority, obj2.Authority) assert.Equal(t, obj1.Mint, obj2.Mint) diff --git a/ocp/rpc/currency/server.go b/ocp/rpc/currency/server.go index efd9027..274939d 100644 --- a/ocp/rpc/currency/server.go +++ b/ocp/rpc/currency/server.go @@ -197,6 +197,23 @@ func (s *currencyServer) GetMints(ctx context.Context, req *currencypb.GetMintsR CreatedAt: timestamppb.New(metadataRecord.CreatedAt), } + for _, link := range metadataRecord.SocialLinks { + switch link.Type { + case currency.SocialLinkTypeWebsite: + protoMetadata.SocialLinks = append(protoMetadata.SocialLinks, ¤cypb.SocialLink{ + Type: ¤cypb.SocialLink_Website_{ + Website: ¤cypb.SocialLink_Website{Url: link.Value}, + }, + }) + case currency.SocialLinkTypeX: + protoMetadata.SocialLinks = append(protoMetadata.SocialLinks, ¤cypb.SocialLink{ + Type: ¤cypb.SocialLink_X_{ + X: ¤cypb.SocialLink_X{Username: link.Value}, + }, + }) + } + } + billColors := metadataRecord.BillColors if len(billColors) == 0 { billColors = []string{"#AAAAAA", "#2C2C2C"}