From 54dac9db73cc9a9c8fb426e7a1b33a219ef98d43 Mon Sep 17 00:00:00 2001 From: yuriy0803 Date: Fri, 2 Sep 2022 18:01:15 +0200 Subject: [PATCH] Per miner payout treshold --- payouts/payer.go | 10 +++++++--- storage/redis.go | 10 ++++++++++ www/app/helpers/format-hashrate.js | 2 +- www/app/templates/account.hbs | 5 +++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/payouts/payer.go b/payouts/payer.go index bb7e230..a8cedf6 100644 --- a/payouts/payer.go +++ b/payouts/payer.go @@ -132,11 +132,15 @@ func (u *PayoutsProcessor) process() { for _, login := range payees { amount, _ := u.backend.GetBalance(login) amountInShannon := big.NewInt(amount) + ptresh, _ := u.backend.GetTreshold(login) + if ptresh <= 10 { + ptresh = u.config.Threshold + } // Shannon^2 = Wei amountInWei := new(big.Int).Mul(amountInShannon, util.Shannon) - if !u.reachedThreshold(amountInShannon) { + if !u.reachedThreshold(amountInShannon, ptresh) { continue } mustPay++ @@ -285,8 +289,8 @@ func (self PayoutsProcessor) checkPeers() bool { return true } -func (self PayoutsProcessor) reachedThreshold(amount *big.Int) bool { - return big.NewInt(self.config.Threshold).Cmp(amount) < 0 +func (self PayoutsProcessor) reachedThreshold(amount *big.Int, threshold int64) bool { + return big.NewInt(threshold).Cmp(amount) < 0 } func formatPendingPayments(list []*storage.PendingPayment) string { diff --git a/storage/redis.go b/storage/redis.go index 9351a59..cc147ac 100644 --- a/storage/redis.go +++ b/storage/redis.go @@ -758,6 +758,16 @@ func (r *RedisClient) GetBalance(login string) (int64, error) { return cmd.Int64() } +func (r *RedisClient) GetTreshold(login string) (int64, error) { + cmd := r.client.HGet(r.formatKey("miners", login), "payouttreshold") + if cmd.Err() == redis.Nil { + return 0, nil + } else if cmd.Err() != nil { + return 0, cmd.Err() + } + return cmd.Int64() +} + func (r *RedisClient) LockPayouts(login string, amount int64) error { key := r.formatKey("payments", "lock") result := r.client.SetNX(key, join(login, amount), 0).Val() diff --git a/www/app/helpers/format-hashrate.js b/www/app/helpers/format-hashrate.js index 11e4524..73f75c5 100644 --- a/www/app/helpers/format-hashrate.js +++ b/www/app/helpers/format-hashrate.js @@ -3,7 +3,7 @@ import Ember from 'ember'; export function formatHashrate(params/*, hash*/) { var hashrate = params[0]; var i = 0; - var units = ['H', 'KH', 'MH', 'GH', 'TH', 'PH']; + var units = ['H/s', 'KH/s', 'MH/s', 'GH/s', 'TH/s', 'PH/s']; while (hashrate > 1000) { hashrate = hashrate / 1000; i++; diff --git a/www/app/templates/account.hbs b/www/app/templates/account.hbs index 6b3594a..9bca454 100644 --- a/www/app/templates/account.hbs +++ b/www/app/templates/account.hbs @@ -11,6 +11,11 @@ Pending Balance: {{format-balance model.stats.balance}}
Credited coins awaiting payout. + {{#if model.stats.payouttreshold}} +
+ Payout Treshold: {{format-balance model.stats.payouttreshold}}
+
+ {{/if}} {{#if model.stats.pending}}
Current Payment: {{format-balance model.stats.pending}}