Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use protobuf marshal/unmarshal in execution database #1312

Merged
merged 2 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions database/execution_db.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package database

import (
"encoding/json"
"errors"
"io"

"github.com/gogo/protobuf/proto"
"github.com/mesg-foundation/engine/execution"
"github.com/mesg-foundation/engine/hash"
"github.com/syndtr/goleveldb/leveldb"
Expand Down Expand Up @@ -100,7 +100,7 @@ func executionFind(db leveldbTxDB, executionHash hash.Hash) (*execution.Executio
return nil, err
}
var execution execution.Execution
if err := json.Unmarshal(data, &execution); err != nil {
if err := proto.Unmarshal(data, &execution); err != nil {
return nil, err
}
return &execution, nil
Expand All @@ -112,7 +112,7 @@ func executionSave(db leveldbTxDB, execution *execution.Execution) error {
if len(execution.Hash) == 0 {
return errors.New("database: can't save execution without hash")
}
data, err := json.Marshal(execution)
data, err := proto.Marshal(execution)
if err != nil {
return err
}
Expand Down
131 changes: 99 additions & 32 deletions execution/execution.pb.go

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

1 change: 1 addition & 0 deletions protobuf/types/execution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package types;
option go_package = "github.com/mesg-foundation/engine/execution";

option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = true;

// Status represents the status of a single execution.
// Note that a valid execution must have only one status
Expand Down
2 changes: 1 addition & 1 deletion sdk/execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestGet(t *testing.T) {
require.NoError(t, sdk.execDB.Save(exec))
got, err := sdk.Get(exec.Hash)
require.NoError(t, err)
require.Equal(t, exec, got)
require.True(t, exec.Equal(got))
}

func TestGetStream(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/api/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestGet(t *testing.T) {

got, err := s.Get(context.Background(), &api.GetExecutionRequest{Hash: exec.Hash})
require.NoError(t, err)
require.Equal(t, got, exec)
require.True(t, got.Equal(exec))
}

func TestUpdate(t *testing.T) {
Expand Down