2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-04 06:00:21 +00:00

loopdb: allow restored databases to contain nil values

This commit is contained in:
Joost Jager 2020-06-23 12:40:35 +02:00
parent 3e71ff0c81
commit eaf8239e49
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

View File

@ -2,7 +2,6 @@ package loopdb
import (
"encoding/hex"
"errors"
"fmt"
"strings"
@ -88,6 +87,15 @@ func restoreDB(bucket *bbolt.Bucket, data map[string]interface{}) error {
for k, v := range data {
key := []byte(k)
// Store nil values.
if v == nil {
err := bucket.Put(key, nil)
if err != nil {
return err
}
continue
}
switch value := v.(type) {
// Key contains value.
@ -109,7 +117,7 @@ func restoreDB(bucket *bbolt.Bucket, data map[string]interface{}) error {
}
default:
return errors.New("invalid type")
return fmt.Errorf("invalid type %T", value)
}
}