Browse Source

Block finders

master
yuriy0803 5 years ago
parent
commit
c96ef0346c
  1. 32
      api/server.go
  2. 15
      storage/redis.go
  3. 1
      www/app/router.js
  4. 17
      www/app/routes/finders.js
  5. 42
      www/app/styles/app.css
  6. 5
      www/app/templates/application.hbs
  7. 28
      www/app/templates/finders.hbs

32
api/server.go

@ -2,7 +2,7 @@ package api
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"sort" "sort"
@ -12,7 +12,7 @@ import (
"time" "time"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/robfig/cron" "github.com/robfig/cron"
"github.com/yuriy0803/open-etc-pool-friends/storage" "github.com/yuriy0803/open-etc-pool-friends/storage"
"github.com/yuriy0803/open-etc-pool-friends/util" "github.com/yuriy0803/open-etc-pool-friends/util"
@ -101,7 +101,7 @@ func (s *ApiServer) Start() {
} }
} }
}() }()
go func() { go func() {
c := cron.New() c := cron.New()
@ -165,6 +165,7 @@ func (s *ApiServer) collectMinerCharts(login string, hash int64, largeHash int64
func (s *ApiServer) listen() { func (s *ApiServer) listen() {
r := mux.NewRouter() r := mux.NewRouter()
r.HandleFunc("/api/finders", s.FindersIndex)
r.HandleFunc("/api/stats", s.StatsIndex) r.HandleFunc("/api/stats", s.StatsIndex)
r.HandleFunc("/api/miners", s.MinersIndex) r.HandleFunc("/api/miners", s.MinersIndex)
r.HandleFunc("/api/blocks", s.BlocksIndex) r.HandleFunc("/api/blocks", s.BlocksIndex)
@ -213,6 +214,25 @@ func (s *ApiServer) collectStats() {
log.Printf("Stats collection finished %s", time.Since(start)) log.Printf("Stats collection finished %s", time.Since(start))
} }
func (s *ApiServer) FindersIndex(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{})
stats := s.getStats()
if stats != nil {
reply["now"] = util.MakeTimestamp()
reply["finders"] = stats["finders"]
}
err := json.NewEncoder(w).Encode(reply)
if err != nil {
log.Println("Error serializing API response: ", err)
}
}
func (s *ApiServer) StatsIndex(w http.ResponseWriter, r *http.Request) { func (s *ApiServer) StatsIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
@ -230,7 +250,7 @@ func (s *ApiServer) StatsIndex(w http.ResponseWriter, r *http.Request) {
if stats != nil { if stats != nil {
reply["now"] = util.MakeTimestamp() reply["now"] = util.MakeTimestamp()
reply["stats"] = stats["stats"] reply["stats"] = stats["stats"]
reply["poolCharts"] = stats["poolCharts"] reply["poolCharts"] = stats["poolCharts"]
reply["hashrate"] = stats["hashrate"] reply["hashrate"] = stats["hashrate"]
reply["minersTotal"] = stats["minersTotal"] reply["minersTotal"] = stats["minersTotal"]
reply["maturedTotal"] = stats["maturedTotal"] reply["maturedTotal"] = stats["maturedTotal"]
@ -349,8 +369,8 @@ func (s *ApiServer) AccountIndex(w http.ResponseWriter, r *http.Request) {
stats[key] = value stats[key] = value
} }
stats["pageSize"] = s.config.Payments stats["pageSize"] = s.config.Payments
stats["minerCharts"], err = s.backend.GetMinerCharts(s.config.MinerChartsNum, login) stats["minerCharts"], err = s.backend.GetMinerCharts(s.config.MinerChartsNum, login)
stats["paymentCharts"], err = s.backend.GetPaymentCharts(login) stats["paymentCharts"], err = s.backend.GetPaymentCharts(login)
reply = &Entry{stats: stats, updatedAt: now} reply = &Entry{stats: stats, updatedAt: now}
s.miners[login] = reply s.miners[login] = reply
} }

15
storage/redis.go

@ -923,6 +923,7 @@ func (r *RedisClient) CollectStats(smallWindow time.Duration, maxBlocks, maxPaym
tx.HGet(r.formatKey("paymentsTotal"), "all") tx.HGet(r.formatKey("paymentsTotal"), "all")
tx.ZRevRangeWithScores(r.formatKey("payments", "all"), 0, maxPayments-1) tx.ZRevRangeWithScores(r.formatKey("payments", "all"), 0, maxPayments-1)
tx.LLen(r.formatKey("lastshares")) tx.LLen(r.formatKey("lastshares"))
tx.ZRevRangeWithScores(r.formatKey("finders"), 0, -1)
return nil return nil
}) })
@ -949,6 +950,9 @@ func (r *RedisClient) CollectStats(smallWindow time.Duration, maxBlocks, maxPaym
stats["payments"] = payments stats["payments"] = payments
stats["paymentsTotal"], _ = cmds[9].(*redis.StringCmd).Int64() stats["paymentsTotal"], _ = cmds[9].(*redis.StringCmd).Int64()
finders := convertFindersResults(cmds[12].(*redis.ZSliceCmd))
stats["finders"] = finders
totalHashrate, miners := convertMinersStats(window, cmds[1].(*redis.ZSliceCmd)) totalHashrate, miners := convertMinersStats(window, cmds[1].(*redis.ZSliceCmd))
stats["miners"] = miners stats["miners"] = miners
stats["minersTotal"] = len(miners) stats["minersTotal"] = len(miners)
@ -1264,6 +1268,17 @@ func convertPaymentsResults(raw *redis.ZSliceCmd) []map[string]interface{} {
return result return result
} }
func convertFindersResults(raw *redis.ZSliceCmd) []map[string]interface{} {
var result []map[string]interface{}
for _, v := range raw.Val() {
miner := make(map[string]interface{})
miner["blocks"] = int64(v.Score)
miner["address"] = v.Member.(string)
result = append(result, miner)
}
return result
}
/* /*
Timestamp int64 `json:"x"` Timestamp int64 `json:"x"`
TimeFormat string `json:"timeFormat"` TimeFormat string `json:"timeFormat"`

1
www/app/router.js

@ -20,6 +20,7 @@ Router.map(function() {
this.route('help'); this.route('help');
this.route('payments'); this.route('payments');
this.route('miners'); this.route('miners');
this.route('finders');
this.route('about'); this.route('about');
this.route('chart'); this.route('chart');
}); });

17
www/app/routes/finders.js

@ -0,0 +1,17 @@
import Ember from 'ember';
import config from '../config/environment';
export default Ember.Route.extend({
model: function() {
var url = config.APP.ApiUrl + 'api/finders';
return Ember.$.getJSON(url).then(function(data) {
data.findersTotal = data.finders.length;
return data;
});
},
setupController: function(controller, model) {
this._super(controller, model);
Ember.run.later(this, this.refresh, 5000);
}
});

42
www/app/styles/app.css

@ -34,48 +34,6 @@ body {
body > .container { body > .container {
padding: 0px 15px 0; padding: 0px 15px 0;
} }
/* doesn't work -------- */
#coin_calculator iframe form{
border:none !important;
border-radius: 0px !important;
background-color: transparent !important;
}
/* Menu CSS Stuff */
.navbar-fixed-bottom .navbar-collapse, .navbar-fixed-top .navbar-collapse {
max-height: unset;
}
.navbar-collapse.in{
overflow: visible;
}
h1 {
font-size: 36px;
line-height: 42px;
}
h2 {
font-size: 24px;
line-height: 32px;
}
h1, h2, h3, h4, h5, h6 {
color: #fff;
margin: 0px 0px 15px 0px;
font-weight: 400;
font-family: 'Poppins', sans-serif;
}
.modal-title{
color:#333;
}
.container .text-muted { .container .text-muted {
margin: 20px 0; margin: 20px 0;
} }

