From 0098635f32ee390613de0b0dc0d105167013e3e1 Mon Sep 17 00:00:00 2001 From: elnosh Date: Wed, 11 Dec 2024 12:34:30 -0500 Subject: [PATCH] add icon url, urls and time to mint info endpoint --- .env.mint.example | 2 ++ cashu/nuts/nut06/nut06.go | 9 +++++++++ cmd/mint/mint.go | 37 +++++++++++++++++++++++++++++-------- mint/config.go | 2 ++ mint/mint.go | 5 ++++- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/.env.mint.example b/.env.mint.example index 05fd726..f20e968 100644 --- a/.env.mint.example +++ b/.env.mint.example @@ -9,6 +9,8 @@ MINT_DESCRIPTION="short mint description" MINT_DESCRIPTION_LONG="a long description of the mint" MINT_CONTACT_INFO=[["email", "contact@me.com"], ["nostr", "npub..."]] MINT_MOTD="message to the users of the mint" +MINT_ICON_URL="https:///icon.jpeg" +MINT_URLS=["https://", "https://"] # mint limits (these are optional but recommended to use) # max balance (in sats). Minting new ecash will be disabled if this balance is reached diff --git a/cashu/nuts/nut06/nut06.go b/cashu/nuts/nut06/nut06.go index 114d77f..b031fb2 100644 --- a/cashu/nuts/nut06/nut06.go +++ b/cashu/nuts/nut06/nut06.go @@ -17,6 +17,9 @@ type MintInfo struct { LongDescription string `json:"description_long,omitempty"` Contact []ContactInfo `json:"contact,omitempty"` Motd string `json:"motd,omitempty"` + IconURL string `json:"icon_url,omitempty"` + URLs []string `json:"urls,omitempty"` + Time int64 `json:"time,omitempty"` Nuts NutsMap `json:"nuts"` } @@ -35,6 +38,9 @@ func (mi *MintInfo) UnmarshalJSON(data []byte) error { LongDescription string `json:"description_long,omitempty"` Contact json.RawMessage `json:"contact,omitempty"` Motd string `json:"motd,omitempty"` + IconURL string `json:"icon_url,omitempty"` + URLs []string `json:"urls,omitempty"` + Time int64 `json:"time,omitempty"` Nuts NutsMap `json:"nuts"` } @@ -48,6 +54,9 @@ func (mi *MintInfo) UnmarshalJSON(data []byte) error { mi.Description = tempInfo.Description mi.LongDescription = tempInfo.LongDescription mi.Motd = tempInfo.Motd + mi.IconURL = tempInfo.IconURL + mi.URLs = tempInfo.URLs + mi.Time = tempInfo.Time mi.Nuts = tempInfo.Nuts json.Unmarshal(tempInfo.Contact, &mi.Contact) diff --git a/cmd/mint/mint.go b/cmd/mint/mint.go index e03b7dc..00b082a 100644 --- a/cmd/mint/mint.go +++ b/cmd/mint/mint.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "log" + "net/url" "os" "os/signal" "path/filepath" @@ -82,19 +83,17 @@ func configFromEnv() (*mint.Config, error) { } mintInfo := mint.MintInfo{ - Name: os.Getenv("MINT_NAME"), - Description: os.Getenv("MINT_DESCRIPTION"), + Name: os.Getenv("MINT_NAME"), + Description: os.Getenv("MINT_DESCRIPTION"), + LongDescription: os.Getenv("MINT_DESCRIPTION_LONG"), + Motd: os.Getenv("MINT_MOTD"), } - mintInfo.LongDescription = os.Getenv("MINT_DESCRIPTION_LONG") - mintInfo.Motd = os.Getenv("MINT_MOTD") - contact := os.Getenv("MINT_CONTACT_INFO") var mintContactInfo []nut06.ContactInfo if len(contact) > 0 { var infoArr [][]string - err := json.Unmarshal([]byte(contact), &infoArr) - if err != nil { + if err := json.Unmarshal([]byte(contact), &infoArr); err != nil { return nil, fmt.Errorf("error parsing contact info: %v", err) } @@ -105,8 +104,30 @@ func configFromEnv() (*mint.Config, error) { } mintInfo.Contact = mintContactInfo - var lightningClient lightning.Client + if len(os.Getenv("MINT_ICON_URL")) > 0 { + iconURL, err := url.Parse(os.Getenv("MINT_ICON_URL")) + if err != nil { + return nil, fmt.Errorf("invalid icon url: %v", err) + } + mintInfo.IconURL = iconURL.String() + } + urls := os.Getenv("MINT_URLS") + if len(urls) > 0 { + urlList := []string{} + if err := json.Unmarshal([]byte(urls), &urlList); err != nil { + return nil, fmt.Errorf("error parsing list of URLs: %v", err) + } + for _, urlString := range urlList { + mintURL, err := url.Parse(urlString) + if err != nil { + return nil, fmt.Errorf("invalid url: %v", err) + } + mintInfo.URLs = append(mintInfo.URLs, mintURL.String()) + } + } + + var lightningClient lightning.Client switch os.Getenv("LIGHTNING_BACKEND") { case "Lnd": // read values for setting up LND diff --git a/mint/config.go b/mint/config.go index 6ec3c37..e084b61 100644 --- a/mint/config.go +++ b/mint/config.go @@ -35,6 +35,8 @@ type MintInfo struct { LongDescription string Contact []nut06.ContactInfo Motd string + IconURL string + URLs []string } type MintMethodSettings struct { diff --git a/mint/mint.go b/mint/mint.go index 2cb1197..d0a403d 100644 --- a/mint/mint.go +++ b/mint/mint.go @@ -1415,12 +1415,15 @@ func (m *Mint) SetMintInfo(mintInfo MintInfo) { LongDescription: mintInfo.LongDescription, Contact: mintInfo.Contact, Motd: mintInfo.Motd, + IconURL: mintInfo.IconURL, + URLs: mintInfo.URLs, + Time: time.Now().Unix(), Nuts: nuts, } m.mintInfo = info } -func (m *Mint) RetrieveMintInfo() (nut06.MintInfo, error) { +func (m Mint) RetrieveMintInfo() (nut06.MintInfo, error) { seed, err := m.db.GetSeed() if err != nil { return nut06.MintInfo{}, err