-
Notifications
You must be signed in to change notification settings - Fork 5
/
bonus.go
74 lines (61 loc) · 1.71 KB
/
bonus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"github.com/eoscanada/eos-go"
"strconv"
)
type PlayerStats struct {
Player string `json:"player"`
SessionsCreated uint64 `json:"sessions_created"`
VolumeReal eos.Asset `json:"volume_real"`
VolumeBonus eos.Asset `json:"volume_bonus"`
ProfitReal eos.Asset `json:"profit_real"`
ProfitBonus eos.Asset `json:"profit_bonus"`
}
type PlayerBalance struct {
Player string `json:"player"`
Balance eos.Asset `json:"balance"`
}
func (app *App) getBonusPlayersStats(lastPlayer string) ([]PlayerStats, error) {
resp, err := app.bcAPI.GetTableRows(eos.GetTableRowsRequest{
Code: string(app.BlockChain.CasinoAccountName),
Scope: string(app.BlockChain.CasinoAccountName),
Table: "playerstats",
LowerBound: strconv.FormatUint(nextPlayer(lastPlayer), 10),
Limit: 100,
JSON: true,
})
if err != nil {
return nil, err
}
var playerStats []PlayerStats
err = resp.JSONToStructs(&playerStats)
if err != nil {
return nil, err
}
return playerStats, nil
}
func (app *App) getBonusPlayersBalance(lastPlayer string) ([]PlayerBalance, error) {
resp, err := app.bcAPI.GetTableRows(eos.GetTableRowsRequest{
Code: string(app.BlockChain.CasinoAccountName),
Scope: string(app.BlockChain.CasinoAccountName),
LowerBound: strconv.FormatUint(nextPlayer(lastPlayer), 10),
Table: "bonusbalance",
Limit: 100,
JSON: true,
})
if err != nil {
return nil, err
}
var playersBalance []PlayerBalance
err = resp.JSONToStructs(&playersBalance)
if err != nil {
return nil, err
}
return playersBalance, nil
}
func nextPlayer(player string) uint64 {
if player == "" {
return 0
}
return eos.MustStringToName(player) + 1
}