Skip to content

Commit

Permalink
Remove the use of codec.MustMarshal when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasMahe committed Nov 8, 2019
1 parent 5aa8278 commit 68aba4d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion sdk/instance/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/instance"
Expand Down Expand Up @@ -67,7 +68,11 @@ func (s *Backend) FetchOrCreate(request cosmostypes.Request, serviceHash hash.Ha
inst.Hash = hash.Dump(inst)

if store := request.KVStore(s.storeKey); !store.Has(inst.Hash) {
store.Set(inst.Hash, codec.MustMarshalBinaryBare(inst))
value, err := codec.MarshalBinaryBare(inst)
if err != nil {
return nil, err
}
store.Set(inst.Hash, value)
}

return inst, nil
Expand Down
7 changes: 6 additions & 1 deletion sdk/ownership/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/ownership"
Expand Down Expand Up @@ -64,7 +65,11 @@ func (s *Backend) CreateServiceOwnership(request cosmostypes.Request, serviceHas
},
}
ownership.Hash = hash.Dump(ownership)
store.Set(ownership.Hash, codec.MustMarshalBinaryBare(ownership))
value, err := codec.MarshalBinaryBare(ownership)
if err != nil {
return nil, err
}
store.Set(ownership.Hash, value)
return ownership, nil
}

Expand Down
7 changes: 6 additions & 1 deletion sdk/service/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/gogo/protobuf/proto"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/protobuf/api"
Expand Down Expand Up @@ -106,7 +107,11 @@ func (s *Backend) Create(request cosmostypes.Request, msg *msgCreateService) (*s
return nil, err
}

store.Set(srv.Hash, codec.MustMarshalBinaryBare(srv))
value, err := codec.MarshalBinaryBare(srv)
if err != nil {
return nil, err
}
store.Set(srv.Hash, value)
return srv, nil
}

Expand Down

0 comments on commit 68aba4d

Please sign in to comment.