5
www/app/templates/application.hbs

@ -36,6 +36,11 @@
<i class="fa fa-users"></i> Miners <i class="fa fa-users"></i> Miners
{{/link-to}} {{/link-to}}
{{/active-li}} {{/active-li}}
{{#active-li currentWhen='finders'}}
{{#link-to 'finders'}}
<i class="fa fa-diamond"></i> Finders
{{/link-to}}
{{/active-li}}
{{#active-li currentWhen='help' }} {{#active-li currentWhen='help' }}
{{#link-to 'help'}} {{#link-to 'help'}}
<i class="fa fa-rocket"></i> Help <i class="fa fa-rocket"></i> Help

28
www/app/templates/finders.hbs

@ -0,0 +1,28 @@
<div class="jumbotron">
<div class="container">
<strong>Miners on the list:</strong> <span class="label label-info">{{model.findersTotal}}</span>
</div>
</div>
<div class="container">
{{#if model.finders}}
<h4>Block finders</h4>
<table class="table table-condensed table-striped">
<thead>
<tr>
<th>Miner</th>
<th>Blocks</th>
</tr>
</thead>
<tbody>
{{#each model.finders as |f|}}
<tr>
<td>{{#link-to 'account' f.address class='hash'}}{{f.address}}{{/link-to}}</td>
<td>{{format-number f.blocks}}</td>
</tr>
{{/each}}
</tbody>
</table>
{{else}}
<h3>No blocks yet</h3>
{{/if}}
</div>
Loading…
Cancel
Save