Additional bond commands (#4)

* Add commands to get bonds by id and owner

* Add commands to get bond module params and balances

* Add commands to refill, withdraw and cancel bond

* Add implementations for bond tx commands

* Use indexed map to implement command for getting bond by owner

* Use collections for bond module params

* Clean up
This commit is contained in:
prathamesh0 2024-02-08 18:53:20 +05:30 committed by GitHub
parent e511051f3e
commit 4da8dd8d7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 11741 additions and 263 deletions

File diff suppressed because it is too large Load Diff

View File

@ -19,15 +19,27 @@ import (
const _ = grpc.SupportPackageIsVersion7
const (
Query_Bonds_FullMethodName = "/cerc.bond.v1.Query/Bonds"
Query_Params_FullMethodName = "/cerc.bond.v1.Query/Params"
Query_Bonds_FullMethodName = "/cerc.bond.v1.Query/Bonds"
Query_GetBondById_FullMethodName = "/cerc.bond.v1.Query/GetBondById"
Query_GetBondsByOwner_FullMethodName = "/cerc.bond.v1.Query/GetBondsByOwner"
Query_GetBondsModuleBalance_FullMethodName = "/cerc.bond.v1.Query/GetBondsModuleBalance"
)
// QueryClient is the client API for Query service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type QueryClient interface {
// Bonds queries bonds list.
// Params queries bonds module params.
Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error)
// Bonds queries bonds list
Bonds(ctx context.Context, in *QueryGetBondsRequest, opts ...grpc.CallOption) (*QueryGetBondsResponse, error)
// GetBondById
GetBondById(ctx context.Context, in *QueryGetBondByIdRequest, opts ...grpc.CallOption) (*QueryGetBondByIdResponse, error)
// Get Bonds list by Owner
GetBondsByOwner(ctx context.Context, in *QueryGetBondsByOwnerRequest, opts ...grpc.CallOption) (*QueryGetBondsByOwnerResponse, error)
// Get Bond module balance
GetBondsModuleBalance(ctx context.Context, in *QueryGetBondModuleBalanceRequest, opts ...grpc.CallOption) (*QueryGetBondModuleBalanceResponse, error)
}
type queryClient struct {
@ -38,6 +50,15 @@ func NewQueryClient(cc grpc.ClientConnInterface) QueryClient {
return &queryClient{cc}
}
func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) {
out := new(QueryParamsResponse)
err := c.cc.Invoke(ctx, Query_Params_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *queryClient) Bonds(ctx context.Context, in *QueryGetBondsRequest, opts ...grpc.CallOption) (*QueryGetBondsResponse, error) {
out := new(QueryGetBondsResponse)
err := c.cc.Invoke(ctx, Query_Bonds_FullMethodName, in, out, opts...)
@ -47,12 +68,47 @@ func (c *queryClient) Bonds(ctx context.Context, in *QueryGetBondsRequest, opts
return out, nil
}
func (c *queryClient) GetBondById(ctx context.Context, in *QueryGetBondByIdRequest, opts ...grpc.CallOption) (*QueryGetBondByIdResponse, error) {
out := new(QueryGetBondByIdResponse)
err := c.cc.Invoke(ctx, Query_GetBondById_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *queryClient) GetBondsByOwner(ctx context.Context, in *QueryGetBondsByOwnerRequest, opts ...grpc.CallOption) (*QueryGetBondsByOwnerResponse, error) {
out := new(QueryGetBondsByOwnerResponse)
err := c.cc.Invoke(ctx, Query_GetBondsByOwner_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *queryClient) GetBondsModuleBalance(ctx context.Context, in *QueryGetBondModuleBalanceRequest, opts ...grpc.CallOption) (*QueryGetBondModuleBalanceResponse, error) {
out := new(QueryGetBondModuleBalanceResponse)
err := c.cc.Invoke(ctx, Query_GetBondsModuleBalance_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// QueryServer is the server API for Query service.
// All implementations must embed UnimplementedQueryServer
// for forward compatibility
type QueryServer interface {
// Bonds queries bonds list.
// Params queries bonds module params.
Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)
// Bonds queries bonds list
Bonds(context.Context, *QueryGetBondsRequest) (*QueryGetBondsResponse, error)
// GetBondById
GetBondById(context.Context, *QueryGetBondByIdRequest) (*QueryGetBondByIdResponse, error)
// Get Bonds list by Owner
GetBondsByOwner(context.Context, *QueryGetBondsByOwnerRequest) (*QueryGetBondsByOwnerResponse, error)
// Get Bond module balance
GetBondsModuleBalance(context.Context, *QueryGetBondModuleBalanceRequest) (*QueryGetBondModuleBalanceResponse, error)
mustEmbedUnimplementedQueryServer()
}
@ -60,9 +116,21 @@ type QueryServer interface {
type UnimplementedQueryServer struct {
}
func (UnimplementedQueryServer) Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Params not implemented")
}
func (UnimplementedQueryServer) Bonds(context.Context, *QueryGetBondsRequest) (*QueryGetBondsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Bonds not implemented")
}
func (UnimplementedQueryServer) GetBondById(context.Context, *QueryGetBondByIdRequest) (*QueryGetBondByIdResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetBondById not implemented")
}
func (UnimplementedQueryServer) GetBondsByOwner(context.Context, *QueryGetBondsByOwnerRequest) (*QueryGetBondsByOwnerResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetBondsByOwner not implemented")
}
func (UnimplementedQueryServer) GetBondsModuleBalance(context.Context, *QueryGetBondModuleBalanceRequest) (*QueryGetBondModuleBalanceResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetBondsModuleBalance not implemented")
}
func (UnimplementedQueryServer) mustEmbedUnimplementedQueryServer() {}
// UnsafeQueryServer may be embedded to opt out of forward compatibility for this service.
@ -76,6 +144,24 @@ func RegisterQueryServer(s grpc.ServiceRegistrar, srv QueryServer) {
s.RegisterService(&Query_ServiceDesc, srv)
}
func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryParamsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).Params(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Query_Params_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Query_Bonds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryGetBondsRequest)
if err := dec(in); err != nil {
@ -94,6 +180,60 @@ func _Query_Bonds_Handler(srv interface{}, ctx context.Context, dec func(interfa
return interceptor(ctx, in, info, handler)
}
func _Query_GetBondById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryGetBondByIdRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).GetBondById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Query_GetBondById_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).GetBondById(ctx, req.(*QueryGetBondByIdRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Query_GetBondsByOwner_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryGetBondsByOwnerRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).GetBondsByOwner(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Query_GetBondsByOwner_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).GetBondsByOwner(ctx, req.(*QueryGetBondsByOwnerRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Query_GetBondsModuleBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryGetBondModuleBalanceRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QueryServer).GetBondsModuleBalance(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Query_GetBondsModuleBalance_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QueryServer).GetBondsModuleBalance(ctx, req.(*QueryGetBondModuleBalanceRequest))
}
return interceptor(ctx, in, info, handler)
}
// Query_ServiceDesc is the grpc.ServiceDesc for Query service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -101,10 +241,26 @@ var Query_ServiceDesc = grpc.ServiceDesc{
ServiceName: "cerc.bond.v1.Query",
HandlerType: (*QueryServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Params",
Handler: _Query_Params_Handler,
},
{
MethodName: "Bonds",
Handler: _Query_Bonds_Handler,
},
{
MethodName: "GetBondById",
Handler: _Query_GetBondById_Handler,
},
{
MethodName: "GetBondsByOwner",
Handler: _Query_GetBondsByOwner_Handler,
},
{
MethodName: "GetBondsModuleBalance",
Handler: _Query_GetBondsModuleBalance_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "cerc/bond/v1/query.proto",

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,10 @@ import (
const _ = grpc.SupportPackageIsVersion7
const (
Msg_CreateBond_FullMethodName = "/cerc.bond.v1.Msg/CreateBond"
Msg_CreateBond_FullMethodName = "/cerc.bond.v1.Msg/CreateBond"
Msg_RefillBond_FullMethodName = "/cerc.bond.v1.Msg/RefillBond"
Msg_WithdrawBond_FullMethodName = "/cerc.bond.v1.Msg/WithdrawBond"
Msg_CancelBond_FullMethodName = "/cerc.bond.v1.Msg/CancelBond"
)
// MsgClient is the client API for Msg service.
@ -28,6 +31,12 @@ const (
type MsgClient interface {
// CreateBond defines a method for creating a new bond.
CreateBond(ctx context.Context, in *MsgCreateBond, opts ...grpc.CallOption) (*MsgCreateBondResponse, error)
// RefillBond defines a method for refilling amount for bond.
RefillBond(ctx context.Context, in *MsgRefillBond, opts ...grpc.CallOption) (*MsgRefillBondResponse, error)
// WithdrawBond defines a method for withdrawing amount from bond.
WithdrawBond(ctx context.Context, in *MsgWithdrawBond, opts ...grpc.CallOption) (*MsgWithdrawBondResponse, error)
// CancelBond defines a method for cancelling a bond.
CancelBond(ctx context.Context, in *MsgCancelBond, opts ...grpc.CallOption) (*MsgCancelBondResponse, error)
}
type msgClient struct {
@ -47,12 +56,45 @@ func (c *msgClient) CreateBond(ctx context.Context, in *MsgCreateBond, opts ...g
return out, nil
}
func (c *msgClient) RefillBond(ctx context.Context, in *MsgRefillBond, opts ...grpc.CallOption) (*MsgRefillBondResponse, error) {
out := new(MsgRefillBondResponse)
err := c.cc.Invoke(ctx, Msg_RefillBond_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *msgClient) WithdrawBond(ctx context.Context, in *MsgWithdrawBond, opts ...grpc.CallOption) (*MsgWithdrawBondResponse, error) {
out := new(MsgWithdrawBondResponse)
err := c.cc.Invoke(ctx, Msg_WithdrawBond_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *msgClient) CancelBond(ctx context.Context, in *MsgCancelBond, opts ...grpc.CallOption) (*MsgCancelBondResponse, error) {
out := new(MsgCancelBondResponse)
err := c.cc.Invoke(ctx, Msg_CancelBond_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// MsgServer is the server API for Msg service.
// All implementations must embed UnimplementedMsgServer
// for forward compatibility
type MsgServer interface {
// CreateBond defines a method for creating a new bond.
CreateBond(context.Context, *MsgCreateBond) (*MsgCreateBondResponse, error)
// RefillBond defines a method for refilling amount for bond.
RefillBond(context.Context, *MsgRefillBond) (*MsgRefillBondResponse, error)
// WithdrawBond defines a method for withdrawing amount from bond.
WithdrawBond(context.Context, *MsgWithdrawBond) (*MsgWithdrawBondResponse, error)
// CancelBond defines a method for cancelling a bond.
CancelBond(context.Context, *MsgCancelBond) (*MsgCancelBondResponse, error)
mustEmbedUnimplementedMsgServer()
}
@ -63,6 +105,15 @@ type UnimplementedMsgServer struct {
func (UnimplementedMsgServer) CreateBond(context.Context, *MsgCreateBond) (*MsgCreateBondResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateBond not implemented")
}
func (UnimplementedMsgServer) RefillBond(context.Context, *MsgRefillBond) (*MsgRefillBondResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method RefillBond not implemented")
}
func (UnimplementedMsgServer) WithdrawBond(context.Context, *MsgWithdrawBond) (*MsgWithdrawBondResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method WithdrawBond not implemented")
}
func (UnimplementedMsgServer) CancelBond(context.Context, *MsgCancelBond) (*MsgCancelBondResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CancelBond not implemented")
}
func (UnimplementedMsgServer) mustEmbedUnimplementedMsgServer() {}
// UnsafeMsgServer may be embedded to opt out of forward compatibility for this service.
@ -94,6 +145,60 @@ func _Msg_CreateBond_Handler(srv interface{}, ctx context.Context, dec func(inte
return interceptor(ctx, in, info, handler)
}
func _Msg_RefillBond_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(MsgRefillBond)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MsgServer).RefillBond(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Msg_RefillBond_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MsgServer).RefillBond(ctx, req.(*MsgRefillBond))
}
return interceptor(ctx, in, info, handler)
}
func _Msg_WithdrawBond_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(MsgWithdrawBond)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MsgServer).WithdrawBond(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Msg_WithdrawBond_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MsgServer).WithdrawBond(ctx, req.(*MsgWithdrawBond))
}
return interceptor(ctx, in, info, handler)
}
func _Msg_CancelBond_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(MsgCancelBond)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MsgServer).CancelBond(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Msg_CancelBond_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MsgServer).CancelBond(ctx, req.(*MsgCancelBond))
}
return interceptor(ctx, in, info, handler)
}
// Msg_ServiceDesc is the grpc.ServiceDesc for Msg service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -105,6 +210,18 @@ var Msg_ServiceDesc = grpc.ServiceDesc{
MethodName: "CreateBond",
Handler: _Msg_CreateBond_Handler,
},
{
MethodName: "RefillBond",
Handler: _Msg_RefillBond_Handler,
},
{
MethodName: "WithdrawBond",
Handler: _Msg_WithdrawBond_Handler,
},
{
MethodName: "CancelBond",
Handler: _Msg_CancelBond_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "cerc/bond/v1/tx.proto",

2
go.mod
View File

@ -15,6 +15,7 @@ replace (
require (
cosmossdk.io/api v0.7.2
cosmossdk.io/client/v2 v2.0.0-beta.1
cosmossdk.io/collections v0.4.0
cosmossdk.io/core v0.11.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.1
@ -37,7 +38,6 @@ require (
)
require (
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/x/tx v0.13.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect

View File

@ -10,6 +10,4 @@ message Module {
option (cosmos.app.v1alpha1.module) = {
go_import : "git.vdb.to/cerc-io/laconic2d/x/bond"
};
// TODO: Setup any config required
}

View File

@ -8,15 +8,45 @@ import "gogoproto/gogo.proto";
import "cerc/bond/v1/bond.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/base/v1beta1/coin.proto";
// import "cosmos/query/v1/query.proto";
// Query defines the gRPC querier service for bond module
service Query {
// Bonds queries bonds list.
// Params queries bonds module params.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cerc/bond/v1/params";
}
// Bonds queries bonds list
rpc Bonds(QueryGetBondsRequest) returns (QueryGetBondsResponse) {
// option (cosmos.query.v1.module_query_safe) = true; // Add?
// Mark query as module_query_safe?
// option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/cerc/bond/v1/bonds";
}
// GetBondById
rpc GetBondById(QueryGetBondByIdRequest) returns (QueryGetBondByIdResponse) {
option (google.api.http).get = "/cerc/bond/v1/bonds/{id}";
}
// Get Bonds list by Owner
rpc GetBondsByOwner(QueryGetBondsByOwnerRequest) returns (QueryGetBondsByOwnerResponse) {
option (google.api.http).get = "/cerc/bond/v1/by-owner/{owner}";
}
// Get Bond module balance
rpc GetBondsModuleBalance(QueryGetBondModuleBalanceRequest) returns (QueryGetBondModuleBalanceResponse) {
option (google.api.http).get = "/cerc/bond/v1/balance";
}
}
// QueryParamsRequest is request for query the bond module params
message QueryParamsRequest {}
// QueryParamsResponse returns response type of bond module params
message QueryParamsResponse {
Params params = 1 [(gogoproto.moretags) = "json:\"params\" yaml:\"params\""];
}
// QueryGetBondById queries a bonds.
@ -33,3 +63,39 @@ message QueryGetBondsResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGetBondById
message QueryGetBondByIdRequest {
string id = 1 [(gogoproto.moretags) = "json:\"id\" yaml:\"id\""];
}
// QueryGetBondByIdResponse returns QueryGetBondById query response
message QueryGetBondByIdResponse {
Bond bond = 1 [(gogoproto.moretags) = "json:\"bond\" yaml:\"bond\""];
}
// QueryGetBondsByOwnerRequest is request type for Query/GetBondsByOwner RPC Method
message QueryGetBondsByOwnerRequest {
string owner = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGetBondsByOwnerResponse is response type for Query/GetBondsByOwner RPC Method
message QueryGetBondsByOwnerResponse {
repeated Bond bonds = 1 [(gogoproto.nullable) = false, (gogoproto.moretags) = "json:\"bonds\" yaml:\"bonds\""];
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGetBondModuleBalanceRequest is request type for bond module balance rpc method
message QueryGetBondModuleBalanceRequest {}
// QueryGetBondModuleBalanceResponse is the response type for bond module balance rpc method
message QueryGetBondModuleBalanceResponse {
repeated cosmos.base.v1beta1.Coin balance = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "json:\"coins\" yaml:\"coins\""
];
}

View File

@ -9,8 +9,6 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
// TODO: Add remaining messages
// Msg defines the bond Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
@ -20,6 +18,20 @@ service Msg {
option (google.api.http).post = "/cerc/bond/v1/create_bond";
};
// RefillBond defines a method for refilling amount for bond.
rpc RefillBond(MsgRefillBond) returns (MsgRefillBondResponse) {
option (google.api.http).post = "/cerc/bond/v1/refill_bond";
};
// WithdrawBond defines a method for withdrawing amount from bond.
rpc WithdrawBond(MsgWithdrawBond) returns (MsgWithdrawBondResponse) {
option (google.api.http).post = "/cerc/bond/v1/withdraw_bond";
};
// CancelBond defines a method for cancelling a bond.
rpc CancelBond(MsgCancelBond) returns (MsgCancelBondResponse) {
option (google.api.http).post = "/cerc/bond/v1/cancel_bond";
};
}
// MsgCreateBond defines a SDK message for creating a new bond.
@ -38,3 +50,46 @@ message MsgCreateBond {
message MsgCreateBondResponse {
string id = 1;
}
// MsgRefillBond defines a SDK message for refill the amount for bond.
message MsgRefillBond {
option (cosmos.msg.v1.signer) = "signer";
string id = 1;
string signer = 2;
repeated cosmos.base.v1beta1.Coin coins = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "json:\"coins\" yaml:\"coins\""
];
}
// MsgRefillBondResponse defines the Msg/RefillBond response type.
message MsgRefillBondResponse {}
// MsgWithdrawBond defines a SDK message for withdrawing amount from bond.
message MsgWithdrawBond {
option (cosmos.msg.v1.signer) = "signer";
string id = 1;
string signer = 2;
repeated cosmos.base.v1beta1.Coin coins = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "json:\"coins\" yaml:\"coins\""
];
}
// MsgWithdrawBondResponse defines the Msg/WithdrawBond response type.
message MsgWithdrawBondResponse {}
// MsgCancelBond defines a SDK message for the cancel the bond.
message MsgCancelBond {
option (cosmos.msg.v1.signer) = "signer";
string id = 1;
string signer = 2;
}
// MsgCancelBondResponse defines the Msg/CancelBond response type.
message MsgCancelBondResponse {}

View File

@ -10,9 +10,9 @@ import (
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgCreateBond{},
// &MsgRefillBond{},
// &MsgCancelBond{},
// &MsgWithdrawBond{},
&MsgRefillBond{},
&MsgCancelBond{},
&MsgWithdrawBond{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

View File

@ -10,6 +10,6 @@ const (
AttributeKeySigner = "signer"
AttributeKeyAmount = "amount"
AttributeKeyBondID = "bond_id"
AttributeKeyBondId = "bond_id"
AttributeValueCategory = ModuleName
)

View File

@ -7,7 +7,9 @@ import (
// InitGenesis initializes the module state from a genesis state.
func (k *Keeper) InitGenesis(ctx sdk.Context, data *bond.GenesisState) error {
k.SetParams(ctx, data.Params)
if err := k.Params.Set(ctx, data.Params); err != nil {
return err
}
// Save bonds in store.
for _, bond := range data.Bonds {
@ -21,7 +23,10 @@ func (k *Keeper) InitGenesis(ctx sdk.Context, data *bond.GenesisState) error {
// ExportGenesis exports the module state to a genesis state.
func (k *Keeper) ExportGenesis(ctx sdk.Context) (*bond.GenesisState, error) {
params := k.GetParams(ctx)
params, err := k.Params.Get(ctx)
if err != nil {
return nil, err
}
bonds, err := k.ListBonds(ctx)
if err != nil {

View File

@ -3,9 +3,11 @@ package keeper
import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"cosmossdk.io/collections"
"cosmossdk.io/collections/indexes"
"cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
@ -18,6 +20,26 @@ import (
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
)
type BondsIndexes struct {
Owner *indexes.Multi[string, string, bondtypes.Bond]
}
func (b BondsIndexes) IndexesList() []collections.Index[string, bondtypes.Bond] {
return []collections.Index[string, bondtypes.Bond]{b.Owner}
}
func newBondIndexes(sb *collections.SchemaBuilder) BondsIndexes {
return BondsIndexes{
Owner: indexes.NewMulti(
sb, bondtypes.BondOwnerIndexPrefix, "bonds_by_owner",
collections.StringKey, collections.StringKey,
func(_ string, v bondtypes.Bond) (string, error) {
return v.Owner, nil
},
),
}
}
type Keeper struct {
// Codecs
cdc codec.BinaryCodec
@ -29,11 +51,10 @@ type Keeper struct {
// Track bond usage in other cosmos-sdk modules (more like a usage tracker).
// usageKeepers []types.BondUsageKeeper
// paramSubspace paramtypes.Subspace
// State management
Schema collections.Schema
Bonds collections.Map[string, bondtypes.Bond]
Params collections.Item[bondtypes.Params]
Bonds *collections.IndexedMap[string, bondtypes.Bond, BondsIndexes]
}
// NewKeeper creates new instances of the bond Keeper
@ -43,21 +64,15 @@ func NewKeeper(
accountKeeper auth.AccountKeeper,
bankKeeper bank.Keeper,
// usageKeepers []types.BondUsageKeeper,
// ps paramtypes.Subspace,
) Keeper {
// set KeyTable if it has not already been set
// if !ps.HasKeyTable() {
// ps = ps.WithKeyTable(types.ParamKeyTable())
// }
sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
Bonds: collections.NewMap(sb, bondtypes.BondsKey, "bonds", collections.StringKey, codec.CollValue[bondtypes.Bond](cdc)),
Params: collections.NewItem(sb, bondtypes.ParamsKeyPrefix, "params", codec.CollValue[bondtypes.Params](cdc)),
Bonds: collections.NewIndexedMap(sb, bondtypes.BondsKeyPrefix, "bonds", collections.StringKey, codec.CollValue[bondtypes.Bond](cdc), newBondIndexes(sb)),
// usageKeepers: usageKeepers,
// paramSubspace: ps,
}
schema, err := sb.Build()
@ -70,58 +85,39 @@ func NewKeeper(
return k
}
// BondID simplifies generation of bond IDs.
type BondID struct {
// BondId simplifies generation of bond Ids.
type BondId struct {
Address sdk.Address
AccNum uint64
Sequence uint64
}
// Generate creates the bond ID.
func (bondID BondID) Generate() string {
// Generate creates the bond Id.
func (bondId BondId) Generate() string {
hasher := sha256.New()
str := fmt.Sprintf("%s:%d:%d", bondID.Address.String(), bondID.AccNum, bondID.Sequence)
str := fmt.Sprintf("%s:%d:%d", bondId.Address.String(), bondId.AccNum, bondId.Sequence)
hasher.Write([]byte(str))
return hex.EncodeToString(hasher.Sum(nil))
}
// CreateBond creates a new bond.
func (k Keeper) CreateBond(ctx sdk.Context, ownerAddress sdk.AccAddress, coins sdk.Coins) (*bondtypes.Bond, error) {
// Check if account has funds.
for _, coin := range coins {
balance := k.bankKeeper.HasBalance(ctx, ownerAddress, coin)
if !balance {
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "failed to create bond; Insufficient funds")
}
}
// Generate bond ID.
account := k.accountKeeper.GetAccount(ctx, ownerAddress)
bondID := BondID{
Address: ownerAddress,
AccNum: account.GetAccountNumber(),
Sequence: account.GetSequence(),
}.Generate()
maxBondAmount := k.getMaxBondAmount(ctx)
bond := bondtypes.Bond{Id: bondID, Owner: ownerAddress.String(), Balance: coins}
if bond.Balance.IsAnyGT(maxBondAmount) {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
}
// Move funds into the bond account module.
err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, ownerAddress, bondtypes.ModuleName, bond.Balance)
// HasBond - checks if a bond by the given Id exists.
func (k Keeper) HasBond(ctx sdk.Context, id string) (bool, error) {
has, err := k.Bonds.Has(ctx, id)
if err != nil {
return nil, err
return false, err
}
// Save bond in store.
if err := k.Bonds.Set(ctx, bond.Id, bond); err != nil {
return nil, err
}
return has, nil
}
return &bond, nil
// SaveBond - saves a bond to the store.
func (k Keeper) SaveBond(ctx sdk.Context, bond *bondtypes.Bond) error {
return k.Bonds.Set(ctx, bond.Id, *bond)
}
// DeleteBond - deletes the bond.
func (k Keeper) DeleteBond(ctx sdk.Context, bond bondtypes.Bond) error {
return k.Bonds.Remove(ctx, bond.Id)
}
// ListBonds - get all bonds.
@ -145,8 +141,222 @@ func (k Keeper) ListBonds(ctx sdk.Context) ([]*bondtypes.Bond, error) {
return bonds, nil
}
func (k Keeper) getMaxBondAmount(ctx sdk.Context) sdk.Coins {
params := k.GetParams(ctx)
maxBondAmount := params.MaxBondAmount
return sdk.NewCoins(maxBondAmount)
func (k Keeper) GetBondById(ctx sdk.Context, id string) (bondtypes.Bond, error) {
bond, err := k.Bonds.Get(ctx, id)
if err != nil {
if errors.Is(err, collections.ErrNotFound) {
return bondtypes.Bond{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
}
return bondtypes.Bond{}, err
}
return bond, nil
}
func (k Keeper) GetBondsByOwner(ctx sdk.Context, owner string) ([]bondtypes.Bond, error) {
iter, err := k.Bonds.Indexes.Owner.MatchExact(ctx, owner)
if err != nil {
return []bondtypes.Bond{}, err
}
return indexes.CollectValues(ctx, k.Bonds, iter)
}
// GetBondModuleBalances gets the bond module account(s) balances.
func (k Keeper) GetBondModuleBalances(ctx sdk.Context) sdk.Coins {
moduleAddress := k.accountKeeper.GetModuleAddress(bondtypes.ModuleName)
balances := k.bankKeeper.GetAllBalances(ctx, moduleAddress)
return balances
}
// CreateBond creates a new bond.
func (k Keeper) CreateBond(ctx sdk.Context, ownerAddress sdk.AccAddress, coins sdk.Coins) (*bondtypes.Bond, error) {
// Check if account has funds.
for _, coin := range coins {
balance := k.bankKeeper.HasBalance(ctx, ownerAddress, coin)
if !balance {
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "failed to create bond; Insufficient funds")
}
}
// Generate bond Id.
account := k.accountKeeper.GetAccount(ctx, ownerAddress)
bondId := BondId{
Address: ownerAddress,
AccNum: account.GetAccountNumber(),
Sequence: account.GetSequence(),
}.Generate()
maxBondAmount, err := k.getMaxBondAmount(ctx)
if err != nil {
return nil, err
}
bond := bondtypes.Bond{Id: bondId, Owner: ownerAddress.String(), Balance: coins}
if bond.Balance.IsAnyGT(maxBondAmount) {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
}
// Move funds into the bond account module.
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, ownerAddress, bondtypes.ModuleName, bond.Balance)
if err != nil {
return nil, err
}
// Save bond in store.
err = k.SaveBond(ctx, &bond)
if err != nil {
return nil, err
}
return &bond, nil
}
func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*bondtypes.Bond, error) {
if has, err := k.HasBond(ctx, id); !has {
if err != nil {
return nil, err
}
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
}
bond, err := k.GetBondById(ctx, id)
if err != nil {
return nil, err
}
if bond.Owner != ownerAddress.String() {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
}
// Check if account has funds.
for _, coin := range coins {
if !k.bankKeeper.HasBalance(ctx, ownerAddress, coin) {
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.")
}
}
maxBondAmount, err := k.getMaxBondAmount(ctx)
if err != nil {
return nil, err
}
updatedBalance := bond.Balance.Add(coins...)
if updatedBalance.IsAnyGT(maxBondAmount) {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
}
// Move funds into the bond account module.
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, ownerAddress, bondtypes.ModuleName, coins)
if err != nil {
return nil, err
}
// Update bond balance and save.
bond.Balance = updatedBalance
err = k.SaveBond(ctx, &bond)
if err != nil {
return nil, err
}
return &bond, nil
}
func (k Keeper) WithdrawBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*bondtypes.Bond, error) {
if has, err := k.HasBond(ctx, id); !has {
if err != nil {
return nil, err
}
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
}
bond, err := k.GetBondById(ctx, id)
if err != nil {
return nil, err
}
if bond.Owner != ownerAddress.String() {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
}
updatedBalance, isNeg := bond.Balance.SafeSub(coins...)
if isNeg {
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient bond balance.")
}
// Move funds from the bond into the account.
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, bondtypes.ModuleName, ownerAddress, coins)
if err != nil {
return nil, err
}
// Update bond balance and save.
bond.Balance = updatedBalance
err = k.SaveBond(ctx, &bond)
if err != nil {
return nil, err
}
return &bond, nil
}
func (k Keeper) CancelBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress) (*bondtypes.Bond, error) {
if has, err := k.HasBond(ctx, id); !has {
if err != nil {
return nil, err
}
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
}
bond, err := k.GetBondById(ctx, id)
if err != nil {
return nil, err
}
if bond.Owner != ownerAddress.String() {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
}
// TODO
// Check if bond is used in other modules.
// for _, usageKeeper := range k.usageKeepers {
// if usageKeeper.UsesBond(ctx, id) {
// return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("Bond in use by the '%s' module.", usageKeeper.ModuleName()))
// }
// }
// Move funds from the bond into the account.
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, bondtypes.ModuleName, ownerAddress, bond.Balance)
if err != nil {
return nil, err
}
// Remove bond from store.
err = k.DeleteBond(ctx, bond)
if err != nil {
return nil, err
}
return &bond, nil
}
// GetParams gets the bond module's parameters.
func (k Keeper) GetParams(ctx sdk.Context) (*bondtypes.Params, error) {
params, err := k.Params.Get(ctx)
if err != nil {
return nil, err
}
return &params, nil
}
func (k Keeper) getMaxBondAmount(ctx sdk.Context) (sdk.Coins, error) {
params, err := k.GetParams(ctx)
if err != nil {
return nil, err
}
maxBondAmount := params.MaxBondAmount
return sdk.NewCoins(maxBondAmount), nil
}

View File

@ -12,7 +12,6 @@ type msgServer struct {
k Keeper
}
// TODO: Generate types
var _ bond.MsgServer = msgServer{}
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
@ -20,10 +19,9 @@ func NewMsgServerImpl(keeper Keeper) bond.MsgServer {
return &msgServer{k: keeper}
}
// TODO: Add remaining write methods
func (ms msgServer) CreateBond(c context.Context, msg *bond.MsgCreateBond) (*bond.MsgCreateBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
@ -48,3 +46,93 @@ func (ms msgServer) CreateBond(c context.Context, msg *bond.MsgCreateBond) (*bon
return &bond.MsgCreateBondResponse{}, nil
}
// RefillBond implements bond.MsgServer.
func (ms msgServer) RefillBond(c context.Context, msg *bond.MsgRefillBond) (*bond.MsgRefillBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
}
_, err = ms.k.RefillBond(ctx, msg.Id, signerAddress, msg.Coins)
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
bond.EventTypeRefillBond,
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
),
})
return &bond.MsgRefillBondResponse{}, nil
}
// WithdrawBond implements bond.MsgServer.
func (ms msgServer) WithdrawBond(c context.Context, msg *bond.MsgWithdrawBond) (*bond.MsgWithdrawBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
}
_, err = ms.k.WithdrawBond(ctx, msg.Id, signerAddress, msg.Coins)
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
bond.EventTypeWithdrawBond,
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id),
sdk.NewAttribute(sdk.AttributeKeyAmount, msg.Coins.String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
),
})
return &bond.MsgWithdrawBondResponse{}, nil
}
// CancelBond implements bond.MsgServer.
func (ms msgServer) CancelBond(c context.Context, msg *bond.MsgCancelBond) (*bond.MsgCancelBondResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
}
_, err = ms.k.CancelBond(ctx, msg.Id, signerAddress)
if err != nil {
return nil, err
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
bond.EventTypeCancelBond,
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
sdk.NewAttribute(bond.AttributeKeyBondId, msg.Id),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, bond.AttributeValueCategory),
sdk.NewAttribute(bond.AttributeKeySigner, msg.Signer),
),
})
return &bond.MsgCancelBondResponse{}, nil
}

