Skip to content

Commit

Permalink
Merge pull request #1272 from mesg-foundation/refactor/servcie-proto-…
Browse files Browse the repository at this point in the history
…hash-type

Use hash.Hash type in service proto definition
  • Loading branch information
Nicolas Mahé authored Aug 30, 2019
2 parents 8738868 + d0547e1 commit e283171
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 78 deletions.
3 changes: 1 addition & 2 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/mesg-foundation/engine/x/xnet"
"github.com/mesg-foundation/engine/x/xos"
"github.com/mesg-foundation/engine/x/xsignal"
"github.com/mr-tron/base58"
"github.com/sirupsen/logrus"
db "github.com/tendermint/tm-db"
)
Expand Down Expand Up @@ -74,7 +73,7 @@ func deployCoreServices(cfg *config.Config, sdk *enginesdk.SDK) error {
return err
}
}
logrus.WithField("module", "main").Infof("Service %q deployed with hash %q", srv.Sid, base58.Encode(srv.Hash))
logrus.WithField("module", "main").Infof("Service %q deployed with hash %q", srv.Sid, srv.Hash.String())
instance, err := sdk.Instance.Create(srv.Hash, xos.EnvMapToSlice(serviceConfig.Env))
if err != nil {
existsError, ok := err.(*instancesdk.AlreadyExistsError)
Expand Down
5 changes: 5 additions & 0 deletions hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (h Hash) Marshal() ([]byte, error) {
return h, nil
}

// MarshalTo marshals hash into slice of bytes. It's used by protobuf.
func (h Hash) MarshalTo(data []byte) (int, error) {
return copy(data, h), nil
}

// Unmarshal unmarshals slice of bytes into hash. It's used by protobuf.
func (h *Hash) Unmarshal(data []byte) error {
*h = data
Expand Down
4 changes: 3 additions & 1 deletion protobuf/types/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ message Service {

// Service's hash.
bytes hash = 10 [
(gogoproto.moretags) = 'validate:"required"'
(gogoproto.moretags) = 'validate:"required"',
(gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
(gogoproto.nullable) = false
];

// Service's sid.
Expand Down
5 changes: 2 additions & 3 deletions sdk/instance/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/mesg-foundation/engine/instance"
"github.com/mesg-foundation/engine/service"
"github.com/mesg-foundation/engine/x/xos"
"github.com/mr-tron/base58"
)

// Start starts the service.
Expand Down Expand Up @@ -39,7 +38,7 @@ func (i *Instance) start(inst *instance.Instance, imageHash string, env []string
Labels: map[string]string{
"mesg.engine": i.engineName,
"mesg.sid": srv.Sid,
"mesg.service": base58.Encode(srv.Hash), // TODO: change to srv.Hash.String() after set custom type in proto
"mesg.service": srv.Hash.String(),
"mesg.instance": inst.Hash.String(),
"mesg.dependency": d.Key,
},
Expand Down Expand Up @@ -67,7 +66,7 @@ func (i *Instance) start(inst *instance.Instance, imageHash string, env []string
Labels: map[string]string{
"mesg.engine": i.engineName,
"mesg.sid": srv.Sid,
"mesg.service": base58.Encode(srv.Hash), // TODO: change to srv.Hash.String() after set custom type in proto
"mesg.service": srv.Hash.String(),
"mesg.instance": inst.Hash.String(),
"mesg.dependency": service.MainServiceKey,
},
Expand Down
146 changes: 74 additions & 72 deletions service/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e283171

Please sign in to comment.