channeldb/codec: add privateKey serialization

This commit is contained in:
Johan T. Halseth 2019-05-23 20:05:26 +02:00
parent 2417f40532
commit f022810f8b
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

View File

@ -148,6 +148,12 @@ func WriteElement(w io.Writer, element interface{}) error {
return err
}
case *btcec.PrivateKey:
b := e.Serialize()
if _, err := w.Write(b); err != nil {
return err
}
case *btcec.PublicKey:
b := e.SerializeCompressed()
if _, err := w.Write(b); err != nil {
@ -320,6 +326,15 @@ func ReadElement(r io.Reader, element interface{}) error {
*e = lnwire.MilliSatoshi(a)
case **btcec.PrivateKey:
var b [btcec.PrivKeyBytesLen]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
}
priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), b[:])
*e = priv
case **btcec.PublicKey:
var b [btcec.PubKeyBytesLenCompressed]byte
if _, err := io.ReadFull(r, b[:]); err != nil {