View File

@ -1,23 +0,0 @@
package keeper
import (
"git.vdb.to/cerc-io/laconic2d/x/bond"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// GetMaxBondAmount max bond amount
func (k Keeper) GetMaxBondAmount(ctx sdk.Context) (res sdk.Coin) {
// TODO: Implement
return sdk.NewCoin(sdk.DefaultBondDenom, bond.DefaultMaxBondAmountTokens)
}
// GetParams - Get all parameter as types.Params.
func (k Keeper) GetParams(ctx sdk.Context) (params bond.Params) {
getMaxBondAmount := k.GetMaxBondAmount(ctx)
return bond.Params{MaxBondAmount: getMaxBondAmount}
}
// SetParams - set the params.
func (k Keeper) SetParams(ctx sdk.Context, params bond.Params) {
// TODO: Implement
}

View File

@ -3,24 +3,38 @@ package keeper
import (
"context"
"git.vdb.to/cerc-io/laconic2d/x/bond"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
// TODO: Add remaining query methods
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
)
type queryServer struct {
k Keeper
}
var _ bond.QueryServer = queryServer{}
var _ bondtypes.QueryServer = queryServer{}
// NewQueryServerImpl returns an implementation of the module QueryServer.
func NewQueryServerImpl(k Keeper) bond.QueryServer {
func NewQueryServerImpl(k Keeper) bondtypes.QueryServer {
return queryServer{k}
}
func (qs queryServer) Bonds(c context.Context, _ *bond.QueryGetBondsRequest) (*bond.QueryGetBondsResponse, error) {
// Params implements bond.QueryServer.
func (qs queryServer) Params(c context.Context, _ *bondtypes.QueryParamsRequest) (*bondtypes.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params, err := qs.k.GetParams(ctx)
if err != nil {
return nil, err
}
return &bondtypes.QueryParamsResponse{Params: params}, nil
}
// Bonds implements bond.QueryServer.
func (qs queryServer) Bonds(c context.Context, _ *bondtypes.QueryGetBondsRequest) (*bondtypes.QueryGetBondsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
resp, err := qs.k.ListBonds(ctx)
@ -28,5 +42,47 @@ func (qs queryServer) Bonds(c context.Context, _ *bond.QueryGetBondsRequest) (*b
return nil, err
}
return &bond.QueryGetBondsResponse{Bonds: resp}, nil
return &bondtypes.QueryGetBondsResponse{Bonds: resp}, nil
}
// GetBondById implements bond.QueryServer.
func (qs queryServer) GetBondById(c context.Context, req *bondtypes.QueryGetBondByIdRequest) (*bondtypes.QueryGetBondByIdResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
bondId := req.GetId()
if len(bondId) == 0 {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id required")
}
bond, err := qs.k.GetBondById(ctx, bondId)
if err != nil {
return nil, err
}
return &bondtypes.QueryGetBondByIdResponse{Bond: &bond}, nil
}
// GetBondsByOwner implements bond.QueryServer.
func (qs queryServer) GetBondsByOwner(c context.Context, req *bondtypes.QueryGetBondsByOwnerRequest) (*bondtypes.QueryGetBondsByOwnerResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
owner := req.GetOwner()
if len(owner) == 0 {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "owner required")
}
bonds, err := qs.k.GetBondsByOwner(ctx, owner)
if err != nil {
return nil, err
}
return &bondtypes.QueryGetBondsByOwnerResponse{Bonds: bonds}, nil
}
// GetBondsModuleBalance implements bond.QueryServer.
func (qs queryServer) GetBondsModuleBalance(c context.Context, _ *bondtypes.QueryGetBondModuleBalanceRequest) (*bondtypes.QueryGetBondModuleBalanceResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
balances := qs.k.GetBondModuleBalances(ctx)
return &bondtypes.QueryGetBondModuleBalanceResponse{Balance: balances}, nil
}

View File

@ -7,11 +7,13 @@ const (
// StoreKey is the string store representation
StoreKey = ModuleName
// TODO: Add required keys
)
// Store prefixes
var (
BondsKey = collections.NewPrefix(0)
// ParamsKey is the prefix for params key
ParamsKeyPrefix = collections.NewPrefix(0)
BondsKeyPrefix = collections.NewPrefix(1)
BondOwnerIndexPrefix = collections.NewPrefix(2)
)

View File

@ -15,12 +15,40 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
Query: &autocliv1.ServiceCommandDescriptor{
Service: bondv1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Params",
Use: "params",
Short: "Get the current bond parameters",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
},
{
RpcMethod: "Bonds",
Use: "list",
Short: "List bonds",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
},
{
RpcMethod: "GetBondById",
Use: "get [bond-id]",
Short: "Get bond info by bond id",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "id"},
},
},
{
RpcMethod: "GetBondsByOwner",
Use: "by-owner [owner-address]",
Short: "Get bonds list by owner address",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "owner"},
},
},
{
RpcMethod: "GetBondsModuleBalance",
Use: "balance",
Short: "Get bond module account balances",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
@ -34,6 +62,32 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
{ProtoField: "coins"},
},
},
{
RpcMethod: "RefillBond",
Use: "refill [bond-id] [amount]",
Short: "Refill bond",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "id"},
{ProtoField: "coins"},
},
},
{
RpcMethod: "WithdrawBond",
Use: "withdraw [bond-id] [amount]",
Short: "Withdraw amount from bond",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "id"},
{ProtoField: "coins"},
},
},
{
RpcMethod: "CancelBond",
Use: "cancel [bond-id]",
Short: "Cancel bond",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "id"},
},
},
},
},
}

