Skip to content

Commit

Permalink
Add validation for grpc requests and cosmos messages
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Nov 21, 2019
1 parent 6df2444 commit 29f5f97
Show file tree
Hide file tree
Showing 22 changed files with 443 additions and 276 deletions.
18 changes: 10 additions & 8 deletions account/account.pb.go

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

44 changes: 23 additions & 21 deletions event/event.pb.go

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

9 changes: 9 additions & 0 deletions hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ func Decode(h string) (Hash, error) {
return Hash(hash), nil
}

// DecodeFromBytes decodes hash and checks it length.
// It returns empty hash on nil slice of bytes.
func DecodeFromBytes(data []byte) (Hash, error) {
if len(data) != size {
return nil, fmt.Errorf("hash: invalid length")
}
return Hash(data), nil
}

// IsZero reports whethere h represents empty hash.
func (h Hash) IsZero() bool {
return len(h) == 0
Expand Down
62 changes: 33 additions & 29 deletions protobuf/api/event.pb.go

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

10 changes: 8 additions & 2 deletions protobuf/api/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ message StreamEventRequest {
message Filter {
// hash to filter events.
bytes hash = 1 [
(gogoproto.moretags) = 'validate:"omitempty,hash"',
(gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
(gogoproto.nullable) = false
];

// instance's hash to filter events.
bytes instanceHash = 2 [
(gogoproto.moretags) = 'validate:"omitempty,hash"',
(gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
(gogoproto.nullable) = false
];

// key is the key of the event.
string key = 3;
string key = 3 [
(gogoproto.moretags) = 'hash:"name:3" validate:"printascii"'
];
}

// Filter used to filter a stream of events.
Expand All @@ -54,7 +58,9 @@ message CreateEventRequest {
];

// key is the key of the event.
string key = 2;
string key = 2 [
(gogoproto.moretags) = 'validate:"printascii"'
];

// data is the data for the event.
mesg.protobuf.Struct data = 3;
Expand Down
Loading

0 comments on commit 29f5f97

Please sign in to comment.