From 5aecfe2871f2b8ecd949e5d8055c0c013bdabb9f Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Sun, 5 Nov 2023 15:14:50 +0100 Subject: [PATCH] settings payoutthreshold --- api/server.go | 46 +++++++++++++++++++++++++++++++++++++++++++++ payouts/payer.go | 2 +- proxy/miner.go | 2 ++ storage/redis.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) diff --git a/api/server.go b/api/server.go index 77de466..6521bf5 100644 --- a/api/server.go +++ b/api/server.go @@ -6,6 +6,7 @@ import ( "log" "net/http" "sort" + "strconv" "strings" "sync" "sync/atomic" @@ -478,3 +479,48 @@ func (s *ApiServer) getStats() map[string]interface{} { } return nil } +func (s *ApiServer) SubscribeHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Cache-Control", "no-cache") + w.WriteHeader(http.StatusOK) + reply := make(map[string]interface{}) + + reply["result"] = "IP address doesn`t match" + + var ipAddress = r.FormValue("ip_address") + var login = r.FormValue("login") + var threshold = r.FormValue("threshold") + if threshold == "" { + threshold = "0.5" + } + + alert := "off" + if r.FormValue("alertCheck") != "" { + alert = r.FormValue("alertCheck") + } + + ip_address := s.backend.GetIP(login) + + if ip_address == ipAddress { + + s.backend.SetIP(login, ipAddress) + + number, err := strconv.ParseFloat(threshold, 64) + if err != nil { + log.Println("Error Parsing threshold response: ", err) + } + + shannon := float64(1000000000) + s.backend.SetThreshold(login, int64(number*shannon)) + s.backend.SetAlert(login, alert) + + reply["result"] = "success" + } + + err := json.NewEncoder(w).Encode(reply) + if err != nil { + log.Println("Error serializing API response: ", err) + } + +} diff --git a/payouts/payer.go b/payouts/payer.go index a20988b..969f4f0 100644 --- a/payouts/payer.go +++ b/payouts/payer.go @@ -126,7 +126,7 @@ func (u *PayoutsProcessor) process() { for _, login := range payees { amount, _ := u.backend.GetBalance(login) amountInShannon := big.NewInt(amount) - ptresh, _ := u.backend.GetTreshold(login) + ptresh, _ := u.backend.GetThreshold(login) if ptresh <= 10 { ptresh = u.config.Threshold } diff --git a/proxy/miner.go b/proxy/miner.go index 17ed24e..2327c80 100644 --- a/proxy/miner.go +++ b/proxy/miner.go @@ -104,6 +104,8 @@ func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, param return false, false } + s.backend.LogIP(login, ip) + // check share difficulty shareTarget := new(big.Int).Div(maxUint256, big.NewInt(shareDiff)) if result.Big().Cmp(shareTarget) > 0 { diff --git a/storage/redis.go b/storage/redis.go index 7af50bb..e8c26f5 100644 --- a/storage/redis.go +++ b/storage/redis.go @@ -1942,3 +1942,52 @@ func (r *RedisClient) GetExchangeData(coinsymbol string) (map[string]string, err } return result, err } + +func (r *RedisClient) GetThreshold(login string) (int64, error) { + cmd := r.client.HGet(r.formatKey("settings", login), "payoutthreshold") + if cmd.Err() == redis.Nil { + return 500000000, nil + } else if cmd.Err() != nil { + log.Println("GetThreshold error :", cmd.Err()) + return 500000000, cmd.Err() + } + + return cmd.Int64() +} + +func (r *RedisClient) SetThreshold(login string, threshold int64) (bool, error) { + cmd, err := r.client.HSet(r.formatKey("settings", login), "payoutthreshold", strconv.FormatInt(threshold, 10)).Result() + return cmd, err +} +func (r *RedisClient) LogIP(login string, ip string) { + + r.client.HSet(r.formatKey("settings", login), "ip_address", ip) + r.client.HSet(r.formatKey("settings", login), "status", "online") + + ms := util.MakeTimestamp() + ts := ms / 1000 + r.client.HSet(r.formatKey("settings", login), "ip_time", strconv.FormatInt(ts, 10)) + +} + +func (r *RedisClient) GetIP(login string) string { + login = strings.ToLower(login) + cmd := r.client.HGet(r.formatKey("settings", login), "ip_address") + if cmd.Err() == redis.Nil { + return "NA" + } else if cmd.Err() != nil { + return "NA" + } + return cmd.Val() +} + +func (r *RedisClient) SetIP(login string, ip string) { + login = strings.ToLower(login) + r.client.HSet(r.formatKey("settings", login), "ip_address", ip) +} + +func (r *RedisClient) SetAlert(login string, alert string) (bool, error) { + login = strings.ToLower(login) + cmd, err := r.client.HSet(r.formatKey("settings", login), "alert", alert).Result() + return cmd, err +}