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
/
info.go
95 lines (82 loc) · 2.5 KB
/
info.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
package render
import (
genModels "github.com/everstake/teztracker/gen/models"
"github.com/everstake/teztracker/models"
)
const annualYield = 7.12
// Info renders price info into OpenAPI model.
func Info(currency string, mi models.MarketInfo, ratio float64, blocks int64) *genModels.Info {
p := mi.GetPrice()
p24 := mi.GetPriceChange()
ratioInPercent := ratio * 100
vol := mi.GetVolume()
mc := mi.GetMarketCap()
return &genModels.Info{
Currency: currency,
Price: &p,
Price24hChange: &p24,
StakingRatio: &ratioInPercent,
AnnualYield: annualYield,
MarketCap: mc,
Volume24h: vol,
CirculatingSupply: mi.GetSupply(),
BlocksInCycle: blocks,
}
}
func ChartData(chd []models.ChartData) []*genModels.ChartsData {
chds := make([]*genModels.ChartsData, len(chd))
for i := range chd {
chds[i] = ChartElement(chd[i])
}
return chds
}
func ChartElement(chd models.ChartData) *genModels.ChartsData {
tm := chd.Timestamp.Unix()
data := &genModels.ChartsData{
Timestamp: &tm,
Activations: chd.Activations,
AverageDelay: chd.AverageDelay,
Blocks: chd.Blocks,
DelegationVolume: chd.DelegationVolume,
Fees: chd.Fees,
Operations: chd.Operations,
TransactionVolume: chd.TransactionVolume,
Bakers: chd.Bakers,
WhaleAccounts: chd.WhaleAccounts,
}
return data
}
func BakerChartData(chd []models.BakerChartData) []*genModels.BakerChartData {
chds := make([]*genModels.BakerChartData, len(chd))
for i := range chd {
chds[i] = BakerChartElement(chd[i])
}
return chds
}
func BakerChartElement(chd models.BakerChartData) *genModels.BakerChartData {
return &genModels.BakerChartData{
Baker: chd.Baker,
BakerName: chd.BakerName,
Rolls: chd.Rolls,
Percent: chd.Percent,
}
}
func BlocksPriorityChartData(chd []models.BlockPriority) []*genModels.BlockPriorityChartData {
chds := make([]*genModels.BlockPriorityChartData, len(chd))
for i := range chd {
chds[i] = BlocksPriorityChartElement(chd[i])
}
return chds
}
func BlocksPriorityChartElement(chd models.BlockPriority) *genModels.BlockPriorityChartData {
return &genModels.BlockPriorityChartData{
Cycle: &chd.Cycle,
CycleStart: GetUnixFromNullTime(chd.CycleStart),
CycleEnd: GetUnixFromNullTime(chd.CycleEnd),
Blocks: &chd.Blocks,
FirstPriority: &chd.FirstPriority,
SecondPriority: &chd.SecondPriority,
ZeroPriority: &chd.ZeroPriority,
ThirdPriority: &chd.ThirdPriority,
}
}