blob: ba087b00d5a71094b400a4eb0933e71d15195417 (
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"
coreDb "github.com/dexon-foundation/dexon-consensus/core/db"
"github.com/dexon-foundation/dexon/log"
"github.com/dexon-foundation/dexon/rlp"
)
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)
}
|