This repository has been archived by the owner on Nov 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
account_baking.go
111 lines (83 loc) · 2.74 KB
/
account_baking.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package services
import (
"github.com/everstake/teztracker/models"
)
func (t *TezTracker) GetAccountBakingList(accountID string, limits Limiter) (count int64, list []models.AccountBaking, err error) {
lastBlock, err := t.repoProvider.GetBlock().Last()
if err != nil {
return 0, nil, err
}
count, list, err = t.repoProvider.GetBaking().BakingList(accountID, limits.Limit(), limits.Offset())
if err != nil {
return 0, nil, err
}
for i := range list {
list[i].Status = getRewardStatus(list[i].Cycle, lastBlock.MetaCycle)
list[i].TotalDeposit = (list[i].Stolen + list[i].Count) * getBlockSecurityDepositByCycle(list[i].Cycle)
}
return count, list, nil
}
func (t *TezTracker) GetAccountFutureBakingList(accountID string) (list []models.AccountBaking, err error) {
lastBlock, err := t.repoProvider.GetBlock().Last()
if err != nil {
return list, err
}
list, err = t.repoProvider.GetBaking().FutureBakingList(accountID)
if err != nil {
return nil, err
}
for i := range list {
list[i].Status = getRewardStatus(list[i].Cycle, lastBlock.MetaCycle)
list[i].TotalDeposit = list[i].Count * getBlockSecurityDepositByCycle(list[i].Cycle)
list[i].Reward = list[i].Count * getBlockRewardByCycle(list[i].Cycle, 0)
}
return list, nil
}
func (t *TezTracker) GetAccountBakedBlocksList(accountID string, cycle int64, limits Limiter) (count int64, list []models.Block, err error) {
count, list, err = t.repoProvider.GetBlock().BakedBlocksList(accountID, cycle, limits.Limit(), limits.Offset())
if err != nil {
return 0, nil, err
}
for i := range list {
list[i].Deposit = getBlockSecurityDepositByCycle(list[i].MetaCycle)
}
return count, list, nil
}
func (t *TezTracker) GetAccountBakingTotal(accountID string) (total models.AccountBaking, err error) {
total, err = t.repoProvider.GetBaking().BakingTotal(accountID)
if err != nil {
return total, err
}
total.TotalDeposit = (total.Stolen + total.Count) * getBlockSecurityDepositByCycle(total.Cycle)
return total, nil
}
func getBlockSecurityDepositByCycle(cycle int64) int64 {
if cycle < GranadaCycle {
return FlorenceBlockSecurityDeposit
}
return GranadaBlockSecurityDeposit
}
func getBlockRewardByCycle(cycle, priority int64) int64 {
if priority == 0 {
if cycle < GranadaCycle {
return FlorenceBlockReward
}
return GranadaBlockReward
}
if cycle < GranadaCycle {
return FlorenceLowPriorityBlockReward
}
return GradanaLowPriorityBlockReward
}
func getEndorsementSecurityDepositByCycle(cycle int64) int64 {
if cycle < GranadaCycle {
return FlorenceEndorsementSecurityDeposit
}
return GranadaEndorsementSecurityDeposit
}
func getEndorsementRewardByCycle(cycle int64) int64 {
if cycle < GranadaCycle {
return FlorenceEndorsementReward
}
return GranadaEndorsementReward
}