From 844058a7cea797370b2d06cc5f3039b132b4cece Mon Sep 17 00:00:00 2001 From: eleijonmarck Date: Mon, 20 Jun 2022 18:11:28 +0200 Subject: [PATCH 1/6] Fix: proto-gen command --- proto/blog/v1/query.proto | 2 +- scripts/protocgen.sh | 4 +- x/blog/query.pb.go | 40 +++++----- x/blog/{common.pb.go => types.pb.go} | 112 +++++++++++++-------------- 4 files changed, 79 insertions(+), 79 deletions(-) rename x/blog/{common.pb.go => types.pb.go} (73%) diff --git a/proto/blog/v1/query.proto b/proto/blog/v1/query.proto index 92c5368..09a3ce7 100644 --- a/proto/blog/v1/query.proto +++ b/proto/blog/v1/query.proto @@ -4,7 +4,7 @@ package blog.v1; option go_package = "github.com/regen-network/bec/x/blog"; import "cosmos/base/query/v1beta1/pagination.proto"; -import "blog/v1/common.proto"; +import "blog/v1/types.proto"; // Query defines the gRPC querier service. service Query { diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index c78de27..7024fcd 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -19,7 +19,7 @@ protoc_gen_gocosmos proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) for dir in $proto_dirs; do - buf protoc \ + buf alpha protoc \ -I "proto" \ -I "third_party/proto" \ --gocosmos_out=plugins=interfacetype+grpc,\ @@ -27,7 +27,7 @@ Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ $(find "${dir}" -maxdepth 1 -name '*.proto') # command to generate gRPC gateway (*.pb.gw.go in respective modules) files - buf protoc \ + buf alpha protoc \ -I "proto" \ -I "third_party/proto" \ --grpc-gateway_out=logtostderr=true:. \ diff --git a/x/blog/query.pb.go b/x/blog/query.pb.go index 24ab822..25f51cf 100644 --- a/x/blog/query.pb.go +++ b/x/blog/query.pb.go @@ -132,26 +132,26 @@ func init() { func init() { proto.RegisterFile("blog/v1/query.proto", fileDescriptor_eb782a0cfb4fa324) } var fileDescriptor_eb782a0cfb4fa324 = []byte{ - // 302 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0xca, 0xc9, 0x4f, - 0xd7, 0x2f, 0x33, 0xd4, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, - 0x62, 0x07, 0x09, 0xea, 0x95, 0x19, 0x4a, 0x69, 0x25, 0xe7, 0x17, 0xe7, 0xe6, 0x17, 0xeb, 0x27, - 0x25, 0x16, 0xa7, 0x42, 0x54, 0xe8, 0x97, 0x19, 0x26, 0xa5, 0x96, 0x24, 0x1a, 0xea, 0x17, 0x24, - 0xa6, 0x67, 0xe6, 0x25, 0x96, 0x64, 0xe6, 0xe7, 0x41, 0x34, 0x49, 0x89, 0xc0, 0x4c, 0x4a, 0xce, - 0xcf, 0xcd, 0x85, 0x89, 0x2a, 0xc5, 0x71, 0x89, 0x04, 0x82, 0xf4, 0x39, 0xe6, 0xe4, 0x04, 0xe4, - 0x17, 0x97, 0x14, 0x07, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0xb9, 0x71, 0x71, 0x21, 0x4c, - 0x90, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd3, 0x83, 0x58, 0xa7, 0x07, 0xb2, 0x4e, 0x0f, - 0xe2, 0x20, 0xa8, 0x75, 0x7a, 0x01, 0x89, 0xe9, 0xa9, 0x50, 0xbd, 0x41, 0x48, 0x3a, 0x95, 0x5a, - 0x19, 0xb9, 0x44, 0xd1, 0x2c, 0x28, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x15, 0x52, 0xe6, 0x62, 0x2d, - 0x00, 0x09, 0x48, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x1b, 0xf1, 0xea, 0x41, 0x3d, 0xa5, 0x07, 0x52, - 0x16, 0x04, 0x91, 0x13, 0x72, 0x47, 0x71, 0x06, 0x13, 0xd8, 0x19, 0xea, 0x04, 0x9d, 0x01, 0xb1, - 0x01, 0xd9, 0x1d, 0x46, 0x41, 0x5c, 0xac, 0x60, 0x67, 0x08, 0x79, 0x72, 0x71, 0xc0, 0x9c, 0x22, - 0x24, 0x0b, 0xb7, 0x13, 0x5b, 0x18, 0x48, 0xc9, 0xe1, 0x92, 0x86, 0x98, 0xef, 0x64, 0x7b, 0xe2, - 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, - 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xca, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, - 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x45, 0xa9, 0xe9, 0xa9, 0x79, 0xba, 0x79, 0xa9, 0x25, 0xe5, 0xf9, - 0x45, 0xd9, 0xfa, 0x49, 0xa9, 0xc9, 0xfa, 0x15, 0xfa, 0x20, 0x73, 0x93, 0xd8, 0xc0, 0x31, 0x60, - 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xde, 0x84, 0x6f, 0x00, 0xe3, 0x01, 0x00, 0x00, + // 301 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x41, 0x4b, 0xf3, 0x30, + 0x18, 0xc7, 0x9b, 0xf7, 0x65, 0x2a, 0x19, 0x5e, 0xa2, 0xc2, 0x28, 0x18, 0xc6, 0x06, 0x3a, 0x04, + 0x13, 0x5a, 0xcf, 0x1e, 0xf4, 0xa0, 0x78, 0x9b, 0x3d, 0x7a, 0x10, 0x9a, 0xf2, 0x50, 0x8b, 0x5d, + 0xd3, 0x35, 0x69, 0x75, 0x1f, 0xc0, 0xbb, 0x1f, 0xcb, 0xe3, 0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 0x9a, 0xa2, 0x65, 0x4d, 0xd1, 0x5b, 0x4d, 0xd1, 0x73, 0x43, 0x9d, 0x65, 0x43, 0x9d, 0xd7, 0x86, + 0x3a, 0x37, 0xe3, 0x38, 0xd1, 0x77, 0xa5, 0x60, 0x91, 0x9c, 0xf1, 0x02, 0x62, 0xc8, 0x8e, 0x33, + 0xd0, 0x0f, 0xb2, 0xb8, 0xe7, 0x02, 0x22, 0xfe, 0xc8, 0x4d, 0xaf, 0xd8, 0x68, 0x5f, 0xe0, 0xe4, + 0x3d, 0x00, 0x00, 0xff, 0xff, 0x83, 0x3d, 0x41, 0xc5, 0xe2, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/blog/common.pb.go b/x/blog/types.pb.go similarity index 73% rename from x/blog/common.pb.go rename to x/blog/types.pb.go index 9247d02..307e7f8 100644 --- a/x/blog/common.pb.go +++ b/x/blog/types.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: blog/v1/common.proto +// source: blog/v1/types.proto package blog @@ -35,7 +35,7 @@ func (m *Post) Reset() { *m = Post{} } func (m *Post) String() string { return proto.CompactTextString(m) } func (*Post) ProtoMessage() {} func (*Post) Descriptor() ([]byte, []int) { - return fileDescriptor_c6ffee525c3f88b0, []int{0} + return fileDescriptor_73573037ee301d2b, []int{0} } func (m *Post) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -96,22 +96,22 @@ func init() { proto.RegisterType((*Post)(nil), "blog.v1.Post") } -func init() { proto.RegisterFile("blog/v1/common.proto", fileDescriptor_c6ffee525c3f88b0) } +func init() { proto.RegisterFile("blog/v1/types.proto", fileDescriptor_73573037ee301d2b) } -var fileDescriptor_c6ffee525c3f88b0 = []byte{ - // 188 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x49, 0xca, 0xc9, 0x4f, - 0xd7, 0x2f, 0x33, 0xd4, 0x4f, 0xce, 0xcf, 0xcd, 0xcd, 0xcf, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, - 0x17, 0x62, 0x07, 0x89, 0xea, 0x95, 0x19, 0x2a, 0xc5, 0x70, 0xb1, 0x04, 0xe4, 0x17, 0x97, 0x08, - 0x09, 0x71, 0xb1, 0x14, 0xe7, 0x94, 0xa6, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0xd9, - 0x42, 0x62, 0x5c, 0x6c, 0x89, 0xa5, 0x25, 0x19, 0xf9, 0x45, 0x12, 0x4c, 0x60, 0x51, 0x28, 0x4f, - 0x48, 0x84, 0x8b, 0xb5, 0x24, 0xb3, 0x24, 0x27, 0x55, 0x82, 0x19, 0x2c, 0x0c, 0xe1, 0x80, 0x4c, - 0x48, 0xca, 0x4f, 0xa9, 0x94, 0x60, 0x81, 0x98, 0x00, 0x62, 0x3b, 0xd9, 0x9e, 0x78, 0x24, 0xc7, - 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, - 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x72, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, - 0x7e, 0xae, 0x7e, 0x51, 0x6a, 0x7a, 0x6a, 0x9e, 0x6e, 0x5e, 0x6a, 0x49, 0x79, 0x7e, 0x51, 0xb6, - 0x7e, 0x52, 0x6a, 0xb2, 0x7e, 0x85, 0x3e, 0xc8, 0x7d, 0x49, 0x6c, 0x60, 0xc7, 0x1a, 0x03, 0x02, - 0x00, 0x00, 0xff, 0xff, 0x4c, 0xc5, 0x0d, 0xef, 0xc4, 0x00, 0x00, 0x00, +var fileDescriptor_73573037ee301d2b = []byte{ + // 187 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0xca, 0xc9, 0x4f, + 0xd7, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x62, 0x07, 0x09, 0xea, 0x95, 0x19, 0x2a, 0xc5, 0x70, 0xb1, 0x04, 0xe4, 0x17, 0x97, 0x08, 0x09, + 0x71, 0xb1, 0x14, 0xe7, 0x94, 0xa6, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0xd9, 0x42, + 0x62, 0x5c, 0x6c, 0x89, 0xa5, 0x25, 0x19, 0xf9, 0x45, 0x12, 0x4c, 0x60, 0x51, 0x28, 0x4f, 0x48, + 0x84, 0x8b, 0xb5, 0x24, 0xb3, 0x24, 0x27, 0x55, 0x82, 0x19, 0x2c, 0x0c, 0xe1, 0x80, 0x4c, 0x48, + 0xca, 0x4f, 0xa9, 0x94, 0x60, 0x81, 0x98, 0x00, 0x62, 0x3b, 0xd9, 0x9e, 0x78, 0x24, 0xc7, 0x78, + 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, + 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x72, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, + 0xae, 0x7e, 0x51, 0x6a, 0x7a, 0x6a, 0x9e, 0x6e, 0x5e, 0x6a, 0x49, 0x79, 0x7e, 0x51, 0xb6, 0x7e, + 0x52, 0x6a, 0xb2, 0x7e, 0x85, 0x3e, 0xc8, 0x7d, 0x49, 0x6c, 0x60, 0xc7, 0x1a, 0x03, 0x02, 0x00, + 0x00, 0xff, 0xff, 0xf7, 0xa2, 0x98, 0xf3, 0xc3, 0x00, 0x00, 0x00, } func (m *Post) Marshal() (dAtA []byte, err error) { @@ -137,36 +137,36 @@ func (m *Post) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.Body) > 0 { i -= len(m.Body) copy(dAtA[i:], m.Body) - i = encodeVarintCommon(dAtA, i, uint64(len(m.Body))) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Body))) i-- dAtA[i] = 0x22 } if len(m.Title) > 0 { i -= len(m.Title) copy(dAtA[i:], m.Title) - i = encodeVarintCommon(dAtA, i, uint64(len(m.Title))) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Title))) i-- dAtA[i] = 0x1a } if len(m.Author) > 0 { i -= len(m.Author) copy(dAtA[i:], m.Author) - i = encodeVarintCommon(dAtA, i, uint64(len(m.Author))) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Author))) i-- dAtA[i] = 0x12 } if len(m.Slug) > 0 { i -= len(m.Slug) copy(dAtA[i:], m.Slug) - i = encodeVarintCommon(dAtA, i, uint64(len(m.Slug))) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Slug))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarintCommon(dAtA []byte, offset int, v uint64) int { - offset -= sovCommon(v) +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -184,28 +184,28 @@ func (m *Post) Size() (n int) { _ = l l = len(m.Slug) if l > 0 { - n += 1 + l + sovCommon(uint64(l)) + n += 1 + l + sovTypes(uint64(l)) } l = len(m.Author) if l > 0 { - n += 1 + l + sovCommon(uint64(l)) + n += 1 + l + sovTypes(uint64(l)) } l = len(m.Title) if l > 0 { - n += 1 + l + sovCommon(uint64(l)) + n += 1 + l + sovTypes(uint64(l)) } l = len(m.Body) if l > 0 { - n += 1 + l + sovCommon(uint64(l)) + n += 1 + l + sovTypes(uint64(l)) } return n } -func sovCommon(x uint64) (n int) { +func sovTypes(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozCommon(x uint64) (n int) { - return sovCommon(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } func (m *Post) Unmarshal(dAtA []byte) error { l := len(dAtA) @@ -215,7 +215,7 @@ func (m *Post) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCommon + return ErrIntOverflowTypes } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -243,7 +243,7 @@ func (m *Post) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCommon + return ErrIntOverflowTypes } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -257,11 +257,11 @@ func (m *Post) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF @@ -275,7 +275,7 @@ func (m *Post) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCommon + return ErrIntOverflowTypes } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -289,11 +289,11 @@ func (m *Post) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF @@ -307,7 +307,7 @@ func (m *Post) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCommon + return ErrIntOverflowTypes } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -321,11 +321,11 @@ func (m *Post) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF @@ -339,7 +339,7 @@ func (m *Post) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowCommon + return ErrIntOverflowTypes } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -353,11 +353,11 @@ func (m *Post) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF @@ -366,15 +366,15 @@ func (m *Post) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipCommon(dAtA[iNdEx:]) + skippy, err := skipTypes(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCommon + return ErrInvalidLengthTypes } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -388,7 +388,7 @@ func (m *Post) Unmarshal(dAtA []byte) error { } return nil } -func skipCommon(dAtA []byte) (n int, err error) { +func skipTypes(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -396,7 +396,7 @@ func skipCommon(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowCommon + return 0, ErrIntOverflowTypes } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -413,7 +413,7 @@ func skipCommon(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowCommon + return 0, ErrIntOverflowTypes } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -429,7 +429,7 @@ func skipCommon(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowCommon + return 0, ErrIntOverflowTypes } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -442,14 +442,14 @@ func skipCommon(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthCommon + return 0, ErrInvalidLengthTypes } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupCommon + return 0, ErrUnexpectedEndOfGroupTypes } depth-- case 5: @@ -458,7 +458,7 @@ func skipCommon(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthCommon + return 0, ErrInvalidLengthTypes } if depth == 0 { return iNdEx, nil @@ -468,7 +468,7 @@ func skipCommon(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthCommon = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowCommon = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupCommon = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") ) From 52ca24fb67cb044e3c5bd77e04e1281324c95c3a Mon Sep 17 00:00:00 2001 From: eleijonmarck Date: Tue, 21 Jun 2022 09:42:19 +0200 Subject: [PATCH 2/6] add: schema for create comment & queryComments --- proto/blog/v1/query.proto | 11 + proto/blog/v1/tx.proto | 12 + proto/blog/v1/types.proto | 8 + x/blog/query.pb.go | 506 +++++++++++++++++++++++++++++++++++-- x/blog/tx.pb.go | 507 +++++++++++++++++++++++++++++++++++++- x/blog/types.pb.go | 293 +++++++++++++++++++++- 6 files changed, 1301 insertions(+), 36 deletions(-) diff --git a/proto/blog/v1/query.proto b/proto/blog/v1/query.proto index 09a3ce7..174a017 100644 --- a/proto/blog/v1/query.proto +++ b/proto/blog/v1/query.proto @@ -9,6 +9,7 @@ import "blog/v1/types.proto"; // Query defines the gRPC querier service. service Query { rpc AllPosts(QueryAllPostsRequest) returns (QueryAllPostsResponse); + rpc AllComments(QueryAllCommentsRequest) returns (QueryAllCommentsResponse); } message QueryAllPostsRequest { @@ -20,3 +21,13 @@ message QueryAllPostsResponse { cosmos.base.query.v1beta1.PageResponse pagination = 2; } + +message QueryAllCommentsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +message QueryAllCommentsResponse { + repeated Comment comments = 1; + + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} diff --git a/proto/blog/v1/tx.proto b/proto/blog/v1/tx.proto index 903b077..e0c9e7d 100644 --- a/proto/blog/v1/tx.proto +++ b/proto/blog/v1/tx.proto @@ -6,6 +6,7 @@ option go_package = "github.com/regen-network/bec/x/blog"; // Msg is the blog.v1 Msg service service Msg { rpc CreatePost(MsgCreatePost) returns (MsgCreatePostResponse); + rpc CreateComment(MsgCreateComment) returns (MsgCreateCommentResponse); } // MsgCreatePost is the Msg/CreatePost request type. @@ -18,3 +19,14 @@ message MsgCreatePost { // MsgCreatePostResponse is the Msg/CreatePost response type. message MsgCreatePostResponse {} + +// MsgCreateComment is the Msg/CreateComment request type. +message MsgCreateComment { + string slug = 1; + string author = 2; + string title = 3; + string body = 4; +} + +// MsgCreateCommentResponse is the Msg/CreateComment response type. +message MsgCreateCommentResponse {} diff --git a/proto/blog/v1/types.proto b/proto/blog/v1/types.proto index c22f1bc..e1134a6 100644 --- a/proto/blog/v1/types.proto +++ b/proto/blog/v1/types.proto @@ -11,3 +11,11 @@ message Post { string title = 3; string body = 4; } + +message Comment { + // post_slug is a short human-readable string for the post, used as unique + // identifier for the post. + string post_slug = 1; + string author = 2; + string body = 3; +} diff --git a/x/blog/query.pb.go b/x/blog/query.pb.go index 25f51cf..05e27ab 100644 --- a/x/blog/query.pb.go +++ b/x/blog/query.pb.go @@ -124,34 +124,136 @@ func (m *QueryAllPostsResponse) GetPagination() *query.PageResponse { return nil } +type QueryAllCommentsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllCommentsRequest) Reset() { *m = QueryAllCommentsRequest{} } +func (m *QueryAllCommentsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllCommentsRequest) ProtoMessage() {} +func (*QueryAllCommentsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_eb782a0cfb4fa324, []int{2} +} +func (m *QueryAllCommentsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllCommentsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllCommentsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllCommentsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllCommentsRequest.Merge(m, src) +} +func (m *QueryAllCommentsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAllCommentsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllCommentsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllCommentsRequest proto.InternalMessageInfo + +func (m *QueryAllCommentsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +type QueryAllCommentsResponse struct { + Comments []*Comment `protobuf:"bytes,1,rep,name=comments,proto3" json:"comments,omitempty"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAllCommentsResponse) Reset() { *m = QueryAllCommentsResponse{} } +func (m *QueryAllCommentsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllCommentsResponse) ProtoMessage() {} +func (*QueryAllCommentsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_eb782a0cfb4fa324, []int{3} +} +func (m *QueryAllCommentsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAllCommentsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllCommentsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAllCommentsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllCommentsResponse.Merge(m, src) +} +func (m *QueryAllCommentsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAllCommentsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllCommentsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllCommentsResponse proto.InternalMessageInfo + +func (m *QueryAllCommentsResponse) GetComments() []*Comment { + if m != nil { + return m.Comments + } + return nil +} + +func (m *QueryAllCommentsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + func init() { proto.RegisterType((*QueryAllPostsRequest)(nil), "blog.v1.QueryAllPostsRequest") proto.RegisterType((*QueryAllPostsResponse)(nil), "blog.v1.QueryAllPostsResponse") + proto.RegisterType((*QueryAllCommentsRequest)(nil), "blog.v1.QueryAllCommentsRequest") + proto.RegisterType((*QueryAllCommentsResponse)(nil), "blog.v1.QueryAllCommentsResponse") } func init() { proto.RegisterFile("blog/v1/query.proto", fileDescriptor_eb782a0cfb4fa324) } var fileDescriptor_eb782a0cfb4fa324 = []byte{ - // 301 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x41, 0x4b, 0xf3, 0x30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, 0x99, 0xb3, 0xc0, 0xee, 0xc8, 0xe5, 0x17, 0x8d, 0x7f, 0xad, - 0xc6, 0xe1, 0x9f, 0x1a, 0x96, 0xb0, 0xee, 0xe1, 0x07, 0xb8, 0xd7, 0x6a, 0x90, 0x2b, 0xbc, 0xf5, - 0xa1, 0x42, 0xf6, 0x57, 0xcc, 0x9f, 0xfe, 0x81, 0x4b, 0x7f, 0x5b, 0xdb, 0xfe, 0xf3, 0xd3, 0x97, - 0x9a, 0xa2, 0x65, 0x4d, 0xd1, 0x5b, 0x4d, 0xd1, 0x73, 0x43, 0x9d, 0x65, 0x43, 0x9d, 0xd7, 0x86, - 0x3a, 0x37, 0xe3, 0x38, 0xd1, 0x77, 0xa5, 0x60, 0x91, 0x9c, 0xf1, 0x02, 0x62, 0xc8, 0x8e, 0x33, - 0xd0, 0x0f, 0xb2, 0xb8, 0xe7, 0x02, 0x22, 0xfe, 0xc8, 0x4d, 0xaf, 0xd8, 0x68, 0x5f, 0xe0, 0xe4, - 0x3d, 0x00, 0x00, 0xff, 0xff, 0x83, 0x3d, 0x41, 0xc5, 0xe2, 0x01, 0x00, 0x00, + // 361 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0xcd, 0x4a, 0xfb, 0x40, + 0x14, 0xc5, 0x3b, 0xff, 0x3f, 0xd5, 0x32, 0x45, 0x90, 0x51, 0xb1, 0x04, 0x1c, 0x6a, 0x0b, 0x5a, + 0x44, 0x67, 0x48, 0x5d, 0xbb, 0x50, 0x41, 0x71, 0x57, 0xb3, 0x74, 0x21, 0x24, 0xe1, 0x12, 0x8b, + 0x4d, 0x26, 0xcd, 0x4c, 0xab, 0x7d, 0x00, 0xf7, 0xfa, 0x12, 0x3e, 0x8b, 0xcb, 0x2e, 0x5d, 0x4a, + 0xfb, 0x22, 0x92, 0xcc, 0x34, 0xf6, 0xc3, 0x8f, 0x4d, 0xb7, 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0x37, 0x5f, 0x11, 0x2e, 0x66, 0x9d, 0xc8, 0x15, 0x2e, 0x4d, 0x4e, 0x40, 0x76, 0xf2, 0xe8, 0xef, + 0x6e, 0x6f, 0xd1, 0x9f, 0x9e, 0x0d, 0x8b, 0x83, 0xcb, 0x53, 0x88, 0xa4, 0xba, 0x20, 0x9f, 0xfb, + 0xc2, 0xd6, 0xee, 0x2f, 0x0a, 0xed, 0x79, 0x76, 0xf2, 0x36, 0xa2, 0x68, 0x38, 0xa2, 0xe8, 0x63, + 0x44, 0xd1, 0xf3, 0x98, 0x16, 0x86, 0x63, 0x5a, 0x78, 0x1f, 0xd3, 0xc2, 0x4d, 0x3d, 0x68, 0xab, + 0xbb, 0x9e, 0xc7, 0x7c, 0x11, 0xf2, 0x04, 0x02, 0x88, 0x8e, 0x22, 0x50, 0x0f, 0x22, 0xb9, 0xe7, + 0x1e, 0xf8, 0xfc, 0x91, 0xa7, 0xd6, 0xde, 0x4a, 0xf6, 0x37, 0x1f, 0x7f, 0x06, 0x00, 0x00, 0xff, + 0xff, 0x3f, 0x5a, 0x6f, 0xb7, 0x2e, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -167,6 +269,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { AllPosts(ctx context.Context, in *QueryAllPostsRequest, opts ...grpc.CallOption) (*QueryAllPostsResponse, error) + AllComments(ctx context.Context, in *QueryAllCommentsRequest, opts ...grpc.CallOption) (*QueryAllCommentsResponse, error) } type queryClient struct { @@ -186,9 +289,19 @@ func (c *queryClient) AllPosts(ctx context.Context, in *QueryAllPostsRequest, op return out, nil } +func (c *queryClient) AllComments(ctx context.Context, in *QueryAllCommentsRequest, opts ...grpc.CallOption) (*QueryAllCommentsResponse, error) { + out := new(QueryAllCommentsResponse) + err := c.cc.Invoke(ctx, "/blog.v1.Query/AllComments", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { AllPosts(context.Context, *QueryAllPostsRequest) (*QueryAllPostsResponse, error) + AllComments(context.Context, *QueryAllCommentsRequest) (*QueryAllCommentsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -198,6 +311,9 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) AllPosts(ctx context.Context, req *QueryAllPostsRequest) (*QueryAllPostsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method AllPosts not implemented") } +func (*UnimplementedQueryServer) AllComments(ctx context.Context, req *QueryAllCommentsRequest) (*QueryAllCommentsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AllComments not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -221,6 +337,24 @@ func _Query_AllPosts_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } +func _Query_AllComments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllCommentsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AllComments(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blog.v1.Query/AllComments", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AllComments(ctx, req.(*QueryAllCommentsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "blog.v1.Query", HandlerType: (*QueryServer)(nil), @@ -229,6 +363,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "AllPosts", Handler: _Query_AllPosts_Handler, }, + { + MethodName: "AllComments", + Handler: _Query_AllComments_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "blog/v1/query.proto", @@ -318,6 +456,90 @@ func (m *QueryAllPostsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryAllCommentsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllCommentsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllCommentsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAllCommentsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAllCommentsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllCommentsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Comments) > 0 { + for iNdEx := len(m.Comments) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Comments[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -361,6 +583,38 @@ func (m *QueryAllPostsResponse) Size() (n int) { return n } +func (m *QueryAllCommentsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllCommentsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Comments) > 0 { + for _, e := range m.Comments { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -579,6 +833,218 @@ func (m *QueryAllPostsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryAllCommentsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllCommentsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllCommentsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAllCommentsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAllCommentsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllCommentsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Comments", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Comments = append(m.Comments, &Comment{}) + if err := m.Comments[len(m.Comments)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/blog/tx.pb.go b/x/blog/tx.pb.go index cf329b3..8805a84 100644 --- a/x/blog/tx.pb.go +++ b/x/blog/tx.pb.go @@ -133,15 +133,123 @@ func (m *MsgCreatePostResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgCreatePostResponse proto.InternalMessageInfo +// MsgCreateComment is the Msg/CreateComment request type. +type MsgCreateComment struct { + Slug string `protobuf:"bytes,1,opt,name=slug,proto3" json:"slug,omitempty"` + Author string `protobuf:"bytes,2,opt,name=author,proto3" json:"author,omitempty"` + Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"` + Body string `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` +} + +func (m *MsgCreateComment) Reset() { *m = MsgCreateComment{} } +func (m *MsgCreateComment) String() string { return proto.CompactTextString(m) } +func (*MsgCreateComment) ProtoMessage() {} +func (*MsgCreateComment) Descriptor() ([]byte, []int) { + return fileDescriptor_f15df8808566170d, []int{2} +} +func (m *MsgCreateComment) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateComment) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateComment.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateComment) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateComment.Merge(m, src) +} +func (m *MsgCreateComment) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateComment) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateComment.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateComment proto.InternalMessageInfo + +func (m *MsgCreateComment) GetSlug() string { + if m != nil { + return m.Slug + } + return "" +} + +func (m *MsgCreateComment) GetAuthor() string { + if m != nil { + return m.Author + } + return "" +} + +func (m *MsgCreateComment) GetTitle() string { + if m != nil { + return m.Title + } + return "" +} + +func (m *MsgCreateComment) GetBody() string { + if m != nil { + return m.Body + } + return "" +} + +// MsgCreateCommentResponse is the Msg/CreateComment response type. +type MsgCreateCommentResponse struct { +} + +func (m *MsgCreateCommentResponse) Reset() { *m = MsgCreateCommentResponse{} } +func (m *MsgCreateCommentResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateCommentResponse) ProtoMessage() {} +func (*MsgCreateCommentResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f15df8808566170d, []int{3} +} +func (m *MsgCreateCommentResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateCommentResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateCommentResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateCommentResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateCommentResponse.Merge(m, src) +} +func (m *MsgCreateCommentResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateCommentResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateCommentResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateCommentResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgCreatePost)(nil), "blog.v1.MsgCreatePost") proto.RegisterType((*MsgCreatePostResponse)(nil), "blog.v1.MsgCreatePostResponse") + proto.RegisterType((*MsgCreateComment)(nil), "blog.v1.MsgCreateComment") + proto.RegisterType((*MsgCreateCommentResponse)(nil), "blog.v1.MsgCreateCommentResponse") } func init() { proto.RegisterFile("blog/v1/tx.proto", fileDescriptor_f15df8808566170d) } var fileDescriptor_f15df8808566170d = []byte{ - // 234 bytes of a gzipped FileDescriptorProto + // 276 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x48, 0xca, 0xc9, 0x4f, 0xd7, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x07, 0x89, 0xe8, 0x95, 0x19, 0x2a, 0xa5, 0x72, 0xf1, 0xfa, 0x16, 0xa7, 0x3b, 0x17, 0xa5, 0x26, 0x96, 0xa4, @@ -149,14 +257,17 @@ var fileDescriptor_f15df8808566170d = []byte{ 0x6a, 0x70, 0x06, 0x81, 0xd9, 0x42, 0x62, 0x5c, 0x6c, 0x89, 0xa5, 0x25, 0x19, 0xf9, 0x45, 0x12, 0x4c, 0x60, 0x51, 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0x82, 0xb9, 0xc2, 0x68, 0x16, 0x23, 0x17, 0xb3, 0x6f, 0x71, 0xba, 0x90, 0x0b, 0x17, 0x17, + 0x52, 0x50, 0x88, 0xe9, 0x41, 0x43, 0x49, 0x0f, 0xc5, 0xed, 0x52, 0x72, 0xd8, 0xc5, 0x61, 0xa6, + 0x09, 0xf9, 0x72, 0xf1, 0xa2, 0x7a, 0x48, 0x12, 0x53, 0x03, 0x54, 0x4a, 0x4a, 0x11, 0xa7, 0x14, + 0xcc, 0x38, 0x27, 0xdb, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, + 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x52, 0x4e, + 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x2f, 0x4a, 0x4d, 0x4f, 0xcd, 0xd3, + 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x4f, 0x4a, 0x4d, 0xd6, 0xaf, 0xd0, 0x07, 0x19, + 0x9d, 0xc4, 0x06, 0x8e, 0x71, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8b, 0xc8, 0xc0, 0xb8, + 0x05, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -172,6 +283,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { CreatePost(ctx context.Context, in *MsgCreatePost, opts ...grpc.CallOption) (*MsgCreatePostResponse, error) + CreateComment(ctx context.Context, in *MsgCreateComment, opts ...grpc.CallOption) (*MsgCreateCommentResponse, error) } type msgClient struct { @@ -191,9 +303,19 @@ func (c *msgClient) CreatePost(ctx context.Context, in *MsgCreatePost, opts ...g return out, nil } +func (c *msgClient) CreateComment(ctx context.Context, in *MsgCreateComment, opts ...grpc.CallOption) (*MsgCreateCommentResponse, error) { + out := new(MsgCreateCommentResponse) + err := c.cc.Invoke(ctx, "/blog.v1.Msg/CreateComment", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { CreatePost(context.Context, *MsgCreatePost) (*MsgCreatePostResponse, error) + CreateComment(context.Context, *MsgCreateComment) (*MsgCreateCommentResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -203,6 +325,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) CreatePost(ctx context.Context, req *MsgCreatePost) (*MsgCreatePostResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CreatePost not implemented") } +func (*UnimplementedMsgServer) CreateComment(ctx context.Context, req *MsgCreateComment) (*MsgCreateCommentResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateComment not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -226,6 +351,24 @@ func _Msg_CreatePost_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } +func _Msg_CreateComment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateComment) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateComment(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/blog.v1.Msg/CreateComment", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateComment(ctx, req.(*MsgCreateComment)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "blog.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -234,6 +377,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "CreatePost", Handler: _Msg_CreatePost_Handler, }, + { + MethodName: "CreateComment", + Handler: _Msg_CreateComment_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "blog/v1/tx.proto", @@ -313,6 +460,80 @@ func (m *MsgCreatePostResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgCreateComment) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateComment) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateComment) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Body) > 0 { + i -= len(m.Body) + copy(dAtA[i:], m.Body) + i = encodeVarintTx(dAtA, i, uint64(len(m.Body))) + i-- + dAtA[i] = 0x22 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintTx(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0x1a + } + if len(m.Author) > 0 { + i -= len(m.Author) + copy(dAtA[i:], m.Author) + i = encodeVarintTx(dAtA, i, uint64(len(m.Author))) + i-- + dAtA[i] = 0x12 + } + if len(m.Slug) > 0 { + i -= len(m.Slug) + copy(dAtA[i:], m.Slug) + i = encodeVarintTx(dAtA, i, uint64(len(m.Slug))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateCommentResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateCommentResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateCommentResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -358,6 +579,40 @@ func (m *MsgCreatePostResponse) Size() (n int) { return n } +func (m *MsgCreateComment) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Slug) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Author) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Title) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Body) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateCommentResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -598,6 +853,240 @@ func (m *MsgCreatePostResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgCreateComment) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateComment: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateComment: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Slug", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Slug = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Author", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Author = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Body = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateCommentResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateCommentResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateCommentResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/blog/types.pb.go b/x/blog/types.pb.go index 307e7f8..70cf7f7 100644 --- a/x/blog/types.pb.go +++ b/x/blog/types.pb.go @@ -92,26 +92,91 @@ func (m *Post) GetBody() string { return "" } +type Comment struct { + // post_slug is a short human-readable string for the post, used as unique + // identifier for the post. + PostSlug string `protobuf:"bytes,1,opt,name=post_slug,json=postSlug,proto3" json:"post_slug,omitempty"` + Author string `protobuf:"bytes,2,opt,name=author,proto3" json:"author,omitempty"` + Body string `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` +} + +func (m *Comment) Reset() { *m = Comment{} } +func (m *Comment) String() string { return proto.CompactTextString(m) } +func (*Comment) ProtoMessage() {} +func (*Comment) Descriptor() ([]byte, []int) { + return fileDescriptor_73573037ee301d2b, []int{1} +} +func (m *Comment) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Comment) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Comment.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Comment) XXX_Merge(src proto.Message) { + xxx_messageInfo_Comment.Merge(m, src) +} +func (m *Comment) XXX_Size() int { + return m.Size() +} +func (m *Comment) XXX_DiscardUnknown() { + xxx_messageInfo_Comment.DiscardUnknown(m) +} + +var xxx_messageInfo_Comment proto.InternalMessageInfo + +func (m *Comment) GetPostSlug() string { + if m != nil { + return m.PostSlug + } + return "" +} + +func (m *Comment) GetAuthor() string { + if m != nil { + return m.Author + } + return "" +} + +func (m *Comment) GetBody() string { + if m != nil { + return m.Body + } + return "" +} + func init() { proto.RegisterType((*Post)(nil), "blog.v1.Post") + proto.RegisterType((*Comment)(nil), "blog.v1.Comment") } func init() { proto.RegisterFile("blog/v1/types.proto", fileDescriptor_73573037ee301d2b) } var fileDescriptor_73573037ee301d2b = []byte{ - // 187 bytes of a gzipped FileDescriptorProto + // 221 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0xca, 0xc9, 0x4f, 0xd7, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x07, 0x09, 0xea, 0x95, 0x19, 0x2a, 0xc5, 0x70, 0xb1, 0x04, 0xe4, 0x17, 0x97, 0x08, 0x09, 0x71, 0xb1, 0x14, 0xe7, 0x94, 0xa6, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0xd9, 0x42, 0x62, 0x5c, 0x6c, 0x89, 0xa5, 0x25, 0x19, 0xf9, 0x45, 0x12, 0x4c, 0x60, 0x51, 0x28, 0x4f, 0x48, 0x84, 0x8b, 0xb5, 0x24, 0xb3, 0x24, 0x27, 0x55, 0x82, 0x19, 0x2c, 0x0c, 0xe1, 0x80, 0x4c, 0x48, - 0xca, 0x4f, 0xa9, 0x94, 0x60, 0x81, 0x98, 0x00, 0x62, 0x3b, 0xd9, 0x9e, 0x78, 0x24, 0xc7, 0x78, - 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, - 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x72, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, - 0xae, 0x7e, 0x51, 0x6a, 0x7a, 0x6a, 0x9e, 0x6e, 0x5e, 0x6a, 0x49, 0x79, 0x7e, 0x51, 0xb6, 0x7e, - 0x52, 0x6a, 0xb2, 0x7e, 0x85, 0x3e, 0xc8, 0x7d, 0x49, 0x6c, 0x60, 0xc7, 0x1a, 0x03, 0x02, 0x00, - 0x00, 0xff, 0xff, 0xf7, 0xa2, 0x98, 0xf3, 0xc3, 0x00, 0x00, 0x00, + 0xca, 0x4f, 0xa9, 0x94, 0x60, 0x81, 0x98, 0x00, 0x62, 0x2b, 0x05, 0x71, 0xb1, 0x3b, 0xe7, 0xe7, + 0xe6, 0xa6, 0xe6, 0x95, 0x08, 0x49, 0x73, 0x71, 0x16, 0xe4, 0x17, 0x97, 0xc4, 0x23, 0xd9, 0xc2, + 0x01, 0x12, 0x08, 0xc6, 0x67, 0x13, 0xcc, 0x4c, 0x66, 0x84, 0x99, 0x4e, 0xb6, 0x27, 0x1e, 0xc9, + 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, + 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9c, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, + 0x9c, 0x9f, 0xab, 0x5f, 0x94, 0x9a, 0x9e, 0x9a, 0xa7, 0x9b, 0x97, 0x5a, 0x52, 0x9e, 0x5f, 0x94, + 0xad, 0x9f, 0x94, 0x9a, 0xac, 0x5f, 0xa1, 0x0f, 0xf2, 0x73, 0x12, 0x1b, 0x38, 0x00, 0x8c, 0x01, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x2e, 0x95, 0xe9, 0x93, 0x17, 0x01, 0x00, 0x00, } func (m *Post) Marshal() (dAtA []byte, err error) { @@ -165,6 +230,50 @@ func (m *Post) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *Comment) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Comment) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Comment) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Body) > 0 { + i -= len(m.Body) + copy(dAtA[i:], m.Body) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Body))) + i-- + dAtA[i] = 0x1a + } + if len(m.Author) > 0 { + i -= len(m.Author) + copy(dAtA[i:], m.Author) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Author))) + i-- + dAtA[i] = 0x12 + } + if len(m.PostSlug) > 0 { + i -= len(m.PostSlug) + copy(dAtA[i:], m.PostSlug) + i = encodeVarintTypes(dAtA, i, uint64(len(m.PostSlug))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { offset -= sovTypes(v) base := offset @@ -201,6 +310,27 @@ func (m *Post) Size() (n int) { return n } +func (m *Comment) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PostSlug) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Author) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Body) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + func sovTypes(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -388,6 +518,155 @@ func (m *Post) Unmarshal(dAtA []byte) error { } return nil } +func (m *Comment) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Comment: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Comment: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PostSlug", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PostSlug = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Author", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Author = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Body = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTypes(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From 407c77ac0cb23ad7ea8f0d93e5b1cafe606607f5 Mon Sep 17 00:00:00 2001 From: eleijonmarck Date: Tue, 21 Jun 2022 10:15:27 +0200 Subject: [PATCH 3/6] refactor: change post to post_slug --- proto/blog/v1/tx.proto | 5 +-- x/blog/keys.go | 3 +- x/blog/tx.pb.go | 100 +++++++++++------------------------------ 3 files changed, 29 insertions(+), 79 deletions(-) diff --git a/proto/blog/v1/tx.proto b/proto/blog/v1/tx.proto index e0c9e7d..7765587 100644 --- a/proto/blog/v1/tx.proto +++ b/proto/blog/v1/tx.proto @@ -22,10 +22,9 @@ message MsgCreatePostResponse {} // MsgCreateComment is the Msg/CreateComment request type. message MsgCreateComment { - string slug = 1; + string post_slug = 1; string author = 2; - string title = 3; - string body = 4; + string body = 3; } // MsgCreateCommentResponse is the Msg/CreateComment response type. diff --git a/x/blog/keys.go b/x/blog/keys.go index d20755d..e0ec75b 100644 --- a/x/blog/keys.go +++ b/x/blog/keys.go @@ -4,7 +4,8 @@ const ( ModuleName = "blog" StoreKey = ModuleName - PostKey = "post" + PostKey = "post" + CommentKey = "post_slug" ) func KeyPrefix(p string) []byte { diff --git a/x/blog/tx.pb.go b/x/blog/tx.pb.go index 8805a84..50f063d 100644 --- a/x/blog/tx.pb.go +++ b/x/blog/tx.pb.go @@ -135,10 +135,9 @@ var xxx_messageInfo_MsgCreatePostResponse proto.InternalMessageInfo // MsgCreateComment is the Msg/CreateComment request type. type MsgCreateComment struct { - Slug string `protobuf:"bytes,1,opt,name=slug,proto3" json:"slug,omitempty"` - Author string `protobuf:"bytes,2,opt,name=author,proto3" json:"author,omitempty"` - Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"` - Body string `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` + PostSlug string `protobuf:"bytes,1,opt,name=post_slug,json=postSlug,proto3" json:"post_slug,omitempty"` + Author string `protobuf:"bytes,2,opt,name=author,proto3" json:"author,omitempty"` + Body string `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` } func (m *MsgCreateComment) Reset() { *m = MsgCreateComment{} } @@ -174,9 +173,9 @@ func (m *MsgCreateComment) XXX_DiscardUnknown() { var xxx_messageInfo_MsgCreateComment proto.InternalMessageInfo -func (m *MsgCreateComment) GetSlug() string { +func (m *MsgCreateComment) GetPostSlug() string { if m != nil { - return m.Slug + return m.PostSlug } return "" } @@ -188,13 +187,6 @@ func (m *MsgCreateComment) GetAuthor() string { return "" } -func (m *MsgCreateComment) GetTitle() string { - if m != nil { - return m.Title - } - return "" -} - func (m *MsgCreateComment) GetBody() string { if m != nil { return m.Body @@ -249,7 +241,7 @@ func init() { func init() { proto.RegisterFile("blog/v1/tx.proto", fileDescriptor_f15df8808566170d) } var fileDescriptor_f15df8808566170d = []byte{ - // 276 bytes of a gzipped FileDescriptorProto + // 297 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x48, 0xca, 0xc9, 0x4f, 0xd7, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x07, 0x89, 0xe8, 0x95, 0x19, 0x2a, 0xa5, 0x72, 0xf1, 0xfa, 0x16, 0xa7, 0x3b, 0x17, 0xa5, 0x26, 0x96, 0xa4, @@ -257,17 +249,18 @@ var fileDescriptor_f15df8808566170d = []byte{ 0x6a, 0x70, 0x06, 0x81, 0xd9, 0x42, 0x62, 0x5c, 0x6c, 0x89, 0xa5, 0x25, 0x19, 0xf9, 0x45, 0x12, 0x4c, 0x60, 0x51, 0x28, 0x4f, 0x48, 0x84, 0x8b, 0xb5, 0x24, 0xb3, 0x24, 0x27, 0x55, 0x82, 0x19, 0x2c, 0x0c, 0xe1, 0x80, 0x4c, 0x48, 0xca, 0x4f, 0xa9, 0x94, 0x60, 0x81, 0x98, 0x00, 0x62, 0x2b, - 0x89, 0x73, 0x89, 0xa2, 0x58, 0x13, 0x94, 0x5a, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0xaa, 0x94, 0xc1, - 0x25, 0x00, 0x97, 0x70, 0xce, 0xcf, 0xcd, 0x4d, 0xcd, 0xa3, 0x95, 0x13, 0xa4, 0xb8, 0x24, 0xd0, - 0x6d, 0x82, 0xb9, 0xc2, 0x68, 0x16, 0x23, 0x17, 0xb3, 0x6f, 0x71, 0xba, 0x90, 0x0b, 0x17, 0x17, - 0x52, 0x50, 0x88, 0xe9, 0x41, 0x43, 0x49, 0x0f, 0xc5, 0xed, 0x52, 0x72, 0xd8, 0xc5, 0x61, 0xa6, - 0x09, 0xf9, 0x72, 0xf1, 0xa2, 0x7a, 0x48, 0x12, 0x53, 0x03, 0x54, 0x4a, 0x4a, 0x11, 0xa7, 0x14, - 0xcc, 0x38, 0x27, 0xdb, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, - 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x52, 0x4e, - 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x2f, 0x4a, 0x4d, 0x4f, 0xcd, 0xd3, - 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x4f, 0x4a, 0x4d, 0xd6, 0xaf, 0xd0, 0x07, 0x19, - 0x9d, 0xc4, 0x06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a, 0x89, 0x0d, 0x1c, 0xc9, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xb3, 0x9b, 0x43, 0x41, 0xf8, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -485,13 +478,6 @@ func (m *MsgCreateComment) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Body) i = encodeVarintTx(dAtA, i, uint64(len(m.Body))) i-- - dAtA[i] = 0x22 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintTx(dAtA, i, uint64(len(m.Title))) - i-- dAtA[i] = 0x1a } if len(m.Author) > 0 { @@ -501,10 +487,10 @@ func (m *MsgCreateComment) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.Slug) > 0 { - i -= len(m.Slug) - copy(dAtA[i:], m.Slug) - i = encodeVarintTx(dAtA, i, uint64(len(m.Slug))) + if len(m.PostSlug) > 0 { + i -= len(m.PostSlug) + copy(dAtA[i:], m.PostSlug) + i = encodeVarintTx(dAtA, i, uint64(len(m.PostSlug))) i-- dAtA[i] = 0xa } @@ -585,7 +571,7 @@ func (m *MsgCreateComment) Size() (n int) { } var l int _ = l - l = len(m.Slug) + l = len(m.PostSlug) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -593,10 +579,6 @@ func (m *MsgCreateComment) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.Title) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } l = len(m.Body) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -884,7 +866,7 @@ func (m *MsgCreateComment) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Slug", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PostSlug", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -912,7 +894,7 @@ func (m *MsgCreateComment) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Slug = string(dAtA[iNdEx:postIndex]) + m.PostSlug = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { @@ -947,38 +929,6 @@ func (m *MsgCreateComment) Unmarshal(dAtA []byte) error { m.Author = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) } From 91dc77a409e2f902cb2e2f631c35d065f0573fba Mon Sep 17 00:00:00 2001 From: eleijonmarck Date: Tue, 21 Jun 2022 10:16:14 +0200 Subject: [PATCH 4/6] add: implement comment functionality --- x/blog/requests.go | 24 ++++++++++++++++++++++++ x/blog/server/msg_server.go | 26 ++++++++++++++++++++++++++ x/blog/server/query_server.go | 24 ++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/x/blog/requests.go b/x/blog/requests.go index f55da6d..2bf22e5 100644 --- a/x/blog/requests.go +++ b/x/blog/requests.go @@ -7,6 +7,7 @@ import ( var ( _ sdk.Msg = &MsgCreatePost{} + _ sdk.Msg = &MsgCreateComment{} ) func (m *MsgCreatePost) ValidateBasic() error { @@ -34,3 +35,26 @@ func (m *MsgCreatePost) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{addr} } + +func (m *MsgCreateComment) ValidateBasic() error { + if m.Author == "" { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no author") + } + if m.Body == "" { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no body") + } + if m.PostSlug == "" { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no slug") + } + + return nil +} + +func (m *MsgCreateComment) GetSigners() []sdk.AccAddress { + addr, err := sdk.AccAddressFromBech32(m.Author) + if err != nil { + panic(err) + } + + return []sdk.AccAddress{addr} +} diff --git a/x/blog/server/msg_server.go b/x/blog/server/msg_server.go index 8b60604..eb7b0a0 100644 --- a/x/blog/server/msg_server.go +++ b/x/blog/server/msg_server.go @@ -38,3 +38,29 @@ func (s serverImpl) CreatePost(goCtx context.Context, request *blog.MsgCreatePos return &blog.MsgCreatePostResponse{}, nil } + +func (s serverImpl) CreateComment(goCtx context.Context, request *blog.MsgCreateComment) (*blog.MsgCreateCommentResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + store := prefix.NewStore(ctx.KVStore(s.storeKey), blog.KeyPrefix(blog.CommentKey)) + + key := []byte(request.PostSlug) + if store.Has(key) { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "duplicate slug %s found", request.PostSlug) + } + + comment := blog.Comment{ + PostSlug: request.PostSlug, + Author: request.Author, + Body: request.Body, + } + + bz, err := s.cdc.Marshal(&comment) + if err != nil { + return nil, err + } + + store.Set(key, bz) + + return &blog.MsgCreateCommentResponse{}, nil +} diff --git a/x/blog/server/query_server.go b/x/blog/server/query_server.go index 57a80e0..f171870 100644 --- a/x/blog/server/query_server.go +++ b/x/blog/server/query_server.go @@ -33,3 +33,27 @@ func (s serverImpl) AllPosts(goCtx context.Context, request *blog.QueryAllPostsR Posts: posts, }, nil } + +func (s serverImpl) AllComments(goCtx context.Context, request *blog.QueryAllCommentsRequest) (*blog.QueryAllCommentsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + store := ctx.KVStore(s.storeKey) + iterator := sdk.KVStorePrefixIterator(store, blog.KeyPrefix(blog.CommentKey)) + + defer iterator.Close() + + var comments []*blog.Comment + for ; iterator.Valid(); iterator.Next() { + var msg blog.Comment + err := s.cdc.Unmarshal(iterator.Value(), &msg) + if err != nil { + return nil, err + } + + comments = append(comments, &msg) + } + + return &blog.QueryAllCommentsResponse{ + Comments: comments, + }, nil +} From 452f6e2c95be77f84503addaa26ccfdb1cf39fe9 Mon Sep 17 00:00:00 2001 From: eleijonmarck Date: Mon, 27 Jun 2022 08:06:54 +0200 Subject: [PATCH 5/6] add: add postslug argument to comment request --- proto/blog/v1/query.proto | 3 +- x/blog/query.pb.go | 102 +++++++++++++++++++++++++++--------- x/blog/requests.go | 6 +-- x/blog/server/msg_server.go | 4 +- 4 files changed, 84 insertions(+), 31 deletions(-) diff --git a/proto/blog/v1/query.proto b/proto/blog/v1/query.proto index 174a017..086c42c 100644 --- a/proto/blog/v1/query.proto +++ b/proto/blog/v1/query.proto @@ -23,7 +23,8 @@ message QueryAllPostsResponse { } message QueryAllCommentsRequest { - cosmos.base.query.v1beta1.PageRequest pagination = 1; + string postSlug = 1; + cosmos.base.query.v1beta1.PageRequest pagination = 2; } message QueryAllCommentsResponse { diff --git a/x/blog/query.pb.go b/x/blog/query.pb.go index 05e27ab..3035655 100644 --- a/x/blog/query.pb.go +++ b/x/blog/query.pb.go @@ -125,7 +125,8 @@ func (m *QueryAllPostsResponse) GetPagination() *query.PageResponse { } type QueryAllCommentsRequest struct { - Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` + PostSlug string `protobuf:"bytes,1,opt,name=postSlug,proto3" json:"postSlug,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryAllCommentsRequest) Reset() { *m = QueryAllCommentsRequest{} } @@ -161,6 +162,13 @@ func (m *QueryAllCommentsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryAllCommentsRequest proto.InternalMessageInfo +func (m *QueryAllCommentsRequest) GetPostSlug() string { + if m != nil { + return m.PostSlug + } + return "" +} + func (m *QueryAllCommentsRequest) GetPagination() *query.PageRequest { if m != nil { return m.Pagination @@ -230,30 +238,31 @@ func init() { func init() { proto.RegisterFile("blog/v1/query.proto", fileDescriptor_eb782a0cfb4fa324) } var fileDescriptor_eb782a0cfb4fa324 = []byte{ - // 361 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0xcd, 0x4a, 0xfb, 0x40, - 0x14, 0xc5, 0x3b, 0xff, 0x3f, 0xd5, 0x32, 0x45, 0x90, 0x51, 0xb1, 0x04, 0x1c, 0x6a, 0x0b, 0x5a, - 0x44, 0x67, 0x48, 0x5d, 0xbb, 0x50, 0x41, 0x71, 0x57, 0xb3, 0x74, 0x21, 0x24, 0xe1, 0x12, 0x8b, - 0x4d, 0x26, 0xcd, 0x4c, 0xab, 0x7d, 0x00, 0xf7, 0xfa, 0x12, 0x3e, 0x8b, 0xcb, 0x2e, 0x5d, 0x4a, - 0xfb, 0x22, 0x92, 0xcc, 0x34, 0xf6, 0xc3, 0x8f, 0x4d, 0xb7, 0x77, 0xce, 0x3d, 0xe7, 0xfc, 0x72, - 0x83, 0x37, 0xbc, 0x8e, 0x08, 0x78, 0xdf, 0xe6, 0xdd, 0x1e, 0x24, 0x03, 0x16, 0x27, 0x42, 0x09, - 0xb2, 0x9a, 0x0e, 0x59, 0xdf, 0xb6, 0x0e, 0x7c, 0x21, 0x43, 0x21, 0xb9, 0xe7, 0x4a, 0xd0, 0x0a, - 0xde, 0xb7, 0x3d, 0x50, 0xae, 0xcd, 0x63, 0x37, 0x68, 0x47, 0xae, 0x6a, 0x8b, 0x48, 0x2f, 0x59, - 0xb9, 0x93, 0x1a, 0xc4, 0x20, 0xf5, 0xb0, 0x76, 0x8b, 0x37, 0xaf, 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b, 0x9e, 0xc7, 0x7c, 0x11, 0xf2, 0x04, 0x02, 0x88, 0x8e, 0x22, 0x50, 0x0f, 0x22, 0xb9, 0xe7, - 0x1e, 0xf8, 0xfc, 0x91, 0xa7, 0xd6, 0xde, 0x4a, 0xf6, 0x37, 0x1f, 0x7f, 0x06, 0x00, 0x00, 0xff, - 0xff, 0x3f, 0x5a, 0x6f, 0xb7, 0x2e, 0x03, 0x00, 0x00, + // 381 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x52, 0xcb, 0x4a, 0xeb, 0x40, + 0x18, 0xee, 0xf4, 0xd0, 0x73, 0x7a, 0xa6, 0x08, 0x12, 0x15, 0x4b, 0xc0, 0xa1, 0xb6, 0xa0, 0x45, + 0x74, 0x86, 0xd4, 0xb5, 0x0b, 0x15, 0x14, 0x77, 0x35, 0xee, 0x5c, 0x08, 0x49, 0x18, 0x62, 0x31, + 0xc9, 0xa4, 0x99, 0x49, 0xb5, 0x0b, 0x97, 0xee, 0xf5, 0x25, 0x7c, 0x16, 0x97, 0x5d, 0xba, 0x94, + 0xf6, 0x45, 0x64, 0x32, 0xd3, 0xf4, 0xe6, 0x05, 0xc4, 0x65, 0xfe, 0xf9, 0xfe, 0xef, 0x96, 0x1f, + 0xae, 0xb8, 0x01, 0xf3, 0x49, 0xcf, 0x22, 0xdd, 0x94, 0x26, 0x7d, 0x1c, 0x27, 0x4c, 0x30, 0xe3, + 0x9f, 0x1c, 0xe2, 0x9e, 0x65, 0xee, 0x78, 0x8c, 0x87, 0x8c, 0x13, 0xd7, 0xe1, 0x54, 0x21, 0x48, + 0xcf, 0x72, 0xa9, 0x70, 0x2c, 0x12, 0x3b, 0x7e, 0x27, 0x72, 0x44, 0x87, 0x45, 0x6a, 0xc9, 0xcc, + 0x99, 0x44, 0x3f, 0xa6, 0x5c, 0x0d, 0xeb, 0x57, 0x70, 0xf5, 0x5c, 0xae, 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, 0x43, 0x04, 0x1e, 0x47, 0xa8, 0x30, 0x18, 0xa1, 0xc2, 0xeb, 0x08, 0x15, 0x2e, + 0x1b, 0x7e, 0x47, 0x5c, 0xa7, 0x2e, 0xf6, 0x58, 0x48, 0x12, 0xea, 0xd3, 0x68, 0x2f, 0xa2, 0xe2, + 0x96, 0x25, 0x37, 0xc4, 0xa5, 0x1e, 0xb9, 0x23, 0x92, 0xda, 0xfd, 0x9b, 0x5d, 0xfa, 0xfe, 0x7b, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x9d, 0x86, 0x43, 0x4a, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -486,6 +495,13 @@ func (m *QueryAllCommentsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) i = encodeVarintQuery(dAtA, i, uint64(size)) } i-- + dAtA[i] = 0x12 + } + if len(m.PostSlug) > 0 { + i -= len(m.PostSlug) + copy(dAtA[i:], m.PostSlug) + i = encodeVarintQuery(dAtA, i, uint64(len(m.PostSlug))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -589,6 +605,10 @@ func (m *QueryAllCommentsRequest) Size() (n int) { } var l int _ = l + l = len(m.PostSlug) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } if m.Pagination != nil { l = m.Pagination.Size() n += 1 + l + sovQuery(uint64(l)) @@ -863,6 +883,38 @@ func (m *QueryAllCommentsRequest) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PostSlug", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PostSlug = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) } diff --git a/x/blog/requests.go b/x/blog/requests.go index 2bf22e5..73a6a4d 100644 --- a/x/blog/requests.go +++ b/x/blog/requests.go @@ -37,15 +37,15 @@ func (m *MsgCreatePost) GetSigners() []sdk.AccAddress { } func (m *MsgCreateComment) ValidateBasic() error { + if m.PostSlug == "" { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no post slug") + } if m.Author == "" { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no author") } if m.Body == "" { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no body") } - if m.PostSlug == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no slug") - } return nil } diff --git a/x/blog/server/msg_server.go b/x/blog/server/msg_server.go index eb7b0a0..f712653 100644 --- a/x/blog/server/msg_server.go +++ b/x/blog/server/msg_server.go @@ -45,8 +45,8 @@ func (s serverImpl) CreateComment(goCtx context.Context, request *blog.MsgCreate store := prefix.NewStore(ctx.KVStore(s.storeKey), blog.KeyPrefix(blog.CommentKey)) key := []byte(request.PostSlug) - if store.Has(key) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "duplicate slug %s found", request.PostSlug) + if !store.Has(key) { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "post %s to comment on does not exist in state", request.PostSlug) } comment := blog.Comment{ From 25995fabbea59af2ac3d63a35a2b1070059468b9 Mon Sep 17 00:00:00 2001 From: eleijonmarck Date: Tue, 28 Jun 2022 07:16:16 +0200 Subject: [PATCH 6/6] WIP: add test for creating comment in cli --- README.md | 6 +++++ x/blog/client/cli/cli_test.go | 51 +++++++++++++++++++++++++++++++++++ x/blog/client/cli/tx.go | 34 +++++++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/README.md b/README.md index 8d8dc9c..53b5261 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,12 @@ A new binary will be created under `./build/regen`. To run the node, you can refer to the documentation [here](https://docs.cosmos.network/master/run-node/). +## Tests +if you would like to run test, run: +```bash +make test +``` + ## Resources - Cosmos SDK Documentation: https://docs.cosmos.network/master/. diff --git a/x/blog/client/cli/cli_test.go b/x/blog/client/cli/cli_test.go index 514cabe..1c471fb 100644 --- a/x/blog/client/cli/cli_test.go +++ b/x/blog/client/cli/cli_test.go @@ -182,6 +182,57 @@ func (s *IntegrationTestSuite) TestAllPosts() { } } +func (s *IntegrationTestSuite) TestCreateComment() { + val0 := s.network.Validators[0] + + testCases := []struct { + postArgs []string + commentArgs []string + name string + expErr bool + expErrMsg string + }{ + { + postArgs: []string{val0.Address.String(), "/post", "title", "body"}, + commentArgs: []string{val0.Address.String(), "/post", "content"}, + name: "valid comment request", + expErr: false, + expErrMsg: "", + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + postcmd := cli.CmdCreatePost() + args := append([]string{ + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + }, tc.postArgs...) + _, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, postcmd, args) + s.Require().NoError(err) + + commentcmd := cli.CmdCreateComment() + args = append([]string{ + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + }, tc.commentArgs...) + fmt.Printf("args %v+", args) + out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, commentcmd, args) + if tc.expErr { + s.Require().Error(err) + s.Require().Contains(err.Error(), tc.expErrMsg) + } else { + var txRes sdk.TxResponse + err := val0.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes) + s.Require().NoError(err) + s.Require().Equal(uint32(0), txRes.Code) + } + }) + } +} + func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } diff --git a/x/blog/client/cli/tx.go b/x/blog/client/cli/tx.go index 8e9f3d3..7c87b8c 100644 --- a/x/blog/client/cli/tx.go +++ b/x/blog/client/cli/tx.go @@ -61,3 +61,37 @@ func CmdCreatePost() *cobra.Command { return cmd } + +func CmdCreateComment() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-comment [author] [post_slug] [body]", + Short: "Creates a new comment on a post", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + err := cmd.Flags().Set(flags.FlagFrom, args[0]) + if err != nil { + return err + } + + argsPostSlug := string(args[1]) + argsBody := string(args[2]) + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := &blog.MsgCreateComment{ + Author: clientCtx.GetFromAddress().String(), + PostSlug: argsPostSlug, + Body: argsBody, + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +}