blob: 373e902ad5aaf5b17b4d168fd462514a8e61abad (
plain) (
blame)
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
|
package rawdb
import (
"bytes"
"github.com/tangerine-network/go-tangerine/log"
"github.com/tangerine-network/go-tangerine/rlp"
coreDb "github.com/tangerine-network/tangerine-consensus/core/db"
)
func ReadCoreDKGProtocolRLP(db DatabaseReader) rlp.RawValue {
data, _ := db.Get(coreDKGProtocolKey)
return data
}
func WriteCoreDKGProtocolRLP(db DatabaseWriter, rlp rlp.RawValue) error {
err := db.Put(coreDKGProtocolKey, rlp)
if err != nil {
log.Crit("Failed to store core DKG private key", "err", err)
}
return err
}
func ReadCoreDKGProtocol(db DatabaseReader) *coreDb.DKGProtocolInfo {
data := ReadCoreDKGProtocolRLP(db)
if len(data) == 0 {
return nil
}
protocol := new(coreDb.DKGProtocolInfo)
if err := rlp.Decode(bytes.NewReader(data), protocol); err != nil {
log.Error("Invalid core DKG protocol RLP", "err", err)
return nil
}
return protocol
}
func WriteCoreDKGProtocol(db DatabaseWriter, protocol *coreDb.DKGProtocolInfo) error {
data, err := rlp.EncodeToBytes(protocol)
if err != nil {
log.Crit("Failed to RLP encode core DKG protocol", "err", err)
return err
}
return WriteCoreDKGProtocolRLP(db, data)
}
|