implement query & update return schema

This commit is contained in:
2022-09-08 22:12:08 +00:00
parent f048bfac01
commit 5cc5bfb9d6
4 changed files with 126 additions and 60 deletions

View File

@@ -2,8 +2,11 @@ package keeper
import (
"context"
"errors"
"fmt"
"colinear/x/colinearcore/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -16,8 +19,22 @@ func (k Keeper) LockedFunds(goCtx context.Context, req *types.QueryLockedFundsRe
ctx := sdk.UnwrapSDKContext(goCtx)
// TODO: Process the query
_ = ctx
if err := sdk.VerifyAddressFormat([]byte(req.Owner)); err != nil {
return nil, fmt.Errorf("address %s is not valid", req.Owner)
}
return &types.QueryLockedFundsResponse{}, nil
lockedUsers, ok := k.GetLockedUsers(ctx)
if !ok {
return nil, errors.New("unable to get locked users")
}
var userAmtStr string
userAmtStr, ok = lockedUsers.Users[req.Owner]
if !ok {
return nil, fmt.Errorf("user %s has not locked any funds", req.Owner)
}
return &types.QueryLockedFundsResponse{
Amount: userAmtStr,
}, nil
}

View File

@@ -590,6 +590,7 @@ func (m *QueryLockedFundsRequest) GetOwner() string {
}
type QueryLockedFundsResponse struct {
Amount string `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"`
}
func (m *QueryLockedFundsResponse) Reset() { *m = QueryLockedFundsResponse{} }
@@ -625,6 +626,13 @@ func (m *QueryLockedFundsResponse) XXX_DiscardUnknown() {
var xxx_messageInfo_QueryLockedFundsResponse proto.InternalMessageInfo
func (m *QueryLockedFundsResponse) GetAmount() string {
if m != nil {
return m.Amount
}
return ""
}
func init() {
proto.RegisterType((*QueryParamsRequest)(nil), "colinear.colinearcore.QueryParamsRequest")
proto.RegisterType((*QueryParamsResponse)(nil), "colinear.colinearcore.QueryParamsResponse")
@@ -645,53 +653,54 @@ func init() {
func init() { proto.RegisterFile("colinearcore/query.proto", fileDescriptor_7b40a5389bf6a896) }
var fileDescriptor_7b40a5389bf6a896 = []byte{
// 735 bytes of a g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, 0xde, 0x70, 0xc5, 0x56, 0x17, 0x6c,
0x0f, 0x50, 0xb5, 0x80, 0x4d, 0x61, 0x91, 0x7d, 0x61, 0xff, 0x03, 0xf4, 0x09, 0x40, 0xa8, 0xea,
0xac, 0x7a, 0x5e, 0x31, 0x61, 0x66, 0xb7, 0x14, 0x13, 0x66, 0xf7, 0x04, 0xae, 0x0a, 0xc2, 0x3b,
0x08, 0x97, 0x13, 0xa2, 0x1f, 0x00, 0x8e, 0x6b, 0x53, 0x89, 0x8a, 0xb5, 0x32, 0xf3, 0x6e, 0x91,
0x73, 0xc7, 0x2b, 0xb8, 0x15, 0x01, 0x57, 0x43, 0xa4, 0x1c, 0x6e, 0x3b, 0x99, 0xf7, 0x7e, 0x0f,
0xbf, 0x00, 0x63, 0x76, 0x4b, 0xad, 0x98, 0x5d, 0x0e, 0xa5, 0x56, 0xcc, 0xd9, 0x18, 0x78, 0x51,
0xf0, 0xde, 0x45, 0x73, 0x7d, 0x44, 0x32, 0xf0, 0x37, 0x1a, 0x7d, 0xeb, 0x33, 0x8a, 0xe9, 0x2e,
0xee, 0x66, 0x76, 0x6f, 0x14, 0x77, 0x33, 0x67, 0x6d, 0xe0, 0x65, 0x41, 0xb7, 0x84, 0x16, 0x8b,
0xe9, 0x5e, 0x25, 0x49, 0x64, 0x5f, 0xac, 0xa1, 0x83, 0xb5, 0x95, 0xc3, 0x63, 0x1b, 0x1c, 0x1d,
0xdb, 0xe0, 0xcf, 0xb1, 0x0d, 0x3e, 0x9c, 0xd8, 0x95, 0xa3, 0x13, 0xbb, 0xf2, 0xeb, 0xc4, 0xae,
0xbc, 0x98, 0xe9, 0x57, 0xe9, 0x99, 0x75, 0xe2, 0xbd, 0x80, 0x45, 0xcd, 0x51, 0xf1, 0x1f, 0x64,
0xf9, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb1, 0x24, 0x22, 0xec, 0xa7, 0x09, 0x00, 0x00,
// 745 bytes of a gzipped FileDescriptorProto
0x1f, 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 0xbf, 0x09, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@@ -1436,6 +1445,13 @@ func (m *QueryLockedFundsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error
_ = i
var l int
_ = l
if len(m.Amount) > 0 {
i -= len(m.Amount)
copy(dAtA[i:], m.Amount)
i = encodeVarintQuery(dAtA, i, uint64(len(m.Amount)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
@@ -1613,6 +1629,10 @@ func (m *QueryLockedFundsResponse) Size() (n int) {
}
var l int
_ = l
l = len(m.Amount)
if l > 0 {
n += 1 + l + sovQuery(uint64(l))
}
return n
}
@@ -2669,6 +2689,38 @@ func (m *QueryLockedFundsResponse) Unmarshal(dAtA []byte) error {
return fmt.Errorf("proto: QueryLockedFundsResponse: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Amount", 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.Amount = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipQuery(dAtA[iNdEx:])