Skip to content

Commit

Permalink
add icon url, urls and time to mint info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
elnosh committed Dec 11, 2024
1 parent f8dd2d3 commit 0098635
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .env.mint.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ MINT_DESCRIPTION="short mint description"
MINT_DESCRIPTION_LONG="a long description of the mint"
MINT_CONTACT_INFO=[["email", "[email protected]"], ["nostr", "npub..."]]
MINT_MOTD="message to the users of the mint"
MINT_ICON_URL="https://<mint>/icon.jpeg"
MINT_URLS=["https://<mint>", "https://<mint2>"]

# mint limits (these are optional but recommended to use)
# max balance (in sats). Minting new ecash will be disabled if this balance is reached
Expand Down
9 changes: 9 additions & 0 deletions cashu/nuts/nut06/nut06.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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"`
}

Expand All @@ -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)

Expand Down
37 changes: 29 additions & 8 deletions cmd/mint/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"net/url"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type MintInfo struct {
LongDescription string
Contact []nut06.ContactInfo
Motd string
IconURL string
URLs []string
}

type MintMethodSettings struct {
Expand Down
5 changes: 4 additions & 1 deletion mint/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0098635

Please sign in to comment.