commit b9b6ab1d48f96e01b6dd1b95e208c526b57acd8b
parent c052449a9a5e846e6c7e9033144ebd0b49ca0bff
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 17 Dec 2023 23:46:59 -0500
configurable xmr price
Diffstat:
10 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/cmd/dkf/migrations/155.sql b/cmd/dkf/migrations/155.sql
@@ -0,0 +1,4 @@
+-- +migrate Up
+ALTER TABLE settings ADD COLUMN monero_price REAL NOT NULL DEFAULT 170;
+
+-- +migrate Down
diff --git a/pkg/actions/actions.go b/pkg/actions/actions.go
@@ -78,6 +78,7 @@ func Start(c *cli.Context) error {
config.PowEnabled.Store(settings.PowEnabled)
config.PokerWithdrawEnabled.Store(settings.PokerWithdrawEnabled)
config.CaptchaDifficulty.Store(settings.CaptchaDifficulty)
+ config.MoneroPrice.Store(settings.MoneroPrice)
config.Xmr()
diff --git a/pkg/config/config.go b/pkg/config/config.go
@@ -89,6 +89,7 @@ var (
CaptchaRequiredGenerated = atom.NewInt64(0)
CaptchaRequiredSuccess = atom.NewInt64(0)
CaptchaRequiredFailed = atom.NewInt64(0)
+ MoneroPrice = atom.NewFloat64(0)
RpsCounter = ratecounter.NewRateCounter()
RejectedReqCounter = ratecounter.NewRateCounter()
diff --git a/pkg/database/tablePokerTables.go b/pkg/database/tablePokerTables.go
@@ -1,6 +1,7 @@
package database
import (
+ "dkforest/pkg/config"
"fmt"
"github.com/dustin/go-humanize"
"github.com/sirupsen/logrus"
@@ -26,8 +27,6 @@ func (d *DkfDB) GetPokerTableBySlug(slug string) (out PokerTable, err error) {
return
}
-const MoneroPrice = 171.7
-
// Piconero the smallest unit of Monero is 1 piconero (0.000000000001 XMR) also known as the atomic unit
// https://www.getmonero.org/resources/moneropedia/denominations.html
type Piconero uint64
@@ -41,7 +40,7 @@ func (p Piconero) XmrStr() string {
}
func (p Piconero) UsdStr() string {
- return fmt.Sprintf("$%.2f", float64(p)/1_000_000_000_000*MoneroPrice)
+ return fmt.Sprintf("$%.2f", float64(p)/1_000_000_000_000*config.MoneroPrice.Load())
}
func (p Piconero) RawString() string { return fmt.Sprintf("%d", p) }
diff --git a/pkg/database/tableSettings.go b/pkg/database/tableSettings.go
@@ -17,6 +17,7 @@ type Settings struct {
PokerWithdrawEnabled bool // either or not poker withdraw is enabled
CaptchaDifficulty int64 // captcha difficulty
PowEnabled bool
+ MoneroPrice float64
}
// GetSettings get the saved settings from the DB
@@ -28,6 +29,7 @@ func (d *DkfDB) GetSettings() (out Settings) {
out.MaybeAuthEnabled = true
out.DownloadsEnabled = true
out.CaptchaDifficulty = 2
+ out.MoneroPrice = 170.0
d.db.Create(&out)
}
return
diff --git a/pkg/web/handlers/admin.go b/pkg/web/handlers/admin.go
@@ -262,6 +262,7 @@ func AdminSettingsHandler(c echo.Context) error {
data.CaptchaDifficulty = settings.CaptchaDifficulty
data.PowEnabled = settings.PowEnabled
data.PokerWithdrawEnabled = settings.PokerWithdrawEnabled
+ data.MoneroPrice = settings.MoneroPrice
if c.Request().Method == http.MethodPost {
formName := c.Request().PostFormValue("formName")
@@ -284,6 +285,7 @@ func AdminSettingsHandler(c echo.Context) error {
settings.CaptchaDifficulty = utils.DoParseInt64(c.Request().PostFormValue("captchaDifficulty"))
settings.PowEnabled = utils.DoParseBool(c.Request().PostFormValue("powEnabled"))
settings.PokerWithdrawEnabled = utils.DoParseBool(c.Request().PostFormValue("pokerWithdrawEnabled"))
+ settings.MoneroPrice = math.Max(utils.DoParseF64(c.Request().PostFormValue("moneroPrice")), 1)
settings.DoSave(db)
config.ProtectHome.Store(settings.ProtectHome)
config.HomeUsersList.Store(settings.HomeUsersList)
@@ -296,6 +298,7 @@ func AdminSettingsHandler(c echo.Context) error {
config.DownloadsEnabled.Store(settings.DownloadsEnabled)
config.ForumEnabled.Store(settings.ForumEnabled)
config.MaybeAuthEnabled.Store(settings.MaybeAuthEnabled)
+ config.MoneroPrice.Store(settings.MoneroPrice)
return c.Redirect(http.StatusFound, "/admin/settings")
}
diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go
@@ -561,6 +561,7 @@ type adminSettingsData struct {
PowEnabled bool
PokerWithdrawEnabled bool
CaptchaDifficulty int64
+ MoneroPrice float64
}
type settingsPGPData struct {
@@ -954,6 +955,7 @@ type TmpTable struct {
}
type pokerData struct {
+ XmrPrice string
XmrBalance database.Piconero
PokerXmrSubAddress string
Img string
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -774,6 +774,7 @@ func PokerHomeHandler(c echo.Context) error {
}
const minWithdrawAmount = 1
var data pokerData
+ data.XmrPrice = fmt.Sprintf("$%.2f", config.MoneroPrice.Load())
data.Transactions, _ = db.GetUserPokerXmrTransactions(authUser.ID)
data.PokerXmrSubAddress = authUser.PokerXmrSubAddress
data.ChipsTest = authUser.ChipsTest
@@ -812,7 +813,7 @@ func PokerHomeHandler(c echo.Context) error {
switch data.HelperType {
case "usd":
amount := utils.DoParseF64(data.HelperAmount)
- pxmr = database.Piconero(amount / database.MoneroPrice * 1_000_000_000_000)
+ pxmr = database.Piconero(amount / config.MoneroPrice.Load() * 1_000_000_000_000)
case "xmr":
amount := utils.DoParseF64(data.HelperAmount)
pxmr = database.Piconero(amount * 1_000_000_000_000)
diff --git a/pkg/web/public/views/pages/admin/settings.gohtml b/pkg/web/public/views/pages/admin/settings.gohtml
@@ -101,6 +101,10 @@
<option value="2"{{ if eq .Data.CaptchaDifficulty 2 }} selected{{ end }}>Hard</option>
</select>
</div>
+ <div>
+ <label class="form-check-label" for="moneroPrice">Monero price</label>
+ <input type="text" name="moneroPrice" id="moneroPrice" value="{{ .Data.MoneroPrice }}" />
+ </div>
<div class="form-group mt-3">
<button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> Save</button>
</div>
diff --git a/pkg/web/public/views/pages/poker.gohtml b/pkg/web/public/views/pages/poker.gohtml
@@ -12,6 +12,7 @@
<img src="data:image/png;base64,{{ .Data.Img }}" class="img-thumbnail" alt="" />
{{ end }}
</div>
+ 1 <small>XMR</small> == {{ .Data.XmrPrice }}<br />
0.01 <small>XMR</small> == 1,000 <small>chips</small><br />
rake is max 7% (rounded down)<br />
rake is capped at 15*big_blind<br />