forked from eosspark/geos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
producer_schedule.go
67 lines (57 loc) · 1.62 KB
/
producer_schedule.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
package types
import (
"github.com/zhangsifeng92/geos/common"
"github.com/zhangsifeng92/geos/crypto/ecc"
)
type ProducerKey struct {
ProducerName common.AccountName `json:"producer_name"`
BlockSigningKey ecc.PublicKey `json:"block_signing_key"`
}
type ProducerScheduleType struct {
Version uint32 `json:"version"`
Producers []ProducerKey `json:"producers"`
}
func (ps *ProducerScheduleType) GetProducerKey(p common.AccountName) (ecc.PublicKey, bool) {
for _, i := range ps.Producers {
if i.ProducerName == p {
return i.BlockSigningKey, true
}
}
return ecc.PublicKey{}, false
}
type SharedProducerScheduleType struct {
Version uint32
Producers []ProducerKey
}
func (spst *SharedProducerScheduleType) Clear() {
spst.Version = 0
spst.Producers = []ProducerKey{}
}
func (s *SharedProducerScheduleType) SharedProducerScheduleType(a ProducerScheduleType) *SharedProducerScheduleType {
s.Version = a.Version
s.Producers = nil
for i := 0; i < len(a.Producers); i++ {
s.Producers = append(s.Producers, a.Producers[i])
}
return s
}
func (s *SharedProducerScheduleType) ProducerScheduleType() *ProducerScheduleType {
var result = ProducerScheduleType{}
result.Version = s.Version
if len(result.Producers) == 0 {
result.Producers = s.Producers
} else {
var step = len(result.Producers)
for _, p := range s.Producers {
result.Producers = append(result.Producers, p)
step++
}
}
return &result
}
func (p SharedProducerScheduleType) IsEmpty() bool {
return p.Version == 0 && len(p.Producers) == 0
}
func (p ProducerScheduleType) IsEmpty() bool {
return p.Version == 0 && len(p.Producers) == 0
}