View File

@ -6,32 +6,27 @@ import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
var _ paramtypes.ParamSet = &Params{}
// Default parameter values.
var DefaultMaxBondAmountTokens = sdkmath.NewInt(100000000000)
// Parameter keys
var ParamStoreKeyMaxBondAmount = []byte("MaxBondAmount")
func NewParams(maxBondAmount sdk.Coin) Params {
return Params{MaxBondAmount: maxBondAmount}
}
// DefaultParams returns default module parameters
// ExtraEIPs is empty to prevent overriding the latest hard fork instruction set
func DefaultParams() Params {
return NewParams(sdk.NewCoin(sdk.DefaultBondDenom, DefaultMaxBondAmountTokens))
}
// ParamSetPairs returns the parameter set pairs.
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyMaxBondAmount, &p.MaxBondAmount, validateMaxBondAmount),
// Validate checks that the parameters have valid values
func (p Params) Validate() error {
if err := validateMaxBondAmount(p.MaxBondAmount); err != nil {
return err
}
return nil
}
func validateMaxBondAmount(i interface{}) error {
@ -46,12 +41,3 @@ func validateMaxBondAmount(i interface{}) error {
return nil
}
// Validate checks that the parameters have valid values
func (p Params) Validate() error {
if err := validateMaxBondAmount(p.MaxBondAmount); err != nil {
return err
}
return nil
}

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,24 @@ var _ = utilities.NewDoubleArray
var _ = descriptor.ForMessage
var _ = metadata.Join
func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryParamsRequest
var metadata runtime.ServerMetadata
msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryParamsRequest
var metadata runtime.ServerMetadata
msg, err := server.Params(ctx, &protoReq)
return msg, metadata, err
}
var (
filter_Query_Bonds_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
@ -69,12 +87,179 @@ func local_request_Query_Bonds_0(ctx context.Context, marshaler runtime.Marshale
}
func request_Query_GetBondById_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryGetBondByIdRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["id"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
}
protoReq.Id, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
}
msg, err := client.GetBondById(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_GetBondById_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryGetBondByIdRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["id"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
}
protoReq.Id, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
}
msg, err := server.GetBondById(ctx, &protoReq)
return msg, metadata, err
}
var (
filter_Query_GetBondsByOwner_0 = &utilities.DoubleArray{Encoding: map[string]int{"owner": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
)
func request_Query_GetBondsByOwner_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryGetBondsByOwnerRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["owner"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "owner")
}
protoReq.Owner, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "owner", err)
}
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetBondsByOwner_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.GetBondsByOwner(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_GetBondsByOwner_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryGetBondsByOwnerRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["owner"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "owner")
}
protoReq.Owner, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "owner", err)
}
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetBondsByOwner_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.GetBondsByOwner(ctx, &protoReq)
return msg, metadata, err
}
func request_Query_GetBondsModuleBalance_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryGetBondModuleBalanceRequest
var metadata runtime.ServerMetadata
msg, err := client.GetBondsModuleBalance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Query_GetBondsModuleBalance_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryGetBondModuleBalanceRequest
var metadata runtime.ServerMetadata
msg, err := server.GetBondsModuleBalance(ctx, &protoReq)
return msg, metadata, err
}
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
// UnaryRPC :call QueryServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.
func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error {
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_Bonds_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@ -98,6 +283,75 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
})
mux.Handle("GET", pattern_Query_GetBondById_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_GetBondById_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_GetBondById_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_GetBondsByOwner_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_GetBondsByOwner_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_GetBondsByOwner_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_GetBondsModuleBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Query_GetBondsModuleBalance_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_GetBondsModuleBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -139,6 +393,26 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc
// "QueryClient" to call the correct interceptors.
func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error {
mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_Bonds_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@ -159,13 +433,89 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
})
mux.Handle("GET", pattern_Query_GetBondById_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_GetBondById_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_GetBondById_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_GetBondsByOwner_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_GetBondsByOwner_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_GetBondsByOwner_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Query_GetBondsModuleBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Query_GetBondsModuleBalance_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Query_GetBondsModuleBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cerc", "bond", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_Bonds_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cerc", "bond", "v1", "bonds"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_GetBondById_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cerc", "bond", "v1", "bonds", "id"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_GetBondsByOwner_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"cerc", "bond", "v1", "by-owner", "owner"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Query_GetBondsModuleBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cerc", "bond", "v1", "balance"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
forward_Query_Params_0 = runtime.ForwardResponseMessage
forward_Query_Bonds_0 = runtime.ForwardResponseMessage
forward_Query_GetBondById_0 = runtime.ForwardResponseMessage
forward_Query_GetBondsByOwner_0 = runtime.ForwardResponseMessage
forward_Query_GetBondsModuleBalance_0 = runtime.ForwardResponseMessage
)

