-
Notifications
You must be signed in to change notification settings - Fork 9
/
consuls.go
78 lines (62 loc) · 1.55 KB
/
consuls.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
package query
import (
"encoding/json"
"github.com/Gravity-Tech/gravity-core/common/account"
"github.com/Gravity-Tech/gravity-core/common/storage"
)
type SignByConsulRq struct {
ConsulPubKey string
ChainType account.ChainType
NebulaId string
RoundId int64
}
func consuls(store *storage.Storage) ([]storage.Consul, error) {
v, err := store.Consuls()
if err != nil && err != storage.ErrKeyNotFound {
return nil, err
}
return v, nil
}
func consulsCandidate(store *storage.Storage) ([]storage.Consul, error) {
v, err := store.ConsulsCandidate()
if err != nil && err != storage.ErrKeyNotFound {
return nil, err
}
return v, nil
}
func signNewConsulsByConsul(store *storage.Storage, value []byte) ([]byte, error) {
var rq SignByConsulRq
err := json.Unmarshal(value, &rq)
if err != nil {
return nil, err
}
consul, err := account.HexToValidatorPubKey(rq.ConsulPubKey)
if err != nil {
return nil, err
}
v, err := store.SignConsulsByConsul(consul, rq.ChainType, rq.RoundId)
if err != nil {
return nil, err
}
return v, nil
}
func signNewOraclesByConsul(store *storage.Storage, value []byte) ([]byte, error) {
var rq SignByConsulRq
err := json.Unmarshal(value, &rq)
if err != nil {
return nil, err
}
consul, err := account.HexToValidatorPubKey(rq.ConsulPubKey)
if err != nil {
return nil, err
}
nebula, err := account.StringToNebulaId(rq.NebulaId, rq.ChainType)
if err != nil {
return nil, err
}
v, err := store.SignOraclesByConsul(consul, nebula, rq.RoundId)
if err != nil {
return nil, err
}
return v, nil
}