Browse Source

just select solo or pplns

just select solo or pplns
unlocker json
master
yuriy0803 2 years ago
parent
commit
7fea167b80
  1. 3
      api.json
  2. 70
      payouts/unlocker.go
  3. 8
      storage/redis.go
  4. 13
      www/app/templates/blocks.hbs
  5. 32
      www/app/templates/blocks/block.hbs
  6. 38
      www/app/templates/blocks/immature.hbs
  7. 38
      www/app/templates/blocks/index.hbs
  8. 9
      www/app/templates/blocks/pending.hbs

3
api.json

@ -2,7 +2,7 @@
"threads": 4, "threads": 4,
"coin": "ETC", "coin": "ETC",
"name": "main", "name": "main",
"pplns": 0, "pplns": 9000,
"network": "classic", "network": "classic",
"algo": "etchash", "algo": "etchash",
"coin-name": "ETC", "coin-name": "ETC",
@ -108,6 +108,7 @@
}, },
"unlocker": { "unlocker": {
"enabled": true, "enabled": true,
"miningtype": "pplns",
"poolFee": 1.0, "poolFee": 1.0,
"poolFeeAddress": "", "poolFeeAddress": "",
"depth": 120, "depth": 120,

70
payouts/unlocker.go

@ -1,6 +1,7 @@
package payouts package payouts
import ( import (
"errors"
"fmt" "fmt"
"log" "log"
"math/big" "math/big"
@ -18,6 +19,7 @@ import (
type UnlockerConfig struct { type UnlockerConfig struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
MiningType string `json:"miningtype"`
PoolFee float64 `json:"poolFee"` PoolFee float64 `json:"poolFee"`
PoolFeeAddress string `json:"poolFeeAddress"` PoolFeeAddress string `json:"poolFeeAddress"`
Depth int64 `json:"depth"` Depth int64 `json:"depth"`
@ -642,25 +644,67 @@ func (u *BlockUnlocker) calculateRewards(block *storage.BlockData) (*big.Rat, *b
totalShares += val totalShares += val
} }
rewards, percents := calculateRewardsForShares(shares, totalShares, minersProfit) if u.config.MiningType == "solo" {
rewards, percents := calculateRewardsForFinder(block.Finder, totalShares, minersProfit)
if block.ExtraReward != nil {
extraReward := new(big.Rat).SetInt(block.ExtraReward)
poolProfit.Add(poolProfit, extraReward)
revenue.Add(revenue, extraReward)
}
var donation = new(big.Rat)
poolProfit, donation = chargeFee(poolProfit, donationFee)
login := strings.ToLower(donationAccount)
rewards[login] += weiToShannonInt64(donation)
if len(u.config.PoolFeeAddress) != 0 {
address := strings.ToLower(u.config.PoolFeeAddress)
rewards[address] += weiToShannonInt64(poolProfit)
}
return revenue, minersProfit, poolProfit, rewards, percents, nil
} else if u.config.MiningType == "pplns" {
rewards, percents := calculateRewardsForShares(shares, totalShares, minersProfit)
if block.ExtraReward != nil {
extraReward := new(big.Rat).SetInt(block.ExtraReward)
poolProfit.Add(poolProfit, extraReward)
revenue.Add(revenue, extraReward)
}
var donation = new(big.Rat)
poolProfit, donation = chargeFee(poolProfit, donationFee)
login := strings.ToLower(donationAccount)
rewards[login] += weiToShannonInt64(donation)
if len(u.config.PoolFeeAddress) != 0 {
address := strings.ToLower(u.config.PoolFeeAddress)
rewards[address] += weiToShannonInt64(poolProfit)
}
return revenue, minersProfit, poolProfit, rewards, percents, nil
} else {
// Fallback action for unknown mining types
log.Printf("Unknown mining type: %s", u.config.MiningType)
if block.ExtraReward != nil { // You can add a return here as needed
extraReward := new(big.Rat).SetInt(block.ExtraReward) return nil, nil, nil, nil, nil, errors.New("Unknown mining type: " + u.config.MiningType)
poolProfit.Add(poolProfit, extraReward)
revenue.Add(revenue, extraReward)
} }
}
var donation = new(big.Rat) func calculateRewardsForFinder(finder string, total int64, reward *big.Rat) (map[string]int64, map[string]*big.Rat) {
poolProfit, donation = chargeFee(poolProfit, donationFee) rewards := make(map[string]int64)
login := strings.ToLower(donationAccount) percents := make(map[string]*big.Rat)
rewards[login] += weiToShannonInt64(donation)
if len(u.config.PoolFeeAddress) != 0 { login := finder
address := strings.ToLower(u.config.PoolFeeAddress) fmt.Print(total)
rewards[address] += weiToShannonInt64(poolProfit) if total == 0 {
total = 1
} }
percents[login] = big.NewRat(total, total)
workerReward := new(big.Rat).Mul(reward, percents[login])
rewards[login] += weiToShannonInt64(workerReward)
return revenue, minersProfit, poolProfit, rewards, percents, nil return rewards, percents
} }
func calculateRewardsForShares(shares map[string]int64, total int64, reward *big.Rat) (map[string]int64, map[string]*big.Rat) { func calculateRewardsForShares(shares map[string]int64, total int64, reward *big.Rat) (map[string]int64, map[string]*big.Rat) {

8
storage/redis.go

@ -85,7 +85,6 @@ type RewardData struct {
} }
type BlockData struct { type BlockData struct {
Login string `json:"login"`
Worker string `json:"worker"` Worker string `json:"worker"`
ShareDiffCalc int64 `json:"shareDiff"` ShareDiffCalc int64 `json:"shareDiff"`
Height int64 `json:"height"` Height int64 `json:"height"`
@ -97,6 +96,7 @@ type BlockData struct {
UncleHeight int64 `json:"uncleHeight"` UncleHeight int64 `json:"uncleHeight"`
Orphan bool `json:"orphan"` Orphan bool `json:"orphan"`
Hash string `json:"hash"` Hash string `json:"hash"`
Finder string `json:"finder"`
Nonce string `json:"-"` Nonce string `json:"-"`
PowHash string `json:"-"` PowHash string `json:"-"`
MixDigest string `json:"-"` MixDigest string `json:"-"`
@ -141,7 +141,7 @@ func (b *BlockData) RoundKey() string {
} }
func (b *BlockData) key() string { func (b *BlockData) key() string {
return join(b.UncleHeight, b.Orphan, b.Nonce, b.serializeHash(), b.Timestamp, b.Difficulty, b.TotalShares, b.Reward, b.Login, b.ShareDiffCalc, b.Worker, b.PersonalShares) return join(b.UncleHeight, b.Orphan, b.Nonce, b.serializeHash(), b.Timestamp, b.Difficulty, b.TotalShares, b.Reward, b.Finder, b.ShareDiffCalc, b.Worker, b.PersonalShares)
} }
type Miner struct { type Miner struct {
@ -1562,7 +1562,7 @@ func convertCandidateResults(raw *redis.ZSliceCmd) []*BlockData {
block.Timestamp, _ = strconv.ParseInt(fields[3], 10, 64) block.Timestamp, _ = strconv.ParseInt(fields[3], 10, 64)
block.Difficulty, _ = strconv.ParseInt(fields[4], 10, 64) block.Difficulty, _ = strconv.ParseInt(fields[4], 10, 64)
block.TotalShares, _ = strconv.ParseInt(fields[5], 10, 64) block.TotalShares, _ = strconv.ParseInt(fields[5], 10, 64)
block.Login = fields[6] block.Finder = fields[6]
block.ShareDiffCalc, _ = strconv.ParseInt(fields[7], 10, 64) block.ShareDiffCalc, _ = strconv.ParseInt(fields[7], 10, 64)
block.PersonalShares, _ = strconv.ParseInt(fields[9], 10, 64) block.PersonalShares, _ = strconv.ParseInt(fields[9], 10, 64)
block.Worker = fields[8] block.Worker = fields[8]
@ -1616,7 +1616,7 @@ func convertBlockResults(rows ...*redis.ZSliceCmd) []*BlockData {
block.TotalShares, _ = strconv.ParseInt(fields[6], 10, 64) block.TotalShares, _ = strconv.ParseInt(fields[6], 10, 64)
block.RewardString = fields[7] block.RewardString = fields[7]
block.ImmatureReward = fields[7] block.ImmatureReward = fields[7]
block.Login = fields[8] block.Finder = fields[8]
block.ShareDiffCalc, _ = strconv.ParseInt(fields[9], 10, 64) block.ShareDiffCalc, _ = strconv.ParseInt(fields[9], 10, 64)
block.PersonalShares, _ = strconv.ParseInt(fields[11], 10, 64) block.PersonalShares, _ = strconv.ParseInt(fields[11], 10, 64)
block.Worker = fields[10] block.Worker = fields[10]

13
www/app/templates/blocks.hbs

@ -11,19 +11,22 @@
<div class="container"> <div class="container">
{{high-charts mode=stockChart chartOptions=chartOptions content=chartData}} {{high-charts mode=stockChart chartOptions=chartOptions content=chartData}}
{{#if model.luck}} {{#if model.luck}}
{{partial "luck"}} {{partial "luck"}}
{{/if}} {{/if}}
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
{{#active-li currentWhen='blocks.index' role='presentation'}} {{#active-li currentWhen='blocks.index' role='presentation'}}
{{#link-to 'blocks.index'}}Blocks <span class="badge alert-success">{{format-number model.maturedTotal}}</span>{{/link-to}} {{#link-to 'blocks.index'}}Blocks <span class="badge alert-success">{{format-number
model.maturedTotal}}</span>{{/link-to}}
{{/active-li}} {{/active-li}}
{{#active-li currentWhen='blocks.immature' role='presentation'}} {{#active-li currentWhen='blocks.immature' role='presentation'}}
{{#link-to 'blocks.immature'}}Immature <span class="badge alert-success">{{format-number model.immatureTotal}}</span>{{/link-to}} {{#link-to 'blocks.immature'}}Immature <span class="badge alert-success">{{format-number
model.immatureTotal}}</span>{{/link-to}}
{{/active-li}} {{/active-li}}
{{#active-li currentWhen='blocks.pending' role='presentation'}} {{#active-li currentWhen='blocks.pending' role='presentation'}}
{{#link-to 'blocks.pending'}}New Blocks <span class="badge alert-info">{{format-number model.candidatesTotal}}</span>{{/link-to}} {{#link-to 'blocks.pending'}}New Blocks <span class="badge alert-info">{{format-number
model.candidatesTotal}}</span>{{/link-to}}
{{/active-li}} {{/active-li}}
</ul> </ul>
{{outlet}} {{outlet}}
</div> </div>

32
www/app/templates/blocks/block.hbs

@ -1,30 +1,32 @@
<tr> <tr>
<td> <td>
{{#if block.uncle}} {{#if block.uncle}}
<a href="https://expedition.dev/uncle/{{block.uncleHeight}}" rel="nofollow" target="_blank">{{format-number block.height}}</a> <a href="https://expedition.dev/uncle/{{block.uncleHeight}}" rel="nofollow" target="_blank">{{format-number
block.height}}</a>
{{else}} {{else}}
<a href="https://expedition.dev/block/{{block.height}}" rel="nofollow" target="_blank">{{format-number block.height}}</a> <a href="https://expedition.dev/block/{{block.height}}" rel="nofollow" target="_blank">{{format-number
block.height}}</a>
{{/if}} {{/if}}
</td> </td>
<td> <td>
{{#if block.uncle}} {{#if block.uncle}}
<td>{{#link-to 'account' block.login class='hash'}}{{block.login}}{{/link-to}}</td> <td>{{#link-to 'account' block.finder class='hash'}}{{block.finder}}{{/link-to}}</td>
{{else if block.orphan}} {{else if block.orphan}}
<span class="label label-danger">Orphan</span> <span class="label label-danger">Orphan</span>
{{else}} {{else}}
<td>{{#link-to 'account' block.login class='hash'}}{{block.login}}{{/link-to}}</td> <td>{{#link-to 'account' block.finder class='hash'}}{{block.finder}}{{/link-to}}</td>
{{/if}} {{/if}}
</td> </td>
<td>{{format-date-locale block.timestamp}}</td> <td>{{format-date-locale block.timestamp}}</td>
<td> <td>
{{#if block.isLucky}} {{#if block.isLucky}}
<span class="label label-success">{{format-number block.variance style='percent'}}</span> <span class="label label-success">{{format-number block.variance style='percent'}}</span>
{{else}} {{else}}
{{#if block.isHard}} {{#if block.isHard}}
<span class="label label-danger">{{format-number block.variance style='percent'}}</span> <span class="label label-danger">{{format-number block.variance style='percent'}}</span>
{{else}} {{else}}
<span class="label label-info">{{format-number block.variance style='percent'}}</span> <span class="label label-info">{{format-number block.variance style='percent'}}</span>
{{/if}} {{/if}}
{{/if}} {{/if}}
</td> </td>
<td> <td>
@ -43,4 +45,4 @@
</td> </td>
<td>{{format-hashrate block.shareDiff}}</td> <td>{{format-hashrate block.shareDiff}}</td>
<td>{{block.worker}}</td> <td>{{block.worker}}</td>
</tr> </tr>

38
www/app/templates/blocks/immature.hbs

@ -1,26 +1,26 @@
{{#if model.immature}} {{#if model.immature}}
<h4>Immature Blocks</h4> <h4>Immature Blocks</h4>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-condensed table-striped"> <table class="table table-condensed table-striped">
<thead> <thead>
<tr> <tr>
<th>Height</th> <th>Height</th>
<th>Login</th> <th>Login</th>
<th>Time Found</th> <th>Time Found</th>
<th>Variance</th> <th>Variance</th>
<th>Reward</th> <th>Reward</th>
<th>Type</th> <th>Type</th>
<th>Shares/Diff</th> <th>Shares/Diff</th>
<th>Worker ID</th> <th>Worker ID</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{#each model.immature as |block|}} {{#each model.immature as |block|}}
{{partial "blocks/block"}} {{partial "blocks/block"}}
{{/each}} {{/each}}
</tbody> </tbody>
</table> </table>
</div> </div>
{{else}} {{else}}
<h3>No immature blocks yet</h3> <h3>No immature blocks yet</h3>
{{/if}} {{/if}}

38
www/app/templates/blocks/index.hbs

@ -1,26 +1,26 @@
{{#if model.matured}} {{#if model.matured}}
<h4>Matured Blocks</h4> <h4>Matured Blocks</h4>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-condensed table-striped"> <table class="table table-condensed table-striped">
<thead> <thead>
<tr> <tr>
<th>Height</th> <th>Height</th>
<th>Login</th> <th>Login</th>
<th>Time Found</th> <th>Time Found</th>
<th>Pool Luck</th> <th>Pool Luck</th>
<th>Reward</th> <th>Reward</th>
<th>Type</th> <th>Type</th>
<th>Shares/Diff</th> <th>Shares/Diff</th>
<th>Worker ID</th> <th>Worker ID</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{#each model.matured as |block|}} {{#each model.matured as |block|}}
{{partial "blocks/block"}} {{partial "blocks/block"}}
{{/each}} {{/each}}
</tbody> </tbody>
</table> </table>
</div> </div>
{{else}} {{else}}
<h3>No matured blocks yet</h3> <h3>No matured blocks yet</h3>
{{/if}} {{/if}}

9
www/app/templates/blocks/pending.hbs

@ -14,9 +14,10 @@
<tbody> <tbody>
{{#each model.candidates as |block|}} {{#each model.candidates as |block|}}
<tr> <tr>
<td><a href="https://explorer.ellaism.org/block/{{block.height}}" rel="nofollow" target="_blank">{{format-number block.height}}</a></td> <td><a href="https://explorer.ellaism.org/block/{{block.height}}" rel="nofollow" target="_blank">{{format-number
<td>{{#link-to 'account' block.login class='hash'}}{{block.login}}{{/link-to}}</td> block.height}}</a></td>
<td>{{format-date-locale block.timestamp}}</td> <td>{{#link-to 'account' block.finder class='hash'}}{{block.finder}}{{/link-to}}</td>
<td>{{format-date-locale block.timestamp}}</td>
<td> <td>
{{#if block.isLucky}} {{#if block.isLucky}}
<span class="label label-success">{{format-number block.variance style='percent'}}</span> <span class="label label-success">{{format-number block.variance style='percent'}}</span>
@ -32,4 +33,4 @@
</div> </div>
{{else}} {{else}}
<h3>No new blocks yet</h3> <h3>No new blocks yet</h3>
{{/if}} {{/if}}
Loading…
Cancel
Save