mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/state: simplify if statement in DBStore.Put()
This commit is contained in:
parent
c35c7ed718
commit
a721fc6b4c
1 changed files with 5 additions and 8 deletions
|
|
@ -88,18 +88,15 @@ func (s *DBStore) Get(key string, i interface{}) (err error) {
|
||||||
// Put stores an object that implements Binary for a specific key.
|
// Put stores an object that implements Binary for a specific key.
|
||||||
func (s *DBStore) Put(key string, i interface{}) (err error) {
|
func (s *DBStore) Put(key string, i interface{}) (err error) {
|
||||||
var bytes []byte
|
var bytes []byte
|
||||||
|
if marshaler, ok := i.(encoding.BinaryMarshaler); ok {
|
||||||
marshaler, ok := i.(encoding.BinaryMarshaler)
|
|
||||||
if !ok {
|
|
||||||
if bytes, err = json.Marshal(i); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if bytes, err = marshaler.MarshalBinary(); err != nil {
|
if bytes, err = marshaler.MarshalBinary(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if bytes, err = json.Marshal(i); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.db.Put([]byte(key), bytes, nil)
|
return s.db.Put([]byte(key), bytes, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue