diff options
Diffstat (limited to 'core/rawdb/accessors_core_dkg_protocol.go')
-rw-r--r-- | core/rawdb/accessors_core_dkg_protocol.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/core/rawdb/accessors_core_dkg_protocol.go b/core/rawdb/accessors_core_dkg_protocol.go new file mode 100644 index 000000000..ba087b00d --- /dev/null +++ b/core/rawdb/accessors_core_dkg_protocol.go @@ -0,0 +1,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) +} |