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,
"coin": "ETC",
"name": "main",
"pplns": 0,
"pplns": 9000,
"network": "classic",
"algo": "etchash",
"coin-name": "ETC",
@ -108,6 +108,7 @@
},
"unlocker": {
"enabled": true,
"miningtype": "pplns",
"poolFee": 1.0,
"poolFeeAddress": "",
"depth": 120,

70
payouts/unlocker.go

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

8
storage/redis.go

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

13
www/app/templates/blocks.hbs

@ -11,19 +11,22 @@
<div class="container">
{{high-charts mode=stockChart chartOptions=chartOptions content=chartData}}
{{#if model.luck}}
{{partial "luck"}}
{{partial "luck"}}
{{/if}}
<ul class="nav nav-tabs">
{{#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 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 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}}
</ul>
{{outlet}}
</div>
</div>

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

@ -1,30 +1,32 @@
<tr>
<td>
{{#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}}
<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}}
</td>
<td>
{{#if block.uncle}}
<td>{{#link-to 'account' block.login class='hash'}}{{block.login}}{{/link-to}}</td>
{{else if block.orphan}}
<span class="label label-danger">Orphan</span>
{{else}}
<td>{{#link-to 'account' block.login class='hash'}}{{block.login}}{{/link-to}}</td>
{{/if}}
<td>{{#link-to 'account' block.finder class='hash'}}{{block.finder}}{{/link-to}}</td>
{{else if block.orphan}}
<span class="label label-danger">Orphan</span>
{{else}}
<td>{{#link-to 'account' block.finder class='hash'}}{{block.finder}}{{/link-to}}</td>
{{/if}}
</td>
<td>{{format-date-locale block.timestamp}}</td>
<td>
{{#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}}
{{#if block.isHard}}
<span class="label label-danger">{{format-number block.variance style='percent'}}</span>
{{else}}
<span class="label label-info">{{format-number block.variance style='percent'}}</span>
{{/if}}
{{#if block.isHard}}
<span class="label label-danger">{{format-number block.variance style='percent'}}</span>
{{else}}
<span class="label label-info">{{format-number block.variance style='percent'}}</span>
{{/if}}
{{/if}}
</td>
<td>
@ -43,4 +45,4 @@
</td>
<td>{{format-hashrate block.shareDiff}}</td>
<td>{{block.worker}}</td>
</tr>
</tr>

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

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

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

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

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

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