-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
35 lines (31 loc) · 903 Bytes
/
helpers.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
package types
import "sort"
type OracleTask struct {
OracleScriptID uint64
Symbols []string
}
func CalculateGas(base, each, n uint64) uint64 {
return base + each*n
}
func ComputeOracleTasks(symbols []SymbolRequest, blockHeight int64) []OracleTask {
symbolMap := make(map[uint64][]string)
// stays the same
for _, symbol := range symbols {
if symbol.BlockInterval != 0 && blockHeight%int64(symbol.BlockInterval) == 0 {
symbolMap[symbol.OracleScriptID] = append(symbolMap[symbol.OracleScriptID], symbol.Symbol)
}
}
tasks := make([]OracleTask, 0, len(symbolMap))
// directly create tasks
for oracleScriptID, symbols := range symbolMap {
tasks = append(tasks, OracleTask{
OracleScriptID: oracleScriptID,
Symbols: symbols,
})
}
// sort them
sort.Slice(tasks, func(i, j int) bool {
return tasks[i].OracleScriptID < tasks[j].OracleScriptID
})
return tasks
}