File diff suppressed because it is too large Load Diff

View File

@ -69,6 +69,114 @@ func local_request_Msg_CreateBond_0(ctx context.Context, marshaler runtime.Marsh
}
var (
filter_Msg_RefillBond_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_Msg_RefillBond_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq MsgRefillBond
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_RefillBond_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.RefillBond(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Msg_RefillBond_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq MsgRefillBond
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_RefillBond_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.RefillBond(ctx, &protoReq)
return msg, metadata, err
}
var (
filter_Msg_WithdrawBond_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_Msg_WithdrawBond_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq MsgWithdrawBond
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_WithdrawBond_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.WithdrawBond(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Msg_WithdrawBond_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq MsgWithdrawBond
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_WithdrawBond_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.WithdrawBond(ctx, &protoReq)
return msg, metadata, err
}
var (
filter_Msg_CancelBond_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_Msg_CancelBond_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq MsgCancelBond
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_CancelBond_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.CancelBond(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Msg_CancelBond_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq MsgCancelBond
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_CancelBond_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.CancelBond(ctx, &protoReq)
return msg, metadata, err
}
// RegisterMsgHandlerServer registers the http handlers for service Msg to "mux".
// UnaryRPC :call MsgServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@ -98,6 +206,75 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server
})
mux.Handle("POST", pattern_Msg_RefillBond_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Msg_RefillBond_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Msg_RefillBond_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Msg_WithdrawBond_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Msg_WithdrawBond_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Msg_WithdrawBond_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Msg_CancelBond_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Msg_CancelBond_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Msg_CancelBond_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -159,13 +336,85 @@ func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client
})
mux.Handle("POST", pattern_Msg_RefillBond_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Msg_RefillBond_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Msg_RefillBond_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Msg_WithdrawBond_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Msg_WithdrawBond_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Msg_WithdrawBond_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Msg_CancelBond_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Msg_CancelBond_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Msg_CancelBond_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Msg_CreateBond_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cerc", "bond", "v1", "create_bond"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Msg_RefillBond_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cerc", "bond", "v1", "refill_bond"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Msg_WithdrawBond_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cerc", "bond", "v1", "withdraw_bond"}, "", runtime.AssumeColonVerbOpt(false)))
pattern_Msg_CancelBond_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cerc", "bond", "v1", "cancel_bond"}, "", runtime.AssumeColonVerbOpt(false)))
)
var (
forward_Msg_CreateBond_0 = runtime.ForwardResponseMessage
forward_Msg_RefillBond_0 = runtime.ForwardResponseMessage
forward_Msg_WithdrawBond_0 = runtime.ForwardResponseMessage
forward_Msg_CancelBond_0 = runtime.ForwardResponseMessage
)