gnunet-gns-registrar

GNU Name System registrar
Log | Files | Refs | README

commit f2955fb0de0d7a2e31ac921107a031f91bab2c3d
parent aef839d11464e817837a9d596f50f0cb918223e5
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Tue, 12 Dec 2023 18:13:15 +0100

Add taler-go support for currency specs

Diffstat:
Mgo.mod | 2+-
Mpkg/rest/gnsregistrar.go | 31+++++++++++--------------------
2 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/go.mod b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/google/uuid v1.4.0 github.com/gorilla/mux v1.8.1 - github.com/schanzen/taler-go v0.0.4 + github.com/schanzen/taler-go v0.0.5 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e golang.org/x/text v0.14.0 gopkg.in/ini.v1 v1.67.0 diff --git a/pkg/rest/gnsregistrar.go b/pkg/rest/gnsregistrar.go @@ -28,22 +28,17 @@ import ( "io" "net/http" "os" - "strconv" "strings" "time" "github.com/gorilla/mux" "github.com/skip2/go-qrcode" - "golang.org/x/text/currency" - "golang.org/x/text/language" - "golang.org/x/text/message" "gopkg.in/ini.v1" "github.com/schanzen/taler-go/pkg/merchant" "github.com/google/uuid" talerutil "github.com/schanzen/taler-go/pkg/util" ) - type RegistrationMetadata struct { Expiration uint64 `json:"expiration"` Paid bool `json:"paid"` @@ -173,18 +168,14 @@ func generateRegistrationId() string { // FIXME: Implement https://docs.taler.net/design-documents/051-fractional-digits.html and move to taler-go func (t *Registrar) localizedAmountString() (string) { - p := message.NewPrinter(language.English) - costStr := t.RegistrationCost.String() - costSplit := strings.Split(costStr, ":") - left := costSplit[0] - right := costSplit[1] - cur, err := currency.ParseISO(left) - if nil != err { - return fmt.Sprintf("%s %s", right, left) - } - amf, _ := strconv.ParseFloat(right, 8) - v := currency.Symbol(cur.Amount(amf)) - return p.Sprint(v) + var currencySpec = talerutil.CurrencySpecification{ + Name: "KUDOS", + NumFractionalNormalDigits: 2, + AllUnitNames: map[int]string{ + 0: "KUDOS", + }, + } + return t.RegistrationCost.Format(currencySpec) } func (t *Registrar) landingPage(w http.ResponseWriter, r *http.Request) { @@ -305,7 +296,7 @@ func (t *Registrar) updateRegistration(w http.ResponseWriter, r *http.Request) { } resp, err := client.Do(req) if err != nil { - http.Redirect(w, r, "/" + "?error=Registration failed: Failed to get zone contents", http.StatusSeeOther) + http.Redirect(w, r, "/" + "?error=Registration failed: Failed to get zone contents", http.StatusSeeOther) fmt.Printf("Failed to get zone contents") return } @@ -338,8 +329,8 @@ func (t *Registrar) updateRegistration(w http.ResponseWriter, r *http.Request) { return } r.ParseForm() - token := r.Form.Get("token") - zkey := r.Form.Get("zkey") + token := r.Form.Get("token") + zkey := r.Form.Get("zkey") if regMetadata.RegistrationID != token { http.Redirect(w, r, "/name/"+vars["label"] + "?error=Unauthorized", http.StatusSeeOther) return