Skip to content

Commit 4117c20

Browse files
committed
Support description and image URL for mint metadata
1 parent ea9792c commit 4117c20

File tree

8 files changed

+70
-33
lines changed

8 files changed

+70
-33
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
filippo.io/edwards25519 v1.1.0
77
github.com/aws/aws-sdk-go-v2 v0.17.0
88
github.com/bits-and-blooms/bloom/v3 v3.1.0
9-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250909140022-32d989862f5a
9+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250919185855-0de34de496c2
1010
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba
1111
github.com/emirpasic/gods v1.12.0
1212
github.com/envoyproxy/protoc-gen-validate v1.2.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
8080
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
8181
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
8282
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
83-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250909140022-32d989862f5a h1:KJHqqNz1gEOhjg97mw1B81Fvd4CClWeaSJw2AMOqSkA=
84-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250909140022-32d989862f5a/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
83+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250919185855-0de34de496c2 h1:IQJnBLjMUNgL2Drqck86/rtsgL38uCQ+vgEUzJbUsL0=
84+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250919185855-0de34de496c2/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
8585
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba h1:Bkp+gmeb6Y2PWXfkSCTMBGWkb2P1BujRDSjWeI+0j5I=
8686
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba/go.mod h1:jSiifpiBpyBQ8q2R0MGEbkSgWC6sbdRTyDBntmW+j1E=
8787
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=

