feat(proto): Add proto messages for x/protocolpool Funds Handling (#18427)

This commit is contained in:
Likhita Polavarapu 2023-11-14 20:22:08 +05:30 committed by GitHub
parent 569e3ff6a0
commit e269c6d5db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 4239 additions and 137 deletions

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,8 @@ const (
Msg_CommunityPoolSpend_FullMethodName = "/cosmos.protocolpool.v1.Msg/CommunityPoolSpend"
Msg_SubmitBudgetProposal_FullMethodName = "/cosmos.protocolpool.v1.Msg/SubmitBudgetProposal"
Msg_ClaimBudget_FullMethodName = "/cosmos.protocolpool.v1.Msg/ClaimBudget"
Msg_CreateContinuousFund_FullMethodName = "/cosmos.protocolpool.v1.Msg/CreateContinuousFund"
Msg_CancelContinuousFund_FullMethodName = "/cosmos.protocolpool.v1.Msg/CancelContinuousFund"
)
// MsgClient is the client API for Msg service.
@ -41,6 +43,10 @@ type MsgClient interface {
SubmitBudgetProposal(ctx context.Context, in *MsgSubmitBudgetProposal, opts ...grpc.CallOption) (*MsgSubmitBudgetProposalResponse, error)
// ClaimBudget defines a method to claim the distributed budget.
ClaimBudget(ctx context.Context, in *MsgClaimBudget, opts ...grpc.CallOption) (*MsgClaimBudgetResponse, error)
// CreateContinuousFund defines a method to add funds continuously.
CreateContinuousFund(ctx context.Context, in *MsgCreateContinuousFund, opts ...grpc.CallOption) (*MsgCreateContinuousFundResponse, error)
// CancelContinuousFund defines a method for cancelling continuous fund.
CancelContinuousFund(ctx context.Context, in *MsgCancelContinuousFund, opts ...grpc.CallOption) (*MsgCancelContinuousFundResponse, error)
}
type msgClient struct {
@ -87,6 +93,24 @@ func (c *msgClient) ClaimBudget(ctx context.Context, in *MsgClaimBudget, opts ..
return out, nil
}
func (c *msgClient) CreateContinuousFund(ctx context.Context, in *MsgCreateContinuousFund, opts ...grpc.CallOption) (*MsgCreateContinuousFundResponse, error) {
out := new(MsgCreateContinuousFundResponse)
err := c.cc.Invoke(ctx, Msg_CreateContinuousFund_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *msgClient) CancelContinuousFund(ctx context.Context, in *MsgCancelContinuousFund, opts ...grpc.CallOption) (*MsgCancelContinuousFundResponse, error) {
out := new(MsgCancelContinuousFundResponse)
err := c.cc.Invoke(ctx, Msg_CancelContinuousFund_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
@ -103,6 +127,10 @@ type MsgServer interface {
SubmitBudgetProposal(context.Context, *MsgSubmitBudgetProposal) (*MsgSubmitBudgetProposalResponse, error)
// ClaimBudget defines a method to claim the distributed budget.
ClaimBudget(context.Context, *MsgClaimBudget) (*MsgClaimBudgetResponse, error)
// CreateContinuousFund defines a method to add funds continuously.
CreateContinuousFund(context.Context, *MsgCreateContinuousFund) (*MsgCreateContinuousFundResponse, error)
// CancelContinuousFund defines a method for cancelling continuous fund.
CancelContinuousFund(context.Context, *MsgCancelContinuousFund) (*MsgCancelContinuousFundResponse, error)
mustEmbedUnimplementedMsgServer()
}
@ -122,6 +150,12 @@ func (UnimplementedMsgServer) SubmitBudgetProposal(context.Context, *MsgSubmitBu
func (UnimplementedMsgServer) ClaimBudget(context.Context, *MsgClaimBudget) (*MsgClaimBudgetResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ClaimBudget not implemented")
}
func (UnimplementedMsgServer) CreateContinuousFund(context.Context, *MsgCreateContinuousFund) (*MsgCreateContinuousFundResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateContinuousFund not implemented")
}
func (UnimplementedMsgServer) CancelContinuousFund(context.Context, *MsgCancelContinuousFund) (*MsgCancelContinuousFundResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CancelContinuousFund not implemented")
}
func (UnimplementedMsgServer) mustEmbedUnimplementedMsgServer() {}
// UnsafeMsgServer may be embedded to opt out of forward compatibility for this service.
@ -207,6 +241,42 @@ func _Msg_ClaimBudget_Handler(srv interface{}, ctx context.Context, dec func(int
return interceptor(ctx, in, info, handler)
}
func _Msg_CreateContinuousFund_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(MsgCreateContinuousFund)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MsgServer).CreateContinuousFund(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Msg_CreateContinuousFund_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MsgServer).CreateContinuousFund(ctx, req.(*MsgCreateContinuousFund))
}
return interceptor(ctx, in, info, handler)
}
func _Msg_CancelContinuousFund_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(MsgCancelContinuousFund)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MsgServer).CancelContinuousFund(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Msg_CancelContinuousFund_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MsgServer).CancelContinuousFund(ctx, req.(*MsgCancelContinuousFund))
}
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)
@ -230,6 +300,14 @@ var Msg_ServiceDesc = grpc.ServiceDesc{
MethodName: "ClaimBudget",
Handler: _Msg_ClaimBudget_Handler,
},
{
MethodName: "CreateContinuousFund",
Handler: _Msg_CreateContinuousFund_Handler,
},
{
MethodName: "CancelContinuousFund",
Handler: _Msg_CancelContinuousFund_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "cosmos/protocolpool/v1/tx.proto",

View File

@ -29,6 +29,12 @@ service Msg {
// ClaimBudget defines a method to claim the distributed budget.
rpc ClaimBudget(MsgClaimBudget) returns (MsgClaimBudgetResponse);
// CreateContinuousFund defines a method to add funds continuously.
rpc CreateContinuousFund(MsgCreateContinuousFund) returns (MsgCreateContinuousFundResponse);
// CancelContinuousFund defines a method for cancelling continuous fund.
rpc CancelContinuousFund(MsgCancelContinuousFund) returns (MsgCancelContinuousFundResponse);
}
// MsgFundCommunityPool allows an account to directly
@ -52,7 +58,7 @@ message MsgFundCommunityPoolResponse {}
message MsgCommunityPoolSpend {
option (cosmos.msg.v1.signer) = "authority";
// authority is the address that controls the module (defaults to x/gov unless overwritten).
// Authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string recipient = 2;
repeated cosmos.base.v1beta1.Coin amount = 3
@ -67,16 +73,16 @@ message MsgCommunityPoolSpendResponse {}
message MsgSubmitBudgetProposal {
option (cosmos.msg.v1.signer) = "authority";
// authority is the address that controls the module (defaults to x/gov unless overwritten).
// Authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// recipient_address is the address of the recipient who can claim the budget.
// RecipientAddress is the address of the recipient who can claim the budget.
string recipient_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// total_budget is the total amount allocated for the budget.
// TotalBudget is the total amount allocated for the budget.
cosmos.base.v1beta1.Coin total_budget = 3;
// start_time is the time when the budget becomes claimable.
// If start_time is less than the current block time, proposal will not be accepted.
// StartTime is the time when the budget becomes claimable.
// If StartTime is less than the current block time, proposal will not be accepted.
google.protobuf.Timestamp start_time = 4 [(gogoproto.stdtime) = true];
// tranches is the number of times the total budget amount is to be distributed.
// Tranches is the number of times the total budget amount is to be distributed.
uint64 tranches = 5;
// Period is the time interval(number of seconds) at which funds distribution should be performed.
// For example, if a period is set to 3600, it represents an action that
@ -101,3 +107,56 @@ message MsgClaimBudgetResponse {
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
;
}
// MsgCreateContinuousFund defines a message for adding continuous funds.
message MsgCreateContinuousFund {
option (cosmos.msg.v1.signer) = "authority";
// Title is the title of the funds.
string title = 1;
// Description of the funds.
string description = 2;
// Authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Recipient address of the account receiving funds.
string recipient = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Metadata is any arbitrary metadata attached.
string metadata = 5;
// Percentage is the percentage of funds to be allocated from Community pool share on block by block,
// till the `cap` is reached or expired.
string percentage = 6 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// Cap is the capital amount, which when its met funds are no longer distributed.
repeated cosmos.base.v1beta1.Coin cap = 7
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// Optional, if expiry is set, removes the state object when expired.
google.protobuf.Timestamp expiry = 8 [(gogoproto.stdtime) = true];
}
// MsgCreateContinuousFundResponse defines the response to executing a
// MsgCreateContinuousFund message.
message MsgCreateContinuousFundResponse {}
// MsgCancelContinuousFund defines a message to cancel continuous funds for a specific recipient.
message MsgCancelContinuousFund {
option (cosmos.msg.v1.signer) = "authority";
// Authority is the account address of authority.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// RecipientAddress is the account address of recipient whose funds are to be cancelled.
string recipient_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
// MsgCancelContinuousFundResponse defines the response to executing a
// MsgCancelContinuousFund message.
message MsgCancelContinuousFundResponse {
// CanceledTime is the canceled time.
google.protobuf.Timestamp canceled_time = 1 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// CanceledHeight defines the canceled block height.
uint64 canceled_height = 2;
// RecipientAddress is the account address of recipient whose funds are cancelled.
string recipient_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

View File

@ -103,6 +103,14 @@ func (k MsgServer) CommunityPoolSpend(ctx context.Context, msg *types.MsgCommuni
return &types.MsgCommunityPoolSpendResponse{}, nil
}
func (k MsgServer) CreateContinuousFund(ctx context.Context, msg *types.MsgCreateContinuousFund) (*types.MsgCreateContinuousFundResponse, error) {
return &types.MsgCreateContinuousFundResponse{}, nil
}
func (k MsgServer) CancelContinuousFund(ctx context.Context, msg *types.MsgCancelContinuousFund) (*types.MsgCancelContinuousFundResponse, error) {
return &types.MsgCancelContinuousFundResponse{}, nil
}
func (k *Keeper) validateAuthority(authority string) error {
if _, err := k.authKeeper.AddressCodec().StringToBytes(authority); err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err)

File diff suppressed because it is too large Load Diff