Browse Source

settings payoutthreshold

master
yuriy0803 2 years ago
parent
commit
5aecfe2871
  1. 46
      api/server.go
  2. 2
      payouts/payer.go
  3. 2
      proxy/miner.go
  4. 49
      storage/redis.go

46
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)
}
}

2
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
}

2
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 {

49
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
}

Loading…
Cancel
Save