pkg/code/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const (
1616
CoreMintDecimals = usdc.Decimals
1717
CoreMintName = "USDC"
1818
CoreMintSymbol = "USDC"
19+
CoreMintDescription = "USDC is a regulated digital currency established in 2018 and issued by Circle, a regulated financial service business that follows strict US laws and standards to protect your money. Every USDC in existence is backed by a US dollar or cash equivalent asset that Circle has in its publicly visible reserves, with assurances issued monthly by a Big Four accounting firm."
20+
CoreMintImageUrl = "https://pbs.twimg.com/profile_images/1916937910928211968/CKblfanr_400x400.png"
1921

2022
// Random value. Replace with real subsidizer public keys
2123
SubsidizerPublicKey = "84ydcM4Yp59W6aZP6eSaKiAMaKidNLfb5k318sT2pm14"

pkg/code/data/currency/model.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ type MultiRateRecord struct {
2222
type MetadataRecord struct {
2323
Id uint64
2424

25-
Name string
26-
Symbol string
25+
Name string
26+
Symbol string
27+
Description string
28+
ImageUrl string
2729

2830
Seed string
2931

@@ -64,6 +66,14 @@ func (m *MetadataRecord) Validate() error {
6466
return errors.New("symbol is required")
6567
}
6668

69+
if len(m.Description) == 0 {
70+
return errors.New("description is required")
71+
}
72+
73+
if len(m.ImageUrl) == 0 {
74+
return errors.New("image url is required")
75+
}
76+
6777
if len(m.Seed) == 0 {
6878
return errors.New("seed is required")
6979
}
@@ -147,8 +157,10 @@ func (m *MetadataRecord) Clone() *MetadataRecord {
147157
return &MetadataRecord{
148158
Id: m.Id,
149159

150-
Name: m.Name,
151-
Symbol: m.Symbol,
160+
Name: m.Name,
161+
Symbol: m.Symbol,
162+
Description: m.Description,
163+
ImageUrl: m.ImageUrl,
152164

153165
Seed: m.Seed,
154166

@@ -186,6 +198,8 @@ func (m *MetadataRecord) CopyTo(dst *MetadataRecord) {
186198

187199
dst.Name = m.Name
188200
dst.Symbol = m.Symbol
201+
dst.Description = m.Description
202+
dst.ImageUrl = m.ImageUrl
189203

190204
dst.Seed = m.Seed
191205

pkg/code/data/currency/postgres/model.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ func fromExchangeRateModel(obj *exchangeRateModel) *currency.ExchangeRateRecord
5151
type metadataModel struct {
5252
Id sql.NullInt64 `db:"id"`
5353

54-
Name string `db:"name"`
55-
Symbol string `db:"symbol"`
54+
Name string `db:"name"`
55+
Symbol string `db:"symbol"`
56+
Description string `db:"description"`
57+
ImageUrl string `db:"image_url"`
5658

5759
Seed string `db:"seed"`
5860

@@ -92,8 +94,10 @@ func toMetadataModel(obj *currency.MetadataRecord) (*metadataModel, error) {
9294
return &metadataModel{
9395
Id: sql.NullInt64{Int64: int64(obj.Id), Valid: obj.Id > 0},
9496

95-
Name: obj.Name,
96-
Symbol: obj.Symbol,
97+
Name: obj.Name,
98+
Symbol: obj.Symbol,
99+
Description: obj.Description,
100+
ImageUrl: obj.ImageUrl,
97101

98102
Seed: obj.Seed,
99103

@@ -130,8 +134,10 @@ func fromMetadataModel(obj *metadataModel) *currency.MetadataRecord {
130134
return &currency.MetadataRecord{
131135
Id: uint64(obj.Id.Int64),
132136

133-
Name: obj.Name,
134-
Symbol: obj.Symbol,
137+
Name: obj.Name,
138+
Symbol: obj.Symbol,
139+
Description: obj.Description,
140+
ImageUrl: obj.ImageUrl,
135141

136142
Seed: obj.Seed,
137143

@@ -246,11 +252,13 @@ func (m *metadataModel) dbSave(ctx context.Context, db *sqlx.DB) error {
246252
return pgutil.ExecuteInTx(ctx, db, sql.LevelDefault, func(tx *sqlx.Tx) error {
247253
err := tx.QueryRowxContext(ctx,
248254
`INSERT INTO `+metadataTableName+`
249-
(name, symbol, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at)
250-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
251-
RETURNING id, name, symbol, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at`,
255+
(name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at)
256+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)
257+
RETURNING id, name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at`,
252258
m.Name,
253259
m.Symbol,
260+
m.Description,
261+
m.ImageUrl,
254262
m.Seed,
255263
m.Authority,
256264
m.Mint,
@@ -347,7 +355,7 @@ func dbGetAllExchangeRatesForRange(ctx context.Context, db *sqlx.DB, symbol stri
347355
func dbGetMetadataByMint(ctx context.Context, db *sqlx.DB, mint string) (*metadataModel, error) {
348356
res := &metadataModel{}
349357
err := db.GetContext(ctx, res,
350-
`SELECT id, name, symbol, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at
358+
`SELECT id, name, symbol, description, image_url, 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, fees_mint, buy_fee_bps, fees_core, sell_fee_bps, created_by, created_at
351359
FROM `+metadataTableName+`
352360
WHERE mint = $1`,
353361
mint,

pkg/code/data/currency/postgres/store_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const (
3535
3636
name TEXT NOT NULL,
3737
symbol TEXT NOT NULL,
38+
description TEXT NOT NULL,
39+
image_url TEXT NOT NULL,
3840
3941
seed TEXT UNIQUE NOT NULL,
4042

pkg/code/data/currency/tests/tests.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ func testGetExchangeRatesInRange(t *testing.T, s currency.Store) {
118118

119119
func testMetadataRoundTrip(t *testing.T, s currency.Store) {
120120
expected := &currency.MetadataRecord{
121-
Name: "Jeffy",
122-
Symbol: "JFY",
121+
Name: "Jeffy",
122+
Symbol: "JFY",
123+
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",
124+
ImageUrl: "https://flipcash-currency-assets.s3.us-east-1.amazonaws.com/52MNGpgvydSwCtC2H4qeiZXZ1TxEuRVCRGa8LAfk2kSj/icon.png",
123125

124126
Seed: "H7WNaHtCa5h2k7AwZ8DbdLfM6bU2bi2jmWiUkFqgeBYk",
125127

@@ -202,6 +204,8 @@ func testReserveRoundTrip(t *testing.T, s currency.Store) {
202204
func assertEquivalentMetadataRecords(t *testing.T, obj1, obj2 *currency.MetadataRecord) {
203205
assert.Equal(t, obj1.Name, obj2.Name)
204206
assert.Equal(t, obj1.Symbol, obj2.Symbol)
207+
assert.Equal(t, obj1.Description, obj2.Description)
208+
assert.Equal(t, obj1.ImageUrl, obj2.ImageUrl)
205209
assert.Equal(t, obj1.Seed, obj2.Seed)
206210
assert.Equal(t, obj1.Authority, obj2.Authority)
207211
assert.Equal(t, obj1.Mint, obj2.Mint)

pkg/code/server/currency/currency.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
currencypb "github.com/code-payments/code-protobuf-api/generated/go/currency/v1"
1515

1616
"github.com/code-payments/code-server/pkg/code/common"
17+
"github.com/code-payments/code-server/pkg/code/config"
1718
currency_util "github.com/code-payments/code-server/pkg/code/currency"
1819
code_data "github.com/code-payments/code-server/pkg/code/data"
1920
"github.com/code-payments/code-server/pkg/code/data/currency"
@@ -83,10 +84,12 @@ func (s *currencyServer) GetMints(ctx context.Context, req *currencypb.GetMintsR
8384
switch mintAccount.PublicKey().ToBase58() {
8485
case common.CoreMintAccount.PublicKey().ToBase58():
8586
protoMetadata = &currencypb.Mint{
86-
Address: protoMintAddress,
87-
Decimals: uint32(common.CoreMintDecimals),
88-
Name: common.CoreMintName,
89-
Symbol: strings.ToUpper(string(common.CoreMintSymbol)),
87+
Address: protoMintAddress,
88+
Decimals: uint32(common.CoreMintDecimals),
89+
Name: common.CoreMintName,
90+
Symbol: strings.ToUpper(string(common.CoreMintSymbol)),
91+
Description: config.CoreMintDescription,
92+
ImageUrl: config.CoreMintImageUrl,
9093
VmMetadata: &currencypb.VmMetadata{
9194
Vm: common.CodeVmAccount.ToProto(),
9295
Authority: common.GetSubsidizer().ToProto(),
@@ -108,6 +111,12 @@ func (s *currencyServer) GetMints(ctx context.Context, req *currencypb.GetMintsR
108111
return nil, status.Error(codes.Internal, "")
109112
}
110113

114+
vmConfig, err := common.GetVmConfigForMint(ctx, s.data, mintAccount)
115+
if err != nil {
116+
log.WithError(err).Warn("failure getting vm config")
117+
return nil, status.Error(codes.Internal, "")
118+
}
119+
111120
seed, err := common.NewAccountFromPublicKeyString(metadataRecord.Seed)
112121
if err != nil {
113122
log.WithError(err).Warn("invalid seed")
@@ -144,18 +153,16 @@ func (s *currencyServer) GetMints(ctx context.Context, req *currencypb.GetMintsR
144153
return nil, status.Error(codes.Internal, "")
145154
}
146155

147-
// todo: Need a DB table for VMs
148-
vmAccount, _ := common.NewAccountFromPublicKeyString("Bii3UFB9DzPq6UxgewF5iv9h1Gi8ZnP6mr7PtocHGNta")
149-
vmAuthorityAccount := currencyAuthorityAccount
150-
151156
protoMetadata = &currencypb.Mint{
152-
Address: protoMintAddress,
153-
Decimals: uint32(metadataRecord.Decimals),
154-
Name: metadataRecord.Name,
155-
Symbol: metadataRecord.Symbol,
157+
Address: protoMintAddress,
158+
Decimals: uint32(metadataRecord.Decimals),
159+
Name: metadataRecord.Name,
160+
Symbol: metadataRecord.Symbol,
161+
Description: metadataRecord.Description,
162+
ImageUrl: metadataRecord.ImageUrl,
156163
VmMetadata: &currencypb.VmMetadata{
157-
Vm: vmAccount.ToProto(),
158-
Authority: vmAuthorityAccount.ToProto(),
164+
Vm: vmConfig.Vm.ToProto(),
165+
Authority: vmConfig.Authority.ToProto(),
159166
LockDurationInDays: uint32(timelock_token.DefaultNumDaysLocked),
160167
},
161168
LaunchpadMetadata: &currencypb.LaunchpadMetadata{

0 commit comments

Comments
 (0)