From 17fb5058f6fa29fb39d171e549782ec9b26a42be Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 19 Jul 2021 14:57:44 +0900 Subject: [PATCH 01/39] add proposal proto for public proposal plan messages --- .../tendermint/farming/v1beta1/proposal.proto | 70 +++++++++++++++++-- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index 3ffef338..b091b4a6 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -9,15 +9,75 @@ import "google/protobuf/any.proto"; option go_package = "github.com/tendermint/farming/x/farming/types"; -// PublicPlanProposal details a proposal for creating a public plan. -message PublicPlanProposal { +// AddPublicPlanProposal details a proposal for creating a public plan. +message AddPublicPlanProposal { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; + // title specifies the title of the plan string title = 1; + + // description specifies the description of the plan string description = 2; - // plans specifies the plan interface(s); it can be FixedAmountPlan or - // RatioPlan - repeated google.protobuf.Any plans = 3; + // staking_coin_weights specifies coin weights for the plan + repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 3 [ + (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false + ]; + + // start_time specifies the start time of the plan + google.protobuf.Timestamp start_time = 7 + [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; + + // end_time specifies the end time of the plan + google.protobuf.Timestamp end_time = 8 + [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; +} + +// UpdatePublicPlanProposal details a proposal for updating an existing public plan. +message UpdatePublicPlanProposal { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + // title specifies the title of the plan + string title = 1; + + // description specifies the description of the plan + string description = 2; + + // plan_id specifies index of the farming plan + uint64 plan_id = 3; + + // staking_coin_weights specifies coin weights for the plan + repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 3 [ + (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false + ]; + + // start_time specifies the start time of the plan + google.protobuf.Timestamp start_time = 7 + [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; + + // end_time specifies the end time of the plan + google.protobuf.Timestamp end_time = 8 + [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; +} + +// DeletePublicPlanProposal details a proposal for deleting an existing public plan. +message DeletePublicPlanProposal { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + // title specifies the title of the plan + string title = 1; + + // description specifies the description of the plan + string description = 2; + + // plan_id specifies index of the farming plan + uint64 plan_id = 3; + } From b694ba1b7efbe9ac532958a5d3ff7a068df9b855 Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 19 Jul 2021 16:21:28 +0900 Subject: [PATCH 02/39] update proto files --- contrib/devtools/Dockerfile | 1 - .../tendermint/farming/v1beta1/farming.proto | 18 +- .../tendermint/farming/v1beta1/proposal.proto | 14 +- x/farming/types/farming.pb.go | 214 +++-- x/farming/types/proposal.pb.go | 844 ++++++++++++++++-- 5 files changed, 936 insertions(+), 155 deletions(-) diff --git a/contrib/devtools/Dockerfile b/contrib/devtools/Dockerfile index 10be4134..e96ccaca 100644 --- a/contrib/devtools/Dockerfile +++ b/contrib/devtools/Dockerfile @@ -6,7 +6,6 @@ ENV GOLANG_PROTOBUF_VERSION=1.3.5 \ GOGO_PROTOBUF_VERSION=1.3.2 \ GRPC_GATEWAY_VERSION=1.14.7 - RUN GO111MODULE=on go get \ github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} \ github.com/gogo/protobuf/protoc-gen-gogo@v${GOGO_PROTOBUF_VERSION} \ diff --git a/proto/tendermint/farming/v1beta1/farming.proto b/proto/tendermint/farming/v1beta1/farming.proto index 13a02a3a..65e81ee8 100644 --- a/proto/tendermint/farming/v1beta1/farming.proto +++ b/proto/tendermint/farming/v1beta1/farming.proto @@ -48,36 +48,40 @@ message BasePlan { // id specifies index of the farming plan uint64 id = 1; + + // name specifies the name for the base plan + string name = 2; + // type specifies the plan type; type 0 is public and 1 is private // public plan must be created through governance proposal and private plan is // created by account - PlanType type = 2; + PlanType type = 3; // farming_pool_address defines the bech32-encoded address of the farming pool - string farming_pool_address = 3 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; + string farming_pool_address = 4 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; // reward_pool_address defines the bech32-encoded address that distributes // reward amount of coins to farmers - string reward_pool_address = 4 [(gogoproto.moretags) = "yaml:\"reward_pool_address\""]; + string reward_pool_address = 5 [(gogoproto.moretags) = "yaml:\"reward_pool_address\""]; // termination_address defines the bech32-encoded address that terminates plan // when the plan ends after the end time, the balance of farming pool address // is transferred to the termination address - string termination_address = 5 [(gogoproto.moretags) = "yaml:\"termination_address\""]; + string termination_address = 6 [(gogoproto.moretags) = "yaml:\"termination_address\""]; // staking_coin_weights specifies coin weights for the plan - repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 6 [ + repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 7 [ (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; // start_time specifies the start time of the plan - google.protobuf.Timestamp start_time = 7 + google.protobuf.Timestamp start_time = 8 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; // end_time specifies the end time of the plan - google.protobuf.Timestamp end_time = 8 + google.protobuf.Timestamp end_time = 9 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; } diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index b091b4a6..e38179e6 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -4,8 +4,9 @@ package tendermint.farming.v1beta1; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; +import "cosmos/base/v1beta1/coin.proto"; import "tendermint/farming/v1beta1/farming.proto"; -import "google/protobuf/any.proto"; +import "google/protobuf/timestamp.proto"; option go_package = "github.com/tendermint/farming/x/farming/types"; @@ -28,11 +29,11 @@ message AddPublicPlanProposal { ]; // start_time specifies the start time of the plan - google.protobuf.Timestamp start_time = 7 + google.protobuf.Timestamp start_time = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; // end_time specifies the end time of the plan - google.protobuf.Timestamp end_time = 8 + google.protobuf.Timestamp end_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; } @@ -51,18 +52,18 @@ message UpdatePublicPlanProposal { uint64 plan_id = 3; // staking_coin_weights specifies coin weights for the plan - repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 3 [ + repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 4 [ (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; // start_time specifies the start time of the plan - google.protobuf.Timestamp start_time = 7 + google.protobuf.Timestamp start_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; // end_time specifies the end time of the plan - google.protobuf.Timestamp end_time = 8 + google.protobuf.Timestamp end_time = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; } @@ -79,5 +80,4 @@ message DeletePublicPlanProposal { // plan_id specifies index of the farming plan uint64 plan_id = 3; - } diff --git a/x/farming/types/farming.pb.go b/x/farming/types/farming.pb.go index dea8c7a9..9b903682 100644 --- a/x/farming/types/farming.pb.go +++ b/x/farming/types/farming.pb.go @@ -114,25 +114,27 @@ var xxx_messageInfo_Params proto.InternalMessageInfo type BasePlan struct { // id specifies index of the farming plan Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + // name specifies the name for the base plan + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` // type specifies the plan type; type 0 is public and 1 is private // public plan must be created through governance proposal and private plan is // created by account - Type PlanType `protobuf:"varint,2,opt,name=type,proto3,enum=cosmos.farming.v1beta1.PlanType" json:"type,omitempty"` + Type PlanType `protobuf:"varint,3,opt,name=type,proto3,enum=cosmos.farming.v1beta1.PlanType" json:"type,omitempty"` // farming_pool_address defines the bech32-encoded address of the farming pool - FarmingPoolAddress string `protobuf:"bytes,3,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` + FarmingPoolAddress string `protobuf:"bytes,4,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` // reward_pool_address defines the bech32-encoded address that distributes // reward amount of coins to farmers - RewardPoolAddress string `protobuf:"bytes,4,opt,name=reward_pool_address,json=rewardPoolAddress,proto3" json:"reward_pool_address,omitempty" yaml:"reward_pool_address"` + RewardPoolAddress string `protobuf:"bytes,5,opt,name=reward_pool_address,json=rewardPoolAddress,proto3" json:"reward_pool_address,omitempty" yaml:"reward_pool_address"` // termination_address defines the bech32-encoded address that terminates plan // when the plan ends after the end time, the balance of farming pool address // is transferred to the termination address - TerminationAddress string `protobuf:"bytes,5,opt,name=termination_address,json=terminationAddress,proto3" json:"termination_address,omitempty" yaml:"termination_address"` + TerminationAddress string `protobuf:"bytes,6,opt,name=termination_address,json=terminationAddress,proto3" json:"termination_address,omitempty" yaml:"termination_address"` // staking_coin_weights specifies coin weights for the plan - StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,6,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` + StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,7,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` // start_time specifies the start time of the plan - StartTime time.Time `protobuf:"bytes,7,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + StartTime time.Time `protobuf:"bytes,8,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` // end_time specifies the end time of the plan - EndTime time.Time `protobuf:"bytes,8,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` + EndTime time.Time `protobuf:"bytes,9,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` } func (m *BasePlan) Reset() { *m = BasePlan{} } @@ -350,70 +352,71 @@ func init() { } var fileDescriptor_5b657e0809d9de86 = []byte{ - // 999 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcf, 0x6f, 0x1a, 0x47, - 0x14, 0x66, 0x30, 0xc6, 0x30, 0xb4, 0x36, 0x8c, 0x1d, 0x0b, 0x93, 0x86, 0x5d, 0xed, 0xa1, 0x42, - 0xae, 0xbc, 0x28, 0x6e, 0x4e, 0xbe, 0x19, 0x63, 0x47, 0xa8, 0x91, 0x43, 0x37, 0xa4, 0x69, 0x7b, - 0x59, 0x0d, 0xec, 0x18, 0xaf, 0x02, 0x3b, 0x74, 0x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, 0x72, 0xe2, 0xeb, 0x0d, 0x25, 0xdf, 0x29, 0x7f, 0xec, 0x5e, - 0x4c, 0xbe, 0xf1, 0xd4, 0xdb, 0x69, 0x3e, 0x51, 0x3f, 0xfd, 0x37, 0x00, 0x00, 0xff, 0xff, 0x7d, - 0xef, 0x41, 0x72, 0x05, 0x0a, 0x00, 0x00, + // 1011 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcf, 0x6f, 0x1b, 0x45, + 0x14, 0xf6, 0x24, 0x8e, 0x63, 0x8f, 0x21, 0xb1, 0x27, 0x69, 0xe4, 0xb8, 0xd4, 0x6b, 0xed, 0x01, + 0x59, 0x41, 0x59, 0xab, 0xa1, 0xa7, 0xdc, 0xb2, 0x71, 0x52, 0x59, 0x54, 0xa9, 0xd9, 0xba, 0x14, + 0xb8, 0xac, 0xc6, 0xde, 0x89, 0xb3, 0xaa, 0x77, 0xc7, 0xec, 0xae, 0xdb, 0xfa, 0x0f, 0x40, 0xaa, + 0x72, 0xaa, 0x10, 0x07, 0x0e, 0x44, 0xaa, 0xe0, 0xd6, 0x33, 0x67, 0xce, 0x95, 0xb8, 0x44, 0x48, + 0x48, 0x88, 0xc3, 0x16, 0x25, 0xff, 0x81, 0xcf, 0x48, 0xa0, 0xf9, 0xb1, 0xce, 0xa4, 0x38, 0x4a, + 0x8d, 0xc4, 0xc9, 0x3b, 0xb3, 0xdf, 0xfb, 0xe6, 0x7b, 0x6f, 0xbe, 0xf7, 0xbc, 0xb0, 0x16, 0x11, + 0xdf, 0x21, 0x81, 0xe7, 0xfa, 0x51, 0xfd, 0x10, 0xb3, 0xdf, 0x5e, 0xfd, 0xc9, 0xed, 0x0e, 0x89, + 0xf0, 0xed, 0x64, 0x6d, 0x0c, 0x02, 0x1a, 0x51, 0xb4, 0xd6, 0xa5, 0xa1, 0x47, 0x43, 0x23, 0xd9, + 0x95, 0xa8,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5a, 0x7b, 0xf6, + 0xc3, 0x83, 0x07, 0xad, 0xbd, 0xdd, 0xe6, 0x7e, 0x73, 0xaf, 0x51, 0x48, 0x95, 0x97, 0x8f, 0x4f, + 0xaa, 0xf9, 0x04, 0x78, 0xe0, 0xf6, 0x51, 0x0d, 0x16, 0x2e, 0xb0, 0xad, 0x87, 0xe6, 0xbd, 0xe6, + 0x6e, 0x01, 0x94, 0xd1, 0xf1, 0x49, 0x75, 0x29, 0x81, 0xb5, 0x86, 0x9d, 0xbe, 0xdb, 0x45, 0x1b, + 0xb0, 0xa8, 0x20, 0xad, 0xe6, 0x67, 0x3b, 0xed, 0xbd, 0xc2, 0x5c, 0x79, 0xe5, 0xf8, 0xa4, 0xba, + 0x3c, 0x81, 0x8a, 0x8f, 0x8c, 0x72, 0xfa, 0xf9, 0x8f, 0x95, 0x94, 0x79, 0xf7, 0xf5, 0x59, 0x05, + 0x9c, 0x9e, 0x55, 0xc0, 0x9f, 0x67, 0x15, 0xf0, 0xe2, 0xbc, 0x92, 0x3a, 0x3d, 0xaf, 0xa4, 0x7e, + 0x3f, 0xaf, 0xa4, 0xbe, 0xdc, 0x54, 0xf2, 0x9d, 0xf2, 0xb1, 0xf7, 0x6c, 0xf2, 0xc4, 0x53, 0xef, + 0x64, 0xf8, 0x44, 0xfd, 0xf8, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0xd8, 0x55, 0xc7, 0x19, + 0x0a, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -499,7 +502,7 @@ func (m *BasePlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n1 i = encodeVarintFarming(dAtA, i, uint64(n1)) i-- - dAtA[i] = 0x42 + dAtA[i] = 0x4a n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) if err2 != nil { return 0, err2 @@ -507,7 +510,7 @@ func (m *BasePlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n2 i = encodeVarintFarming(dAtA, i, uint64(n2)) i-- - dAtA[i] = 0x3a + dAtA[i] = 0x42 if len(m.StakingCoinWeights) > 0 { for iNdEx := len(m.StakingCoinWeights) - 1; iNdEx >= 0; iNdEx-- { { @@ -519,7 +522,7 @@ func (m *BasePlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintFarming(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x32 + dAtA[i] = 0x3a } } if len(m.TerminationAddress) > 0 { @@ -527,26 +530,33 @@ func (m *BasePlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.TerminationAddress) i = encodeVarintFarming(dAtA, i, uint64(len(m.TerminationAddress))) i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 } if len(m.RewardPoolAddress) > 0 { i -= len(m.RewardPoolAddress) copy(dAtA[i:], m.RewardPoolAddress) i = encodeVarintFarming(dAtA, i, uint64(len(m.RewardPoolAddress))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a } if len(m.FarmingPoolAddress) > 0 { i -= len(m.FarmingPoolAddress) copy(dAtA[i:], m.FarmingPoolAddress) i = encodeVarintFarming(dAtA, i, uint64(len(m.FarmingPoolAddress))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } if m.Type != 0 { i = encodeVarintFarming(dAtA, i, uint64(m.Type)) i-- - dAtA[i] = 0x10 + dAtA[i] = 0x18 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintFarming(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 } if m.Id != 0 { i = encodeVarintFarming(dAtA, i, uint64(m.Id)) @@ -808,6 +818,10 @@ func (m *BasePlan) Size() (n int) { if m.Id != 0 { n += 1 + sovFarming(uint64(m.Id)) } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovFarming(uint64(l)) + } if m.Type != 0 { n += 1 + sovFarming(uint64(m.Type)) } @@ -1113,6 +1127,38 @@ func (m *BasePlan) Unmarshal(dAtA []byte) error { } } case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFarming + } + 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 ErrInvalidLengthFarming + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFarming + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) } @@ -1131,7 +1177,7 @@ func (m *BasePlan) Unmarshal(dAtA []byte) error { break } } - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) } @@ -1163,7 +1209,7 @@ func (m *BasePlan) Unmarshal(dAtA []byte) error { } m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field RewardPoolAddress", wireType) } @@ -1195,7 +1241,7 @@ func (m *BasePlan) Unmarshal(dAtA []byte) error { } m.RewardPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field TerminationAddress", wireType) } @@ -1227,7 +1273,7 @@ func (m *BasePlan) Unmarshal(dAtA []byte) error { } m.TerminationAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 6: + case 7: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) } @@ -1261,7 +1307,7 @@ func (m *BasePlan) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 7: + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) } @@ -1294,7 +1340,7 @@ func (m *BasePlan) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 8: + case 9: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) } diff --git a/x/farming/types/proposal.pb.go b/x/farming/types/proposal.pb.go index 8e599db3..96de56d7 100644 --- a/x/farming/types/proposal.pb.go +++ b/x/farming/types/proposal.pb.go @@ -5,19 +5,24 @@ package types import ( fmt "fmt" - types "github.com/cosmos/cosmos-sdk/codec/types" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" _ "github.com/regen-network/cosmos-proto" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" + time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -25,26 +30,31 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// PublicPlanProposal details a proposal for creating a public plan. -type PublicPlanProposal struct { - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` +// AddPublicPlanProposal details a proposal for creating a public plan. +type AddPublicPlanProposal struct { + // title specifies the title of the plan + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // description specifies the description of the plan Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // plans specifies the plan interface(s); it can be FixedAmountPlan or - // RatioPlan - Plans []*types.Any `protobuf:"bytes,3,rep,name=plans,proto3" json:"plans,omitempty"` + // staking_coin_weights specifies coin weights for the plan + StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` + // start_time specifies the start time of the plan + StartTime time.Time `protobuf:"bytes,4,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + // end_time specifies the end time of the plan + EndTime time.Time `protobuf:"bytes,5,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` } -func (m *PublicPlanProposal) Reset() { *m = PublicPlanProposal{} } -func (*PublicPlanProposal) ProtoMessage() {} -func (*PublicPlanProposal) Descriptor() ([]byte, []int) { +func (m *AddPublicPlanProposal) Reset() { *m = AddPublicPlanProposal{} } +func (*AddPublicPlanProposal) ProtoMessage() {} +func (*AddPublicPlanProposal) Descriptor() ([]byte, []int) { return fileDescriptor_4719b03c30c7910a, []int{0} } -func (m *PublicPlanProposal) XXX_Unmarshal(b []byte) error { +func (m *AddPublicPlanProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *PublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *AddPublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_PublicPlanProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_AddPublicPlanProposal.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -54,20 +64,112 @@ func (m *PublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *PublicPlanProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_PublicPlanProposal.Merge(m, src) +func (m *AddPublicPlanProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddPublicPlanProposal.Merge(m, src) } -func (m *PublicPlanProposal) XXX_Size() int { +func (m *AddPublicPlanProposal) XXX_Size() int { return m.Size() } -func (m *PublicPlanProposal) XXX_DiscardUnknown() { - xxx_messageInfo_PublicPlanProposal.DiscardUnknown(m) +func (m *AddPublicPlanProposal) XXX_DiscardUnknown() { + xxx_messageInfo_AddPublicPlanProposal.DiscardUnknown(m) } -var xxx_messageInfo_PublicPlanProposal proto.InternalMessageInfo +var xxx_messageInfo_AddPublicPlanProposal proto.InternalMessageInfo + +// UpdatePublicPlanProposal details a proposal for updating an existing public plan. +type UpdatePublicPlanProposal struct { + // title specifies the title of the plan + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // description specifies the description of the plan + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // plan_id specifies index of the farming plan + PlanId uint64 `protobuf:"varint,3,opt,name=plan_id,json=planId,proto3" json:"plan_id,omitempty"` + // staking_coin_weights specifies coin weights for the plan + StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,4,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` + // start_time specifies the start time of the plan + StartTime time.Time `protobuf:"bytes,5,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + // end_time specifies the end time of the plan + EndTime time.Time `protobuf:"bytes,6,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` +} + +func (m *UpdatePublicPlanProposal) Reset() { *m = UpdatePublicPlanProposal{} } +func (*UpdatePublicPlanProposal) ProtoMessage() {} +func (*UpdatePublicPlanProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_4719b03c30c7910a, []int{1} +} +func (m *UpdatePublicPlanProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UpdatePublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UpdatePublicPlanProposal.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 *UpdatePublicPlanProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdatePublicPlanProposal.Merge(m, src) +} +func (m *UpdatePublicPlanProposal) XXX_Size() int { + return m.Size() +} +func (m *UpdatePublicPlanProposal) XXX_DiscardUnknown() { + xxx_messageInfo_UpdatePublicPlanProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdatePublicPlanProposal proto.InternalMessageInfo + +// DeletePublicPlanProposal details a proposal for deleting an existing public plan. +type DeletePublicPlanProposal struct { + // title specifies the title of the plan + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // description specifies the description of the plan + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // plan_id specifies index of the farming plan + PlanId uint64 `protobuf:"varint,3,opt,name=plan_id,json=planId,proto3" json:"plan_id,omitempty"` +} + +func (m *DeletePublicPlanProposal) Reset() { *m = DeletePublicPlanProposal{} } +func (*DeletePublicPlanProposal) ProtoMessage() {} +func (*DeletePublicPlanProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_4719b03c30c7910a, []int{2} +} +func (m *DeletePublicPlanProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DeletePublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DeletePublicPlanProposal.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 *DeletePublicPlanProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeletePublicPlanProposal.Merge(m, src) +} +func (m *DeletePublicPlanProposal) XXX_Size() int { + return m.Size() +} +func (m *DeletePublicPlanProposal) XXX_DiscardUnknown() { + xxx_messageInfo_DeletePublicPlanProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_DeletePublicPlanProposal proto.InternalMessageInfo func init() { - proto.RegisterType((*PublicPlanProposal)(nil), "tendermint.farming.v1beta1.PublicPlanProposal") + proto.RegisterType((*AddPublicPlanProposal)(nil), "tendermint.farming.v1beta1.AddPublicPlanProposal") + proto.RegisterType((*UpdatePublicPlanProposal)(nil), "tendermint.farming.v1beta1.UpdatePublicPlanProposal") + proto.RegisterType((*DeletePublicPlanProposal)(nil), "tendermint.farming.v1beta1.DeletePublicPlanProposal") } func init() { @@ -75,28 +177,42 @@ func init() { } var fileDescriptor_4719b03c30c7910a = []byte{ - // 281 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x49, 0xcd, 0x4b, - 0x49, 0x2d, 0xca, 0xcd, 0xcc, 0x2b, 0xd1, 0x4f, 0x4b, 0x04, 0xd1, 0xe9, 0xfa, 0x65, 0x86, 0x49, - 0xa9, 0x25, 0x89, 0x86, 0xfa, 0x05, 0x45, 0xf9, 0x05, 0xf9, 0xc5, 0x89, 0x39, 0x7a, 0x05, 0x45, - 0xf9, 0x25, 0xf9, 0x42, 0x52, 0x08, 0xa5, 0x7a, 0x50, 0xa5, 0x7a, 0x50, 0xa5, 0x52, 0x22, 0xe9, - 0xf9, 0xe9, 0xf9, 0x60, 0x65, 0xfa, 0x20, 0x16, 0x44, 0x87, 0x94, 0x64, 0x72, 0x7e, 0x71, 0x6e, - 0x7e, 0x71, 0x3c, 0x44, 0x02, 0xc2, 0x81, 0x4a, 0x69, 0xe0, 0xb1, 0x17, 0x66, 0x38, 0xd4, 0x90, - 0xf4, 0xfc, 0xfc, 0xf4, 0x9c, 0x54, 0x7d, 0x30, 0x2f, 0xa9, 0x34, 0x4d, 0x3f, 0x31, 0xaf, 0x12, - 0x22, 0xa5, 0xd4, 0xc4, 0xc8, 0x25, 0x14, 0x50, 0x9a, 0x94, 0x93, 0x99, 0x1c, 0x90, 0x93, 0x98, - 0x17, 0x00, 0x75, 0xae, 0x90, 0x08, 0x17, 0x6b, 0x49, 0x66, 0x49, 0x4e, 0xaa, 0x04, 0xa3, 0x02, - 0xa3, 0x06, 0x67, 0x10, 0x84, 0x23, 0xa4, 0xc0, 0xc5, 0x9d, 0x92, 0x5a, 0x9c, 0x5c, 0x94, 0x59, - 0x50, 0x92, 0x99, 0x9f, 0x27, 0xc1, 0x04, 0x96, 0x43, 0x16, 0x12, 0xd2, 0xe2, 0x62, 0x2d, 0xc8, - 0x49, 0xcc, 0x2b, 0x96, 0x60, 0x56, 0x60, 0xd6, 0xe0, 0x36, 0x12, 0xd1, 0x83, 0xd8, 0xac, 0x07, - 0xb3, 0x59, 0xcf, 0x31, 0xaf, 0x32, 0x08, 0xa2, 0xc4, 0x8a, 0xa3, 0x63, 0x81, 0x3c, 0xc3, 0x8c, - 0x05, 0xf2, 0x0c, 0x4e, 0xee, 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, - 0x9b, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x8f, 0xc5, 0xbb, 0x15, 0x70, - 0x56, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x1e, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x17, 0x42, 0x58, 0x21, 0x93, 0x01, 0x00, 0x00, -} - -func (m *PublicPlanProposal) Marshal() (dAtA []byte, err error) { + // 498 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x54, 0x31, 0x6f, 0xd4, 0x30, + 0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, 0x98, 0x22, 0x49, 0xdd, + 0xdf, 0xfc, 0x78, 0xe6, 0x19, 0x9f, 0xce, 0x3c, 0x23, 0x98, 0x5b, 0xc0, 0x79, 0x55, 0x23, 0x28, + 0xf0, 0x1a, 0x13, 0xbb, 0x07, 0x36, 0xea, 0x12, 0xd2, 0x94, 0x20, 0xc7, 0xf2, 0xcd, 0xb0, 0x97, + 0x0c, 0x24, 0x7c, 0x81, 0x7e, 0x1d, 0x65, 0xef, 0xbf, 0x8d, 0xb2, 0xff, 0x97, 0xa2, 0x1c, 0xac, + 0x3d, 0xca, 0x19, 0x70, 0x0e, 0x70, 0x89, 0xff, 0x49, 0x92, 0x57, 0x6d, 0x27, 0xcf, 0xe7, 0x0b, + 0xd7, 0x3c, 0x5f, 0xb8, 0xe6, 0xf7, 0x85, 0x6b, 0x9e, 0x2e, 0x5d, 0xe3, 0x7c, 0xe9, 0x1a, 0xdf, + 0x96, 0xae, 0xf1, 0x76, 0xe7, 0x5a, 0x12, 0x37, 0xfc, 0x60, 0x3e, 0xac, 0x4e, 0x6d, 0x28, 0xd9, + 0xa0, 0xf5, 0xe0, 0xc9, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x69, 0xb9, 0x1b, 0x30, 0x25, 0x05, + 0x00, 0x00, +} + +func (m *AddPublicPlanProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -106,20 +222,36 @@ func (m *PublicPlanProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *PublicPlanProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *AddPublicPlanProposal) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *PublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *AddPublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.Plans) > 0 { - for iNdEx := len(m.Plans) - 1; iNdEx >= 0; iNdEx-- { + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintProposal(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x2a + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintProposal(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x22 + if len(m.StakingCoinWeights) > 0 { + for iNdEx := len(m.StakingCoinWeights) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Plans[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.StakingCoinWeights[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -147,6 +279,120 @@ func (m *PublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *UpdatePublicPlanProposal) 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 *UpdatePublicPlanProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UpdatePublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintProposal(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x32 + n4, err4 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintProposal(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x2a + if len(m.StakingCoinWeights) > 0 { + for iNdEx := len(m.StakingCoinWeights) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StakingCoinWeights[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProposal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if m.PlanId != 0 { + i = encodeVarintProposal(dAtA, i, uint64(m.PlanId)) + i-- + dAtA[i] = 0x18 + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DeletePublicPlanProposal) 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 *DeletePublicPlanProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DeletePublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PlanId != 0 { + i = encodeVarintProposal(dAtA, i, uint64(m.PlanId)) + i-- + dAtA[i] = 0x18 + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { offset -= sovProposal(v) base := offset @@ -158,7 +404,34 @@ func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *PublicPlanProposal) Size() (n int) { +func (m *AddPublicPlanProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + if len(m.StakingCoinWeights) > 0 { + for _, e := range m.StakingCoinWeights { + l = e.Size() + n += 1 + l + sovProposal(uint64(l)) + } + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime) + n += 1 + l + sovProposal(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime) + n += 1 + l + sovProposal(uint64(l)) + return n +} + +func (m *UpdatePublicPlanProposal) Size() (n int) { if m == nil { return 0 } @@ -172,12 +445,39 @@ func (m *PublicPlanProposal) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - if len(m.Plans) > 0 { - for _, e := range m.Plans { + if m.PlanId != 0 { + n += 1 + sovProposal(uint64(m.PlanId)) + } + if len(m.StakingCoinWeights) > 0 { + for _, e := range m.StakingCoinWeights { l = e.Size() n += 1 + l + sovProposal(uint64(l)) } } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime) + n += 1 + l + sovProposal(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime) + n += 1 + l + sovProposal(uint64(l)) + return n +} + +func (m *DeletePublicPlanProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + if m.PlanId != 0 { + n += 1 + sovProposal(uint64(m.PlanId)) + } return n } @@ -187,7 +487,7 @@ func sovProposal(x uint64) (n int) { func sozProposal(x uint64) (n int) { return sovProposal(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { +func (m *AddPublicPlanProposal) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -210,10 +510,10 @@ func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: PublicPlanProposal: wiretype end group for non-group") + return fmt.Errorf("proto: AddPublicPlanProposal: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: PublicPlanProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: AddPublicPlanProposal: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -282,7 +582,74 @@ func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Plans", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StakingCoinWeights = append(m.StakingCoinWeights, types.DecCoin{}) + if err := m.StakingCoinWeights[len(m.StakingCoinWeights)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -309,8 +676,7 @@ func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Plans = append(m.Plans, &types.Any{}) - if err := m.Plans[len(m.Plans)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.EndTime, dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -335,6 +701,372 @@ func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { } return nil } +func (m *UpdatePublicPlanProposal) 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 ErrIntOverflowProposal + } + 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: UpdatePublicPlanProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UpdatePublicPlanProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PlanId", wireType) + } + m.PlanId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PlanId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StakingCoinWeights = append(m.StakingCoinWeights, types.DecCoin{}) + if err := m.StakingCoinWeights[len(m.StakingCoinWeights)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.EndTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DeletePublicPlanProposal) 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 ErrIntOverflowProposal + } + 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: DeletePublicPlanProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeletePublicPlanProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PlanId", wireType) + } + m.PlanId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PlanId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipProposal(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From f5574387cdf1fc71477f44ca0380aeabb3e206c2 Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 19 Jul 2021 17:19:43 +0900 Subject: [PATCH 03/39] temp --- x/farming/types/codec.go | 4 +- x/farming/types/genesis.go | 4 - x/farming/types/plan.go | 3 +- x/farming/types/plan_test.go | 4 +- x/farming/types/proposal.go | 165 +++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 80 deletions(-) diff --git a/x/farming/types/codec.go b/x/farming/types/codec.go index 2ccda7c8..cc52a486 100644 --- a/x/farming/types/codec.go +++ b/x/farming/types/codec.go @@ -32,7 +32,9 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations( (*govtypes.Content)(nil), - &PublicPlanProposal{}, + &AddPublicPlanProposal{}, + &UpdatePublicPlanProposal{}, + &DeletePublicPlanProposal{}, ) registry.RegisterInterface( diff --git a/x/farming/types/genesis.go b/x/farming/types/genesis.go index 0981893d..b6c44859 100644 --- a/x/farming/types/genesis.go +++ b/x/farming/types/genesis.go @@ -50,10 +50,6 @@ func ValidateGenesis(data GenesisState) error { // Validate validates PlanRecord. func (r PlanRecord) Validate() error { - _, err := UnpackPlan(&r.Plan) - if err != nil { - return err - } if err := r.FarmingPoolCoins.Validate(); err != nil { return err } diff --git a/x/farming/types/plan.go b/x/farming/types/plan.go index b618cfb5..ea9433ad 100644 --- a/x/farming/types/plan.go +++ b/x/farming/types/plan.go @@ -21,9 +21,10 @@ var ( // NewBasePlan creates a new BasePlan object //nolint:interfacer -func NewBasePlan(id uint64, typ PlanType, farmingPoolAddr, terminationAddr string, coinWeights sdk.DecCoins, startTime, endTime time.Time) *BasePlan { +func NewBasePlan(id uint64, name string, typ PlanType, farmingPoolAddr, terminationAddr string, coinWeights sdk.DecCoins, startTime, endTime time.Time) *BasePlan { basePlan := &BasePlan{ Id: id, + Name: name, Type: typ, FarmingPoolAddress: farmingPoolAddr, RewardPoolAddress: GenerateRewardPoolAcc(PlanName(id, typ, farmingPoolAddr)).String(), diff --git a/x/farming/types/plan_test.go b/x/farming/types/plan_test.go index dd0014f9..611bc15e 100644 --- a/x/farming/types/plan_test.go +++ b/x/farming/types/plan_test.go @@ -21,6 +21,7 @@ func TestGetPoolInformation(t *testing.T) { testCases := []struct { planId uint64 + name string planType types.PlanType farmingPoolAddr string rewardPoolAddr string @@ -30,6 +31,7 @@ func TestGetPoolInformation(t *testing.T) { }{ { planId: uint64(1), + name: "", planType: types.PlanTypePublic, farmingPoolAddr: sdk.AccAddress([]byte("farmingPoolAddr1")).String(), rewardPoolAddr: "cosmos1yqurgw7xa94psk95ctje76ferlddg8vykflaln6xsgarj5w6jkrsuvh9dj", @@ -40,7 +42,7 @@ func TestGetPoolInformation(t *testing.T) { for _, tc := range testCases { planName := types.PlanName(tc.planId, tc.planType, tc.farmingPoolAddr) rewardPoolAcc := types.GenerateRewardPoolAcc(planName) - basePlan := types.NewBasePlan(tc.planId, tc.planType, tc.farmingPoolAddr, commonTerminationAcc.String(), commonCoinWeights, commonStartTime, commonEndTime) + basePlan := types.NewBasePlan(tc.planId, tc.name, tc.planType, tc.farmingPoolAddr, commonTerminationAcc.String(), commonCoinWeights, commonStartTime, commonEndTime) require.Equal(t, basePlan.RewardPoolAddress, rewardPoolAcc.String()) } } diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 896134a3..6f2c961f 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -2,106 +2,125 @@ package types import ( "fmt" + time "time" - "github.com/gogo/protobuf/proto" - - "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" gov "github.com/cosmos/cosmos-sdk/x/gov/types" ) const ( - ProposalTypePublicPlan string = "PublicPlan" + ProposalTypeAddPublicPlan string = "AddPublicPlan" + ProposalTypeUpdatePublicPlan string = "UpdatePublicPlan" + ProposalTypeDeletePublicPlan string = "DeletePublicPlan" ) // Implements Proposal Interface -var _ gov.Content = &PublicPlanProposal{} +var _ gov.Content = &AddPublicPlanProposal{} +var _ gov.Content = &UpdatePublicPlanProposal{} +var _ gov.Content = &DeletePublicPlanProposal{} func init() { - gov.RegisterProposalType(ProposalTypePublicPlan) - gov.RegisterProposalTypeCodec(&PublicPlanProposal{}, "cosmos-sdk/PublicPlanProposal") + gov.RegisterProposalType(ProposalTypeAddPublicPlan) + gov.RegisterProposalTypeCodec(&AddPublicPlanProposal{}, "cosmos-sdk/AddPublicPlanProposal") + gov.RegisterProposalType(ProposalTypeUpdatePublicPlan) + gov.RegisterProposalTypeCodec(&UpdatePublicPlanProposal{}, "cosmos-sdk/UpdatePublicPlanProposal") + gov.RegisterProposalType(ProposalTypeDeletePublicPlan) + gov.RegisterProposalTypeCodec(&DeletePublicPlanProposal{}, "cosmos-sdk/DeletePublicPlanProposal") } -func NewPublicPlanProposal(title, description string, plans []PlanI) (gov.Content, error) { - plansAny, err := PackPlans(plans) - if err != nil { - panic(err) - } - - return &PublicPlanProposal{ - Title: title, - Description: description, - Plans: plansAny, +func NewAddPublicPlanProposal(title, description string, coinWeights sdk.DecCoins, startTime, endTime time.Time) (gov.Content, error) { + return &AddPublicPlanProposal{ + Title: title, + Description: description, + StakingCoinWeights: coinWeights, + StartTime: startTime, + EndTime: endTime, }, nil } -func (p *PublicPlanProposal) GetTitle() string { return p.Title } +func (p *AddPublicPlanProposal) GetTitle() string { return p.Title } -func (p *PublicPlanProposal) GetDescription() string { return p.Description } +func (p *AddPublicPlanProposal) GetDescription() string { return p.Description } -func (p *PublicPlanProposal) ProposalRoute() string { return RouterKey } +func (p *AddPublicPlanProposal) ProposalRoute() string { return RouterKey } -func (p *PublicPlanProposal) ProposalType() string { return ProposalTypePublicPlan } +func (p *AddPublicPlanProposal) ProposalType() string { return ProposalTypeAddPublicPlan } -func (p *PublicPlanProposal) ValidateBasic() error { - for _, plan := range p.Plans { - _, ok := plan.GetCachedValue().(PlanI) - if !ok { - return fmt.Errorf("expected planI") - } - // TODO: PlanI needs ValidateBasic()? - // if err := p.ValidateBasic(); err != nil { - // return err - // } - } +func (p *AddPublicPlanProposal) ValidateBasic() error { + // TODO: not implemented yet return gov.ValidateAbstract(p) } -func (p PublicPlanProposal) String() string { - return fmt.Sprintf(`Create FixedAmountPlan Proposal: - Title: %s - Description: %s - Plans: %s -`, p.Title, p.Description, p.Plans) +func (p AddPublicPlanProposal) String() string { + return fmt.Sprintf(`Add Public Plan Proposal: + Title: %s + Description: %s + StakingCoinWeights: %s + StartTime: %s + EndTime: %s +`, p.Title, p.Description, p.StakingCoinWeights, p.StartTime, p.EndTime) +} + +func NewUpdatePublicPlanProposal(title, description string, id uint64, coinWeights sdk.DecCoins, startTime, endTime time.Time) (gov.Content, error) { + return &UpdatePublicPlanProposal{ + Title: title, + Description: description, + PlanId: id, + StakingCoinWeights: coinWeights, + StartTime: startTime, + EndTime: endTime, + }, nil } -// PackPlans converts PlanIs to Any slice. -func PackPlans(plans []PlanI) ([]*types.Any, error) { - plansAny := make([]*types.Any, len(plans)) - for i, plan := range plans { - msg, ok := plan.(proto.Message) - if !ok { - return nil, fmt.Errorf("cannot proto marshal %T", plan) - } - any, err := types.NewAnyWithValue(msg) - if err != nil { - return nil, err - } - plansAny[i] = any - } - - return plansAny, nil +func (p *UpdatePublicPlanProposal) GetTitle() string { return p.Title } + +func (p *UpdatePublicPlanProposal) GetDescription() string { return p.Description } + +func (p *UpdatePublicPlanProposal) ProposalRoute() string { return RouterKey } + +func (p *UpdatePublicPlanProposal) ProposalType() string { return ProposalTypeUpdatePublicPlan } + +func (p *UpdatePublicPlanProposal) ValidateBasic() error { + // TODO: not implemented yet + return gov.ValidateAbstract(p) } -// UnpackPlans converts Any slice to PlanIs. -func UnpackPlans(plansAny []*types.Any) ([]PlanI, error) { - plans := make([]PlanI, len(plansAny)) - for i, any := range plansAny { - p, ok := any.GetCachedValue().(PlanI) - if !ok { - return nil, fmt.Errorf("expected planI") - } - plans[i] = p - } - - return plans, nil +func (p UpdatePublicPlanProposal) String() string { + return fmt.Sprintf(`Update Public Plan Proposal: + Title: %s + Description: %s + PlanId: %s + StakingCoinWeights: %s + StartTime: %s + EndTime: %s +`, p.Title, p.Description, p.PlanId, p.StakingCoinWeights, p.StartTime, p.EndTime) } -// UnpackPlan converts Any slice to PlanI. -func UnpackPlan(any *types.Any) (PlanI, error) { - p, ok := any.GetCachedValue().(PlanI) - if !ok { - return nil, fmt.Errorf("expected planI") - } +func NewDeletePublicPlanProposal(title, description string, id uint64) (gov.Content, error) { + return &DeletePublicPlanProposal{ + Title: title, + Description: description, + PlanId: id, + }, nil +} + +func (p *DeletePublicPlanProposal) GetTitle() string { return p.Title } + +func (p *DeletePublicPlanProposal) GetDescription() string { return p.Description } + +func (p *DeletePublicPlanProposal) ProposalRoute() string { return RouterKey } + +func (p *DeletePublicPlanProposal) ProposalType() string { return ProposalTypeUpdatePublicPlan } + +func (p *DeletePublicPlanProposal) ValidateBasic() error { + // TODO: not implemented yet + return gov.ValidateAbstract(p) +} - return p, nil +func (p DeletePublicPlanProposal) String() string { + return fmt.Sprintf(`Delete Public Plan Proposal: + Title: %s + Description: %s + PlanId: %s +`, p.Title, p.Description, p.PlanId) } From 13fcc4676ab46d18a9ea728864c0883156323fa2 Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 19 Jul 2021 21:00:55 +0900 Subject: [PATCH 04/39] change method name to prevent from duplicate --- x/farming/types/plan.go | 11 +++-------- x/farming/types/plan_test.go | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/x/farming/types/plan.go b/x/farming/types/plan.go index ea9433ad..d6facdf3 100644 --- a/x/farming/types/plan.go +++ b/x/farming/types/plan.go @@ -27,7 +27,7 @@ func NewBasePlan(id uint64, name string, typ PlanType, farmingPoolAddr, terminat Name: name, Type: typ, FarmingPoolAddress: farmingPoolAddr, - RewardPoolAddress: GenerateRewardPoolAcc(PlanName(id, typ, farmingPoolAddr)).String(), + RewardPoolAddress: GenerateRewardPoolAcc(PlanUniqueKey(id, typ, farmingPoolAddr)).String(), TerminationAddress: terminationAddr, StakingCoinWeights: coinWeights, StartTime: startTime, @@ -162,13 +162,8 @@ func NewRatioPlan(basePlan *BasePlan, epochRatio sdk.Dec) *RatioPlan { } } -// GetPlanName returns unique name of the plan -func (plan BasePlan) Name() string { - return PlanName(plan.Id, plan.Type, plan.FarmingPoolAddress) -} - -// PlanName returns unique name of the plan consists of given Id, Type and FarmingPoolAddress. -func PlanName(id uint64, typ PlanType, farmingPoolAddr string) string { +// PlanUniqueKey returns unique name of the plan consists of given Id, Type and FarmingPoolAddress. +func PlanUniqueKey(id uint64, typ PlanType, farmingPoolAddr string) string { poolNameObjects := make([]string, 3) poolNameObjects[0] = strconv.FormatUint(id, 10) poolNameObjects[1] = strconv.FormatInt(int64(typ), 10) diff --git a/x/farming/types/plan_test.go b/x/farming/types/plan_test.go index 611bc15e..08e57528 100644 --- a/x/farming/types/plan_test.go +++ b/x/farming/types/plan_test.go @@ -40,8 +40,8 @@ func TestGetPoolInformation(t *testing.T) { } for _, tc := range testCases { - planName := types.PlanName(tc.planId, tc.planType, tc.farmingPoolAddr) - rewardPoolAcc := types.GenerateRewardPoolAcc(planName) + uniqueKey := types.PlanUniqueKey(tc.planId, tc.planType, tc.farmingPoolAddr) + rewardPoolAcc := types.GenerateRewardPoolAcc(uniqueKey) basePlan := types.NewBasePlan(tc.planId, tc.name, tc.planType, tc.farmingPoolAddr, commonTerminationAcc.String(), commonCoinWeights, commonStartTime, commonEndTime) require.Equal(t, basePlan.RewardPoolAddress, rewardPoolAcc.String()) } From b47f8e362dd4e754dc3eb085ace1c0208009711b Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 19 Jul 2021 22:37:31 +0900 Subject: [PATCH 05/39] WIP: designing what args to accept for adding plan proposal... --- x/farming/client/cli/tx.go | 185 +++++++++++++++++++++++++++ x/farming/client/cli/utils.go | 24 ++++ x/farming/client/cli/utils_test.go | 103 +++++++++++++++ x/farming/client/proposal_handler.go | 21 +-- x/farming/client/rest/rest.go | 24 ++++ x/farming/keeper/msg_server.go | 6 +- x/farming/keeper/plan.go | 6 +- x/farming/keeper/plan_test.go | 3 +- x/farming/keeper/proposal_handler.go | 52 ++------ x/farming/types/proposal.go | 34 +++++ 10 files changed, 402 insertions(+), 56 deletions(-) create mode 100644 x/farming/client/cli/utils.go create mode 100644 x/farming/client/cli/utils_test.go create mode 100644 x/farming/client/rest/rest.go diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index a3d72d44..cc6d2513 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -9,6 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" + "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + gov "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/spf13/cobra" "github.com/tendermint/farming/x/farming/types" @@ -235,3 +237,186 @@ $ %s tx %s claim --from mykey return cmd } + +// TODO: not implemented yet +// GetCmdSubmitAddPublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. +func GetCmdSubmitAddPublicPlanProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-public-farming-plan [proposal-file] [flags]", + Args: cobra.ExactArgs(1), + Short: "Submit a public farming plan creation", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a a public farming plan creation along with an initial deposit. +The proposal details must be supplied via a JSON file. + +Example: +$ %s tx gov submit-proposal public-farming-plan --from= --deposit= + +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) + if err != nil { + return err + } + + deposit, err := sdk.ParseCoinsNormalized(depositStr) + if err != nil { + return err + } + + title := "title" + desc := "description" + coinWeights := sdk.NewDecCoins(sdk.NewDecCoin("test", sdk.NewInt(1))) + startTime := time.Now().UTC() + endTime := startTime.AddDate(1, 0, 0) + + content, err := types.NewAddPublicPlanProposal(title, desc, coinWeights, startTime, endTime) + if err != nil { + return err + } + + from := clientCtx.GetFromAddress() + + msg, err := gov.NewMsgSubmitProposal(content, deposit, from) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") + + return cmd +} + +// TODO: not implemented yet +// GetCmdSubmitUpdatePublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. +func GetCmdSubmitUpdatePublicPlanProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-public-farming-plan [proposal-file] [flags]", + Args: cobra.ExactArgs(1), + Short: "Submit a public farming plan creation", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a a public farming plan creation along with an initial deposit. +The proposal details must be supplied via a JSON file. + +Example: +$ %s tx gov submit-proposal public-farming-plan --from= --deposit= + +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) + if err != nil { + return err + } + + deposit, err := sdk.ParseCoinsNormalized(depositStr) + if err != nil { + return err + } + + title := "title" + desc := "description" + coinWeights := sdk.NewDecCoins(sdk.NewDecCoin("test", sdk.NewInt(1))) + startTime := time.Now().UTC() + endTime := startTime.AddDate(1, 0, 0) + + content, err := types.NewAddPublicPlanProposal(title, desc, coinWeights, startTime, endTime) + if err != nil { + return err + } + + from := clientCtx.GetFromAddress() + + msg, err := gov.NewMsgSubmitProposal(content, deposit, from) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") + + return cmd +} + +// TODO: not implemented yet +// GetCmdSubmitDeletePublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. +func GetCmdSubmitDeletePublicPlanProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-public-farming-plan [proposal-file] [flags]", + Args: cobra.ExactArgs(1), + Short: "Submit a public farming plan creation", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a a public farming plan creation along with an initial deposit. +The proposal details must be supplied via a JSON file. + +Example: +$ %s tx gov submit-proposal public-farming-plan --from= --deposit= + +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) + if err != nil { + return err + } + + deposit, err := sdk.ParseCoinsNormalized(depositStr) + if err != nil { + return err + } + + title := "title" + desc := "description" + coinWeights := sdk.NewDecCoins(sdk.NewDecCoin("test", sdk.NewInt(1))) + startTime := time.Now().UTC() + endTime := startTime.AddDate(1, 0, 0) + + content, err := types.NewAddPublicPlanProposal(title, desc, coinWeights, startTime, endTime) + if err != nil { + return err + } + + from := clientCtx.GetFromAddress() + + msg, err := gov.NewMsgSubmitProposal(content, deposit, from) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") + + return cmd +} diff --git a/x/farming/client/cli/utils.go b/x/farming/client/cli/utils.go new file mode 100644 index 00000000..70597652 --- /dev/null +++ b/x/farming/client/cli/utils.go @@ -0,0 +1,24 @@ +package cli + +import ( + "io/ioutil" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/tendermint/farming/x/farming/types" +) + +// ParsePublicPlanProposal reads and parses a PublicPlanProposal from a file. +func ParsePublicPlanProposal(cdc codec.JSONCodec, proposalFile string) (types.AddPublicPlanProposal, error) { + proposal := types.AddPublicPlanProposal{} + + contents, err := ioutil.ReadFile(proposalFile) + if err != nil { + return proposal, err + } + + if err = cdc.UnmarshalJSON(contents, &proposal); err != nil { + return proposal, err + } + + return proposal, nil +} diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go new file mode 100644 index 00000000..3b800f3b --- /dev/null +++ b/x/farming/client/cli/utils_test.go @@ -0,0 +1,103 @@ +package cli_test + +import ( + "fmt" + "io/ioutil" + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + farmingapp "github.com/tendermint/farming/app" + "github.com/tendermint/farming/x/farming/keeper" + "github.com/tendermint/farming/x/farming/types" +) + +func createTestInput() (*farmingapp.FarmingApp, sdk.Context) { + app := farmingapp.Setup(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + + app.FarmingKeeper = keeper.NewKeeper( + app.AppCodec(), + app.GetKey(types.StoreKey), + app.GetSubspace(types.ModuleName), + app.AccountKeeper, + app.BankKeeper, + app.DistrKeeper, + map[string]bool{}, + ) + + return app, ctx +} + +func TestParseJSONFile(t *testing.T) { + app, _ := createTestInput() + + proposalFile := "./proposal.json" + + proposal := types.AddPublicPlanProposal{} + + contents, err := ioutil.ReadFile(proposalFile) + require.NoError(t, err) + + err = app.AppCodec().UnmarshalJSON(contents, &proposal) + require.NoError(t, err) + + // err = proposal.UnpackInterfaces(app.AppCodec()) + // require.NoError(t, err) + + plans, err := types.UnpackPlans(proposal.Plans) + require.NoError(t, err) + + for _, plan := range plans { + switch p := plan.(type) { + case *types.FixedAmountPlan: + fmt.Println("EpochAmt: ", p.EpochAmount) + default: + } + } +} + +func TestMarshalPublic(t *testing.T) { + app, _ := createTestInput() + + farmingPoolAddr := sdk.AccAddress([]byte("farmingPoolAddr")) + terminationAddr := sdk.AccAddress([]byte("terminationAddr")) + coinWeights := sdk.NewDecCoins( + sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, + ) + startTime := time.Now().UTC() + endTime := startTime.AddDate(1, 0, 0) + name := "" + + proposal := types.AddPublicPlanProposal{} + proposal.Title = "Public Plan Test" + proposal.Description = "TEST..." + + basePlan := types.NewBasePlan( + 1, + name, + types.PlanTypePublic, + farmingPoolAddr.String(), + terminationAddr.String(), + coinWeights, + startTime, + endTime, + ) + + epochAmt := sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(1))) + + fixedPlan := types.NewFixedAmountPlan(basePlan, epochAmt) + + plans, err := types.PackPlans([]types.PlanI{fixedPlan}) + require.NoError(t, err) + + proposal.Plans = plans + + bz, err := app.AppCodec().MarshalJSON(&proposal) + require.NoError(t, err) + + fmt.Println("bz: ", string(bz)) +} diff --git a/x/farming/client/proposal_handler.go b/x/farming/client/proposal_handler.go index d5703867..9e3f3d63 100644 --- a/x/farming/client/proposal_handler.go +++ b/x/farming/client/proposal_handler.go @@ -1,12 +1,15 @@ package client -// import ( -// "github.com/tendermint/farming/x/farming/client/cli" -// "github.com/tendermint/farming/x/farming/client/rest" -// govclient "github.com/cosmos/cosmos-sdk/x/gov/client" -// ) +import ( + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" -// // ProposalHandler is the public plan creation handler. -// var ( -// ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitProposal, rest.ProposalRESTHandler) -// ) + "github.com/tendermint/farming/x/farming/client/cli" + "github.com/tendermint/farming/x/farming/client/rest" +) + +// ProposalHandler is the public plan creation handler. +var ( + AddProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitAddPublicPlanProposal, rest.ProposalRESTHandler) + UpdateProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitUpdatePublicPlanProposal, rest.ProposalRESTHandler) + DeleteProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitDeletePublicPlanProposal, rest.ProposalRESTHandler) +) diff --git a/x/farming/client/rest/rest.go b/x/farming/client/rest/rest.go new file mode 100644 index 00000000..5d18f8f2 --- /dev/null +++ b/x/farming/client/rest/rest.go @@ -0,0 +1,24 @@ +package rest + +import ( + "net/http" + + "github.com/cosmos/cosmos-sdk/client" + govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" +) + +// TODO: not implemented yet + +// TODO add proto compatible Handler after x/gov migration +// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route. +func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { + return govrest.ProposalRESTHandler{ + SubRoute: "farming_plan", + Handler: postProposalHandlerFn(clientCtx), + } +} + +func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + } +} diff --git a/x/farming/keeper/msg_server.go b/x/farming/keeper/msg_server.go index c06710d1..f23a8b61 100644 --- a/x/farming/keeper/msg_server.go +++ b/x/farming/keeper/msg_server.go @@ -30,7 +30,8 @@ var _ types.MsgServer = msgServer{} func (k msgServer) CreateFixedAmountPlan(goCtx context.Context, msg *types.MsgCreateFixedAmountPlan) (*types.MsgCreateFixedAmountPlanResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - fixedPlan := k.Keeper.CreateFixedAmountPlan(ctx, msg, types.PlanTypePrivate) + name := "" + fixedPlan := k.Keeper.CreateFixedAmountPlan(ctx, msg, name, types.PlanTypePrivate) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( @@ -50,7 +51,8 @@ func (k msgServer) CreateFixedAmountPlan(goCtx context.Context, msg *types.MsgCr func (k msgServer) CreateRatioPlan(goCtx context.Context, msg *types.MsgCreateRatioPlan) (*types.MsgCreateRatioPlanResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - ratioPlan := k.Keeper.CreateRatioPlan(ctx, msg, types.PlanTypePrivate) + name := "" + ratioPlan := k.Keeper.CreateRatioPlan(ctx, msg, name, types.PlanTypePrivate) ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( diff --git a/x/farming/keeper/plan.go b/x/farming/keeper/plan.go index 4126fe1b..2302c405 100644 --- a/x/farming/keeper/plan.go +++ b/x/farming/keeper/plan.go @@ -115,13 +115,14 @@ func (k Keeper) SetPlanIdByFarmerAddrIndex(ctx sdk.Context, farmerAcc sdk.AccAdd } // CreateFixedAmountPlan sets fixed amount plan. -func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixedAmountPlan, typ types.PlanType) *types.FixedAmountPlan { +func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixedAmountPlan, name string, typ types.PlanType) *types.FixedAmountPlan { nextId := k.GetNextPlanIDWithUpdate(ctx) farmingPoolAddr := msg.FarmingPoolAddress terminationAddr := farmingPoolAddr basePlan := types.NewBasePlan( nextId, + name, typ, farmingPoolAddr, terminationAddr, @@ -138,13 +139,14 @@ func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixed } // CreateRatioPlan sets ratio plan. -func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, typ types.PlanType) *types.RatioPlan { +func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, name string, typ types.PlanType) *types.RatioPlan { nextId := k.GetNextPlanIDWithUpdate(ctx) farmingPoolAddr := msg.FarmingPoolAddress terminationAddr := farmingPoolAddr basePlan := types.NewBasePlan( nextId, + name, typ, farmingPoolAddr, terminationAddr, diff --git a/x/farming/keeper/plan_test.go b/x/farming/keeper/plan_test.go index a4122419..d46ebdf6 100644 --- a/x/farming/keeper/plan_test.go +++ b/x/farming/keeper/plan_test.go @@ -14,6 +14,7 @@ import ( func TestGetSetNewPlan(t *testing.T) { app, ctx := createTestApp(true) + name := "" farmingPoolAddr := sdk.AccAddress([]byte("farmingPoolAddr")) terminationAddr := sdk.AccAddress([]byte("terminationAddr")) farmerAddr := sdk.AccAddress([]byte("farmer")) @@ -23,7 +24,7 @@ func TestGetSetNewPlan(t *testing.T) { ) startTime := time.Now().UTC() endTime := startTime.AddDate(1, 0, 0) - basePlan := types.NewBasePlan(1, 1, farmingPoolAddr.String(), terminationAddr.String(), coinWeights, startTime, endTime) + basePlan := types.NewBasePlan(1, name, 1, farmingPoolAddr.String(), terminationAddr.String(), coinWeights, startTime, endTime) fixedPlan := types.NewFixedAmountPlan(basePlan, sdk.NewCoins(sdk.NewCoin("testFarmCoinDenom", sdk.NewInt(1000000)))) app.FarmingKeeper.SetPlan(ctx, fixedPlan) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 75571ba6..6b3b4de2 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -1,54 +1,22 @@ package keeper import ( - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/farming/x/farming/types" ) -// HandlePublicPlanProposal is a handler for executing a fixed amount plan creation proposal. -func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, plansAny []*codectypes.Any) error { - plans, err := types.UnpackPlans(plansAny) - if err != nil { - return err - } - - for _, plan := range plans { - switch p := plan.(type) { - case *types.FixedAmountPlan: - msg := types.NewMsgCreateFixedAmountPlan( - p.GetFarmingPoolAddress(), - p.GetStakingCoinWeights(), - p.GetStartTime(), - p.GetEndTime(), - p.EpochAmount, - ) - - fixedPlan := k.CreateFixedAmountPlan(ctx, msg, types.PlanTypePublic) - - logger := k.Logger(ctx) - logger.Info("created public fixed amount plan", "fixed_amount_plan", fixedPlan) - - case *types.RatioPlan: - msg := types.NewMsgCreateRatioPlan( - p.GetFarmingPoolAddress(), - p.GetStakingCoinWeights(), - p.GetStartTime(), - p.GetEndTime(), - p.EpochRatio, - ) - - ratioPlan := k.CreateRatioPlan(ctx, msg, types.PlanTypePublic) - - logger := k.Logger(ctx) - logger.Info("created public fixed amount plan", "ratio_plan", ratioPlan) +// HandleAddPublicPlanProposal is a handler for executing a public plan creation proposal. +func HandleAddPublicPlanProposal(ctx sdk.Context, k Keeper, p *types.AddPublicPlanProposal) error { + return nil +} - default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized farming proposal plan type: %T", p) - } - } +// HandleUpdatePublicPlanProposal is a handler for executing an update to the public plan. +func HandleUpdatePublicPlanProposal(ctx sdk.Context, k Keeper, p *types.UpdatePublicPlanProposal) error { + return nil +} +// HandleDeletePublicPlanProposal is a handler for executing a removal of the public plan. +func HandleDeletePublicPlanProposal(ctx sdk.Context, k Keeper, p *types.DeletePublicPlanProposal) error { return nil } diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 6f2c961f..ff5ffefb 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -4,8 +4,10 @@ import ( "fmt" time "time" + "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" gov "github.com/cosmos/cosmos-sdk/x/gov/types" + proto "github.com/gogo/protobuf/proto" ) const ( @@ -124,3 +126,35 @@ func (p DeletePublicPlanProposal) String() string { PlanId: %s `, p.Title, p.Description, p.PlanId) } + +// PackPlans converts PlanIs to Any slice. +func PackPlans(plans []PlanI) ([]*types.Any, error) { + plansAny := make([]*types.Any, len(plans)) + for i, plan := range plans { + msg, ok := plan.(proto.Message) + if !ok { + return nil, fmt.Errorf("cannot proto marshal %T", plan) + } + any, err := types.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + plansAny[i] = any + } + + return plansAny, nil +} + +// UnpackPlans converts Any slice to PlanIs. +func UnpackPlans(plansAny []*types.Any) ([]PlanI, error) { + plans := make([]PlanI, len(plansAny)) + for i, any := range plansAny { + p, ok := any.GetCachedValue().(PlanI) + if !ok { + return nil, fmt.Errorf("expected planI") + } + plans[i] = p + } + + return plans, nil +} From 3d230f3103d377810350e7d9c6fb6ca58b58161f Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 20 Jul 2021 18:26:07 +0900 Subject: [PATCH 06/39] change binary name to farmingd --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 495d10b7..8e709ad0 100644 --- a/Makefile +++ b/Makefile @@ -49,8 +49,8 @@ build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags)) # process linker flags -ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=simd \ - -X github.com/cosmos/cosmos-sdk/version.AppName=simd \ +ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=farmingd \ + -X github.com/cosmos/cosmos-sdk/version.AppName=farmingd \ -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \ @@ -75,9 +75,9 @@ include contrib/devtools/Makefile build: go.sum ifeq ($(OS),Windows_NT) - go build $(BUILD_FLAGS) -o build/simd.exe ./cmd/farmingd + go build $(BUILD_FLAGS) -o build/farmingd.exe ./cmd/farmingd else - go build $(BUILD_FLAGS) -o build/simd ./cmd/farmingd + go build $(BUILD_FLAGS) -o build/farmingd ./cmd/farmingd endif build-linux: go.sum @@ -90,7 +90,7 @@ build-reproducible: go.sum $(DOCKER) rm latest-build || true $(DOCKER) run --volume=$(CURDIR):/sources:ro \ --env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm64' \ - --env APP=simd \ + --env APP=farmingd \ --env VERSION=$(VERSION) \ --env COMMIT=$(COMMIT) \ --env LEDGER_ENABLED=$(LEDGER_ENABLED) \ From 25e83e8d3c9112eb18e5f38e18fcbc5049f1bc0b Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 20 Jul 2021 19:41:08 +0900 Subject: [PATCH 07/39] change proposal design - update proposal proto messages --- app/app.go | 2 + .../tendermint/farming/v1beta1/farming.proto | 1 - .../tendermint/farming/v1beta1/proposal.proto | 99 ++- x/farming/client/cli/tx.go | 131 +-- x/farming/client/cli/utils.go | 4 +- x/farming/client/cli/utils_test.go | 83 +- x/farming/client/proposal_handler.go | 4 +- x/farming/handler.go | 10 +- x/farming/keeper/proposal_handler.go | 13 +- x/farming/types/codec.go | 4 +- x/farming/types/errors.go | 1 + x/farming/types/plan.go | 7 + x/farming/types/proposal.go | 159 +--- x/farming/types/proposal.pb.go | 756 +++++++++++++----- 14 files changed, 724 insertions(+), 550 deletions(-) diff --git a/app/app.go b/app/app.go index 708a8997..0b1d1c34 100644 --- a/app/app.go +++ b/app/app.go @@ -88,6 +88,7 @@ import ( farmingparams "github.com/tendermint/farming/app/params" "github.com/tendermint/farming/x/farming" + farmingclient "github.com/tendermint/farming/x/farming/client" farmingkeeper "github.com/tendermint/farming/x/farming/keeper" farmingtypes "github.com/tendermint/farming/x/farming/types" @@ -114,6 +115,7 @@ var ( distr.AppModuleBasic{}, gov.NewAppModuleBasic( paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, + farmingclient.AddProposalHandler, // todo: farming proposal handler ), params.AppModuleBasic{}, diff --git a/proto/tendermint/farming/v1beta1/farming.proto b/proto/tendermint/farming/v1beta1/farming.proto index 65e81ee8..cde9c869 100644 --- a/proto/tendermint/farming/v1beta1/farming.proto +++ b/proto/tendermint/farming/v1beta1/farming.proto @@ -48,7 +48,6 @@ message BasePlan { // id specifies index of the farming plan uint64 id = 1; - // name specifies the name for the base plan string name = 2; diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index e38179e6..123e805b 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -10,17 +10,45 @@ import "google/protobuf/timestamp.proto"; option go_package = "github.com/tendermint/farming/x/farming/types"; -// AddPublicPlanProposal details a proposal for creating a public plan. -message AddPublicPlanProposal { +// PublicPlanProposal details a proposal for creating a public plan. +message PublicPlanProposal { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; // title specifies the title of the plan - string title = 1; + string title = 1; // description specifies the description of the plan string description = 2; + // name specifies the plan name that describes what plan is for + string name = 3; + + // add_request_proposals specifies AddRequestProposal object + repeated AddRequestProposal add_request_proposals = 4 [(gogoproto.moretags) = "yaml:\"add_request_proposals\""]; + + // update_request_proposals specifies UpdateRequestProposal object + repeated UpdateRequestProposal update_request_proposals = 5 + [(gogoproto.moretags) = "yaml:\" update_request_proposals\""]; + + // delete_request_proposals specifies DeleteRequestProposal object + repeated DeleteRequestProposal delete_request_proposals = 6 + [(gogoproto.moretags) = "yaml:\"delete_request_proposals\""]; +} + +// AddRequestProposal details a proposal for creating a public plan. +message AddRequestProposal { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + // farming_pool_address defines the bech32-encoded address of the farming pool + string farming_pool_address = 1 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; + + // termination_address defines the bech32-encoded address that terminates plan + // when the plan ends after the end time, the balance of farming pool address + // is transferred to the termination address + string termination_address = 2 [(gogoproto.moretags) = "yaml:\"termination_address\""]; + // staking_coin_weights specifies coin weights for the plan repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 3 [ (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", @@ -35,23 +63,39 @@ message AddPublicPlanProposal { // end_time specifies the end time of the plan google.protobuf.Timestamp end_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; + + // epoch_amount specifies the distributing amount for each epoch + repeated cosmos.base.v1beta1.Coin epoch_amount = 6 [ + (gogoproto.moretags) = "yaml:\"epoch_amount\"", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.nullable) = false + ]; + + // epoch_ratio specifies the distributing amount by ratio + string epoch_ratio = 7 [ + (gogoproto.moretags) = "yaml:\"epoch_ratio\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } -// UpdatePublicPlanProposal details a proposal for updating an existing public plan. -message UpdatePublicPlanProposal { +// UpdateRequestProposal details a proposal for updating an existing public plan. +message UpdateRequestProposal { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; - // title specifies the title of the plan - string title = 1; - - // description specifies the description of the plan - string description = 2; - // plan_id specifies index of the farming plan - uint64 plan_id = 3; + uint64 plan_id = 1; + + // farming_pool_address defines the bech32-encoded address of the farming pool + string farming_pool_address = 2 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; + + // termination_address defines the bech32-encoded address that terminates plan + // when the plan ends after the end time, the balance of farming pool address + // is transferred to the termination address + string termination_address = 3 [(gogoproto.moretags) = "yaml:\"termination_address\""]; - // staking_coin_weights specifies coin weights for the plan + // staking_coin_weights specifies coin weights for the plan repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 4 [ (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", @@ -65,19 +109,26 @@ message UpdatePublicPlanProposal { // end_time specifies the end time of the plan google.protobuf.Timestamp end_time = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; -} -// DeletePublicPlanProposal details a proposal for deleting an existing public plan. -message DeletePublicPlanProposal { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; + // epoch_amount specifies the distributing amount for each epoch + repeated cosmos.base.v1beta1.Coin epoch_amount = 7 [ + (gogoproto.moretags) = "yaml:\"epoch_amount\"", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.nullable) = false + ]; - // title specifies the title of the plan - string title = 1; + // epoch_ratio specifies the distributing amount by ratio + string epoch_ratio = 8 [ + (gogoproto.moretags) = "yaml:\"epoch_ratio\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} + +// DeleteRequestProposal details a proposal for deleting an existing public plan. +message DeleteRequestProposal { + // option (gogoproto.goproto_getters) = false; - // description specifies the description of the plan - string description = 2; - // plan_id specifies index of the farming plan - uint64 plan_id = 3; + uint64 plan_id = 1; } diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index cc6d2513..8a4a23b7 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -239,8 +239,8 @@ $ %s tx %s claim --from mykey } // TODO: not implemented yet -// GetCmdSubmitAddPublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. -func GetCmdSubmitAddPublicPlanProposal() *cobra.Command { +// GetCmdSubmitPublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. +func GetCmdSubmitPublicPlanProposal() *cobra.Command { cmd := &cobra.Command{ Use: "add-public-farming-plan [proposal-file] [flags]", Args: cobra.ExactArgs(1), @@ -272,135 +272,14 @@ $ %s tx gov submit-proposal public-farming-plan --from=< return err } - title := "title" - desc := "description" - coinWeights := sdk.NewDecCoins(sdk.NewDecCoin("test", sdk.NewInt(1))) - startTime := time.Now().UTC() - endTime := startTime.AddDate(1, 0, 0) - - content, err := types.NewAddPublicPlanProposal(title, desc, coinWeights, startTime, endTime) - if err != nil { - return err - } - - from := clientCtx.GetFromAddress() - - msg, err := gov.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") - - return cmd -} - -// TODO: not implemented yet -// GetCmdSubmitUpdatePublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. -func GetCmdSubmitUpdatePublicPlanProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "add-public-farming-plan [proposal-file] [flags]", - Args: cobra.ExactArgs(1), - Short: "Submit a public farming plan creation", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a a public farming plan creation along with an initial deposit. -The proposal details must be supplied via a JSON file. - -Example: -$ %s tx gov submit-proposal public-farming-plan --from= --deposit= - -`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) - if err != nil { - return err - } - - deposit, err := sdk.ParseCoinsNormalized(depositStr) - if err != nil { - return err - } - - title := "title" - desc := "description" - coinWeights := sdk.NewDecCoins(sdk.NewDecCoin("test", sdk.NewInt(1))) - startTime := time.Now().UTC() - endTime := startTime.AddDate(1, 0, 0) - - content, err := types.NewAddPublicPlanProposal(title, desc, coinWeights, startTime, endTime) - if err != nil { - return err - } - - from := clientCtx.GetFromAddress() - - msg, err := gov.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") - - return cmd -} - -// TODO: not implemented yet -// GetCmdSubmitDeletePublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. -func GetCmdSubmitDeletePublicPlanProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "add-public-farming-plan [proposal-file] [flags]", - Args: cobra.ExactArgs(1), - Short: "Submit a public farming plan creation", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a a public farming plan creation along with an initial deposit. -The proposal details must be supplied via a JSON file. - -Example: -$ %s tx gov submit-proposal public-farming-plan --from= --deposit= - -`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) - if err != nil { - return err - } - - deposit, err := sdk.ParseCoinsNormalized(depositStr) + proposal, err := ParsePublicPlanProposal(clientCtx.Codec, args[0]) if err != nil { return err } - title := "title" - desc := "description" - coinWeights := sdk.NewDecCoins(sdk.NewDecCoin("test", sdk.NewInt(1))) - startTime := time.Now().UTC() - endTime := startTime.AddDate(1, 0, 0) + name := "" - content, err := types.NewAddPublicPlanProposal(title, desc, coinWeights, startTime, endTime) + content, err := types.NewPublicPlanProposal(proposal.Title, proposal.Description, name, []*types.AddRequestProposal{}, []*types.UpdateRequestProposal{}, []*types.DeleteRequestProposal{}) if err != nil { return err } diff --git a/x/farming/client/cli/utils.go b/x/farming/client/cli/utils.go index 70597652..c4bf7943 100644 --- a/x/farming/client/cli/utils.go +++ b/x/farming/client/cli/utils.go @@ -8,8 +8,8 @@ import ( ) // ParsePublicPlanProposal reads and parses a PublicPlanProposal from a file. -func ParsePublicPlanProposal(cdc codec.JSONCodec, proposalFile string) (types.AddPublicPlanProposal, error) { - proposal := types.AddPublicPlanProposal{} +func ParsePublicPlanProposal(cdc codec.JSONCodec, proposalFile string) (types.PublicPlanProposal, error) { + proposal := types.PublicPlanProposal{} contents, err := ioutil.ReadFile(proposalFile) if err != nil { diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go index 3b800f3b..cd81036b 100644 --- a/x/farming/client/cli/utils_test.go +++ b/x/farming/client/cli/utils_test.go @@ -1,10 +1,8 @@ package cli_test import ( - "fmt" "io/ioutil" "testing" - "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -37,67 +35,50 @@ func TestParseJSONFile(t *testing.T) { proposalFile := "./proposal.json" - proposal := types.AddPublicPlanProposal{} + proposal := types.PublicPlanProposal{} contents, err := ioutil.ReadFile(proposalFile) require.NoError(t, err) err = app.AppCodec().UnmarshalJSON(contents, &proposal) require.NoError(t, err) - - // err = proposal.UnpackInterfaces(app.AppCodec()) - // require.NoError(t, err) - - plans, err := types.UnpackPlans(proposal.Plans) - require.NoError(t, err) - - for _, plan := range plans { - switch p := plan.(type) { - case *types.FixedAmountPlan: - fmt.Println("EpochAmt: ", p.EpochAmount) - default: - } - } } -func TestMarshalPublic(t *testing.T) { - app, _ := createTestInput() +// func TestMarshalPublic(t *testing.T) { +// app, _ := createTestInput() - farmingPoolAddr := sdk.AccAddress([]byte("farmingPoolAddr")) - terminationAddr := sdk.AccAddress([]byte("terminationAddr")) - coinWeights := sdk.NewDecCoins( - sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, - ) - startTime := time.Now().UTC() - endTime := startTime.AddDate(1, 0, 0) - name := "" - - proposal := types.AddPublicPlanProposal{} - proposal.Title = "Public Plan Test" - proposal.Description = "TEST..." - - basePlan := types.NewBasePlan( - 1, - name, - types.PlanTypePublic, - farmingPoolAddr.String(), - terminationAddr.String(), - coinWeights, - startTime, - endTime, - ) +// farmingPoolAddr := sdk.AccAddress([]byte("farmingPoolAddr")) +// terminationAddr := sdk.AccAddress([]byte("terminationAddr")) +// coinWeights := sdk.NewDecCoins(sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}) +// startTime := time.Now().UTC() +// endTime := startTime.AddDate(1, 0, 0) +// name := "" - epochAmt := sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(1))) +// proposal := types.AddPublicPlanProposal{} +// proposal.Title = "Public Plan Test" +// proposal.Description = "TEST..." - fixedPlan := types.NewFixedAmountPlan(basePlan, epochAmt) +// basePlan := types.NewBasePlan( +// 1, +// name, +// types.PlanTypePublic, +// farmingPoolAddr.String(), +// terminationAddr.String(), +// coinWeights, +// startTime, +// endTime, +// ) +// epochRatio := sdk.NewDec(1.0) - plans, err := types.PackPlans([]types.PlanI{fixedPlan}) - require.NoError(t, err) +// ratioPlan := types.NewRatioPlan(basePlan, epochRatio) - proposal.Plans = plans +// plans, err := types.PackPlans([]types.PlanI{ratioPlan}) +// require.NoError(t, err) - bz, err := app.AppCodec().MarshalJSON(&proposal) - require.NoError(t, err) +// proposal.Plans = plans - fmt.Println("bz: ", string(bz)) -} +// bz, err := app.AppCodec().MarshalJSON(&proposal) +// require.NoError(t, err) + +// fmt.Println("bz: ", string(bz)) +// } diff --git a/x/farming/client/proposal_handler.go b/x/farming/client/proposal_handler.go index 9e3f3d63..a2a816f2 100644 --- a/x/farming/client/proposal_handler.go +++ b/x/farming/client/proposal_handler.go @@ -9,7 +9,5 @@ import ( // ProposalHandler is the public plan creation handler. var ( - AddProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitAddPublicPlanProposal, rest.ProposalRESTHandler) - UpdateProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitUpdatePublicPlanProposal, rest.ProposalRESTHandler) - DeleteProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitDeletePublicPlanProposal, rest.ProposalRESTHandler) + AddProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, rest.ProposalRESTHandler) ) diff --git a/x/farming/handler.go b/x/farming/handler.go index 03ec28d2..d7bdddbc 100644 --- a/x/farming/handler.go +++ b/x/farming/handler.go @@ -45,8 +45,14 @@ func NewHandler(k keeper.Keeper) sdk.Handler { func NewPublicPlanProposal(k keeper.Keeper) govtypes.Handler { return func(ctx sdk.Context, content govtypes.Content) error { switch c := content.(type) { - case *types.PublicPlanProposal: - return keeper.HandlePublicPlanProposal(ctx, k, c.Plans) + case *types.AddPublicPlanProposal: + return keeper.HandleAddPublicPlanProposal(ctx, k, c.Plans) + + case *types.UpdatePublicPlanProposal: + return keeper.HandleUpdatePublicPlanProposal(ctx, k, c) + + case *types.DeletePublicPlanProposal: + return keeper.HandleDeletePublicPlanProposal(ctx, k, c) default: return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized farming proposal content type: %T", c) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 6b3b4de2..275ed2f2 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -7,16 +7,7 @@ import ( ) // HandleAddPublicPlanProposal is a handler for executing a public plan creation proposal. -func HandleAddPublicPlanProposal(ctx sdk.Context, k Keeper, p *types.AddPublicPlanProposal) error { - return nil -} - -// HandleUpdatePublicPlanProposal is a handler for executing an update to the public plan. -func HandleUpdatePublicPlanProposal(ctx sdk.Context, k Keeper, p *types.UpdatePublicPlanProposal) error { - return nil -} - -// HandleDeletePublicPlanProposal is a handler for executing a removal of the public plan. -func HandleDeletePublicPlanProposal(ctx sdk.Context, k Keeper, p *types.DeletePublicPlanProposal) error { +func HandleAddPublicPlanProposal(ctx sdk.Context, k Keeper, publicPlanProposal *types.PublicPlanProposal) error { + // TODO: not implemented yet return nil } diff --git a/x/farming/types/codec.go b/x/farming/types/codec.go index cc52a486..2ccda7c8 100644 --- a/x/farming/types/codec.go +++ b/x/farming/types/codec.go @@ -32,9 +32,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations( (*govtypes.Content)(nil), - &AddPublicPlanProposal{}, - &UpdatePublicPlanProposal{}, - &DeletePublicPlanProposal{}, + &PublicPlanProposal{}, ) registry.RegisterInterface( diff --git a/x/farming/types/errors.go b/x/farming/types/errors.go index bf116311..8a6dc1c0 100644 --- a/x/farming/types/errors.go +++ b/x/farming/types/errors.go @@ -17,4 +17,5 @@ var ( ErrStakingNotExists = sdkerrors.Register(ModuleName, 10, "staking not exists") ErrRewardNotExists = sdkerrors.Register(ModuleName, 11, "reward not exists") ErrInsufficientStakingAmount = sdkerrors.Register(ModuleName, 12, "insufficient staking amount") + ErrInvalidNameLength = sdkerrors.Register(ModuleName, 13, "invalid name length") ) diff --git a/x/farming/types/plan.go b/x/farming/types/plan.go index d6facdf3..11922395 100644 --- a/x/farming/types/plan.go +++ b/x/farming/types/plan.go @@ -14,6 +14,10 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) +const ( + MaxNameLength int = 140 +) + var ( _ PlanI = (*FixedAmountPlan)(nil) _ PlanI = (*RatioPlan)(nil) @@ -125,6 +129,9 @@ func (plan BasePlan) Validate() error { if _, err := sdk.AccAddressFromBech32(plan.TerminationAddress); err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid termination address %q: %v", plan.TerminationAddress, err) } + if len(plan.Name) > MaxNameLength { + return sdkerrors.Wrapf(ErrInvalidNameLength, "plan name is longer than max length of %d", MaxNameLength) + } if err := plan.StakingCoinWeights.Validate(); err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid staking coin weights: %v", err) } diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index ff5ffefb..777321f9 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -2,159 +2,64 @@ package types import ( "fmt" - time "time" - "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" gov "github.com/cosmos/cosmos-sdk/x/gov/types" - proto "github.com/gogo/protobuf/proto" ) const ( - ProposalTypeAddPublicPlan string = "AddPublicPlan" - ProposalTypeUpdatePublicPlan string = "UpdatePublicPlan" - ProposalTypeDeletePublicPlan string = "DeletePublicPlan" + ProposalTypePublicPlan string = "PublicPlan" ) // Implements Proposal Interface -var _ gov.Content = &AddPublicPlanProposal{} -var _ gov.Content = &UpdatePublicPlanProposal{} -var _ gov.Content = &DeletePublicPlanProposal{} +var _ gov.Content = &PublicPlanProposal{} func init() { - gov.RegisterProposalType(ProposalTypeAddPublicPlan) - gov.RegisterProposalTypeCodec(&AddPublicPlanProposal{}, "cosmos-sdk/AddPublicPlanProposal") - gov.RegisterProposalType(ProposalTypeUpdatePublicPlan) - gov.RegisterProposalTypeCodec(&UpdatePublicPlanProposal{}, "cosmos-sdk/UpdatePublicPlanProposal") - gov.RegisterProposalType(ProposalTypeDeletePublicPlan) - gov.RegisterProposalTypeCodec(&DeletePublicPlanProposal{}, "cosmos-sdk/DeletePublicPlanProposal") + gov.RegisterProposalType(ProposalTypePublicPlan) + gov.RegisterProposalTypeCodec(&PublicPlanProposal{}, "cosmos-sdk/PublicPlanProposal") } -func NewAddPublicPlanProposal(title, description string, coinWeights sdk.DecCoins, startTime, endTime time.Time) (gov.Content, error) { - return &AddPublicPlanProposal{ - Title: title, - Description: description, - StakingCoinWeights: coinWeights, - StartTime: startTime, - EndTime: endTime, +func NewPublicPlanProposal(title, description, name string, addReq []*AddRequestProposal, + updateReq []*UpdateRequestProposal, deleteReq []*DeleteRequestProposal) (gov.Content, error) { + return &PublicPlanProposal{ + Title: title, + Description: description, + Name: name, + AddRequestProposals: addReq, + UpdateRequestProposals: updateReq, + DeleteRequestProposals: deleteReq, }, nil } -func (p *AddPublicPlanProposal) GetTitle() string { return p.Title } +func (p *PublicPlanProposal) GetTitle() string { return p.Title } -func (p *AddPublicPlanProposal) GetDescription() string { return p.Description } +func (p *PublicPlanProposal) GetDescription() string { return p.Description } -func (p *AddPublicPlanProposal) ProposalRoute() string { return RouterKey } +func (p *PublicPlanProposal) ProposalRoute() string { return RouterKey } -func (p *AddPublicPlanProposal) ProposalType() string { return ProposalTypeAddPublicPlan } +func (p *PublicPlanProposal) ProposalType() string { return ProposalTypePublicPlan } -func (p *AddPublicPlanProposal) ValidateBasic() error { +func (p *PublicPlanProposal) ValidateBasic() error { // TODO: not implemented yet return gov.ValidateAbstract(p) } -func (p AddPublicPlanProposal) String() string { - return fmt.Sprintf(`Add Public Plan Proposal: - Title: %s - Description: %s - StakingCoinWeights: %s - StartTime: %s - EndTime: %s -`, p.Title, p.Description, p.StakingCoinWeights, p.StartTime, p.EndTime) +func (p PublicPlanProposal) String() string { + return fmt.Sprintf(`Public Plan Proposal: + Title: %s + Description: %s + AddRequestProposals: %s + UpdateRequestProposals: %s + DeleteRequestProposals: %s +`, p.Title, p.Description, p.AddRequestProposals, p.UpdateRequestProposals, p.DeleteRequestProposals) } -func NewUpdatePublicPlanProposal(title, description string, id uint64, coinWeights sdk.DecCoins, startTime, endTime time.Time) (gov.Content, error) { - return &UpdatePublicPlanProposal{ - Title: title, - Description: description, - PlanId: id, - StakingCoinWeights: coinWeights, +func NewAddRequestProposal(title, description, name string, addReq []*AddRequestProposal, + updateReq []*UpdateRequestProposal, deleteReq []*DeleteRequestProposal) (AddRequestProposal, error) { + return &AddRequestProposal{ + FarmingPoolAddress: farmingPoolAddr, + TerminationAddress: terminationAddr, + StakingCoinWeights: stakingCoinWeights, StartTime: startTime, EndTime: endTime, }, nil } - -func (p *UpdatePublicPlanProposal) GetTitle() string { return p.Title } - -func (p *UpdatePublicPlanProposal) GetDescription() string { return p.Description } - -func (p *UpdatePublicPlanProposal) ProposalRoute() string { return RouterKey } - -func (p *UpdatePublicPlanProposal) ProposalType() string { return ProposalTypeUpdatePublicPlan } - -func (p *UpdatePublicPlanProposal) ValidateBasic() error { - // TODO: not implemented yet - return gov.ValidateAbstract(p) -} - -func (p UpdatePublicPlanProposal) String() string { - return fmt.Sprintf(`Update Public Plan Proposal: - Title: %s - Description: %s - PlanId: %s - StakingCoinWeights: %s - StartTime: %s - EndTime: %s -`, p.Title, p.Description, p.PlanId, p.StakingCoinWeights, p.StartTime, p.EndTime) -} - -func NewDeletePublicPlanProposal(title, description string, id uint64) (gov.Content, error) { - return &DeletePublicPlanProposal{ - Title: title, - Description: description, - PlanId: id, - }, nil -} - -func (p *DeletePublicPlanProposal) GetTitle() string { return p.Title } - -func (p *DeletePublicPlanProposal) GetDescription() string { return p.Description } - -func (p *DeletePublicPlanProposal) ProposalRoute() string { return RouterKey } - -func (p *DeletePublicPlanProposal) ProposalType() string { return ProposalTypeUpdatePublicPlan } - -func (p *DeletePublicPlanProposal) ValidateBasic() error { - // TODO: not implemented yet - return gov.ValidateAbstract(p) -} - -func (p DeletePublicPlanProposal) String() string { - return fmt.Sprintf(`Delete Public Plan Proposal: - Title: %s - Description: %s - PlanId: %s -`, p.Title, p.Description, p.PlanId) -} - -// PackPlans converts PlanIs to Any slice. -func PackPlans(plans []PlanI) ([]*types.Any, error) { - plansAny := make([]*types.Any, len(plans)) - for i, plan := range plans { - msg, ok := plan.(proto.Message) - if !ok { - return nil, fmt.Errorf("cannot proto marshal %T", plan) - } - any, err := types.NewAnyWithValue(msg) - if err != nil { - return nil, err - } - plansAny[i] = any - } - - return plansAny, nil -} - -// UnpackPlans converts Any slice to PlanIs. -func UnpackPlans(plansAny []*types.Any) ([]PlanI, error) { - plans := make([]PlanI, len(plansAny)) - for i, any := range plansAny { - p, ok := any.GetCachedValue().(PlanI) - if !ok { - return nil, fmt.Errorf("expected planI") - } - plans[i] = p - } - - return plans, nil -} diff --git a/x/farming/types/proposal.pb.go b/x/farming/types/proposal.pb.go index 96de56d7..31114250 100644 --- a/x/farming/types/proposal.pb.go +++ b/x/farming/types/proposal.pb.go @@ -30,12 +30,62 @@ var _ = time.Kitchen // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// AddPublicPlanProposal details a proposal for creating a public plan. -type AddPublicPlanProposal struct { +// PublicPlanProposal details a proposal for creating a public plan. +type PublicPlanProposal struct { // title specifies the title of the plan Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` // description specifies the description of the plan Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // name specifies the plan name that describes what plan is for + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + // add_request_proposals specifies AddRequestProposal object + AddRequestProposals []*AddRequestProposal `protobuf:"bytes,4,rep,name=add_request_proposals,json=addRequestProposals,proto3" json:"add_request_proposals,omitempty" yaml:"add_request_proposals"` + // update_request_proposals specifies UpdateRequestProposal object + UpdateRequestProposals []*UpdateRequestProposal `protobuf:"bytes,5,rep,name=update_request_proposals,json=updateRequestProposals,proto3" json:"update_request_proposals,omitempty" yaml:" update_request_proposals"` + // delete_request_proposals specifies DeleteRequestProposal object + DeleteRequestProposals []*DeleteRequestProposal `protobuf:"bytes,6,rep,name=delete_request_proposals,json=deleteRequestProposals,proto3" json:"delete_request_proposals,omitempty" yaml:"delete_request_proposals"` +} + +func (m *PublicPlanProposal) Reset() { *m = PublicPlanProposal{} } +func (*PublicPlanProposal) ProtoMessage() {} +func (*PublicPlanProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_4719b03c30c7910a, []int{0} +} +func (m *PublicPlanProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PublicPlanProposal.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 *PublicPlanProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_PublicPlanProposal.Merge(m, src) +} +func (m *PublicPlanProposal) XXX_Size() int { + return m.Size() +} +func (m *PublicPlanProposal) XXX_DiscardUnknown() { + xxx_messageInfo_PublicPlanProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_PublicPlanProposal proto.InternalMessageInfo + +// AddRequestProposal details a proposal for creating a public plan. +type AddRequestProposal struct { + // farming_pool_address defines the bech32-encoded address of the farming pool + FarmingPoolAddress string `protobuf:"bytes,1,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` + // termination_address defines the bech32-encoded address that terminates plan + // when the plan ends after the end time, the balance of farming pool address + // is transferred to the termination address + TerminationAddress string `protobuf:"bytes,2,opt,name=termination_address,json=terminationAddress,proto3" json:"termination_address,omitempty" yaml:"termination_address"` // staking_coin_weights specifies coin weights for the plan StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` // start_time specifies the start time of the plan @@ -44,17 +94,17 @@ type AddPublicPlanProposal struct { EndTime time.Time `protobuf:"bytes,5,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` } -func (m *AddPublicPlanProposal) Reset() { *m = AddPublicPlanProposal{} } -func (*AddPublicPlanProposal) ProtoMessage() {} -func (*AddPublicPlanProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_4719b03c30c7910a, []int{0} +func (m *AddRequestProposal) Reset() { *m = AddRequestProposal{} } +func (*AddRequestProposal) ProtoMessage() {} +func (*AddRequestProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_4719b03c30c7910a, []int{1} } -func (m *AddPublicPlanProposal) XXX_Unmarshal(b []byte) error { +func (m *AddRequestProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *AddPublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *AddRequestProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_AddPublicPlanProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_AddRequestProposal.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -64,26 +114,28 @@ func (m *AddPublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byt return b[:n], nil } } -func (m *AddPublicPlanProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddPublicPlanProposal.Merge(m, src) +func (m *AddRequestProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddRequestProposal.Merge(m, src) } -func (m *AddPublicPlanProposal) XXX_Size() int { +func (m *AddRequestProposal) XXX_Size() int { return m.Size() } -func (m *AddPublicPlanProposal) XXX_DiscardUnknown() { - xxx_messageInfo_AddPublicPlanProposal.DiscardUnknown(m) +func (m *AddRequestProposal) XXX_DiscardUnknown() { + xxx_messageInfo_AddRequestProposal.DiscardUnknown(m) } -var xxx_messageInfo_AddPublicPlanProposal proto.InternalMessageInfo +var xxx_messageInfo_AddRequestProposal proto.InternalMessageInfo -// UpdatePublicPlanProposal details a proposal for updating an existing public plan. -type UpdatePublicPlanProposal struct { - // title specifies the title of the plan - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // description specifies the description of the plan - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` +// UpdateRequestProposal details a proposal for updating an existing public plan. +type UpdateRequestProposal struct { // plan_id specifies index of the farming plan - PlanId uint64 `protobuf:"varint,3,opt,name=plan_id,json=planId,proto3" json:"plan_id,omitempty"` + PlanId uint64 `protobuf:"varint,1,opt,name=plan_id,json=planId,proto3" json:"plan_id,omitempty"` + // farming_pool_address defines the bech32-encoded address of the farming pool + FarmingPoolAddress string `protobuf:"bytes,2,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` + // termination_address defines the bech32-encoded address that terminates plan + // when the plan ends after the end time, the balance of farming pool address + // is transferred to the termination address + TerminationAddress string `protobuf:"bytes,3,opt,name=termination_address,json=terminationAddress,proto3" json:"termination_address,omitempty" yaml:"termination_address"` // staking_coin_weights specifies coin weights for the plan StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,4,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` // start_time specifies the start time of the plan @@ -92,17 +144,17 @@ type UpdatePublicPlanProposal struct { EndTime time.Time `protobuf:"bytes,6,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` } -func (m *UpdatePublicPlanProposal) Reset() { *m = UpdatePublicPlanProposal{} } -func (*UpdatePublicPlanProposal) ProtoMessage() {} -func (*UpdatePublicPlanProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_4719b03c30c7910a, []int{1} +func (m *UpdateRequestProposal) Reset() { *m = UpdateRequestProposal{} } +func (*UpdateRequestProposal) ProtoMessage() {} +func (*UpdateRequestProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_4719b03c30c7910a, []int{2} } -func (m *UpdatePublicPlanProposal) XXX_Unmarshal(b []byte) error { +func (m *UpdateRequestProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *UpdatePublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *UpdateRequestProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_UpdatePublicPlanProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_UpdateRequestProposal.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -112,39 +164,36 @@ func (m *UpdatePublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([] return b[:n], nil } } -func (m *UpdatePublicPlanProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdatePublicPlanProposal.Merge(m, src) +func (m *UpdateRequestProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateRequestProposal.Merge(m, src) } -func (m *UpdatePublicPlanProposal) XXX_Size() int { +func (m *UpdateRequestProposal) XXX_Size() int { return m.Size() } -func (m *UpdatePublicPlanProposal) XXX_DiscardUnknown() { - xxx_messageInfo_UpdatePublicPlanProposal.DiscardUnknown(m) +func (m *UpdateRequestProposal) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateRequestProposal.DiscardUnknown(m) } -var xxx_messageInfo_UpdatePublicPlanProposal proto.InternalMessageInfo +var xxx_messageInfo_UpdateRequestProposal proto.InternalMessageInfo -// DeletePublicPlanProposal details a proposal for deleting an existing public plan. -type DeletePublicPlanProposal struct { - // title specifies the title of the plan - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - // description specifies the description of the plan - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` +// DeleteRequestProposal details a proposal for deleting an existing public plan. +type DeleteRequestProposal struct { // plan_id specifies index of the farming plan - PlanId uint64 `protobuf:"varint,3,opt,name=plan_id,json=planId,proto3" json:"plan_id,omitempty"` + PlanId uint64 `protobuf:"varint,1,opt,name=plan_id,json=planId,proto3" json:"plan_id,omitempty"` } -func (m *DeletePublicPlanProposal) Reset() { *m = DeletePublicPlanProposal{} } -func (*DeletePublicPlanProposal) ProtoMessage() {} -func (*DeletePublicPlanProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_4719b03c30c7910a, []int{2} +func (m *DeleteRequestProposal) Reset() { *m = DeleteRequestProposal{} } +func (m *DeleteRequestProposal) String() string { return proto.CompactTextString(m) } +func (*DeleteRequestProposal) ProtoMessage() {} +func (*DeleteRequestProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_4719b03c30c7910a, []int{3} } -func (m *DeletePublicPlanProposal) XXX_Unmarshal(b []byte) error { +func (m *DeleteRequestProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *DeletePublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *DeleteRequestProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_DeletePublicPlanProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_DeleteRequestProposal.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -154,22 +203,30 @@ func (m *DeletePublicPlanProposal) XXX_Marshal(b []byte, deterministic bool) ([] return b[:n], nil } } -func (m *DeletePublicPlanProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_DeletePublicPlanProposal.Merge(m, src) +func (m *DeleteRequestProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteRequestProposal.Merge(m, src) } -func (m *DeletePublicPlanProposal) XXX_Size() int { +func (m *DeleteRequestProposal) XXX_Size() int { return m.Size() } -func (m *DeletePublicPlanProposal) XXX_DiscardUnknown() { - xxx_messageInfo_DeletePublicPlanProposal.DiscardUnknown(m) +func (m *DeleteRequestProposal) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteRequestProposal.DiscardUnknown(m) } -var xxx_messageInfo_DeletePublicPlanProposal proto.InternalMessageInfo +var xxx_messageInfo_DeleteRequestProposal proto.InternalMessageInfo + +func (m *DeleteRequestProposal) GetPlanId() uint64 { + if m != nil { + return m.PlanId + } + return 0 +} func init() { - proto.RegisterType((*AddPublicPlanProposal)(nil), "tendermint.farming.v1beta1.AddPublicPlanProposal") - proto.RegisterType((*UpdatePublicPlanProposal)(nil), "tendermint.farming.v1beta1.UpdatePublicPlanProposal") - proto.RegisterType((*DeletePublicPlanProposal)(nil), "tendermint.farming.v1beta1.DeletePublicPlanProposal") + proto.RegisterType((*PublicPlanProposal)(nil), "tendermint.farming.v1beta1.PublicPlanProposal") + proto.RegisterType((*AddRequestProposal)(nil), "tendermint.farming.v1beta1.AddRequestProposal") + proto.RegisterType((*UpdateRequestProposal)(nil), "tendermint.farming.v1beta1.UpdateRequestProposal") + proto.RegisterType((*DeleteRequestProposal)(nil), "tendermint.farming.v1beta1.DeleteRequestProposal") } func init() { @@ -177,42 +234,54 @@ func init() { } var fileDescriptor_4719b03c30c7910a = []byte{ - // 498 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x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xee, 0x6d, 0xa5, 0xdb, 0xbd, 0x54, 0xaa, 0x1b, 0x98, 0x22, 0x49, 0xdd, - 0xdf, 0xfc, 0x78, 0xe6, 0x19, 0x9f, 0xce, 0x3c, 0x23, 0x98, 0x5b, 0xc0, 0x79, 0x55, 0x23, 0x28, - 0xf0, 0x1a, 0x13, 0xbb, 0x07, 0x36, 0xea, 0x12, 0xd2, 0x94, 0x20, 0xc7, 0xf2, 0xcd, 0xb0, 0x97, - 0x0c, 0x24, 0x7c, 0x81, 0x7e, 0x1d, 0x65, 0xef, 0xbf, 0x8d, 0xb2, 0xff, 0x97, 0xa2, 0x1c, 0xac, - 0x3d, 0xca, 0x19, 0x70, 0x0e, 0x70, 0x89, 0xff, 0x49, 0x92, 0x57, 0x6d, 0x27, 0xcf, 0xe7, 0x0b, - 0xd7, 0x3c, 0x5f, 0xb8, 0xe6, 0xf7, 0x85, 0x6b, 0x9e, 0x2e, 0x5d, 0xe3, 0x7c, 0xe9, 0x1a, 0xdf, - 0x96, 0xae, 0xf1, 0x76, 0xe7, 0x5a, 0x12, 0x37, 0xfc, 0x60, 0x3e, 0xac, 0x4e, 0x6d, 0x28, 0xd9, - 0xa0, 0xf5, 0xe0, 0xc9, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x69, 0xb9, 0x1b, 0x30, 0x25, 0x05, - 0x00, 0x00, + // 691 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0x8e, 0x1b, 0x27, 0x6d, 0xaf, 0x03, 0xe2, 0x9a, 0x16, 0x93, 0x16, 0x3b, 0x32, 0x0c, 0x41, + 0xa8, 0x36, 0x2d, 0x5b, 0xb7, 0x06, 0x24, 0xc4, 0x44, 0xb0, 0x40, 0x20, 0x16, 0xeb, 0x92, 0xbb, + 0xba, 0x56, 0x6d, 0x9f, 0xf1, 0x5d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 0x3d, 0x0f, 0x5f, 0xe0, 0xa9, + 0x9e, 0x99, 0xb9, 0x71, 0xcf, 0x54, 0x6f, 0xde, 0x33, 0xfa, 0x7f, 0xeb, 0x99, 0xda, 0x3f, 0xf2, + 0x4c, 0xfd, 0xc6, 0x3d, 0xf3, 0x18, 0x2c, 0x95, 0xfe, 0x56, 0x4d, 0xb5, 0x4c, 0xe7, 0xf9, 0xd1, + 0xa9, 0xa9, 0x1d, 0x9f, 0x9a, 0xda, 0x9f, 0x53, 0x53, 0xdb, 0x3f, 0x33, 0x2b, 0xc7, 0x67, 0x66, + 0xe5, 0xf7, 0x99, 0x59, 0x79, 0xbf, 0x36, 0x31, 0xc4, 0x92, 0x3f, 0xc2, 0xcf, 0xe3, 0x93, 0x98, + 0x67, 0xaf, 0x2e, 0xe4, 0x3f, 0xf9, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x05, 0xf1, 0xfd, 0x3a, 0xcd, + 0x07, 0x00, 0x00, } -func (m *AddPublicPlanProposal) Marshal() (dAtA []byte, err error) { +func (m *PublicPlanProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -222,12 +291,98 @@ func (m *AddPublicPlanProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *AddPublicPlanProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *PublicPlanProposal) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *AddPublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *PublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DeleteRequestProposals) > 0 { + for iNdEx := len(m.DeleteRequestProposals) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DeleteRequestProposals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProposal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if len(m.UpdateRequestProposals) > 0 { + for iNdEx := len(m.UpdateRequestProposals) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.UpdateRequestProposals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProposal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.AddRequestProposals) > 0 { + for iNdEx := len(m.AddRequestProposals) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AddRequestProposals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProposal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *AddRequestProposal) 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 *AddRequestProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AddRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -262,24 +417,24 @@ func (m *AddPublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x1a } } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + if len(m.TerminationAddress) > 0 { + i -= len(m.TerminationAddress) + copy(dAtA[i:], m.TerminationAddress) + i = encodeVarintProposal(dAtA, i, uint64(len(m.TerminationAddress))) i-- dAtA[i] = 0x12 } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + if len(m.FarmingPoolAddress) > 0 { + i -= len(m.FarmingPoolAddress) + copy(dAtA[i:], m.FarmingPoolAddress) + i = encodeVarintProposal(dAtA, i, uint64(len(m.FarmingPoolAddress))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *UpdatePublicPlanProposal) Marshal() (dAtA []byte, err error) { +func (m *UpdateRequestProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -289,12 +444,12 @@ func (m *UpdatePublicPlanProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *UpdatePublicPlanProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *UpdateRequestProposal) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *UpdatePublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *UpdateRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -329,29 +484,29 @@ func (m *UpdatePublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error dAtA[i] = 0x22 } } - if m.PlanId != 0 { - i = encodeVarintProposal(dAtA, i, uint64(m.PlanId)) + if len(m.TerminationAddress) > 0 { + i -= len(m.TerminationAddress) + copy(dAtA[i:], m.TerminationAddress) + i = encodeVarintProposal(dAtA, i, uint64(len(m.TerminationAddress))) i-- - dAtA[i] = 0x18 + dAtA[i] = 0x1a } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + if len(m.FarmingPoolAddress) > 0 { + i -= len(m.FarmingPoolAddress) + copy(dAtA[i:], m.FarmingPoolAddress) + i = encodeVarintProposal(dAtA, i, uint64(len(m.FarmingPoolAddress))) i-- dAtA[i] = 0x12 } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + if m.PlanId != 0 { + i = encodeVarintProposal(dAtA, i, uint64(m.PlanId)) i-- - dAtA[i] = 0xa + dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func (m *DeletePublicPlanProposal) Marshal() (dAtA []byte, err error) { +func (m *DeleteRequestProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -361,12 +516,12 @@ func (m *DeletePublicPlanProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *DeletePublicPlanProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *DeleteRequestProposal) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *DeletePublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *DeleteRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -374,21 +529,7 @@ func (m *DeletePublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error if m.PlanId != 0 { i = encodeVarintProposal(dAtA, i, uint64(m.PlanId)) i-- - dAtA[i] = 0x18 - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa + dAtA[i] = 0x8 } return len(dAtA) - i, nil } @@ -404,7 +545,7 @@ func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *AddPublicPlanProposal) Size() (n int) { +func (m *PublicPlanProposal) Size() (n int) { if m == nil { return 0 } @@ -418,36 +559,45 @@ func (m *AddPublicPlanProposal) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - if len(m.StakingCoinWeights) > 0 { - for _, e := range m.StakingCoinWeights { + l = len(m.Name) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + if len(m.AddRequestProposals) > 0 { + for _, e := range m.AddRequestProposals { + l = e.Size() + n += 1 + l + sovProposal(uint64(l)) + } + } + if len(m.UpdateRequestProposals) > 0 { + for _, e := range m.UpdateRequestProposals { + l = e.Size() + n += 1 + l + sovProposal(uint64(l)) + } + } + if len(m.DeleteRequestProposals) > 0 { + for _, e := range m.DeleteRequestProposals { l = e.Size() n += 1 + l + sovProposal(uint64(l)) } } - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime) - n += 1 + l + sovProposal(uint64(l)) - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime) - n += 1 + l + sovProposal(uint64(l)) return n } -func (m *UpdatePublicPlanProposal) Size() (n int) { +func (m *AddRequestProposal) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Title) + l = len(m.FarmingPoolAddress) if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - l = len(m.Description) + l = len(m.TerminationAddress) if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - if m.PlanId != 0 { - n += 1 + sovProposal(uint64(m.PlanId)) - } if len(m.StakingCoinWeights) > 0 { for _, e := range m.StakingCoinWeights { l = e.Size() @@ -461,20 +611,42 @@ func (m *UpdatePublicPlanProposal) Size() (n int) { return n } -func (m *DeletePublicPlanProposal) Size() (n int) { +func (m *UpdateRequestProposal) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Title) + if m.PlanId != 0 { + n += 1 + sovProposal(uint64(m.PlanId)) + } + l = len(m.FarmingPoolAddress) if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - l = len(m.Description) + l = len(m.TerminationAddress) if l > 0 { n += 1 + l + sovProposal(uint64(l)) } + if len(m.StakingCoinWeights) > 0 { + for _, e := range m.StakingCoinWeights { + l = e.Size() + n += 1 + l + sovProposal(uint64(l)) + } + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime) + n += 1 + l + sovProposal(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime) + n += 1 + l + sovProposal(uint64(l)) + return n +} + +func (m *DeleteRequestProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l if m.PlanId != 0 { n += 1 + sovProposal(uint64(m.PlanId)) } @@ -487,7 +659,7 @@ func sovProposal(x uint64) (n int) { func sozProposal(x uint64) (n int) { return sovProposal(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *AddPublicPlanProposal) Unmarshal(dAtA []byte) error { +func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -510,10 +682,10 @@ func (m *AddPublicPlanProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: AddPublicPlanProposal: wiretype end group for non-group") + return fmt.Errorf("proto: PublicPlanProposal: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: AddPublicPlanProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: PublicPlanProposal: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -582,7 +754,39 @@ func (m *AddPublicPlanProposal) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AddRequestProposals", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -609,14 +813,14 @@ func (m *AddPublicPlanProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.StakingCoinWeights = append(m.StakingCoinWeights, types.DecCoin{}) - if err := m.StakingCoinWeights[len(m.StakingCoinWeights)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.AddRequestProposals = append(m.AddRequestProposals, &AddRequestProposal{}) + if err := m.AddRequestProposals[len(m.AddRequestProposals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 4: + case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UpdateRequestProposals", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -643,13 +847,14 @@ func (m *AddPublicPlanProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { + m.UpdateRequestProposals = append(m.UpdateRequestProposals, &UpdateRequestProposal{}) + if err := m.UpdateRequestProposals[len(m.UpdateRequestProposals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field DeleteRequestProposals", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -676,7 +881,8 @@ func (m *AddPublicPlanProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.EndTime, dAtA[iNdEx:postIndex]); err != nil { + m.DeleteRequestProposals = append(m.DeleteRequestProposals, &DeleteRequestProposal{}) + if err := m.DeleteRequestProposals[len(m.DeleteRequestProposals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -701,7 +907,7 @@ func (m *AddPublicPlanProposal) Unmarshal(dAtA []byte) error { } return nil } -func (m *UpdatePublicPlanProposal) Unmarshal(dAtA []byte) error { +func (m *AddRequestProposal) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -724,15 +930,15 @@ func (m *UpdatePublicPlanProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: UpdatePublicPlanProposal: wiretype end group for non-group") + return fmt.Errorf("proto: AddRequestProposal: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: UpdatePublicPlanProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: AddRequestProposal: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -760,11 +966,11 @@ func (m *UpdatePublicPlanProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Title = string(dAtA[iNdEx:postIndex]) + m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TerminationAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -792,28 +998,9 @@ func (m *UpdatePublicPlanProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Description = string(dAtA[iNdEx:postIndex]) + m.TerminationAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PlanId", wireType) - } - m.PlanId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.PlanId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) } @@ -847,7 +1034,7 @@ func (m *UpdatePublicPlanProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) } @@ -880,7 +1067,7 @@ func (m *UpdatePublicPlanProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 6: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) } @@ -934,7 +1121,7 @@ func (m *UpdatePublicPlanProposal) Unmarshal(dAtA []byte) error { } return nil } -func (m *DeletePublicPlanProposal) Unmarshal(dAtA []byte) error { +func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -957,15 +1144,34 @@ func (m *DeletePublicPlanProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: DeletePublicPlanProposal: wiretype end group for non-group") + return fmt.Errorf("proto: UpdateRequestProposal: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: DeletePublicPlanProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: UpdateRequestProposal: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PlanId", wireType) + } + m.PlanId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PlanId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -993,11 +1199,11 @@ func (m *DeletePublicPlanProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Title = string(dAtA[iNdEx:postIndex]) + m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TerminationAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1025,9 +1231,159 @@ func (m *DeletePublicPlanProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Description = string(dAtA[iNdEx:postIndex]) + m.TerminationAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StakingCoinWeights = append(m.StakingCoinWeights, types.DecCoin{}) + if err := m.StakingCoinWeights[len(m.StakingCoinWeights)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.EndTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DeleteRequestProposal) 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 ErrIntOverflowProposal + } + 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: DeleteRequestProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DeleteRequestProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field PlanId", wireType) } From ddf5eece7aada3e3fa682c83865a2c93ced26c44 Mon Sep 17 00:00:00 2001 From: kogisin Date: Sat, 24 Jul 2021 20:40:03 +0900 Subject: [PATCH 08/39] add private plans and public plans are work in progress --- .../tendermint/farming/v1beta1/proposal.proto | 13 +- x/farming/client/cli/tx.go | 122 +++++++---- x/farming/client/cli/utils.go | 52 +++++ x/farming/handler.go | 10 +- x/farming/keeper/msg_server.go | 10 +- x/farming/keeper/plan.go | 26 +-- x/farming/keeper/proposal_handler.go | 4 +- x/farming/types/proposal.go | 11 - x/farming/types/proposal.pb.go | 202 +++++++++++++----- 9 files changed, 309 insertions(+), 141 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index 123e805b..1a4922da 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -25,11 +25,12 @@ message PublicPlanProposal { string name = 3; // add_request_proposals specifies AddRequestProposal object - repeated AddRequestProposal add_request_proposals = 4 [(gogoproto.moretags) = "yaml:\"add_request_proposals\""]; + repeated AddRequestProposal add_request_proposals = 4 + [(gogoproto.moretags) = "yaml:\"add_request_proposals\""]; // update_request_proposals specifies UpdateRequestProposal object repeated UpdateRequestProposal update_request_proposals = 5 - [(gogoproto.moretags) = "yaml:\" update_request_proposals\""]; + [(gogoproto.moretags) = "yaml:\"update_request_proposals\""]; // delete_request_proposals specifies DeleteRequestProposal object repeated DeleteRequestProposal delete_request_proposals = 6 @@ -38,9 +39,6 @@ message PublicPlanProposal { // AddRequestProposal details a proposal for creating a public plan. message AddRequestProposal { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - // farming_pool_address defines the bech32-encoded address of the farming pool string farming_pool_address = 1 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; @@ -81,9 +79,6 @@ message AddRequestProposal { // UpdateRequestProposal details a proposal for updating an existing public plan. message UpdateRequestProposal { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - // plan_id specifies index of the farming plan uint64 plan_id = 1; @@ -127,8 +122,6 @@ message UpdateRequestProposal { // DeleteRequestProposal details a proposal for deleting an existing public plan. message DeleteRequestProposal { - // option (gogoproto.goproto_getters) = false; - // plan_id specifies index of the farming plan uint64 plan_id = 1; } diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index 547b76f2..4955ed03 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -3,12 +3,12 @@ package cli import ( "fmt" "strings" - "time" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" gov "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -40,14 +40,34 @@ func GetTxCmd() *cobra.Command { func NewCreateFixedAmountPlanCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "create-fixed-plan", - Aliases: []string{"cf"}, - Args: cobra.ExactArgs(0), - Short: "create fixed amount farming plan", + Use: "create-private-fixed-plan [plan-file]", + Args: cobra.ExactArgs(1), + Short: "create private fixed amount farming plan", Long: strings.TrimSpace( - fmt.Sprintf(`Create fixed amount farming plan. + fmt.Sprintf(`Create private fixed amount farming plan. +The plan details must be provided through a JSON file. + Example: -$ %s tx %s create-fixed-plan --from mykey +$ %s tx %s create-private-fixed-plan --from mykey + +Where plan.json contains: + +{ + "staking_coin_weights": [ + { + "denom": "uatom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-24T08:41:21.662422Z", + "end_time": "2022-07-28T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] +} `, version.AppName, types.ModuleName, ), @@ -57,28 +77,28 @@ $ %s tx %s create-fixed-plan --from mykey if err != nil { return err } - planCreator := clientCtx.GetFromAddress() - fmt.Println("planCreator: ", planCreator) - - // TODO: replace dummy data - farmingPoolAddr := sdk.AccAddress{} - stakingCoinWeights := sdk.DecCoins{} - startTime := time.Time{} - endTime := time.Time{} - epochAmount := sdk.Coins{} + plan, err := ParsePrivateFixedPlanProposal(args[0]) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse json file: %w", err) + } msg := types.NewMsgCreateFixedAmountPlan( - farmingPoolAddr, - stakingCoinWeights, - startTime, - endTime, - epochAmount, + clientCtx.GetFromAddress(), + plan.StakingCoinWeights, + plan.StartTime, + plan.EndTime, + plan.EpochAmount, ) + if err = msg.ValidateBasic(); err != nil { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + flags.AddTxFlagsToCmd(cmd) return cmd @@ -86,14 +106,34 @@ $ %s tx %s create-fixed-plan --from mykey func NewCreateRatioPlanCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "create-ratio-plan", - Aliases: []string{"cr"}, - Args: cobra.ExactArgs(0), - Short: "create ratio farming plan", + Use: "create-private-ratio-plan [plan-file]", + Args: cobra.ExactArgs(0), + Short: "create private ratio farming plan", Long: strings.TrimSpace( - fmt.Sprintf(`Create ratio farming plan. + fmt.Sprintf(`Create private ratio farming plan. +The plan details must be provided through a JSON file. + Example: -$ %s tx %s create-ratio-plan --from mykey +$ %s tx %s create-private-ratio-plan --from mykey + +Where plan.json contains: + +{ + "staking_coin_weights": [ + { + "denom": "uatom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-24T08:41:21.662422Z", + "end_time": "2022-07-28T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] +} `, version.AppName, types.ModuleName, ), @@ -103,28 +143,28 @@ $ %s tx %s create-ratio-plan --from mykey if err != nil { return err } - planCreator := clientCtx.GetFromAddress() - fmt.Println("planCreator: ", planCreator) - - // TODO: replace dummy data - farmingPoolAddr := sdk.AccAddress{} - stakingCoinWeights := sdk.DecCoins{} - startTime := time.Time{} - endTime := time.Time{} - epochRatio := sdk.Dec{} + plan, err := ParsePrivateRatioPlanProposal(args[0]) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse json file: %w", err) + } msg := types.NewMsgCreateRatioPlan( - farmingPoolAddr, - stakingCoinWeights, - startTime, - endTime, - epochRatio, + clientCtx.GetFromAddress(), + plan.StakingCoinWeights, + plan.StartTime, + plan.EndTime, + plan.EpochRatio, ) + if err = msg.ValidateBasic(); err != nil { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } + flags.AddTxFlagsToCmd(cmd) return cmd diff --git a/x/farming/client/cli/utils.go b/x/farming/client/cli/utils.go index c4bf7943..f10813d3 100644 --- a/x/farming/client/cli/utils.go +++ b/x/farming/client/cli/utils.go @@ -1,12 +1,64 @@ package cli import ( + "encoding/json" "io/ioutil" + "time" "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/farming/x/farming/types" ) +// PrivateFixedPlanRequest defines CLI request for a private fixed plan. +type PrivateFixedPlanRequest struct { + StakingCoinWeights sdk.DecCoins `json:"staking_coin_weights"` + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` + EpochAmount sdk.Coins `json:"epoch_amount"` +} + +// PrivateRatioPlanRequest defines CLI request for a private ratio plan. +type PrivateRatioPlanRequest struct { + StakingCoinWeights sdk.DecCoins `json:"staking_coin_weights"` + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` + EpochRatio sdk.Dec `json:"epoch_ratio"` +} + +// ParsePrivateFixedPlanProposal reads and parses a PrivateFixedPlanRequest from a file. +func ParsePrivateFixedPlanProposal(file string) (PrivateFixedPlanRequest, error) { + plan := PrivateFixedPlanRequest{} + + contents, err := ioutil.ReadFile(file) + if err != nil { + return plan, err + } + + if err = json.Unmarshal(contents, &plan); err != nil { + return plan, err + } + + return plan, nil +} + +// ParsePrivateRatioPlanProposal reads and parses a PrivateRatioPlanRequest from a file. +func ParsePrivateRatioPlanProposal(file string) (PrivateRatioPlanRequest, error) { + plan := PrivateRatioPlanRequest{} + + contents, err := ioutil.ReadFile(file) + if err != nil { + return plan, err + } + + if err = json.Unmarshal(contents, &plan); err != nil { + return plan, err + } + + return plan, nil +} + // ParsePublicPlanProposal reads and parses a PublicPlanProposal from a file. func ParsePublicPlanProposal(cdc codec.JSONCodec, proposalFile string) (types.PublicPlanProposal, error) { proposal := types.PublicPlanProposal{} diff --git a/x/farming/handler.go b/x/farming/handler.go index d7bdddbc..50de9cdb 100644 --- a/x/farming/handler.go +++ b/x/farming/handler.go @@ -45,14 +45,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler { func NewPublicPlanProposal(k keeper.Keeper) govtypes.Handler { return func(ctx sdk.Context, content govtypes.Content) error { switch c := content.(type) { - case *types.AddPublicPlanProposal: - return keeper.HandleAddPublicPlanProposal(ctx, k, c.Plans) - - case *types.UpdatePublicPlanProposal: - return keeper.HandleUpdatePublicPlanProposal(ctx, k, c) - - case *types.DeletePublicPlanProposal: - return keeper.HandleDeletePublicPlanProposal(ctx, k, c) + case *types.PublicPlanProposal: + return keeper.HandlePublicPlanProposal(ctx, k, c) default: return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized farming proposal content type: %T", c) diff --git a/x/farming/keeper/msg_server.go b/x/farming/keeper/msg_server.go index 2d58ca47..866b0928 100644 --- a/x/farming/keeper/msg_server.go +++ b/x/farming/keeper/msg_server.go @@ -31,7 +31,10 @@ func (k msgServer) CreateFixedAmountPlan(goCtx context.Context, msg *types.MsgCr ctx := sdk.UnwrapSDKContext(goCtx) name := "" - fixedPlan := k.Keeper.CreateFixedAmountPlan(ctx, msg, name, types.PlanTypePrivate) + fixedPlan, err := k.Keeper.CreateFixedAmountPlan(ctx, msg, name, types.PlanTypePrivate) + if err != nil { + return nil, err + } ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( @@ -52,7 +55,10 @@ func (k msgServer) CreateRatioPlan(goCtx context.Context, msg *types.MsgCreateRa ctx := sdk.UnwrapSDKContext(goCtx) name := "" - ratioPlan := k.Keeper.CreateRatioPlan(ctx, msg, name, types.PlanTypePrivate) + ratioPlan, err := k.Keeper.CreateRatioPlan(ctx, msg, name, types.PlanTypePrivate) + if err != nil { + return nil, err + } ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( diff --git a/x/farming/keeper/plan.go b/x/farming/keeper/plan.go index 438bf470..86e6aa09 100644 --- a/x/farming/keeper/plan.go +++ b/x/farming/keeper/plan.go @@ -163,11 +163,13 @@ func (k Keeper) UnmarshalPlan(bz []byte) (plan types.PlanI, err error) { } // CreateFixedAmountPlan sets fixed amount plan. -func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixedAmountPlan, name string, typ types.PlanType) *types.FixedAmountPlan { +func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixedAmountPlan, + name string, typ types.PlanType) (*types.FixedAmountPlan, error) { + nextId := k.GetNextPlanIDWithUpdate(ctx) farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(msg.FarmingPoolAddress) if err != nil { - return err + return nil, err } terminationAddrAcc := farmingPoolAddrAcc @@ -176,16 +178,16 @@ func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixed balances := k.bankKeeper.GetAllBalances(ctx, farmingPoolAddrAcc) _, hasNeg := balances.SafeSub(params.PrivatePlanCreationFee) if hasNeg { - return sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient balance to pay private plan creation fee") + return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient balance to pay private plan creation fee") } farmingFeeCollectorAcc, err := sdk.AccAddressFromBech32(params.FarmingFeeCollector) if err != nil { - return err + return nil, err } if err := k.bankKeeper.SendCoins(ctx, farmingPoolAddrAcc, farmingFeeCollectorAcc, params.PrivatePlanCreationFee); err != nil { - return err + return nil, err } basePlan := types.NewBasePlan( @@ -214,15 +216,15 @@ func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixed ), }) - return nil + return fixedPlan, nil } // CreateRatioPlan sets ratio plan. -func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, name string, typ types.PlanType) *types.RatioPlan { +func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, name string, typ types.PlanType) (*types.RatioPlan, error) { nextId := k.GetNextPlanIDWithUpdate(ctx) farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(msg.FarmingPoolAddress) if err != nil { - return err + return nil, err } terminationAddrAcc := farmingPoolAddrAcc @@ -231,16 +233,16 @@ func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, balances := k.bankKeeper.GetAllBalances(ctx, farmingPoolAddrAcc) _, hasNeg := balances.SafeSub(params.PrivatePlanCreationFee) if hasNeg { - return sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient balance to pay private plan creation fee") + return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient balance to pay private plan creation fee") } farmingFeeCollectorAcc, err := sdk.AccAddressFromBech32(params.FarmingFeeCollector) if err != nil { - return err + return nil, err } if err := k.bankKeeper.SendCoins(ctx, farmingPoolAddrAcc, farmingFeeCollectorAcc, params.PrivatePlanCreationFee); err != nil { - return err + return nil, err } basePlan := types.NewBasePlan( @@ -269,5 +271,5 @@ func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, ), }) - return nil + return ratioPlan, nil } diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 275ed2f2..e1836121 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -6,8 +6,8 @@ import ( "github.com/tendermint/farming/x/farming/types" ) -// HandleAddPublicPlanProposal is a handler for executing a public plan creation proposal. -func HandleAddPublicPlanProposal(ctx sdk.Context, k Keeper, publicPlanProposal *types.PublicPlanProposal) error { +// HandlePublicPlanProposal is a handler for executing a public plan creation proposal. +func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, publicPlanProposal *types.PublicPlanProposal) error { // TODO: not implemented yet return nil } diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 777321f9..8aa6055f 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -52,14 +52,3 @@ func (p PublicPlanProposal) String() string { DeleteRequestProposals: %s `, p.Title, p.Description, p.AddRequestProposals, p.UpdateRequestProposals, p.DeleteRequestProposals) } - -func NewAddRequestProposal(title, description, name string, addReq []*AddRequestProposal, - updateReq []*UpdateRequestProposal, deleteReq []*DeleteRequestProposal) (AddRequestProposal, error) { - return &AddRequestProposal{ - FarmingPoolAddress: farmingPoolAddr, - TerminationAddress: terminationAddr, - StakingCoinWeights: stakingCoinWeights, - StartTime: startTime, - EndTime: endTime, - }, nil -} diff --git a/x/farming/types/proposal.pb.go b/x/farming/types/proposal.pb.go index eca8dda1..a03a440a 100644 --- a/x/farming/types/proposal.pb.go +++ b/x/farming/types/proposal.pb.go @@ -41,7 +41,7 @@ type PublicPlanProposal struct { // add_request_proposals specifies AddRequestProposal object AddRequestProposals []*AddRequestProposal `protobuf:"bytes,4,rep,name=add_request_proposals,json=addRequestProposals,proto3" json:"add_request_proposals,omitempty" yaml:"add_request_proposals"` // update_request_proposals specifies UpdateRequestProposal object - UpdateRequestProposals []*UpdateRequestProposal `protobuf:"bytes,5,rep,name=update_request_proposals,json=updateRequestProposals,proto3" json:"update_request_proposals,omitempty" yaml:" update_request_proposals"` + UpdateRequestProposals []*UpdateRequestProposal `protobuf:"bytes,5,rep,name=update_request_proposals,json=updateRequestProposals,proto3" json:"update_request_proposals,omitempty" yaml:"update_request_proposals"` // delete_request_proposals specifies DeleteRequestProposal object DeleteRequestProposals []*DeleteRequestProposal `protobuf:"bytes,6,rep,name=delete_request_proposals,json=deleteRequestProposals,proto3" json:"delete_request_proposals,omitempty" yaml:"delete_request_proposals"` } @@ -98,8 +98,9 @@ type AddRequestProposal struct { EpochRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=epoch_ratio,json=epochRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_ratio" yaml:"epoch_ratio"` } -func (m *AddRequestProposal) Reset() { *m = AddRequestProposal{} } -func (*AddRequestProposal) ProtoMessage() {} +func (m *AddRequestProposal) Reset() { *m = AddRequestProposal{} } +func (m *AddRequestProposal) String() string { return proto.CompactTextString(m) } +func (*AddRequestProposal) ProtoMessage() {} func (*AddRequestProposal) Descriptor() ([]byte, []int) { return fileDescriptor_4719b03c30c7910a, []int{1} } @@ -130,6 +131,48 @@ func (m *AddRequestProposal) XXX_DiscardUnknown() { var xxx_messageInfo_AddRequestProposal proto.InternalMessageInfo +func (m *AddRequestProposal) GetFarmingPoolAddress() string { + if m != nil { + return m.FarmingPoolAddress + } + return "" +} + +func (m *AddRequestProposal) GetTerminationAddress() string { + if m != nil { + return m.TerminationAddress + } + return "" +} + +func (m *AddRequestProposal) GetStakingCoinWeights() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.StakingCoinWeights + } + return nil +} + +func (m *AddRequestProposal) GetStartTime() time.Time { + if m != nil { + return m.StartTime + } + return time.Time{} +} + +func (m *AddRequestProposal) GetEndTime() time.Time { + if m != nil { + return m.EndTime + } + return time.Time{} +} + +func (m *AddRequestProposal) GetEpochAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.EpochAmount + } + return nil +} + // UpdateRequestProposal details a proposal for updating an existing public plan. type UpdateRequestProposal struct { // plan_id specifies index of the farming plan @@ -152,8 +195,9 @@ type UpdateRequestProposal struct { EpochRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=epoch_ratio,json=epochRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_ratio" yaml:"epoch_ratio"` } -func (m *UpdateRequestProposal) Reset() { *m = UpdateRequestProposal{} } -func (*UpdateRequestProposal) ProtoMessage() {} +func (m *UpdateRequestProposal) Reset() { *m = UpdateRequestProposal{} } +func (m *UpdateRequestProposal) String() string { return proto.CompactTextString(m) } +func (*UpdateRequestProposal) ProtoMessage() {} func (*UpdateRequestProposal) Descriptor() ([]byte, []int) { return fileDescriptor_4719b03c30c7910a, []int{2} } @@ -184,6 +228,55 @@ func (m *UpdateRequestProposal) XXX_DiscardUnknown() { var xxx_messageInfo_UpdateRequestProposal proto.InternalMessageInfo +func (m *UpdateRequestProposal) GetPlanId() uint64 { + if m != nil { + return m.PlanId + } + return 0 +} + +func (m *UpdateRequestProposal) GetFarmingPoolAddress() string { + if m != nil { + return m.FarmingPoolAddress + } + return "" +} + +func (m *UpdateRequestProposal) GetTerminationAddress() string { + if m != nil { + return m.TerminationAddress + } + return "" +} + +func (m *UpdateRequestProposal) GetStakingCoinWeights() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.StakingCoinWeights + } + return nil +} + +func (m *UpdateRequestProposal) GetStartTime() time.Time { + if m != nil { + return m.StartTime + } + return time.Time{} +} + +func (m *UpdateRequestProposal) GetEndTime() time.Time { + if m != nil { + return m.EndTime + } + return time.Time{} +} + +func (m *UpdateRequestProposal) GetEpochAmount() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.EpochAmount + } + return nil +} + // DeleteRequestProposal details a proposal for deleting an existing public plan. type DeleteRequestProposal struct { // plan_id specifies index of the farming plan @@ -242,56 +335,55 @@ func init() { } var fileDescriptor_4719b03c30c7910a = []byte{ - // 778 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcf, 0x4f, 0xe3, 0x46, - 0x14, 0x8e, 0xc9, 0x2f, 0x98, 0x54, 0xaa, 0x3a, 0x04, 0x6a, 0x02, 0xb5, 0x23, 0xb7, 0xaa, 0x52, - 0x55, 0xd8, 0x85, 0xde, 0xb8, 0x91, 0x22, 0xa1, 0x9e, 0x9a, 0x5a, 0xad, 0x5a, 0xed, 0xc5, 0x9a, - 0x64, 0x86, 0x60, 0x61, 0x7b, 0xbc, 0x9e, 0xc9, 0xee, 0x72, 0x67, 0xa5, 0x3d, 0xb2, 0x37, 0x8e, - 0x68, 0x8f, 0xfb, 0x97, 0x70, 0xe4, 0xb8, 0xda, 0x83, 0x59, 0xc1, 0x7f, 0x90, 0xbf, 0x60, 0xe5, - 0x99, 0x71, 0x88, 0xc0, 0x01, 0x0e, 0x20, 0x71, 0xf2, 0xbc, 0x99, 0xf7, 0x7d, 0xef, 0x9b, 0x37, - 0xef, 0x53, 0x02, 0x7e, 0xe1, 0x24, 0xc2, 0x24, 0x09, 0xfd, 0x88, 0x3b, 0x7b, 0x28, 0xfb, 0x0e, - 0x9d, 0x57, 0x1b, 0x7d, 0xc2, 0xd1, 0x86, 0x13, 0x27, 0x34, 0xa6, 0x0c, 0x05, 0x76, 0x9c, 0x50, - 0x4e, 0x61, 0xeb, 0x3a, 0xd5, 0x56, 0xa9, 0xb6, 0x4a, 0x6d, 0x35, 0x87, 0x74, 0x48, 0x45, 0x9a, - 0x93, 0xad, 0x24, 0xa2, 0xb5, 0x32, 0xa0, 0x2c, 0xa4, 0xcc, 0x93, 0x07, 0x32, 0x50, 0x47, 0x86, - 0x8c, 0x9c, 0x3e, 0x62, 0x64, 0x52, 0x70, 0x40, 0xfd, 0x48, 0x9d, 0x77, 0xee, 0xd0, 0x95, 0x17, - 0x97, 0x99, 0xe6, 0x90, 0xd2, 0x61, 0x40, 0x1c, 0x11, 0xf5, 0x47, 0x7b, 0x0e, 0xf7, 0x43, 0xc2, - 0x38, 0x0a, 0x63, 0x99, 0x60, 0x9d, 0x54, 0x00, 0xec, 0x8d, 0xfa, 0x81, 0x3f, 0xe8, 0x05, 0x28, - 0xea, 0xa9, 0x4b, 0xc1, 0x26, 0xa8, 0x72, 0x9f, 0x07, 0x44, 0xd7, 0xda, 0x5a, 0x67, 0xc1, 0x95, - 0x01, 0x6c, 0x83, 0x06, 0x26, 0x6c, 0x90, 0xf8, 0x31, 0xf7, 0x69, 0xa4, 0xcf, 0x89, 0xb3, 0xe9, - 0x2d, 0x08, 0x41, 0x25, 0x42, 0x21, 0xd1, 0xcb, 0xe2, 0x48, 0xac, 0xe1, 0x91, 0x06, 0x96, 0x10, - 0xc6, 0x5e, 0x42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 0xb2, 0x79, 0x0d, - 0x01, 0xdd, 0x16, 0x48, 0x48, 0x80, 0x0c, 0xbd, 0x24, 0x7b, 0x71, 0xbd, 0x2e, 0x66, 0x64, 0x27, - 0x2b, 0xf5, 0x39, 0x35, 0x7f, 0x7e, 0xd8, 0x9b, 0x8c, 0x53, 0x13, 0x4e, 0x8b, 0x12, 0x54, 0x96, - 0x0b, 0x44, 0xe4, 0x66, 0xc1, 0x94, 0x0d, 0x4e, 0x6b, 0x60, 0xa9, 0xd0, 0xfb, 0xf0, 0x7b, 0x50, - 0x8f, 0x03, 0x14, 0x79, 0x3e, 0x16, 0xc3, 0x5f, 0x71, 0x6b, 0x59, 0xf8, 0x27, 0x9e, 0x69, 0x91, - 0xb9, 0x47, 0xb7, 0x48, 0xf9, 0xf1, 0x2d, 0x52, 0x79, 0xb6, 0x16, 0xa9, 0x3e, 0x91, 0x45, 0x6a, - 0x4f, 0x65, 0x91, 0xfa, 0xb3, 0xb0, 0xc8, 0xfc, 0x93, 0x5b, 0xe4, 0x37, 0xb0, 0x54, 0xf8, 0x4b, - 0x34, 0xd3, 0x21, 0xdd, 0xdd, 0xb3, 0x4b, 0x43, 0x3b, 0xbf, 0x34, 0xb4, 0x2f, 0x97, 0x86, 0x76, - 0x7c, 0x65, 0x94, 0xce, 0xaf, 0x8c, 0xd2, 0xa7, 0x2b, 0xa3, 0xf4, 0x62, 0x7d, 0x4a, 0x5f, 0xc1, - 0xdf, 0x9c, 0x37, 0x93, 0x95, 0x90, 0xda, 0xaf, 0x89, 0xd7, 0xfa, 0xfd, 0x6b, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x3b, 0x4d, 0x19, 0xe0, 0xab, 0x09, 0x00, 0x00, + // 766 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcf, 0x4f, 0xdb, 0x48, + 0x14, 0x8e, 0xc9, 0x2f, 0x98, 0xac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3, 0x07, + 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x69, 0xcf, 0x69, 0x1c, 0x96, 0x09, 0x00, 0x00, } func (m *PublicPlanProposal) Marshal() (dAtA []byte, err error) { From 1cd663cd5d388e0b2fa33eb0956d030c61a30e16 Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 26 Jul 2021 11:39:30 +0900 Subject: [PATCH 09/39] update cli commands for private plans --- x/farming/client/cli/tx.go | 7 ++-- x/farming/client/cli/utils_test.go | 63 +++++++++++++----------------- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index 4955ed03..8be7348b 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -80,7 +80,7 @@ Where plan.json contains: plan, err := ParsePrivateFixedPlanProposal(args[0]) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse json file: %w", err) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file: %w", args[0], err) } msg := types.NewMsgCreateFixedAmountPlan( @@ -107,7 +107,7 @@ Where plan.json contains: func NewCreateRatioPlanCmd() *cobra.Command { cmd := &cobra.Command{ Use: "create-private-ratio-plan [plan-file]", - Args: cobra.ExactArgs(0), + Args: cobra.ExactArgs(1), Short: "create private ratio farming plan", Long: strings.TrimSpace( fmt.Sprintf(`Create private ratio farming plan. @@ -146,7 +146,7 @@ Where plan.json contains: plan, err := ParsePrivateRatioPlanProposal(args[0]) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse json file: %w", err) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file: %w", args[0], err) } msg := types.NewMsgCreateRatioPlan( @@ -270,7 +270,6 @@ $ %s tx %s harvest --from mykey return cmd } -// TODO: not implemented yet // GetCmdSubmitPublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. func GetCmdSubmitPublicPlanProposal() *cobra.Command { cmd := &cobra.Command{ diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go index cd81036b..70fb4662 100644 --- a/x/farming/client/cli/utils_test.go +++ b/x/farming/client/cli/utils_test.go @@ -1,6 +1,7 @@ package cli_test import ( + "encoding/json" "io/ioutil" "testing" @@ -9,6 +10,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" farmingapp "github.com/tendermint/farming/app" + "github.com/tendermint/farming/x/farming/client/cli" "github.com/tendermint/farming/x/farming/keeper" "github.com/tendermint/farming/x/farming/types" ) @@ -44,41 +46,30 @@ func TestParseJSONFile(t *testing.T) { require.NoError(t, err) } -// func TestMarshalPublic(t *testing.T) { -// app, _ := createTestInput() - -// farmingPoolAddr := sdk.AccAddress([]byte("farmingPoolAddr")) -// terminationAddr := sdk.AccAddress([]byte("terminationAddr")) -// coinWeights := sdk.NewDecCoins(sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}) -// startTime := time.Now().UTC() -// endTime := startTime.AddDate(1, 0, 0) -// name := "" - -// proposal := types.AddPublicPlanProposal{} -// proposal.Title = "Public Plan Test" -// proposal.Description = "TEST..." - -// basePlan := types.NewBasePlan( -// 1, -// name, -// types.PlanTypePublic, -// farmingPoolAddr.String(), -// terminationAddr.String(), -// coinWeights, -// startTime, -// endTime, -// ) -// epochRatio := sdk.NewDec(1.0) - -// ratioPlan := types.NewRatioPlan(basePlan, epochRatio) - -// plans, err := types.PackPlans([]types.PlanI{ratioPlan}) -// require.NoError(t, err) - -// proposal.Plans = plans +func TestParsePrivateFixedPlan(t *testing.T) { + fixedPlanStr := `{ + "staking_coin_weights": [ + { + "denom": "poolCoinDenom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] +} +` + plan := cli.PrivateFixedPlanRequest{} -// bz, err := app.AppCodec().MarshalJSON(&proposal) -// require.NoError(t, err) + contents := []byte(fixedPlanStr) + err := json.Unmarshal(contents, &plan) + require.NoError(t, err) -// fmt.Println("bz: ", string(bz)) -// } + require.Equal(t, "1.000000000000000000poolCoinDenom", plan.StakingCoinWeights.String()) + require.Equal(t, "1uatom", plan.EpochAmount.String()) +} From a5bb036fe2b868cfdf75c515af16029433d02182 Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 26 Jul 2021 13:03:20 +0900 Subject: [PATCH 10/39] add tests for private farming plan command line interfaces --- x/farming/client/cli/tx.go | 22 +++--- x/farming/client/cli/utils.go | 8 +-- x/farming/client/cli/utils_test.go | 106 +++++++++++++++++++++-------- 3 files changed, 92 insertions(+), 44 deletions(-) diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index 8be7348b..179431d4 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -12,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" gov "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/spf13/cobra" "github.com/tendermint/farming/x/farming/types" ) @@ -78,9 +79,9 @@ Where plan.json contains: return err } - plan, err := ParsePrivateFixedPlanProposal(args[0]) + plan, err := ParsePrivateFixedPlan(args[0]) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file: %w", args[0], err) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file: %v", args[0], err) } msg := types.NewMsgCreateFixedAmountPlan( @@ -125,14 +126,9 @@ Where plan.json contains: "amount": "1.000000000000000000" } ], - "start_time": "2021-07-24T08:41:21.662422Z", - "end_time": "2022-07-28T08:41:21.662422Z", - "epoch_amount": [ - { - "denom": "uatom", - "amount": "1" - } - ] + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_ratio":"1.000000000000000000" } `, version.AppName, types.ModuleName, @@ -144,9 +140,9 @@ Where plan.json contains: return err } - plan, err := ParsePrivateRatioPlanProposal(args[0]) + plan, err := ParsePrivateRatioPlan(args[0]) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file: %w", args[0], err) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file: %v", args[0], err) } msg := types.NewMsgCreateRatioPlan( diff --git a/x/farming/client/cli/utils.go b/x/farming/client/cli/utils.go index f10813d3..5f3f09f1 100644 --- a/x/farming/client/cli/utils.go +++ b/x/farming/client/cli/utils.go @@ -27,8 +27,8 @@ type PrivateRatioPlanRequest struct { EpochRatio sdk.Dec `json:"epoch_ratio"` } -// ParsePrivateFixedPlanProposal reads and parses a PrivateFixedPlanRequest from a file. -func ParsePrivateFixedPlanProposal(file string) (PrivateFixedPlanRequest, error) { +// ParsePrivateFixedPlan reads and parses a PrivateFixedPlanRequest from a file. +func ParsePrivateFixedPlan(file string) (PrivateFixedPlanRequest, error) { plan := PrivateFixedPlanRequest{} contents, err := ioutil.ReadFile(file) @@ -43,8 +43,8 @@ func ParsePrivateFixedPlanProposal(file string) (PrivateFixedPlanRequest, error) return plan, nil } -// ParsePrivateRatioPlanProposal reads and parses a PrivateRatioPlanRequest from a file. -func ParsePrivateRatioPlanProposal(file string) (PrivateRatioPlanRequest, error) { +// ParsePrivateRatioPlan reads and parses a PrivateRatioPlanRequest from a file. +func ParsePrivateRatioPlan(file string) (PrivateRatioPlanRequest, error) { plan := PrivateRatioPlanRequest{} contents, err := ioutil.ReadFile(file) diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go index 70fb4662..aca35d84 100644 --- a/x/farming/client/cli/utils_test.go +++ b/x/farming/client/cli/utils_test.go @@ -1,22 +1,24 @@ package cli_test import ( - "encoding/json" - "io/ioutil" "testing" + "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - farmingapp "github.com/tendermint/farming/app" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + + simapp "github.com/tendermint/farming/app" + "github.com/tendermint/farming/app/params" "github.com/tendermint/farming/x/farming/client/cli" "github.com/tendermint/farming/x/farming/keeper" "github.com/tendermint/farming/x/farming/types" ) -func createTestInput() (*farmingapp.FarmingApp, sdk.Context) { - app := farmingapp.Setup(false) +func createTestInput() (*simapp.FarmingApp, sdk.Context) { + app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.FarmingKeeper = keeper.NewKeeper( @@ -32,25 +34,12 @@ func createTestInput() (*farmingapp.FarmingApp, sdk.Context) { return app, ctx } -func TestParseJSONFile(t *testing.T) { - app, _ := createTestInput() - - proposalFile := "./proposal.json" - - proposal := types.PublicPlanProposal{} - - contents, err := ioutil.ReadFile(proposalFile) - require.NoError(t, err) - - err = app.AppCodec().UnmarshalJSON(contents, &proposal) - require.NoError(t, err) -} - func TestParsePrivateFixedPlan(t *testing.T) { - fixedPlanStr := `{ + okJSON := testutil.WriteToNewTempFile(t, ` +{ "staking_coin_weights": [ { - "denom": "poolCoinDenom", + "denom": "PoolCoinDenom", "amount": "1.000000000000000000" } ], @@ -63,13 +52,76 @@ func TestParsePrivateFixedPlan(t *testing.T) { } ] } -` - plan := cli.PrivateFixedPlanRequest{} +`) - contents := []byte(fixedPlanStr) - err := json.Unmarshal(contents, &plan) + plan, err := cli.ParsePrivateFixedPlan(okJSON.Name()) require.NoError(t, err) - require.Equal(t, "1.000000000000000000poolCoinDenom", plan.StakingCoinWeights.String()) + require.Equal(t, "1.000000000000000000PoolCoinDenom", plan.StakingCoinWeights.String()) + require.Equal(t, "2021-07-15T08:41:21.662422Z", plan.StartTime.Format(time.RFC3339Nano)) + require.Equal(t, "2022-07-16T08:41:21.662422Z", plan.EndTime.Format(time.RFC3339Nano)) require.Equal(t, "1uatom", plan.EpochAmount.String()) } + +func TestParsePrivateRatioPlan(t *testing.T) { + okJSON := testutil.WriteToNewTempFile(t, ` +{ + "staking_coin_weights": [ + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_ratio":"1.000000000000000000" +} +`) + + plan, err := cli.ParsePrivateRatioPlan(okJSON.Name()) + require.NoError(t, err) + + require.Equal(t, "1.000000000000000000PoolCoinDenom", plan.StakingCoinWeights.String()) + require.Equal(t, "2021-07-15T08:41:21.662422Z", plan.StartTime.Format(time.RFC3339Nano)) + require.Equal(t, "2022-07-16T08:41:21.662422Z", plan.EndTime.Format(time.RFC3339Nano)) + require.Equal(t, "1.000000000000000000", plan.EpochRatio.String()) +} + +func TestParsePublicPlanProposal(t *testing.T) { + encodingConfig := params.MakeTestEncodingConfig() + + okJSON := testutil.WriteToNewTempFile(t, ` +{ + "title": "Public Farming Plan", + "description": "Are you ready to farm?", + "name": "First Public Farming Plan", + "add_request_proposals": [ + { + "farming_pool_address": "cosmos1mzgucqnfr2l8cj5apvdpllhzt4zeuh2cshz5xu", + "termination_address": "cosmos1mzgucqnfr2l8cj5apvdpllhzt4zeuh2cshz5xu", + "staking_coin_weights": [ + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] + } + ] +} +`) + + proposal, err := cli.ParsePublicPlanProposal(encodingConfig.Marshaler, okJSON.Name()) + require.NoError(t, err) + + require.Equal(t, "Public Farming Plan", proposal.Title) + require.Equal(t, "Are you ready to farm?", proposal.Description) + require.Equal(t, "First Public Farming Plan", proposal.Name) +} From ed0520fbda40fe2af2a86b54b252fb1ba640989f Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 26 Jul 2021 22:49:53 +0900 Subject: [PATCH 11/39] add public plan proposal --- x/farming/client/cli/tx.go | 41 ++++++-- x/farming/client/cli/utils_test.go | 22 ----- x/farming/keeper/plan.go | 8 +- x/farming/keeper/proposal_handler.go | 134 ++++++++++++++++++++++++++- x/farming/types/proposal.go | 4 +- 5 files changed, 173 insertions(+), 36 deletions(-) diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index 179431d4..68be5af9 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -266,19 +266,47 @@ $ %s tx %s harvest --from mykey return cmd } -// GetCmdSubmitPublicPlanProposal implements a command handler for submitting a public farming plan creation transaction. +// GetCmdSubmitPublicPlanProposal implements a command handler for submitting a public farming plan +// to create, update, delete transaction. func GetCmdSubmitPublicPlanProposal() *cobra.Command { cmd := &cobra.Command{ - Use: "add-public-farming-plan [proposal-file] [flags]", + Use: "public-farming-plan [proposal-file] [flags]", Args: cobra.ExactArgs(1), - Short: "Submit a public farming plan creation", + Short: "Submit a public farming plan", Long: strings.TrimSpace( - fmt.Sprintf(`Submit a a public farming plan creation along with an initial deposit. + fmt.Sprintf(`Submit a a public farming plan along with an initial deposit. The proposal details must be supplied via a JSON file. Example: $ %s tx gov submit-proposal public-farming-plan --from= --deposit= +Where proposal.json contains: + +{ + "title": "Public Farming Plan", + "description": "Are you ready to farm?", + "name": "Cosmos Hub Community Tax", + "add_request_proposals": [ + { + "farming_pool_address": "cosmos1mzgucqnfr2l8cj5apvdpllhzt4zeuh2cshz5xu", + "termination_address": "cosmos1mzgucqnfr2l8cj5apvdpllhzt4zeuh2cshz5xu", + "staking_coin_weights": [ + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] + } + ] +} `, version.AppName, ), @@ -304,9 +332,8 @@ $ %s tx gov submit-proposal public-farming-plan --from=< return err } - name := "" - - content, err := types.NewPublicPlanProposal(proposal.Title, proposal.Description, name, []*types.AddRequestProposal{}, []*types.UpdateRequestProposal{}, []*types.DeleteRequestProposal{}) + content, err := types.NewPublicPlanProposal(proposal.Title, proposal.Description, proposal.Name, + proposal.AddRequestProposals, proposal.UpdateRequestProposals, proposal.DeleteRequestProposals) if err != nil { return err } diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go index aca35d84..62c40421 100644 --- a/x/farming/client/cli/utils_test.go +++ b/x/farming/client/cli/utils_test.go @@ -5,35 +5,13 @@ import ( "time" "github.com/stretchr/testify/require" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" - simapp "github.com/tendermint/farming/app" "github.com/tendermint/farming/app/params" "github.com/tendermint/farming/x/farming/client/cli" - "github.com/tendermint/farming/x/farming/keeper" - "github.com/tendermint/farming/x/farming/types" ) -func createTestInput() (*simapp.FarmingApp, sdk.Context) { - app := simapp.Setup(false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - app.FarmingKeeper = keeper.NewKeeper( - app.AppCodec(), - app.GetKey(types.StoreKey), - app.GetSubspace(types.ModuleName), - app.AccountKeeper, - app.BankKeeper, - app.DistrKeeper, - map[string]bool{}, - ) - - return app, ctx -} - func TestParsePrivateFixedPlan(t *testing.T) { okJSON := testutil.WriteToNewTempFile(t, ` { diff --git a/x/farming/keeper/plan.go b/x/farming/keeper/plan.go index 86e6aa09..3eb3c1e8 100644 --- a/x/farming/keeper/plan.go +++ b/x/farming/keeper/plan.go @@ -176,9 +176,9 @@ func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixed params := k.GetParams(ctx) balances := k.bankKeeper.GetAllBalances(ctx, farmingPoolAddrAcc) - _, hasNeg := balances.SafeSub(params.PrivatePlanCreationFee) + diffs, hasNeg := balances.SafeSub(params.PrivatePlanCreationFee) if hasNeg { - return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient balance to pay private plan creation fee") + return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s requires %s more coins to pay private plan createion fee", msg.FarmingPoolAddress, diffs.String()) } farmingFeeCollectorAcc, err := sdk.AccAddressFromBech32(params.FarmingFeeCollector) @@ -231,9 +231,9 @@ func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, params := k.GetParams(ctx) balances := k.bankKeeper.GetAllBalances(ctx, farmingPoolAddrAcc) - _, hasNeg := balances.SafeSub(params.PrivatePlanCreationFee) + diffs, hasNeg := balances.SafeSub(params.PrivatePlanCreationFee) if hasNeg { - return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient balance to pay private plan creation fee") + return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s requires %s more coins to pay private plan createion fee", msg.FarmingPoolAddress, diffs.String()) } farmingFeeCollectorAcc, err := sdk.AccAddressFromBech32(params.FarmingFeeCollector) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index e1836121..a0437def 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -2,12 +2,142 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/farming/x/farming/types" ) // HandlePublicPlanProposal is a handler for executing a public plan creation proposal. -func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, publicPlanProposal *types.PublicPlanProposal) error { - // TODO: not implemented yet +func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicPlanProposal) error { + if err := proposal.ValidateBasic(); err != nil { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) + } + + switch { + case proposal.AddRequestProposals != nil: + if err := k.AddPublicPlanProposal(ctx, proposal.Name, proposal.AddRequestProposals); err != nil { + return err + } + case proposal.UpdateRequestProposals != nil: + if err := k.UpdatePublicPlanProposal(ctx, proposal.UpdateRequestProposals); err != nil { + return err + } + case proposal.DeleteRequestProposals != nil: + if err := k.DeletePublicPlanProposal(ctx, proposal.DeleteRequestProposals); err != nil { + return err + } + default: + sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unexpected public plan proposal %s", proposal.String()) + } + + return nil +} + +// AddPublicPlanProposal adds a new public plan once the governance proposal is passed. +func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals []*types.AddRequestProposal) error { + for _, p := range proposals { + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) + if err != nil { + return err + } + + if !p.EpochAmount.IsZero() && !p.EpochAmount.IsAnyNegative() { + msg := types.NewMsgCreateFixedAmountPlan( + farmingPoolAddrAcc, + p.GetStakingCoinWeights(), + p.GetStartTime(), + p.GetEndTime(), + p.EpochAmount, + ) + + plan, err := k.CreateFixedAmountPlan(ctx, msg, name, types.PlanTypePublic) + if err != nil { + return err + } + + logger := k.Logger(ctx) + logger.Info("created public fixed amount plan", "fixed_amount_plan", plan) + } + + if !p.EpochRatio.IsZero() || !p.EpochRatio.IsNegative() { + msg := types.NewMsgCreateRatioPlan( + farmingPoolAddrAcc, + p.GetStakingCoinWeights(), + p.GetStartTime(), + p.GetEndTime(), + p.EpochRatio, + ) + + plan, err := k.CreateRatioPlan(ctx, msg, name, types.PlanTypePublic) + if err != nil { + return err + } + + logger := k.Logger(ctx) + logger.Info("created public ratio amount plan", "ratio_plan", plan) + } + } + + return nil +} + +// UpdatePublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed. +func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.UpdateRequestProposal) error { + for _, proposal := range proposals { + plan, found := k.GetPlan(ctx, proposal.GetPlanId()) + if !found { + return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", proposal.GetPlanId()) + } + + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetFarmingPoolAddress()) + if err != nil { + return err + } + + terminationAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetTerminationAddress()) + if err != nil { + return err + } + + switch p := plan.(type) { + case *types.FixedAmountPlan: + p.SetFarmingPoolAddress(farmingPoolAddrAcc) + p.SetTerminationAddress(terminationAddrAcc) + p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()) + p.SetStartTime(proposal.GetStartTime()) + p.SetEndTime(proposal.GetStartTime()) + p.EpochAmount = proposal.GetEpochAmount() + + k.SetPlan(ctx, p) + + case *types.RatioPlan: + p.SetFarmingPoolAddress(farmingPoolAddrAcc) + p.SetTerminationAddress(terminationAddrAcc) + p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()) + p.SetStartTime(proposal.GetStartTime()) + p.SetEndTime(proposal.GetStartTime()) + p.EpochRatio = proposal.EpochRatio + + k.SetPlan(ctx, p) + + default: + return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized plan type: %T", p) + } + } + + return nil +} + +// DeletePublicPlanProposal delets public plan proposal once the governance proposal is passed. +func (k Keeper) DeletePublicPlanProposal(ctx sdk.Context, proposals []*types.DeleteRequestProposal) error { + for _, p := range proposals { + plan, found := k.GetPlan(ctx, p.GetPlanId()) + if !found { + return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", p.GetPlanId()) + } + + k.RemovePlan(ctx, plan) + } + return nil } diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 8aa6055f..69e6eefe 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -39,7 +39,9 @@ func (p *PublicPlanProposal) ProposalRoute() string { return RouterKey } func (p *PublicPlanProposal) ProposalType() string { return ProposalTypePublicPlan } func (p *PublicPlanProposal) ValidateBasic() error { - // TODO: not implemented yet + // if p.AddRequestProposals == nil && p.UpdateRequestProposals == nil && p.DeleteRequestProposals == nil { + // return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proposal must not be empty") + // } return gov.ValidateAbstract(p) } From 2edf4f79551ba7e077d743db643fb096b5d3b22f Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 26 Jul 2021 22:57:05 +0900 Subject: [PATCH 12/39] add nolint:errcheck for now --- x/farming/keeper/proposal_handler.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index a0437def..885e7466 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -101,22 +101,22 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd switch p := plan.(type) { case *types.FixedAmountPlan: - p.SetFarmingPoolAddress(farmingPoolAddrAcc) - p.SetTerminationAddress(terminationAddrAcc) - p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()) - p.SetStartTime(proposal.GetStartTime()) - p.SetEndTime(proposal.GetStartTime()) - p.EpochAmount = proposal.GetEpochAmount() + p.SetFarmingPoolAddress(farmingPoolAddrAcc) // nolint:errcheck + p.SetTerminationAddress(terminationAddrAcc) // nolint:errcheck + p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()) // nolint:errcheck + p.SetStartTime(proposal.GetStartTime()) // nolint:errcheck + p.SetEndTime(proposal.GetStartTime()) // nolint:errcheck + p.EpochAmount = proposal.GetEpochAmount() // nolint:errcheck k.SetPlan(ctx, p) case *types.RatioPlan: - p.SetFarmingPoolAddress(farmingPoolAddrAcc) - p.SetTerminationAddress(terminationAddrAcc) - p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()) - p.SetStartTime(proposal.GetStartTime()) - p.SetEndTime(proposal.GetStartTime()) - p.EpochRatio = proposal.EpochRatio + p.SetFarmingPoolAddress(farmingPoolAddrAcc) // nolint:errcheck + p.SetTerminationAddress(terminationAddrAcc) // nolint:errcheck + p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()) // nolint:errcheck + p.SetStartTime(proposal.GetStartTime()) // nolint:errcheck + p.SetEndTime(proposal.GetStartTime()) // nolint:errcheck + p.EpochRatio = proposal.EpochRatio // nolint:errcheck k.SetPlan(ctx, p) From 6dbf2bb8fa17c4133cb5cb07fb35eecf3ac27c9c Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 26 Jul 2021 23:07:56 +0900 Subject: [PATCH 13/39] fix golint by adding return value for sdkerrors.Wrapf --- x/farming/keeper/proposal_handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 885e7466..a030a81b 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -27,7 +27,7 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP return err } default: - sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unexpected public plan proposal %s", proposal.String()) + return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unexpected public plan proposal %s", proposal.String()) } return nil From 2eafaddefa52b0b26facba7c8c5a902f7a687a52 Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 27 Jul 2021 11:49:10 +0900 Subject: [PATCH 14/39] add name filed in both create fixed amount plan and ratio plan messages --- .../tendermint/farming/v1beta1/proposal.proto | 7 +- proto/tendermint/farming/v1beta1/tx.proto | 26 +- x/farming/types/tx.pb.go | 245 ++++++++++++------ 3 files changed, 187 insertions(+), 91 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index 1a4922da..c63a4f12 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -25,8 +25,7 @@ message PublicPlanProposal { string name = 3; // add_request_proposals specifies AddRequestProposal object - repeated AddRequestProposal add_request_proposals = 4 - [(gogoproto.moretags) = "yaml:\"add_request_proposals\""]; + repeated AddRequestProposal add_request_proposals = 4 [(gogoproto.moretags) = "yaml:\"add_request_proposals\""]; // update_request_proposals specifies UpdateRequestProposal object repeated UpdateRequestProposal update_request_proposals = 5 @@ -69,7 +68,7 @@ message AddRequestProposal { (gogoproto.nullable) = false ]; - // epoch_ratio specifies the distributing amount by ratio + // epoch_ratio specifies the distributing amount by ratio string epoch_ratio = 7 [ (gogoproto.moretags) = "yaml:\"epoch_ratio\"", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", @@ -112,7 +111,7 @@ message UpdateRequestProposal { (gogoproto.nullable) = false ]; - // epoch_ratio specifies the distributing amount by ratio + // epoch_ratio specifies the distributing amount by ratio string epoch_ratio = 8 [ (gogoproto.moretags) = "yaml:\"epoch_ratio\"", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", diff --git a/proto/tendermint/farming/v1beta1/tx.proto b/proto/tendermint/farming/v1beta1/tx.proto index ea5081e8..c7566ef1 100644 --- a/proto/tendermint/farming/v1beta1/tx.proto +++ b/proto/tendermint/farming/v1beta1/tx.proto @@ -33,26 +33,29 @@ service Msg { message MsgCreateFixedAmountPlan { option (gogoproto.goproto_getters) = false; + // name specifies the name for the plan + string name = 1; + // farming_pool_address defines the bech32-encoded address of the farming pool - string farming_pool_address = 1 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; + string farming_pool_address = 2 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; // staking_coin_weights specifies coins weight for the plan - repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 2 [ + repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 3 [ (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; // start_time specifies the start time of the plan - google.protobuf.Timestamp start_time = 3 + google.protobuf.Timestamp start_time = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; // end_time specifies the end time of the plan - google.protobuf.Timestamp end_time = 4 + google.protobuf.Timestamp end_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; // epoch_amount specifies the distributing amount for each epoch - repeated cosmos.base.v1beta1.Coin epoch_amount = 5 [ + repeated cosmos.base.v1beta1.Coin epoch_amount = 6 [ (gogoproto.moretags) = "yaml:\"epoch_amount\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false @@ -68,26 +71,29 @@ message MsgCreateFixedAmountPlanResponse {} message MsgCreateRatioPlan { option (gogoproto.goproto_getters) = false; + // name specifies the name for the plan + string name = 1; + // farming_pool_address defines the bech32-encoded address of the farming pool - string farming_pool_address = 1 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; + string farming_pool_address = 2 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; // staking_coin_weights specifies coins weight for the plan - repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 2 [ + repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 3 [ (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; // start_time specifies the start time of the plan - google.protobuf.Timestamp start_time = 3 + google.protobuf.Timestamp start_time = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; // end_time specifies the end time of the plan - google.protobuf.Timestamp end_time = 4 + google.protobuf.Timestamp end_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; // epoch_ratio specifies the distributing amount by ratio - string epoch_ratio = 5 [ + string epoch_ratio = 6 [ (gogoproto.moretags) = "yaml:\"epoch_ratio\"", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false diff --git a/x/farming/types/tx.pb.go b/x/farming/types/tx.pb.go index a7dd6699..81fe7c37 100644 --- a/x/farming/types/tx.pb.go +++ b/x/farming/types/tx.pb.go @@ -38,16 +38,18 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgCreateFixedAmountPlan defines a SDK message for creating a new fixed // amount farming plan. type MsgCreateFixedAmountPlan struct { + // name specifies the name for the plan + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // farming_pool_address defines the bech32-encoded address of the farming pool - FarmingPoolAddress string `protobuf:"bytes,1,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` + FarmingPoolAddress string `protobuf:"bytes,2,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` // staking_coin_weights specifies coins weight for the plan - StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` + StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` // start_time specifies the start time of the plan - StartTime time.Time `protobuf:"bytes,3,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + StartTime time.Time `protobuf:"bytes,4,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` // end_time specifies the end time of the plan - EndTime time.Time `protobuf:"bytes,4,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` + EndTime time.Time `protobuf:"bytes,5,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` // epoch_amount specifies the distributing amount for each epoch - EpochAmount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,5,rep,name=epoch_amount,json=epochAmount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"epoch_amount" yaml:"epoch_amount"` + EpochAmount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=epoch_amount,json=epochAmount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"epoch_amount" yaml:"epoch_amount"` } func (m *MsgCreateFixedAmountPlan) Reset() { *m = MsgCreateFixedAmountPlan{} } @@ -124,16 +126,18 @@ var xxx_messageInfo_MsgCreateFixedAmountPlanResponse proto.InternalMessageInfo // MsgCreateRatioPlan defines a SDK message for creating a new ratio farming // plan. type MsgCreateRatioPlan struct { + // name specifies the name for the plan + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // farming_pool_address defines the bech32-encoded address of the farming pool - FarmingPoolAddress string `protobuf:"bytes,1,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` + FarmingPoolAddress string `protobuf:"bytes,2,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` // staking_coin_weights specifies coins weight for the plan - StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` + StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` // start_time specifies the start time of the plan - StartTime time.Time `protobuf:"bytes,3,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + StartTime time.Time `protobuf:"bytes,4,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` // end_time specifies the end time of the plan - EndTime time.Time `protobuf:"bytes,4,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` + EndTime time.Time `protobuf:"bytes,5,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` // epoch_ratio specifies the distributing amount by ratio - EpochRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=epoch_ratio,json=epochRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_ratio" yaml:"epoch_ratio"` + EpochRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=epoch_ratio,json=epochRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_ratio" yaml:"epoch_ratio"` } func (m *MsgCreateRatioPlan) Reset() { *m = MsgCreateRatioPlan{} } @@ -461,57 +465,58 @@ func init() { } var fileDescriptor_a33d9a3ff13f514a = []byte{ - // 794 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0x4f, 0x4f, 0xd4, 0x4e, - 0x18, 0xde, 0xfe, 0x58, 0xfe, 0x0d, 0xfc, 0x44, 0xca, 0x4a, 0x96, 0x82, 0xed, 0xa6, 0x26, 0x66, - 0x83, 0xa1, 0x95, 0xf5, 0x62, 0xb8, 0xb1, 0x10, 0x21, 0x26, 0x6b, 0xb0, 0x68, 0xfc, 0x73, 0xd9, - 0xcc, 0x6e, 0x87, 0xd2, 0xb0, 0xed, 0xac, 0x9d, 0x59, 0x04, 0xaf, 0xc6, 0x04, 0x2f, 0x86, 0x8f, - 0x60, 0xbc, 0x98, 0x78, 0xf5, 0x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, 0xf4, 0xd2, 0x92, 0x1e, 0x81, 0x89, 0x33, 0x83, - 0x65, 0x23, 0x1f, 0x7b, 0xbc, 0xaa, 0xe1, 0xb2, 0x7a, 0xda, 0xd6, 0x94, 0x94, 0xe9, 0xe3, 0x20, - 0xdd, 0x1a, 0x4f, 0x24, 0xb3, 0xcc, 0xf6, 0xce, 0x64, 0x24, 0xce, 0x8e, 0x32, 0x2a, 0xbd, 0xcf, - 0x82, 0xbe, 0x0a, 0x71, 0xe4, 0xb7, 0x12, 0xb8, 0x91, 0xfe, 0xc5, 0xbb, 0x6b, 0xa4, 0x7f, 0x99, - 0x8d, 0xcb, 0xee, 0x34, 0xe5, 0x7e, 0xaf, 0x11, 0x51, 0x36, 0xf2, 0x2b, 0x30, 0x76, 0xfe, 0x06, - 0x9c, 0xed, 0x4a, 0x16, 0x63, 0x95, 0xd2, 0xd5, 0xb1, 0xf1, 0x91, 0xeb, 0xa0, 0x9f, 0x0f, 0x4b, - 0xa1, 0x43, 0x30, 0x43, 0x28, 0xc5, 0x6e, 0x88, 0x98, 0xf4, 0x05, 0x18, 0x8c, 0x7c, 0xab, 0x77, - 0x08, 0x12, 0x18, 0x65, 0xb6, 0x3b, 0x26, 0x49, 0x1d, 0xf9, 0xa7, 0x13, 0xb5, 0xc0, 0x74, 0xa4, - 0x3e, 0xe7, 0x85, 0xf2, 0xca, 0xc1, 0xb1, 0x2a, 0x1d, 0x1e, 0xab, 0xd2, 0xaf, 0x63, 0x55, 0xda, - 0x3f, 0x51, 0x33, 0x87, 0x27, 0x6a, 0xe6, 0xc7, 0x89, 0x9a, 0x79, 0x39, 0x97, 0x98, 0x86, 0x94, - 0x3f, 0x73, 0x3b, 0xf1, 0x13, 0x1b, 0x8c, 0xda, 0x00, 0xbb, 0x49, 0xef, 0xfd, 0x0e, 0x00, 0x00, - 0xff, 0xff, 0x8c, 0xa3, 0x43, 0xb8, 0xf9, 0x09, 0x00, 0x00, + // 801 bytes of a gzipped FileDescriptorProto + 0x1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x2f, 0x22, + 0x7b, 0x4b, 0x77, 0x45, 0x5f, 0x13, 0x71, 0x5f, 0xa2, 0x56, 0x3b, 0x38, 0x56, 0x25, 0x73, 0x84, + 0xdd, 0x08, 0xe1, 0xd0, 0x04, 0xc3, 0xc8, 0xb7, 0x39, 0xef, 0x60, 0x4f, 0xde, 0x19, 0xc1, 0x3b, + 0xce, 0x79, 0xa3, 0x4a, 0xce, 0x3a, 0x84, 0x7c, 0x9b, 0x71, 0x7e, 0x92, 0xc0, 0x18, 0x6a, 0xe0, + 0xda, 0x56, 0xc5, 0x62, 0xc7, 0x99, 0xcb, 0x30, 0x2b, 0xa7, 0x3b, 0x5a, 0xc9, 0x7c, 0x5c, 0x15, + 0xbc, 0x93, 0x82, 0x37, 0x51, 0x1c, 0xfa, 0x57, 0xb8, 0x86, 0x7f, 0xdc, 0xbc, 0x51, 0x56, 0xca, + 0x53, 0xb4, 0x98, 0xde, 0xff, 0xaa, 0xa6, 0x34, 0x0d, 0xe4, 0xaf, 0xca, 0x98, 0x89, 0x48, 0x03, + 0xfb, 0x04, 0x69, 0x3f, 0xd3, 0x00, 0xc6, 0x20, 0xd3, 0xa2, 0x2e, 0xfe, 0x1f, 0xc1, 0x7f, 0x3a, + 0x82, 0x08, 0xf0, 0x24, 0x54, 0x82, 0xf0, 0x30, 0x73, 0x19, 0x76, 0x38, 0x2b, 0x61, 0xe9, 0xef, + 0x96, 0x7a, 0xff, 0x7a, 0x5e, 0x9c, 0xb6, 0x54, 0x98, 0xcc, 0x23, 0xa3, 0xd2, 0x4c, 0xc0, 0x56, + 0x2c, 0x24, 0x22, 0x61, 0xb3, 0x40, 0xbe, 0x1c, 0x9e, 0x38, 0x5b, 0x3f, 0x24, 0x30, 0x5c, 0x26, + 0xce, 0x06, 0xb5, 0xb6, 0x11, 0x9c, 0x02, 0x99, 0x30, 0x00, 0x28, 0x10, 0x99, 0x12, 0x2b, 0xb8, + 0x2f, 0x81, 0x9b, 0xc9, 0xa3, 0x0b, 0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 0xa9, 0xa3, + 0xfc, 0x74, 0xa3, 0x16, 0x98, 0xae, 0xd4, 0x17, 0xb2, 0x50, 0x5a, 0x3d, 0x6c, 0x2b, 0xd2, 0x51, + 0x5b, 0x91, 0xfe, 0xb4, 0x15, 0xe9, 0xe0, 0x44, 0x49, 0x1d, 0x9d, 0x28, 0xa9, 0x5f, 0x27, 0x4a, + 0xea, 0xed, 0x7c, 0x62, 0x1a, 0x3a, 0xfc, 0xe9, 0xdb, 0x8d, 0xaf, 0xd8, 0x60, 0x54, 0x33, 0xec, + 0x4d, 0xfa, 0xe8, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0xcb, 0xdb, 0xb7, 0x21, 0x0a, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -781,7 +786,7 @@ func (m *MsgCreateFixedAmountPlan) MarshalToSizedBuffer(dAtA []byte) (int, error i = encodeVarintTx(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 } } n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):]) @@ -791,7 +796,7 @@ func (m *MsgCreateFixedAmountPlan) MarshalToSizedBuffer(dAtA []byte) (int, error i -= n1 i = encodeVarintTx(dAtA, i, uint64(n1)) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) if err2 != nil { return 0, err2 @@ -799,7 +804,7 @@ func (m *MsgCreateFixedAmountPlan) MarshalToSizedBuffer(dAtA []byte) (int, error i -= n2 i = encodeVarintTx(dAtA, i, uint64(n2)) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 if len(m.StakingCoinWeights) > 0 { for iNdEx := len(m.StakingCoinWeights) - 1; iNdEx >= 0; iNdEx-- { { @@ -811,7 +816,7 @@ func (m *MsgCreateFixedAmountPlan) MarshalToSizedBuffer(dAtA []byte) (int, error i = encodeVarintTx(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } } if len(m.FarmingPoolAddress) > 0 { @@ -819,6 +824,13 @@ func (m *MsgCreateFixedAmountPlan) MarshalToSizedBuffer(dAtA []byte) (int, error copy(dAtA[i:], m.FarmingPoolAddress) i = encodeVarintTx(dAtA, i, uint64(len(m.FarmingPoolAddress))) i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTx(dAtA, i, uint64(len(m.Name))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -876,7 +888,7 @@ func (m *MsgCreateRatioPlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTx(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):]) if err3 != nil { return 0, err3 @@ -884,7 +896,7 @@ func (m *MsgCreateRatioPlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n3 i = encodeVarintTx(dAtA, i, uint64(n3)) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a n4, err4 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) if err4 != nil { return 0, err4 @@ -892,7 +904,7 @@ func (m *MsgCreateRatioPlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n4 i = encodeVarintTx(dAtA, i, uint64(n4)) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 if len(m.StakingCoinWeights) > 0 { for iNdEx := len(m.StakingCoinWeights) - 1; iNdEx >= 0; iNdEx-- { { @@ -904,7 +916,7 @@ func (m *MsgCreateRatioPlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTx(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } } if len(m.FarmingPoolAddress) > 0 { @@ -912,6 +924,13 @@ func (m *MsgCreateRatioPlan) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.FarmingPoolAddress) i = encodeVarintTx(dAtA, i, uint64(len(m.FarmingPoolAddress))) i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTx(dAtA, i, uint64(len(m.Name))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -1153,6 +1172,10 @@ func (m *MsgCreateFixedAmountPlan) Size() (n int) { } var l int _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } l = len(m.FarmingPoolAddress) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -1191,6 +1214,10 @@ func (m *MsgCreateRatioPlan) Size() (n int) { } var l int _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } l = len(m.FarmingPoolAddress) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -1339,6 +1366,38 @@ func (m *MsgCreateFixedAmountPlan) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", 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.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) } @@ -1370,7 +1429,7 @@ func (m *MsgCreateFixedAmountPlan) Unmarshal(dAtA []byte) error { } m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) } @@ -1404,7 +1463,7 @@ func (m *MsgCreateFixedAmountPlan) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) } @@ -1437,7 +1496,7 @@ func (m *MsgCreateFixedAmountPlan) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) } @@ -1470,7 +1529,7 @@ func (m *MsgCreateFixedAmountPlan) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EpochAmount", wireType) } @@ -1605,6 +1664,38 @@ func (m *MsgCreateRatioPlan) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", 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.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) } @@ -1636,7 +1727,7 @@ func (m *MsgCreateRatioPlan) Unmarshal(dAtA []byte) error { } m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) } @@ -1670,7 +1761,7 @@ func (m *MsgCreateRatioPlan) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) } @@ -1703,7 +1794,7 @@ func (m *MsgCreateRatioPlan) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) } @@ -1736,7 +1827,7 @@ func (m *MsgCreateRatioPlan) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EpochRatio", wireType) } From e26e4cc449b8c74858ff0b63eecaab904c582fc1 Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 27 Jul 2021 12:00:08 +0900 Subject: [PATCH 15/39] apply feedback --- x/farming/client/cli/tx.go | 4 +++ x/farming/client/cli/utils.go | 2 ++ x/farming/client/cli/utils_test.go | 4 +++ x/farming/handler_test.go | 4 +++ x/farming/keeper/proposal_handler.go | 46 ++++++++++++++++++++-------- x/farming/types/msgs.go | 4 +++ x/farming/types/msgs_test.go | 42 +++++++++++++------------ 7 files changed, 74 insertions(+), 32 deletions(-) diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index 68be5af9..18859e60 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -54,6 +54,7 @@ $ %s tx %s create-private-fixed-plan --from mykey Where plan.json contains: { + "name": "This plan intends to provide incentives for Cosmonauts!", "staking_coin_weights": [ { "denom": "uatom", @@ -85,6 +86,7 @@ Where plan.json contains: } msg := types.NewMsgCreateFixedAmountPlan( + plan.Name, clientCtx.GetFromAddress(), plan.StakingCoinWeights, plan.StartTime, @@ -120,6 +122,7 @@ $ %s tx %s create-private-ratio-plan --from mykey Where plan.json contains: { + "name": "This plan intends to provide incentives for Cosmonauts!", "staking_coin_weights": [ { "denom": "uatom", @@ -146,6 +149,7 @@ Where plan.json contains: } msg := types.NewMsgCreateRatioPlan( + plan.Name, clientCtx.GetFromAddress(), plan.StakingCoinWeights, plan.StartTime, diff --git a/x/farming/client/cli/utils.go b/x/farming/client/cli/utils.go index 5f3f09f1..fd3d3977 100644 --- a/x/farming/client/cli/utils.go +++ b/x/farming/client/cli/utils.go @@ -13,6 +13,7 @@ import ( // PrivateFixedPlanRequest defines CLI request for a private fixed plan. type PrivateFixedPlanRequest struct { + Name string `json:"name"` StakingCoinWeights sdk.DecCoins `json:"staking_coin_weights"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` @@ -21,6 +22,7 @@ type PrivateFixedPlanRequest struct { // PrivateRatioPlanRequest defines CLI request for a private ratio plan. type PrivateRatioPlanRequest struct { + Name string `json:"name"` StakingCoinWeights sdk.DecCoins `json:"staking_coin_weights"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go index 62c40421..0e186a07 100644 --- a/x/farming/client/cli/utils_test.go +++ b/x/farming/client/cli/utils_test.go @@ -15,6 +15,7 @@ import ( func TestParsePrivateFixedPlan(t *testing.T) { okJSON := testutil.WriteToNewTempFile(t, ` { + "name": "This plan intends to provide incentives for Cosmonauts!", "staking_coin_weights": [ { "denom": "PoolCoinDenom", @@ -35,6 +36,7 @@ func TestParsePrivateFixedPlan(t *testing.T) { plan, err := cli.ParsePrivateFixedPlan(okJSON.Name()) require.NoError(t, err) + require.Equal(t, "This plan intends to provide incentives for Cosmonauts!", plan.Name) require.Equal(t, "1.000000000000000000PoolCoinDenom", plan.StakingCoinWeights.String()) require.Equal(t, "2021-07-15T08:41:21.662422Z", plan.StartTime.Format(time.RFC3339Nano)) require.Equal(t, "2022-07-16T08:41:21.662422Z", plan.EndTime.Format(time.RFC3339Nano)) @@ -44,6 +46,7 @@ func TestParsePrivateFixedPlan(t *testing.T) { func TestParsePrivateRatioPlan(t *testing.T) { okJSON := testutil.WriteToNewTempFile(t, ` { + "name": "This plan intends to provide incentives for Cosmonauts!", "staking_coin_weights": [ { "denom": "PoolCoinDenom", @@ -59,6 +62,7 @@ func TestParsePrivateRatioPlan(t *testing.T) { plan, err := cli.ParsePrivateRatioPlan(okJSON.Name()) require.NoError(t, err) + require.Equal(t, "This plan intends to provide incentives for Cosmonauts!", plan.Name) require.Equal(t, "1.000000000000000000PoolCoinDenom", plan.StakingCoinWeights.String()) require.Equal(t, "2021-07-15T08:41:21.662422Z", plan.StartTime.Format(time.RFC3339Nano)) require.Equal(t, "2022-07-16T08:41:21.662422Z", plan.EndTime.Format(time.RFC3339Nano)) diff --git a/x/farming/handler_test.go b/x/farming/handler_test.go index 0ec86b78..c1883a45 100644 --- a/x/farming/handler_test.go +++ b/x/farming/handler_test.go @@ -40,6 +40,7 @@ func createTestInput() (*farmingapp.FarmingApp, sdk.Context, []sdk.AccAddress) { func TestMsgCreateFixedAmountPlan(t *testing.T) { app, ctx, addrs := createTestInput() + name := "test" farmingPoolAddr := addrs[0] stakingCoinWeights := sdk.NewDecCoins( sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, @@ -49,6 +50,7 @@ func TestMsgCreateFixedAmountPlan(t *testing.T) { epochAmount := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1))) msg := types.NewMsgCreateFixedAmountPlan( + name, farmingPoolAddr, stakingCoinWeights, startTime, @@ -68,6 +70,7 @@ func TestMsgCreateFixedAmountPlan(t *testing.T) { func TestMsgCreateRatioPlan(t *testing.T) { app, ctx, addrs := createTestInput() + name := "Test" farmingPoolAddr := addrs[0] stakingCoinWeights := sdk.NewDecCoins( sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, @@ -77,6 +80,7 @@ func TestMsgCreateRatioPlan(t *testing.T) { epochAmount := sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(1))) msg := types.NewMsgCreateFixedAmountPlan( + name, farmingPoolAddr, stakingCoinWeights, startTime, diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index a030a81b..6ea952df 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -43,6 +43,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals [] if !p.EpochAmount.IsZero() && !p.EpochAmount.IsAnyNegative() { msg := types.NewMsgCreateFixedAmountPlan( + name, farmingPoolAddrAcc, p.GetStakingCoinWeights(), p.GetStartTime(), @@ -61,6 +62,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals [] if !p.EpochRatio.IsZero() || !p.EpochRatio.IsNegative() { msg := types.NewMsgCreateRatioPlan( + name, farmingPoolAddrAcc, p.GetStakingCoinWeights(), p.GetStartTime(), @@ -101,22 +103,42 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd switch p := plan.(type) { case *types.FixedAmountPlan: - p.SetFarmingPoolAddress(farmingPoolAddrAcc) // nolint:errcheck - p.SetTerminationAddress(terminationAddrAcc) // nolint:errcheck - p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()) // nolint:errcheck - p.SetStartTime(proposal.GetStartTime()) // nolint:errcheck - p.SetEndTime(proposal.GetStartTime()) // nolint:errcheck - p.EpochAmount = proposal.GetEpochAmount() // nolint:errcheck + if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { + return err + } + if err := p.SetTerminationAddress(terminationAddrAcc); err != nil { + return err + } + if err := p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()); err != nil { + return err + } + if err := p.SetStartTime(proposal.GetStartTime()); err != nil { + return err + } + if err := p.SetEndTime(proposal.GetStartTime()); err != nil { + return err + } + p.EpochAmount = proposal.GetEpochAmount() k.SetPlan(ctx, p) case *types.RatioPlan: - p.SetFarmingPoolAddress(farmingPoolAddrAcc) // nolint:errcheck - p.SetTerminationAddress(terminationAddrAcc) // nolint:errcheck - p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()) // nolint:errcheck - p.SetStartTime(proposal.GetStartTime()) // nolint:errcheck - p.SetEndTime(proposal.GetStartTime()) // nolint:errcheck - p.EpochRatio = proposal.EpochRatio // nolint:errcheck + if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { + return err + } + if err := p.SetTerminationAddress(terminationAddrAcc); err != nil { + return err + } + if err := p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()); err != nil { + return err + } + if err := p.SetStartTime(proposal.GetStartTime()); err != nil { + return err + } + if err := p.SetEndTime(proposal.GetStartTime()); err != nil { + return err + } + p.EpochRatio = proposal.EpochRatio k.SetPlan(ctx, p) diff --git a/x/farming/types/msgs.go b/x/farming/types/msgs.go index 7a0e7eb8..fa11875b 100644 --- a/x/farming/types/msgs.go +++ b/x/farming/types/msgs.go @@ -27,6 +27,7 @@ const ( // NewMsgCreateFixedAmountPlan creates a new MsgCreateFixedAmountPlan. func NewMsgCreateFixedAmountPlan( + name string, farmingPoolAddr sdk.AccAddress, stakingCoinWeights sdk.DecCoins, startTime time.Time, @@ -34,6 +35,7 @@ func NewMsgCreateFixedAmountPlan( epochAmount sdk.Coins, ) *MsgCreateFixedAmountPlan { return &MsgCreateFixedAmountPlan{ + Name: name, FarmingPoolAddress: farmingPoolAddr.String(), StakingCoinWeights: stakingCoinWeights, StartTime: startTime, @@ -90,6 +92,7 @@ func (msg MsgCreateFixedAmountPlan) GetCreator() sdk.AccAddress { // NewMsgCreateRatioPlan creates a new MsgCreateRatioPlan. func NewMsgCreateRatioPlan( + name string, farmingPoolAddr sdk.AccAddress, stakingCoinWeights sdk.DecCoins, startTime time.Time, @@ -97,6 +100,7 @@ func NewMsgCreateRatioPlan( epochRatio sdk.Dec, ) *MsgCreateRatioPlan { return &MsgCreateRatioPlan{ + Name: name, FarmingPoolAddress: farmingPoolAddr.String(), StakingCoinWeights: stakingCoinWeights, StartTime: startTime, diff --git a/x/farming/types/msgs_test.go b/x/farming/types/msgs_test.go index 7a11a4c9..07947296 100644 --- a/x/farming/types/msgs_test.go +++ b/x/farming/types/msgs_test.go @@ -14,6 +14,7 @@ import ( ) func TestMsgCreateFixedAmountPlan(t *testing.T) { + name := "Test" farmingPoolAddr := sdk.AccAddress(crypto.AddressHash([]byte("farmingPoolAddr"))) stakingCoinWeights := sdk.NewDecCoins( sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, @@ -29,36 +30,36 @@ func TestMsgCreateFixedAmountPlan(t *testing.T) { { "", // empty means no error expected types.NewMsgCreateFixedAmountPlan( - farmingPoolAddr, stakingCoinWeights, startTime, - endTime, sdk.Coins{sdk.NewCoin("uatom", sdk.NewInt(1))}, + name, farmingPoolAddr, stakingCoinWeights, + startTime, endTime, sdk.Coins{sdk.NewCoin("uatom", sdk.NewInt(1))}, ), }, { "invalid farming pool address \"\": empty address string is not allowed: invalid address", types.NewMsgCreateFixedAmountPlan( - sdk.AccAddress{}, stakingCoinWeights, startTime, - endTime, sdk.Coins{sdk.NewCoin("uatom", sdk.NewInt(1))}, + name, sdk.AccAddress{}, stakingCoinWeights, + startTime, endTime, sdk.Coins{sdk.NewCoin("uatom", sdk.NewInt(1))}, ), }, { "end time 2020-11-01T22:08:41Z must be greater than start time 2021-11-01T22:08:41Z: invalid plan end time", types.NewMsgCreateFixedAmountPlan( - farmingPoolAddr, stakingCoinWeights, startTime, - startTime.AddDate(-1, 0, 0), sdk.Coins{sdk.NewCoin("uatom", sdk.NewInt(1))}, + name, farmingPoolAddr, stakingCoinWeights, + startTime, startTime.AddDate(-1, 0, 0), sdk.Coins{sdk.NewCoin("uatom", sdk.NewInt(1))}, ), }, { "staking coin weights must not be empty", types.NewMsgCreateFixedAmountPlan( - farmingPoolAddr, sdk.NewDecCoins(), startTime, - endTime, sdk.Coins{sdk.NewCoin("uatom", sdk.NewInt(1))}, + name, farmingPoolAddr, sdk.NewDecCoins(), + startTime, endTime, sdk.Coins{sdk.NewCoin("uatom", sdk.NewInt(1))}, ), }, { "epoch amount must not be empty", types.NewMsgCreateFixedAmountPlan( - farmingPoolAddr, stakingCoinWeights, startTime, - endTime, sdk.Coins{}, + name, farmingPoolAddr, stakingCoinWeights, + startTime, endTime, sdk.Coins{}, ), }, } @@ -82,6 +83,7 @@ func TestMsgCreateFixedAmountPlan(t *testing.T) { } func TestMsgCreateRatioPlan(t *testing.T) { + name := "Test" farmingPoolAddr := sdk.AccAddress(crypto.AddressHash([]byte("farmingPoolAddr"))) stakingCoinWeights := sdk.NewDecCoins( sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, @@ -97,36 +99,36 @@ func TestMsgCreateRatioPlan(t *testing.T) { { "", // empty means no error expected types.NewMsgCreateRatioPlan( - farmingPoolAddr, stakingCoinWeights, startTime, - endTime, sdk.NewDec(1), + name, farmingPoolAddr, stakingCoinWeights, + startTime, endTime, sdk.NewDec(1), ), }, { "invalid farming pool address \"\": empty address string is not allowed: invalid address", types.NewMsgCreateRatioPlan( - sdk.AccAddress{}, stakingCoinWeights, startTime, - endTime, sdk.NewDec(1), + name, sdk.AccAddress{}, stakingCoinWeights, + startTime, endTime, sdk.NewDec(1), ), }, { "end time 2020-11-01T22:08:41Z must be greater than start time 2021-11-01T22:08:41Z: invalid plan end time", types.NewMsgCreateRatioPlan( - farmingPoolAddr, stakingCoinWeights, startTime, - startTime.AddDate(-1, 0, 0), sdk.NewDec(1), + name, farmingPoolAddr, stakingCoinWeights, + startTime, startTime.AddDate(-1, 0, 0), sdk.NewDec(1), ), }, { "staking coin weights must not be empty", types.NewMsgCreateRatioPlan( - farmingPoolAddr, sdk.NewDecCoins(), startTime, - endTime, sdk.NewDec(1), + name, farmingPoolAddr, sdk.NewDecCoins(), + startTime, endTime, sdk.NewDec(1), ), }, { "invalid plan epoch ratio", types.NewMsgCreateRatioPlan( - farmingPoolAddr, stakingCoinWeights, startTime, - endTime, sdk.NewDec(-1), + name, farmingPoolAddr, stakingCoinWeights, + startTime, endTime, sdk.NewDec(-1), ), }, } From ac0d5152bb6f606472474431e6d4b65781ba1629 Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 27 Jul 2021 17:26:29 +0900 Subject: [PATCH 16/39] add validation and fix public ratio plan creation logic --- x/farming/handler_test.go | 2 +- x/farming/keeper/proposal_handler.go | 11 ++++++++++- x/farming/types/msgs_test.go | 4 ++-- x/farming/types/proposal.go | 7 ++++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/x/farming/handler_test.go b/x/farming/handler_test.go index c1883a45..7b3f6537 100644 --- a/x/farming/handler_test.go +++ b/x/farming/handler_test.go @@ -70,7 +70,7 @@ func TestMsgCreateFixedAmountPlan(t *testing.T) { func TestMsgCreateRatioPlan(t *testing.T) { app, ctx, addrs := createTestInput() - name := "Test" + name := "test" farmingPoolAddr := addrs[0] stakingCoinWeights := sdk.NewDecCoins( sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 6ea952df..1db192b8 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -60,7 +60,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals [] logger.Info("created public fixed amount plan", "fixed_amount_plan", plan) } - if !p.EpochRatio.IsZero() || !p.EpochRatio.IsNegative() { + if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNil() && !p.EpochRatio.IsNegative() { msg := types.NewMsgCreateRatioPlan( name, farmingPoolAddrAcc, @@ -122,6 +122,9 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd k.SetPlan(ctx, p) + logger := k.Logger(ctx) + logger.Info("updated public fixed amount plan", "fixed_amount_plan", plan) + case *types.RatioPlan: if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { return err @@ -142,6 +145,9 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd k.SetPlan(ctx, p) + logger := k.Logger(ctx) + logger.Info("updated public ratio plan", "ratio_plan", plan) + default: return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized plan type: %T", p) } @@ -159,6 +165,9 @@ func (k Keeper) DeletePublicPlanProposal(ctx sdk.Context, proposals []*types.Del } k.RemovePlan(ctx, plan) + + logger := k.Logger(ctx) + logger.Info("removed public ratio plan", "plan_id", plan.GetId()) } return nil diff --git a/x/farming/types/msgs_test.go b/x/farming/types/msgs_test.go index 07947296..3a146697 100644 --- a/x/farming/types/msgs_test.go +++ b/x/farming/types/msgs_test.go @@ -14,7 +14,7 @@ import ( ) func TestMsgCreateFixedAmountPlan(t *testing.T) { - name := "Test" + name := "test" farmingPoolAddr := sdk.AccAddress(crypto.AddressHash([]byte("farmingPoolAddr"))) stakingCoinWeights := sdk.NewDecCoins( sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, @@ -83,7 +83,7 @@ func TestMsgCreateFixedAmountPlan(t *testing.T) { } func TestMsgCreateRatioPlan(t *testing.T) { - name := "Test" + name := "test" farmingPoolAddr := sdk.AccAddress(crypto.AddressHash([]byte("farmingPoolAddr"))) stakingCoinWeights := sdk.NewDecCoins( sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 69e6eefe..c157cfb1 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -3,6 +3,7 @@ package types import ( "fmt" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" gov "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -39,9 +40,9 @@ func (p *PublicPlanProposal) ProposalRoute() string { return RouterKey } func (p *PublicPlanProposal) ProposalType() string { return ProposalTypePublicPlan } func (p *PublicPlanProposal) ValidateBasic() error { - // if p.AddRequestProposals == nil && p.UpdateRequestProposals == nil && p.DeleteRequestProposals == nil { - // return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proposal must not be empty") - // } + if p.AddRequestProposals == nil && p.UpdateRequestProposals == nil && p.DeleteRequestProposals == nil { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proposal request must not be empty") + } return gov.ValidateAbstract(p) } From af70b8e4367e25c470a4cd7bd0245406576842dd Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 27 Jul 2021 17:51:02 +0900 Subject: [PATCH 17/39] remove empty name field and use the one from the passed argument --- x/farming/client/cli/tx.go | 7 +++---- x/farming/keeper/msg_server.go | 6 ++---- x/farming/keeper/plan.go | 10 ++++------ x/farming/keeper/proposal_handler.go | 4 ++-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index 18859e60..4a3e05e5 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -82,7 +82,7 @@ Where plan.json contains: plan, err := ParsePrivateFixedPlan(args[0]) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file: %v", args[0], err) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file due to %v", args[0], err) } msg := types.NewMsgCreateFixedAmountPlan( @@ -145,7 +145,7 @@ Where plan.json contains: plan, err := ParsePrivateRatioPlan(args[0]) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file: %v", args[0], err) + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "failed to parse %s file due to %v", args[0], err) } msg := types.NewMsgCreateRatioPlan( @@ -270,8 +270,7 @@ $ %s tx %s harvest --from mykey return cmd } -// GetCmdSubmitPublicPlanProposal implements a command handler for submitting a public farming plan -// to create, update, delete transaction. +// GetCmdSubmitPublicPlanProposal implements a command handler for submitting a public farming plan transaction to create, update, delete plan. func GetCmdSubmitPublicPlanProposal() *cobra.Command { cmd := &cobra.Command{ Use: "public-farming-plan [proposal-file] [flags]", diff --git a/x/farming/keeper/msg_server.go b/x/farming/keeper/msg_server.go index 866b0928..4abeba55 100644 --- a/x/farming/keeper/msg_server.go +++ b/x/farming/keeper/msg_server.go @@ -30,8 +30,7 @@ var _ types.MsgServer = msgServer{} func (k msgServer) CreateFixedAmountPlan(goCtx context.Context, msg *types.MsgCreateFixedAmountPlan) (*types.MsgCreateFixedAmountPlanResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - name := "" - fixedPlan, err := k.Keeper.CreateFixedAmountPlan(ctx, msg, name, types.PlanTypePrivate) + fixedPlan, err := k.Keeper.CreateFixedAmountPlan(ctx, msg, types.PlanTypePrivate) if err != nil { return nil, err } @@ -54,8 +53,7 @@ func (k msgServer) CreateFixedAmountPlan(goCtx context.Context, msg *types.MsgCr func (k msgServer) CreateRatioPlan(goCtx context.Context, msg *types.MsgCreateRatioPlan) (*types.MsgCreateRatioPlanResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - name := "" - ratioPlan, err := k.Keeper.CreateRatioPlan(ctx, msg, name, types.PlanTypePrivate) + ratioPlan, err := k.Keeper.CreateRatioPlan(ctx, msg, types.PlanTypePrivate) if err != nil { return nil, err } diff --git a/x/farming/keeper/plan.go b/x/farming/keeper/plan.go index 3eb3c1e8..96c75769 100644 --- a/x/farming/keeper/plan.go +++ b/x/farming/keeper/plan.go @@ -163,9 +163,7 @@ func (k Keeper) UnmarshalPlan(bz []byte) (plan types.PlanI, err error) { } // CreateFixedAmountPlan sets fixed amount plan. -func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixedAmountPlan, - name string, typ types.PlanType) (*types.FixedAmountPlan, error) { - +func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixedAmountPlan, typ types.PlanType) (*types.FixedAmountPlan, error) { nextId := k.GetNextPlanIDWithUpdate(ctx) farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(msg.FarmingPoolAddress) if err != nil { @@ -192,7 +190,7 @@ func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixed basePlan := types.NewBasePlan( nextId, - name, + msg.Name, typ, farmingPoolAddrAcc.String(), terminationAddrAcc.String(), @@ -220,7 +218,7 @@ func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixed } // CreateRatioPlan sets ratio plan. -func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, name string, typ types.PlanType) (*types.RatioPlan, error) { +func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, typ types.PlanType) (*types.RatioPlan, error) { nextId := k.GetNextPlanIDWithUpdate(ctx) farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(msg.FarmingPoolAddress) if err != nil { @@ -247,7 +245,7 @@ func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, basePlan := types.NewBasePlan( nextId, - name, + msg.Name, typ, farmingPoolAddrAcc.String(), terminationAddrAcc.String(), diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 1db192b8..d7a8275b 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -51,7 +51,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals [] p.EpochAmount, ) - plan, err := k.CreateFixedAmountPlan(ctx, msg, name, types.PlanTypePublic) + plan, err := k.CreateFixedAmountPlan(ctx, msg, types.PlanTypePublic) if err != nil { return err } @@ -70,7 +70,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals [] p.EpochRatio, ) - plan, err := k.CreateRatioPlan(ctx, msg, name, types.PlanTypePublic) + plan, err := k.CreateRatioPlan(ctx, msg, types.PlanTypePublic) if err != nil { return err } From 5ad0c333351502f5cf93e91489ac8c7c287e83f4 Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 27 Jul 2021 17:56:32 +0900 Subject: [PATCH 18/39] remove unused rest code --- x/farming/client/proposal_handler.go | 3 +-- x/farming/client/rest/rest.go | 24 ------------------------ 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 x/farming/client/rest/rest.go diff --git a/x/farming/client/proposal_handler.go b/x/farming/client/proposal_handler.go index a2a816f2..c52de7a5 100644 --- a/x/farming/client/proposal_handler.go +++ b/x/farming/client/proposal_handler.go @@ -4,10 +4,9 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/tendermint/farming/x/farming/client/cli" - "github.com/tendermint/farming/x/farming/client/rest" ) // ProposalHandler is the public plan creation handler. var ( - AddProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, rest.ProposalRESTHandler) + AddProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, nil) ) diff --git a/x/farming/client/rest/rest.go b/x/farming/client/rest/rest.go deleted file mode 100644 index 5d18f8f2..00000000 --- a/x/farming/client/rest/rest.go +++ /dev/null @@ -1,24 +0,0 @@ -package rest - -import ( - "net/http" - - "github.com/cosmos/cosmos-sdk/client" - govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" -) - -// TODO: not implemented yet - -// TODO add proto compatible Handler after x/gov migration -// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route. -func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { - return govrest.ProposalRESTHandler{ - SubRoute: "farming_plan", - Handler: postProposalHandlerFn(clientCtx), - } -} - -func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - } -} From 7c56ea7400b0396387a73c7fd7ea77e76a09c86b Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 27 Jul 2021 21:33:01 +0900 Subject: [PATCH 19/39] move the name field inside the AddRequestProposal --- .../tendermint/farming/v1beta1/proposal.proto | 26 +- x/farming/client/cli/tx.go | 2 +- x/farming/client/cli/utils_test.go | 3 +- x/farming/keeper/proposal_handler.go | 8 +- x/farming/types/proposal.go | 3 +- x/farming/types/proposal.pb.go | 248 +++++++++--------- 6 files changed, 147 insertions(+), 143 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index c63a4f12..3d58ed01 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -21,55 +21,55 @@ message PublicPlanProposal { // description specifies the description of the plan string description = 2; - // name specifies the plan name that describes what plan is for - string name = 3; - // add_request_proposals specifies AddRequestProposal object - repeated AddRequestProposal add_request_proposals = 4 [(gogoproto.moretags) = "yaml:\"add_request_proposals\""]; + repeated AddRequestProposal add_request_proposals = 3 [(gogoproto.moretags) = "yaml:\"add_request_proposals\""]; // update_request_proposals specifies UpdateRequestProposal object - repeated UpdateRequestProposal update_request_proposals = 5 + repeated UpdateRequestProposal update_request_proposals = 4 [(gogoproto.moretags) = "yaml:\"update_request_proposals\""]; // delete_request_proposals specifies DeleteRequestProposal object - repeated DeleteRequestProposal delete_request_proposals = 6 + repeated DeleteRequestProposal delete_request_proposals = 5 [(gogoproto.moretags) = "yaml:\"delete_request_proposals\""]; } // AddRequestProposal details a proposal for creating a public plan. message AddRequestProposal { + // name specifies the plan name that describes what plan is for + string name = 1; + // farming_pool_address defines the bech32-encoded address of the farming pool - string farming_pool_address = 1 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; + string farming_pool_address = 2 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; // termination_address defines the bech32-encoded address that terminates plan // when the plan ends after the end time, the balance of farming pool address // is transferred to the termination address - string termination_address = 2 [(gogoproto.moretags) = "yaml:\"termination_address\""]; + string termination_address = 3 [(gogoproto.moretags) = "yaml:\"termination_address\""]; // staking_coin_weights specifies coin weights for the plan - repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 3 [ + repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 4 [ (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; // start_time specifies the start time of the plan - google.protobuf.Timestamp start_time = 4 + google.protobuf.Timestamp start_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; // end_time specifies the end time of the plan - google.protobuf.Timestamp end_time = 5 + google.protobuf.Timestamp end_time = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; // epoch_amount specifies the distributing amount for each epoch - repeated cosmos.base.v1beta1.Coin epoch_amount = 6 [ + repeated cosmos.base.v1beta1.Coin epoch_amount = 7 [ (gogoproto.moretags) = "yaml:\"epoch_amount\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false ]; // epoch_ratio specifies the distributing amount by ratio - string epoch_ratio = 7 [ + string epoch_ratio = 8 [ (gogoproto.moretags) = "yaml:\"epoch_ratio\"", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index 4a3e05e5..2695f0bf 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -335,7 +335,7 @@ Where proposal.json contains: return err } - content, err := types.NewPublicPlanProposal(proposal.Title, proposal.Description, proposal.Name, + content, err := types.NewPublicPlanProposal(proposal.Title, proposal.Description, proposal.AddRequestProposals, proposal.UpdateRequestProposals, proposal.DeleteRequestProposals) if err != nil { return err diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go index 0e186a07..a80196d1 100644 --- a/x/farming/client/cli/utils_test.go +++ b/x/farming/client/cli/utils_test.go @@ -76,9 +76,9 @@ func TestParsePublicPlanProposal(t *testing.T) { { "title": "Public Farming Plan", "description": "Are you ready to farm?", - "name": "First Public Farming Plan", "add_request_proposals": [ { + "name": "First Public Farming Plan", "farming_pool_address": "cosmos1mzgucqnfr2l8cj5apvdpllhzt4zeuh2cshz5xu", "termination_address": "cosmos1mzgucqnfr2l8cj5apvdpllhzt4zeuh2cshz5xu", "staking_coin_weights": [ @@ -105,5 +105,4 @@ func TestParsePublicPlanProposal(t *testing.T) { require.Equal(t, "Public Farming Plan", proposal.Title) require.Equal(t, "Are you ready to farm?", proposal.Description) - require.Equal(t, "First Public Farming Plan", proposal.Name) } diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index d7a8275b..784e9169 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -15,7 +15,7 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP switch { case proposal.AddRequestProposals != nil: - if err := k.AddPublicPlanProposal(ctx, proposal.Name, proposal.AddRequestProposals); err != nil { + if err := k.AddPublicPlanProposal(ctx, proposal.AddRequestProposals); err != nil { return err } case proposal.UpdateRequestProposals != nil: @@ -34,7 +34,7 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP } // AddPublicPlanProposal adds a new public plan once the governance proposal is passed. -func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals []*types.AddRequestProposal) error { +func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddRequestProposal) error { for _, p := range proposals { farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { @@ -43,7 +43,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals [] if !p.EpochAmount.IsZero() && !p.EpochAmount.IsAnyNegative() { msg := types.NewMsgCreateFixedAmountPlan( - name, + p.GetName(), farmingPoolAddrAcc, p.GetStakingCoinWeights(), p.GetStartTime(), @@ -62,7 +62,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, name string, proposals [] if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNil() && !p.EpochRatio.IsNegative() { msg := types.NewMsgCreateRatioPlan( - name, + p.GetName(), farmingPoolAddrAcc, p.GetStakingCoinWeights(), p.GetStartTime(), diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index c157cfb1..9c4d37e9 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -19,12 +19,11 @@ func init() { gov.RegisterProposalTypeCodec(&PublicPlanProposal{}, "cosmos-sdk/PublicPlanProposal") } -func NewPublicPlanProposal(title, description, name string, addReq []*AddRequestProposal, +func NewPublicPlanProposal(title, description string, addReq []*AddRequestProposal, updateReq []*UpdateRequestProposal, deleteReq []*DeleteRequestProposal) (gov.Content, error) { return &PublicPlanProposal{ Title: title, Description: description, - Name: name, AddRequestProposals: addReq, UpdateRequestProposals: updateReq, DeleteRequestProposals: deleteReq, diff --git a/x/farming/types/proposal.pb.go b/x/farming/types/proposal.pb.go index a03a440a..5aa9abc4 100644 --- a/x/farming/types/proposal.pb.go +++ b/x/farming/types/proposal.pb.go @@ -36,14 +36,12 @@ type PublicPlanProposal struct { Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` // description specifies the description of the plan Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // name specifies the plan name that describes what plan is for - Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` // add_request_proposals specifies AddRequestProposal object - AddRequestProposals []*AddRequestProposal `protobuf:"bytes,4,rep,name=add_request_proposals,json=addRequestProposals,proto3" json:"add_request_proposals,omitempty" yaml:"add_request_proposals"` + AddRequestProposals []*AddRequestProposal `protobuf:"bytes,3,rep,name=add_request_proposals,json=addRequestProposals,proto3" json:"add_request_proposals,omitempty" yaml:"add_request_proposals"` // update_request_proposals specifies UpdateRequestProposal object - UpdateRequestProposals []*UpdateRequestProposal `protobuf:"bytes,5,rep,name=update_request_proposals,json=updateRequestProposals,proto3" json:"update_request_proposals,omitempty" yaml:"update_request_proposals"` + UpdateRequestProposals []*UpdateRequestProposal `protobuf:"bytes,4,rep,name=update_request_proposals,json=updateRequestProposals,proto3" json:"update_request_proposals,omitempty" yaml:"update_request_proposals"` // delete_request_proposals specifies DeleteRequestProposal object - DeleteRequestProposals []*DeleteRequestProposal `protobuf:"bytes,6,rep,name=delete_request_proposals,json=deleteRequestProposals,proto3" json:"delete_request_proposals,omitempty" yaml:"delete_request_proposals"` + DeleteRequestProposals []*DeleteRequestProposal `protobuf:"bytes,5,rep,name=delete_request_proposals,json=deleteRequestProposals,proto3" json:"delete_request_proposals,omitempty" yaml:"delete_request_proposals"` } func (m *PublicPlanProposal) Reset() { *m = PublicPlanProposal{} } @@ -80,22 +78,24 @@ var xxx_messageInfo_PublicPlanProposal proto.InternalMessageInfo // AddRequestProposal details a proposal for creating a public plan. type AddRequestProposal struct { + // name specifies the plan name that describes what plan is for + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // farming_pool_address defines the bech32-encoded address of the farming pool - FarmingPoolAddress string `protobuf:"bytes,1,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` + FarmingPoolAddress string `protobuf:"bytes,2,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` // termination_address defines the bech32-encoded address that terminates plan // when the plan ends after the end time, the balance of farming pool address // is transferred to the termination address - TerminationAddress string `protobuf:"bytes,2,opt,name=termination_address,json=terminationAddress,proto3" json:"termination_address,omitempty" yaml:"termination_address"` + TerminationAddress string `protobuf:"bytes,3,opt,name=termination_address,json=terminationAddress,proto3" json:"termination_address,omitempty" yaml:"termination_address"` // staking_coin_weights specifies coin weights for the plan - StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` + StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,4,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` // start_time specifies the start time of the plan - StartTime time.Time `protobuf:"bytes,4,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + StartTime time.Time `protobuf:"bytes,5,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` // end_time specifies the end time of the plan - EndTime time.Time `protobuf:"bytes,5,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` + EndTime time.Time `protobuf:"bytes,6,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` // epoch_amount specifies the distributing amount for each epoch - EpochAmount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=epoch_amount,json=epochAmount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"epoch_amount" yaml:"epoch_amount"` + EpochAmount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,7,rep,name=epoch_amount,json=epochAmount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"epoch_amount" yaml:"epoch_amount"` // epoch_ratio specifies the distributing amount by ratio - EpochRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=epoch_ratio,json=epochRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_ratio" yaml:"epoch_ratio"` + EpochRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=epoch_ratio,json=epochRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_ratio" yaml:"epoch_ratio"` } func (m *AddRequestProposal) Reset() { *m = AddRequestProposal{} } @@ -131,6 +131,13 @@ func (m *AddRequestProposal) XXX_DiscardUnknown() { var xxx_messageInfo_AddRequestProposal proto.InternalMessageInfo +func (m *AddRequestProposal) GetName() string { + if m != nil { + return m.Name + } + return "" +} + func (m *AddRequestProposal) GetFarmingPoolAddress() string { if m != nil { return m.FarmingPoolAddress @@ -335,55 +342,54 @@ func init() { } var fileDescriptor_4719b03c30c7910a = []byte{ - // 766 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcf, 0x4f, 0xdb, 0x48, - 0x14, 0x8e, 0xc9, 0x2f, 0x98, 0xac, 0xb4, 0xda, 0x21, 0xb0, 0x26, 0xb0, 0x76, 0xe4, 0x95, 0x56, - 0x59, 0x55, 0xd8, 0x85, 0xde, 0xb8, 0x91, 0x22, 0xa1, 0x9e, 0x9a, 0x5a, 0xad, 0x5a, 0xf5, 0x62, - 0x4d, 0x32, 0x43, 0xb0, 0xb0, 0x3d, 0xae, 0x67, 0xd2, 0x96, 0x7b, 0x2b, 0xf5, 0xc8, 0xa9, 0xed, - 0x11, 0xf5, 0xd8, 0xbf, 0x84, 0x23, 0xc7, 0xaa, 0x87, 0x50, 0xc1, 0x7f, 0x90, 0x63, 0x4f, 0x95, - 0x67, 0xc6, 0x21, 0x2a, 0x0e, 0x70, 0x00, 0x89, 0x93, 0xe7, 0xcd, 0xbc, 0xef, 0x7b, 0xdf, 0xbc, - 0x79, 0x9f, 0x12, 0xf0, 0x3f, 0x27, 0x11, 0x26, 0x49,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xc1, 0xc7, 0x0a, 0x58, 0xc8, - 0x35, 0x3c, 0xfc, 0x1b, 0x54, 0xe3, 0x00, 0x45, 0x9e, 0x8f, 0xc5, 0xc8, 0x97, 0xdc, 0x4a, 0x1a, - 0x3e, 0xc2, 0x53, 0x8d, 0x31, 0x73, 0xe3, 0xc6, 0x28, 0xde, 0xbc, 0x31, 0x4a, 0x77, 0xd6, 0x18, - 0xe5, 0x5b, 0x32, 0x46, 0xe5, 0xb6, 0x8c, 0x51, 0xbd, 0x13, 0xc6, 0x98, 0xbd, 0x25, 0x63, 0xdc, - 0x07, 0x0b, 0xb9, 0xbf, 0x3a, 0x53, 0x7d, 0xd1, 0xde, 0x3e, 0x3a, 0x35, 0xb4, 0xe3, 0x53, 0x43, - 0xfb, 0x71, 0x6a, 0x68, 0x07, 0x67, 0x46, 0xe1, 0xf8, 0xcc, 0x28, 0x7c, 0x3b, 0x33, 0x0a, 0x2f, - 0x57, 0x27, 0x54, 0xe5, 0xfc, 0xa3, 0x79, 0x3b, 0x5e, 0x09, 0x81, 0xdd, 0x8a, 0x78, 0xa3, 0x07, - 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x69, 0xcf, 0x69, 0x1c, 0x96, 0x09, 0x00, 0x00, + // 739 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0xc1, 0x4f, 0xdb, 0x3c, + 0x1c, 0x6d, 0x3e, 0x4a, 0x01, 0xf7, 0x93, 0x3e, 0x7d, 0xa6, 0xb0, 0x52, 0x58, 0x52, 0x65, 0xd2, + 0xd4, 0x69, 0x22, 0x19, 0xec, 0xc6, 0x8d, 0x0e, 0x09, 0xed, 0xb4, 0xce, 0xda, 0xb4, 0x69, 0x97, + 0xc8, 0xad, 0x4d, 0x89, 0x48, 0xe2, 0x2c, 0x76, 0xb7, 0x71, 0xde, 0x26, 0xed, 0x34, 0x71, 0x9a, + 0x76, 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, 0x12, 0xba, 0x29, 0x91, 0x90, 0x02, 0x55, 0x7a, 0x49, 0x76, 0xe3, 0xf5, 0x59, 0xf9, 0x46, + 0xb6, 0xb2, 0xad, 0x7e, 0xa6, 0xd6, 0xdd, 0xeb, 0xdd, 0xc9, 0x30, 0xb5, 0xe0, 0xb8, 0x28, 0x49, + 0x65, 0x23, 0x20, 0x2b, 0x24, 0x8b, 0x2f, 0x15, 0xb0, 0x50, 0xf8, 0x47, 0x00, 0xde, 0x02, 0x33, + 0x71, 0x80, 0x23, 0xcf, 0x27, 0x32, 0x16, 0x65, 0x54, 0xc9, 0xca, 0xc7, 0xe4, 0x26, 0x18, 0x37, + 0xc1, 0xf8, 0x0b, 0x82, 0xf1, 0x00, 0x2c, 0x14, 0xfe, 0x27, 0x9a, 0x98, 0x8b, 0xf6, 0xf6, 0xd1, + 0xa9, 0x69, 0x1c, 0x9f, 0x9a, 0xc6, 0xaf, 0x53, 0xd3, 0x38, 0x38, 0x33, 0x4b, 0xc7, 0x67, 0x66, + 0xe9, 0xc7, 0x99, 0x59, 0x7a, 0xb5, 0x3a, 0xa6, 0xaa, 0xe0, 0x17, 0xcd, 0xbb, 0xd1, 0x48, 0x0a, + 0xec, 0x56, 0xe4, 0x1d, 0x3d, 0xfc, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x24, 0xaa, 0xa2, 0xb3, 0x96, + 0x09, 0x00, 0x00, } func (m *PublicPlanProposal) Marshal() (dAtA []byte, err error) { @@ -417,7 +423,7 @@ func (m *PublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x32 + dAtA[i] = 0x2a } } if len(m.UpdateRequestProposals) > 0 { @@ -431,7 +437,7 @@ func (m *PublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x22 } } if len(m.AddRequestProposals) > 0 { @@ -445,16 +451,9 @@ func (m *PublicPlanProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 + dAtA[i] = 0x1a } } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintProposal(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0x1a - } if len(m.Description) > 0 { i -= len(m.Description) copy(dAtA[i:], m.Description) @@ -501,7 +500,7 @@ func (m *AddRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x3a + dAtA[i] = 0x42 if len(m.EpochAmount) > 0 { for iNdEx := len(m.EpochAmount) - 1; iNdEx >= 0; iNdEx-- { { @@ -513,7 +512,7 @@ func (m *AddRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x32 + dAtA[i] = 0x3a } } n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):]) @@ -523,7 +522,7 @@ func (m *AddRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n1 i = encodeVarintProposal(dAtA, i, uint64(n1)) i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) if err2 != nil { return 0, err2 @@ -531,7 +530,7 @@ func (m *AddRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n2 i = encodeVarintProposal(dAtA, i, uint64(n2)) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a if len(m.StakingCoinWeights) > 0 { for iNdEx := len(m.StakingCoinWeights) - 1; iNdEx >= 0; iNdEx-- { { @@ -543,7 +542,7 @@ func (m *AddRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } } if len(m.TerminationAddress) > 0 { @@ -551,13 +550,20 @@ func (m *AddRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.TerminationAddress) i = encodeVarintProposal(dAtA, i, uint64(len(m.TerminationAddress))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(m.FarmingPoolAddress) > 0 { i -= len(m.FarmingPoolAddress) copy(dAtA[i:], m.FarmingPoolAddress) i = encodeVarintProposal(dAtA, i, uint64(len(m.FarmingPoolAddress))) i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Name))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -712,10 +718,6 @@ func (m *PublicPlanProposal) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - l = len(m.Name) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } if len(m.AddRequestProposals) > 0 { for _, e := range m.AddRequestProposals { l = e.Size() @@ -743,6 +745,10 @@ func (m *AddRequestProposal) Size() (n int) { } var l int _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } l = len(m.FarmingPoolAddress) if l > 0 { n += 1 + l + sovProposal(uint64(l)) @@ -922,38 +928,6 @@ func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { m.Description = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - 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 ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field AddRequestProposals", wireType) } @@ -987,7 +961,7 @@ func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field UpdateRequestProposals", wireType) } @@ -1021,7 +995,7 @@ func (m *PublicPlanProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 6: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field DeleteRequestProposals", wireType) } @@ -1106,6 +1080,38 @@ func (m *AddRequestProposal) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) } @@ -1137,7 +1143,7 @@ func (m *AddRequestProposal) Unmarshal(dAtA []byte) error { } m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field TerminationAddress", wireType) } @@ -1169,7 +1175,7 @@ func (m *AddRequestProposal) Unmarshal(dAtA []byte) error { } m.TerminationAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) } @@ -1203,7 +1209,7 @@ func (m *AddRequestProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) } @@ -1236,7 +1242,7 @@ func (m *AddRequestProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) } @@ -1269,7 +1275,7 @@ func (m *AddRequestProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 6: + case 7: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EpochAmount", wireType) } @@ -1303,7 +1309,7 @@ func (m *AddRequestProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 7: + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EpochRatio", wireType) } From 195ae6669bd427eede01f73855a0053cedc1df63 Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 27 Jul 2021 21:55:35 +0900 Subject: [PATCH 20/39] add description on PublicPlanProposal message --- proto/tendermint/farming/v1beta1/proposal.proto | 4 +++- x/farming/types/proposal.pb.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index 3d58ed01..bca0d2cc 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -10,7 +10,9 @@ import "google/protobuf/timestamp.proto"; option go_package = "github.com/tendermint/farming/x/farming/types"; -// PublicPlanProposal details a proposal for creating a public plan. +// PublicPlanProposal defines a public farming plan governance proposal that receives one of the following requests: +// A request that creates a public farming plan, a request that updates the plan, and a reuqest that deletes the plan. +// For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed amount plan or ratio plan. message PublicPlanProposal { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; diff --git a/x/farming/types/proposal.pb.go b/x/farming/types/proposal.pb.go index 5aa9abc4..4bf29d3b 100644 --- a/x/farming/types/proposal.pb.go +++ b/x/farming/types/proposal.pb.go @@ -30,7 +30,9 @@ var _ = time.Kitchen // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// PublicPlanProposal details a proposal for creating a public plan. +// PublicPlanProposal defines a public farming plan governance proposal that receives one of the following requests: +// A request that creates a public farming plan, a request that updates the plan, and a reuqest that deletes the plan. +// For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed amount plan or ratio plan. type PublicPlanProposal struct { // title specifies the title of the plan Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` From ce770543609ecc8bb5ddd3a7d421451a13694cd4 Mon Sep 17 00:00:00 2001 From: kogisin Date: Tue, 27 Jul 2021 22:10:41 +0900 Subject: [PATCH 21/39] fix typo and add 09_proposal.md --- .../tendermint/farming/v1beta1/proposal.proto | 2 +- x/farming/spec/09_proposal.md | 89 +++++++++++++++++++ x/farming/types/proposal.pb.go | 2 +- 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 x/farming/spec/09_proposal.md diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index bca0d2cc..ba19c8a9 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -11,7 +11,7 @@ import "google/protobuf/timestamp.proto"; option go_package = "github.com/tendermint/farming/x/farming/types"; // PublicPlanProposal defines a public farming plan governance proposal that receives one of the following requests: -// A request that creates a public farming plan, a request that updates the plan, and a reuqest that deletes the plan. +// A request that creates a public farming plan, a request that updates the plan, and a request that deletes the plan. // For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed amount plan or ratio plan. message PublicPlanProposal { option (gogoproto.goproto_getters) = false; diff --git a/x/farming/spec/09_proposal.md b/x/farming/spec/09_proposal.md new file mode 100644 index 00000000..652e6fa2 --- /dev/null +++ b/x/farming/spec/09_proposal.md @@ -0,0 +1,89 @@ + + +# Proposal + +The farming module contains the following public plan governance proposal that receives one of the following requests. A request `AddRequestProposal` that creates a public farming plan, a request `UpdateRequestProposal` that updates the plan, and a request `DeleteRequestProposal` that deletes the plan. For most cases, it expects that a single request is used, but note that `PublicPlanProposal` accepts more than a single request to cover broader use cases. Also, + +## PublicPlanProposal + +```go +// PublicPlanProposal defines a public farming plan governance proposal that receives one of the following requests: +// A request that creates a public farming plan, a request that updates the plan, and a request that deletes the plan. +// For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed amount plan or ratio plan. +type PublicPlanProposal struct { + // title specifies the title of the plan + Title string + // description specifies the description of the plan + Description string + // add_request_proposals specifies AddRequestProposal object + AddRequestProposals []*AddRequestProposal + // update_request_proposals specifies UpdateRequestProposal object + UpdateRequestProposals []*UpdateRequestProposal + // delete_request_proposals specifies DeleteRequestProposal object + DeleteRequestProposals []*DeleteRequestProposal +} +``` + +## AddRequestProposal + +Note that when requesting `AddRequestProposal` depending on which field is passed, either `EpochAmount` or `EpochRatio`, it creates a `FixedAmountPlan` or `RatioPlan`. + +```go +// AddRequestProposal details a proposal for creating a public plan. +type AddRequestProposal struct { + // name specifies the plan name that describes what plan is for + Name string + // farming_pool_address defines the bech32-encoded address of the farming pool + FarmingPoolAddress string + // termination_address defines the bech32-encoded address that terminates plan + // when the plan ends after the end time, the balance of farming pool address + // is transferred to the termination address + TerminationAddress string + // staking_coin_weights specifies coin weights for the plan + StakingCoinWeights sdk.DecCoins + // start_time specifies the start time of the plan + StartTime time.Time + // end_time specifies the end time of the plan + EndTime time.Time + // epoch_amount specifies the distributing amount for each epoch + EpochAmount sdk.Coins + // epoch_ratio specifies the distributing amount by ratio + EpochRatio sdk.Dec +} +``` + +## UpdateRequestProposal + +```go +// UpdateRequestProposal details a proposal for updating an existing public plan. +type UpdateRequestProposal struct { + // plan_id specifies index of the farming plan + PlanId uint64 + // farming_pool_address defines the bech32-encoded address of the farming pool + FarmingPoolAddress string + // termination_address defines the bech32-encoded address that terminates plan + // when the plan ends after the end time, the balance of farming pool address + // is transferred to the termination address + TerminationAddress string + // staking_coin_weights specifies coin weights for the plan + StakingCoinWeights sdk.DecCoins + // start_time specifies the start time of the plan + StartTime time.Time + // end_time specifies the end time of the plan + EndTime time.Time + // epoch_amount specifies the distributing amount for each epoch + EpochAmount sdk.Coins + // epoch_ratio specifies the distributing amount by ratio + EpochRatio sdk.Dec +} +``` + +## DeleteRequestProposal + +```go +// DeleteRequestProposal details a proposal for deleting an existing public plan. +type DeleteRequestProposal struct { + // plan_id specifies index of the farming plan + PlanId uint64 +} +``` \ No newline at end of file diff --git a/x/farming/types/proposal.pb.go b/x/farming/types/proposal.pb.go index 4bf29d3b..3f03dc20 100644 --- a/x/farming/types/proposal.pb.go +++ b/x/farming/types/proposal.pb.go @@ -31,7 +31,7 @@ var _ = time.Kitchen const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // PublicPlanProposal defines a public farming plan governance proposal that receives one of the following requests: -// A request that creates a public farming plan, a request that updates the plan, and a reuqest that deletes the plan. +// A request that creates a public farming plan, a request that updates the plan, and a request that deletes the plan. // For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed amount plan or ratio plan. type PublicPlanProposal struct { // title specifies the title of the plan From e8b292452692f234f1bfe92099d2ed3ad8c9a205 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 10:49:23 +0900 Subject: [PATCH 22/39] add name field in update plan proposal --- .../tendermint/farming/v1beta1/proposal.proto | 17 +- x/farming/keeper/proposal_handler.go | 2 + x/farming/types/proposal.pb.go | 187 +++++++++++------- 3 files changed, 132 insertions(+), 74 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index ba19c8a9..7654a201 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -83,38 +83,41 @@ message UpdateRequestProposal { // plan_id specifies index of the farming plan uint64 plan_id = 1; + // name specifies the plan name that describes what plan is for + string name = 2; + // farming_pool_address defines the bech32-encoded address of the farming pool - string farming_pool_address = 2 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; + string farming_pool_address = 3 [(gogoproto.moretags) = "yaml:\"farming_pool_address\""]; // termination_address defines the bech32-encoded address that terminates plan // when the plan ends after the end time, the balance of farming pool address // is transferred to the termination address - string termination_address = 3 [(gogoproto.moretags) = "yaml:\"termination_address\""]; + string termination_address = 4 [(gogoproto.moretags) = "yaml:\"termination_address\""]; // staking_coin_weights specifies coin weights for the plan - repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 4 [ + repeated cosmos.base.v1beta1.DecCoin staking_coin_weights = 5 [ (gogoproto.moretags) = "yaml:\"staking_coin_weights\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; // start_time specifies the start time of the plan - google.protobuf.Timestamp start_time = 5 + google.protobuf.Timestamp start_time = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; // end_time specifies the end time of the plan - google.protobuf.Timestamp end_time = 6 + google.protobuf.Timestamp end_time = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; // epoch_amount specifies the distributing amount for each epoch - repeated cosmos.base.v1beta1.Coin epoch_amount = 7 [ + repeated cosmos.base.v1beta1.Coin epoch_amount = 8 [ (gogoproto.moretags) = "yaml:\"epoch_amount\"", (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false ]; // epoch_ratio specifies the distributing amount by ratio - string epoch_ratio = 8 [ + string epoch_ratio = 9 [ (gogoproto.moretags) = "yaml:\"epoch_ratio\"", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 784e9169..579b7d45 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -118,6 +118,7 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd if err := p.SetEndTime(proposal.GetStartTime()); err != nil { return err } + p.Name = proposal.GetName() p.EpochAmount = proposal.GetEpochAmount() k.SetPlan(ctx, p) @@ -141,6 +142,7 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd if err := p.SetEndTime(proposal.GetStartTime()); err != nil { return err } + p.Name = proposal.GetName() p.EpochRatio = proposal.EpochRatio k.SetPlan(ctx, p) diff --git a/x/farming/types/proposal.pb.go b/x/farming/types/proposal.pb.go index 3f03dc20..57f8c3b6 100644 --- a/x/farming/types/proposal.pb.go +++ b/x/farming/types/proposal.pb.go @@ -186,22 +186,24 @@ func (m *AddRequestProposal) GetEpochAmount() github_com_cosmos_cosmos_sdk_types type UpdateRequestProposal struct { // plan_id specifies index of the farming plan PlanId uint64 `protobuf:"varint,1,opt,name=plan_id,json=planId,proto3" json:"plan_id,omitempty"` + // name specifies the plan name that describes what plan is for + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` // farming_pool_address defines the bech32-encoded address of the farming pool - FarmingPoolAddress string `protobuf:"bytes,2,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` + FarmingPoolAddress string `protobuf:"bytes,3,opt,name=farming_pool_address,json=farmingPoolAddress,proto3" json:"farming_pool_address,omitempty" yaml:"farming_pool_address"` // termination_address defines the bech32-encoded address that terminates plan // when the plan ends after the end time, the balance of farming pool address // is transferred to the termination address - TerminationAddress string `protobuf:"bytes,3,opt,name=termination_address,json=terminationAddress,proto3" json:"termination_address,omitempty" yaml:"termination_address"` + TerminationAddress string `protobuf:"bytes,4,opt,name=termination_address,json=terminationAddress,proto3" json:"termination_address,omitempty" yaml:"termination_address"` // staking_coin_weights specifies coin weights for the plan - StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,4,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` + StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,5,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` // start_time specifies the start time of the plan - StartTime time.Time `protobuf:"bytes,5,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + StartTime time.Time `protobuf:"bytes,6,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` // end_time specifies the end time of the plan - EndTime time.Time `protobuf:"bytes,6,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` + EndTime time.Time `protobuf:"bytes,7,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` // epoch_amount specifies the distributing amount for each epoch - EpochAmount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,7,rep,name=epoch_amount,json=epochAmount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"epoch_amount" yaml:"epoch_amount"` + EpochAmount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,8,rep,name=epoch_amount,json=epochAmount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"epoch_amount" yaml:"epoch_amount"` // epoch_ratio specifies the distributing amount by ratio - EpochRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=epoch_ratio,json=epochRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_ratio" yaml:"epoch_ratio"` + EpochRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=epoch_ratio,json=epochRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"epoch_ratio" yaml:"epoch_ratio"` } func (m *UpdateRequestProposal) Reset() { *m = UpdateRequestProposal{} } @@ -244,6 +246,13 @@ func (m *UpdateRequestProposal) GetPlanId() uint64 { return 0 } +func (m *UpdateRequestProposal) GetName() string { + if m != nil { + return m.Name + } + return "" +} + func (m *UpdateRequestProposal) GetFarmingPoolAddress() string { if m != nil { return m.FarmingPoolAddress @@ -344,54 +353,55 @@ func init() { } var fileDescriptor_4719b03c30c7910a = []byte{ - // 739 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0xc1, 0x4f, 0xdb, 0x3c, - 0x1c, 0x6d, 0x3e, 0x4a, 0x01, 0xf7, 0x93, 0x3e, 0x7d, 0xa6, 0xb0, 0x52, 0x58, 0x52, 0x65, 0xd2, - 0xd4, 0x69, 0x22, 0x19, 0xec, 0xc6, 0x8d, 0x0e, 0x09, 0xed, 0xb4, 0xce, 0xda, 0xb4, 0x69, 0x97, - 0xc8, 0xad, 0x4d, 0x89, 0x48, 0xe2, 0x2c, 0x76, 0xb7, 0x71, 0xde, 0x26, 0xed, 0x34, 0x71, 0x9a, - 0x76, 0x44, 0x3b, 0xee, 0x2f, 0xe1, 0xc8, 0x71, 0xda, 0x21, 0x4c, 0xf0, 0x1f, 0xf4, 0x2f, 0x98, - 0x62, 0x3b, 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ad, 0x7e, 0xa6, 0xd6, 0xdd, 0xeb, 0xdd, 0xc9, 0x30, 0xb5, 0xe0, 0xb8, 0x28, 0x49, - 0x65, 0x23, 0x20, 0x2b, 0x24, 0x8b, 0x2f, 0x15, 0xb0, 0x50, 0xf8, 0x47, 0x00, 0xde, 0x02, 0x33, - 0x71, 0x80, 0x23, 0xcf, 0x27, 0x32, 0x16, 0x65, 0x54, 0xc9, 0xca, 0xc7, 0xe4, 0x26, 0x18, 0x37, - 0xc1, 0xf8, 0x0b, 0x82, 0xf1, 0x00, 0x2c, 0x14, 0xfe, 0x27, 0x9a, 0x98, 0x8b, 0xf6, 0xf6, 0xd1, - 0xa9, 0x69, 0x1c, 0x9f, 0x9a, 0xc6, 0xaf, 0x53, 0xd3, 0x38, 0x38, 0x33, 0x4b, 0xc7, 0x67, 0x66, - 0xe9, 0xc7, 0x99, 0x59, 0x7a, 0xb5, 0x3a, 0xa6, 0xaa, 0xe0, 0x17, 0xcd, 0xbb, 0xd1, 0x48, 0x0a, - 0xec, 0x56, 0xe4, 0x1d, 0x3d, 0xfc, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x24, 0xaa, 0xa2, 0xb3, 0x96, - 0x09, 0x00, 0x00, + // 765 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4f, 0x4f, 0xdb, 0x3c, + 0x1c, 0x6e, 0xe8, 0x5f, 0xdc, 0x57, 0x7a, 0xf5, 0x9a, 0xc2, 0x5b, 0x0a, 0x4b, 0xaa, 0x4c, 0x9a, + 0x3a, 0x4d, 0x24, 0x83, 0xdd, 0xb8, 0xd1, 0x21, 0xa1, 0x9d, 0xd6, 0x45, 0x9b, 0x36, 0xed, 0x12, + 0xb9, 0xb5, 0x29, 0x11, 0x49, 0x9c, 0xc5, 0xee, 0x36, 0xce, 0xdb, 0xa4, 0x9d, 0x26, 0x8e, 0x3b, + 0xa2, 0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0xf2, 0x6e, 0x40, 0x18, 0x77, 0x53, 0x97, 0x58, 0x3d, + 0xdf, 0xcc, 0xb7, 0xaa, 0x6b, 0x96, 0x35, 0xdd, 0x27, 0x6b, 0x03, 0x63, 0x47, 0xe2, 0x52, 0x1d, + 0xed, 0xe6, 0x68, 0x68, 0x2c, 0xef, 0xa1, 0xc0, 0x5f, 0x37, 0x33, 0x69, 0x4d, 0x67, 0x0e, 0x5d, + 0x40, 0x31, 0xb8, 0xaf, 0x81, 0xfa, 0x20, 0xc2, 0x88, 0x93, 0x0c, 0x25, 0x05, 0xa1, 0x64, 0xf5, + 0x32, 0x25, 0xaf, 0x04, 0xf6, 0x6f, 0x31, 0xf7, 0x47, 0x43, 0xc3, 0x90, 0x62, 0xa6, 0x91, 0x9b, + 0xce, 0xc2, 0x20, 0x0b, 0x2b, 0x25, 0x61, 0xe2, 0x93, 0x4c, 0x49, 0xc5, 0xab, 0x25, 0x6d, 0x0a, + 0xec, 0x25, 0x92, 0xa6, 0x91, 0x9b, 0xce, 0x02, 0xce, 0xc2, 0xb2, 0xf5, 0xca, 0xd7, 0x03, 0x23, + 0xf7, 0xfd, 0xc0, 0xc8, 0x99, 0xdf, 0x4a, 0x00, 0x5e, 0x74, 0x1f, 0x42, 0x50, 0x08, 0x51, 0x90, + 0x3e, 0x02, 0x31, 0x86, 0x2f, 0x40, 0x4d, 0x49, 0x73, 0x23, 0x4a, 0x7d, 0x17, 0x61, 0x1c, 0x13, + 0xc6, 0xe4, 0x63, 0x68, 0x1b, 0xa3, 0xa1, 0xb1, 0x24, 0xf5, 0x64, 0x75, 0x99, 0x0e, 0x54, 0xd3, + 0x1d, 0x4a, 0xfd, 0x0d, 0x39, 0x09, 0x9f, 0x83, 0x39, 0x2e, 0x4e, 0x8d, 0x92, 0x37, 0x34, 0x66, + 0xcc, 0x0b, 0x46, 0x7d, 0x34, 0x34, 0x1a, 0x92, 0x31, 0xa3, 0xc9, 0x74, 0xe0, 0xc4, 0x6c, 0x4a,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x86, 0x40, 0x42, 0x02, 0x64, 0xe9, 0xc6, 0xc9, 0x8d, 0xd7, 0x2b, 0xe2, 0x8d, + 0x6c, 0x26, 0x5b, 0xfd, 0x1a, 0x1a, 0x0f, 0xae, 0x77, 0x27, 0xa3, 0xa1, 0x01, 0x27, 0x45, 0x09, + 0x2a, 0xd3, 0x01, 0xa2, 0x72, 0x44, 0x71, 0x58, 0x02, 0xf3, 0x99, 0x7f, 0x04, 0xe0, 0xff, 0xa0, + 0x1c, 0xf9, 0x28, 0x74, 0x3d, 0x2c, 0x62, 0x51, 0x70, 0x4a, 0x49, 0xf9, 0x0c, 0x8f, 0xc3, 0x32, + 0x73, 0x8d, 0xb0, 0xe4, 0x6f, 0x3c, 0x2c, 0x85, 0x9b, 0x0f, 0x4b, 0xf1, 0xce, 0x86, 0xa5, 0x74, + 0x4b, 0x61, 0x29, 0xdf, 0x56, 0x58, 0x2a, 0x77, 0x22, 0x2c, 0xb3, 0xb7, 0x14, 0x96, 0xc7, 0x60, + 0x3e, 0xf3, 0xbf, 0xd3, 0xd4, 0xac, 0xb4, 0xb7, 0x8e, 0x4e, 0x75, 0xed, 0xf8, 0x54, 0xd7, 0x7e, + 0x9f, 0xea, 0xda, 0xfe, 0x99, 0x9e, 0x3b, 0x3e, 0xd3, 0x73, 0x3f, 0xcf, 0xf4, 0xdc, 0xdb, 0x95, + 0x09, 0x55, 0x19, 0xbf, 0x72, 0x3e, 0x8e, 0x47, 0x42, 0x60, 0xb7, 0x24, 0xee, 0xe8, 0xc9, 0x9f, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xf1, 0x6e, 0x1e, 0xce, 0xaa, 0x09, 0x00, 0x00, } func (m *PublicPlanProposal) Marshal() (dAtA []byte, err error) { @@ -600,7 +610,7 @@ func (m *UpdateRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x42 + dAtA[i] = 0x4a if len(m.EpochAmount) > 0 { for iNdEx := len(m.EpochAmount) - 1; iNdEx >= 0; iNdEx-- { { @@ -612,7 +622,7 @@ func (m *UpdateRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x3a + dAtA[i] = 0x42 } } n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):]) @@ -622,7 +632,7 @@ func (m *UpdateRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n3 i = encodeVarintProposal(dAtA, i, uint64(n3)) i-- - dAtA[i] = 0x32 + dAtA[i] = 0x3a n4, err4 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) if err4 != nil { return 0, err4 @@ -630,7 +640,7 @@ func (m *UpdateRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n4 i = encodeVarintProposal(dAtA, i, uint64(n4)) i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 if len(m.StakingCoinWeights) > 0 { for iNdEx := len(m.StakingCoinWeights) - 1; iNdEx >= 0; iNdEx-- { { @@ -642,7 +652,7 @@ func (m *UpdateRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintProposal(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a } } if len(m.TerminationAddress) > 0 { @@ -650,13 +660,20 @@ func (m *UpdateRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.TerminationAddress) i = encodeVarintProposal(dAtA, i, uint64(len(m.TerminationAddress))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } if len(m.FarmingPoolAddress) > 0 { i -= len(m.FarmingPoolAddress) copy(dAtA[i:], m.FarmingPoolAddress) i = encodeVarintProposal(dAtA, i, uint64(len(m.FarmingPoolAddress))) i-- + dAtA[i] = 0x1a + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Name))) + i-- dAtA[i] = 0x12 } if m.PlanId != 0 { @@ -789,6 +806,10 @@ func (m *UpdateRequestProposal) Size() (n int) { if m.PlanId != 0 { n += 1 + sovProposal(uint64(m.PlanId)) } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } l = len(m.FarmingPoolAddress) if l > 0 { n += 1 + l + sovProposal(uint64(l)) @@ -1415,6 +1436,38 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { } } case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field FarmingPoolAddress", wireType) } @@ -1446,7 +1499,7 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { } m.FarmingPoolAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field TerminationAddress", wireType) } @@ -1478,7 +1531,7 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { } m.TerminationAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StakingCoinWeights", wireType) } @@ -1512,7 +1565,7 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) } @@ -1545,7 +1598,7 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 6: + case 7: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) } @@ -1578,7 +1631,7 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 7: + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EpochAmount", wireType) } @@ -1612,7 +1665,7 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 8: + case 9: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field EpochRatio", wireType) } From c40d32f6efa82109638ab5b49f3757eae179f71b Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 10:53:02 +0900 Subject: [PATCH 23/39] make indentation consistent and change variable name --- x/farming/client/cli/tx.go | 18 +++++++++--------- x/farming/client/proposal_handler.go | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x/farming/client/cli/tx.go b/x/farming/client/cli/tx.go index 2695f0bf..b7b2e467 100644 --- a/x/farming/client/cli/tx.go +++ b/x/farming/client/cli/tx.go @@ -56,10 +56,10 @@ Where plan.json contains: { "name": "This plan intends to provide incentives for Cosmonauts!", "staking_coin_weights": [ - { - "denom": "uatom", - "amount": "1.000000000000000000" - } + { + "denom": "uatom", + "amount": "1.000000000000000000" + } ], "start_time": "2021-07-24T08:41:21.662422Z", "end_time": "2022-07-28T08:41:21.662422Z", @@ -124,14 +124,14 @@ Where plan.json contains: { "name": "This plan intends to provide incentives for Cosmonauts!", "staking_coin_weights": [ - { - "denom": "uatom", - "amount": "1.000000000000000000" - } + { + "denom": "uatom", + "amount": "1.000000000000000000" + } ], "start_time": "2021-07-15T08:41:21.662422Z", "end_time": "2022-07-16T08:41:21.662422Z", - "epoch_ratio":"1.000000000000000000" + "epoch_ratio": "1.000000000000000000" } `, version.AppName, types.ModuleName, diff --git a/x/farming/client/proposal_handler.go b/x/farming/client/proposal_handler.go index c52de7a5..b933d630 100644 --- a/x/farming/client/proposal_handler.go +++ b/x/farming/client/proposal_handler.go @@ -8,5 +8,5 @@ import ( // ProposalHandler is the public plan creation handler. var ( - AddProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, nil) + ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, nil) ) From adf7f92608b0b38778640a66e8303865a56537b7 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 10:54:13 +0900 Subject: [PATCH 24/39] reformat json --- x/farming/client/cli/utils_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go index a80196d1..f057128d 100644 --- a/x/farming/client/cli/utils_test.go +++ b/x/farming/client/cli/utils_test.go @@ -17,10 +17,10 @@ func TestParsePrivateFixedPlan(t *testing.T) { { "name": "This plan intends to provide incentives for Cosmonauts!", "staking_coin_weights": [ - { - "denom": "PoolCoinDenom", - "amount": "1.000000000000000000" - } + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } ], "start_time": "2021-07-15T08:41:21.662422Z", "end_time": "2022-07-16T08:41:21.662422Z", @@ -48,14 +48,14 @@ func TestParsePrivateRatioPlan(t *testing.T) { { "name": "This plan intends to provide incentives for Cosmonauts!", "staking_coin_weights": [ - { - "denom": "PoolCoinDenom", - "amount": "1.000000000000000000" - } + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } ], "start_time": "2021-07-15T08:41:21.662422Z", "end_time": "2022-07-16T08:41:21.662422Z", - "epoch_ratio":"1.000000000000000000" + "epoch_ratio": "1.000000000000000000" } `) From 1dea61baf62b2f89f1936011384cb44fe043b022 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 11:00:37 +0900 Subject: [PATCH 25/39] fix broken app --- app/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index 3684eeb6..bdc2025d 100644 --- a/app/app.go +++ b/app/app.go @@ -115,7 +115,7 @@ var ( distr.AppModuleBasic{}, gov.NewAppModuleBasic( paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler, - farmingclient.AddProposalHandler, + farmingclient.ProposalHandler, // todo: farming proposal handler ), params.AppModuleBasic{}, From 132026e01afea2303e516f0f2011efc7afbd3303 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 11:29:15 +0900 Subject: [PATCH 26/39] use three ifs instead of switch case and use else if to prevent from creating more than one plan type --- x/farming/keeper/proposal_handler.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 579b7d45..65e6ccd0 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -13,21 +13,22 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) } - switch { - case proposal.AddRequestProposals != nil: + if proposal.AddRequestProposals != nil { if err := k.AddPublicPlanProposal(ctx, proposal.AddRequestProposals); err != nil { return err } - case proposal.UpdateRequestProposals != nil: + } + + if proposal.UpdateRequestProposals != nil { if err := k.UpdatePublicPlanProposal(ctx, proposal.UpdateRequestProposals); err != nil { return err } - case proposal.DeleteRequestProposals != nil: + } + + if proposal.DeleteRequestProposals != nil { if err := k.DeletePublicPlanProposal(ctx, proposal.DeleteRequestProposals); err != nil { return err } - default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unexpected public plan proposal %s", proposal.String()) } return nil @@ -58,9 +59,8 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq logger := k.Logger(ctx) logger.Info("created public fixed amount plan", "fixed_amount_plan", plan) - } - if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNil() && !p.EpochRatio.IsNegative() { + } else if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNil() && !p.EpochRatio.IsNegative() { msg := types.NewMsgCreateRatioPlan( p.GetName(), farmingPoolAddrAcc, From 154b903dadda4433ec0fb5ab1708dc2cd66571d7 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 13:30:52 +0900 Subject: [PATCH 27/39] add detailed validation logics for AddRequestProposal, UpdateRequestProposal, DeleteRequestProposal --- x/farming/keeper/proposal_handler.go | 12 ++++++ x/farming/types/plan.go | 2 +- x/farming/types/proposal.go | 55 ++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 65e6ccd0..86bfdb9e 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -37,6 +37,10 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP // AddPublicPlanProposal adds a new public plan once the governance proposal is passed. func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddRequestProposal) error { for _, p := range proposals { + if err := p.Validate(); err != nil { + return err + } + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { return err @@ -86,6 +90,10 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq // UpdatePublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed. func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.UpdateRequestProposal) error { for _, proposal := range proposals { + if err := proposal.Validate(); err != nil { + return err + } + plan, found := k.GetPlan(ctx, proposal.GetPlanId()) if !found { return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", proposal.GetPlanId()) @@ -161,6 +169,10 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd // DeletePublicPlanProposal delets public plan proposal once the governance proposal is passed. func (k Keeper) DeletePublicPlanProposal(ctx sdk.Context, proposals []*types.DeleteRequestProposal) error { for _, p := range proposals { + if err := p.Validate(); err != nil { + return err + } + plan, found := k.GetPlan(ctx, p.GetPlanId()) if !found { return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", p.GetPlanId()) diff --git a/x/farming/types/plan.go b/x/farming/types/plan.go index 19938e54..90c57f0a 100644 --- a/x/farming/types/plan.go +++ b/x/farming/types/plan.go @@ -130,7 +130,7 @@ func (plan BasePlan) Validate() error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid termination address %q: %v", plan.TerminationAddress, err) } if len(plan.Name) > MaxNameLength { - return sdkerrors.Wrapf(ErrInvalidNameLength, "plan name is longer than max length of %d", MaxNameLength) + return sdkerrors.Wrapf(ErrInvalidNameLength, "plan name cannot be longer than max length of %d", MaxNameLength) } if err := plan.StakingCoinWeights.Validate(); err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid staking coin weights: %v", err) diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 9c4d37e9..142818b2 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -3,6 +3,7 @@ package types import ( "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" gov "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -54,3 +55,57 @@ func (p PublicPlanProposal) String() string { DeleteRequestProposals: %s `, p.Title, p.Description, p.AddRequestProposals, p.UpdateRequestProposals, p.DeleteRequestProposals) } + +func (p *AddRequestProposal) Validate() error { + if len(p.Name) > MaxNameLength { + return sdkerrors.Wrapf(ErrInvalidNameLength, "plan name cannot be longer than max length of %d", MaxNameLength) + } + if _, err := sdk.AccAddressFromBech32(p.FarmingPoolAddress); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid farming pool address %q: %v", p.FarmingPoolAddress, err) + } + if _, err := sdk.AccAddressFromBech32(p.TerminationAddress); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid termination address %q: %v", p.TerminationAddress, err) + } + if err := p.StakingCoinWeights.Validate(); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid staking coin weights: %v", err) + } + if !p.EndTime.After(p.StartTime) { + return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", p.EndTime, p.StartTime) + } + if !p.EpochAmount.Empty() && !p.EpochRatio.IsZero() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "epoch amount or epoch ratio must be provided") + } + return nil +} + +func (p *UpdateRequestProposal) Validate() error { + if p.PlanId == 0 { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid plan id: %d", p.PlanId) + } + if len(p.Name) > MaxNameLength { + return sdkerrors.Wrapf(ErrInvalidNameLength, "plan name cannot be longer than max length of %d", MaxNameLength) + } + if _, err := sdk.AccAddressFromBech32(p.FarmingPoolAddress); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid farming pool address %q: %v", p.FarmingPoolAddress, err) + } + if _, err := sdk.AccAddressFromBech32(p.TerminationAddress); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid termination address %q: %v", p.TerminationAddress, err) + } + if err := p.StakingCoinWeights.Validate(); err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid staking coin weights: %v", err) + } + if !p.EndTime.After(p.StartTime) { + return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", p.EndTime, p.StartTime) + } + if !p.EpochAmount.Empty() && !p.EpochRatio.IsZero() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "epoch amount or epoch ratio must be provided") + } + return nil +} + +func (p *DeleteRequestProposal) Validate() error { + if p.PlanId == 0 { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid plan id: %d", p.PlanId) + } + return nil +} From 672bb5a472d92df19731f0ce2569dc7fc1c7f8e2 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 13:54:22 +0900 Subject: [PATCH 28/39] re: add detailed validation logics for AddRequestProposal, UpdateRequestProposal, DeleteRequestProposal --- x/farming/client/proposal_handler.go | 3 ++- x/farming/client/rest/rest.go | 24 ++++++++++++++++++++++++ x/farming/keeper/proposal_handler.go | 12 ------------ x/farming/types/proposal.go | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 x/farming/client/rest/rest.go diff --git a/x/farming/client/proposal_handler.go b/x/farming/client/proposal_handler.go index b933d630..a8d00a97 100644 --- a/x/farming/client/proposal_handler.go +++ b/x/farming/client/proposal_handler.go @@ -4,9 +4,10 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/tendermint/farming/x/farming/client/cli" + "github.com/tendermint/farming/x/farming/client/rest" ) // ProposalHandler is the public plan creation handler. var ( - ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, nil) + ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, rest.ProposalRESTHandler) ) diff --git a/x/farming/client/rest/rest.go b/x/farming/client/rest/rest.go new file mode 100644 index 00000000..53a4b251 --- /dev/null +++ b/x/farming/client/rest/rest.go @@ -0,0 +1,24 @@ +package rest + +import ( + "net/http" + + "github.com/cosmos/cosmos-sdk/client" + govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" +) + +// TODO: not implemented yet; although this legacy REST API may not be needed, +// it needs for ProposalHandler; otherwise it throws panic when starting the chain + +// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route. +func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { + return govrest.ProposalRESTHandler{ + SubRoute: "farming_plan", + Handler: postProposalHandlerFn(clientCtx), + } +} + +func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + } +} diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 86bfdb9e..65e6ccd0 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -37,10 +37,6 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP // AddPublicPlanProposal adds a new public plan once the governance proposal is passed. func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddRequestProposal) error { for _, p := range proposals { - if err := p.Validate(); err != nil { - return err - } - farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { return err @@ -90,10 +86,6 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq // UpdatePublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed. func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.UpdateRequestProposal) error { for _, proposal := range proposals { - if err := proposal.Validate(); err != nil { - return err - } - plan, found := k.GetPlan(ctx, proposal.GetPlanId()) if !found { return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", proposal.GetPlanId()) @@ -169,10 +161,6 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd // DeletePublicPlanProposal delets public plan proposal once the governance proposal is passed. func (k Keeper) DeletePublicPlanProposal(ctx sdk.Context, proposals []*types.DeleteRequestProposal) error { for _, p := range proposals { - if err := p.Validate(); err != nil { - return err - } - plan, found := k.GetPlan(ctx, p.GetPlanId()) if !found { return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", p.GetPlanId()) diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 142818b2..48e1ebd1 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -43,6 +43,21 @@ func (p *PublicPlanProposal) ValidateBasic() error { if p.AddRequestProposals == nil && p.UpdateRequestProposals == nil && p.DeleteRequestProposals == nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proposal request must not be empty") } + for _, ap := range p.AddRequestProposals { + if err := ap.Validate(); err != nil { + return err + } + } + for _, up := range p.UpdateRequestProposals { + if err := up.Validate(); err != nil { + return err + } + } + for _, dp := range p.DeleteRequestProposals { + if err := dp.Validate(); err != nil { + return err + } + } return gov.ValidateAbstract(p) } From e6a004b033788e0d17e59f963db42f7647925f41 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 21:33:42 +0900 Subject: [PATCH 29/39] add skeleton for docs #21 --- docs/Explanation/ADR/README.md | 11 +++++++++++ docs/How-To/README.md | 0 docs/README.md | 9 +++++++++ docs/Tutorials/README.md | 1 + 4 files changed, 21 insertions(+) create mode 100644 docs/Explanation/ADR/README.md create mode 100644 docs/How-To/README.md create mode 100644 docs/README.md create mode 100644 docs/Tutorials/README.md diff --git a/docs/Explanation/ADR/README.md b/docs/Explanation/ADR/README.md new file mode 100644 index 00000000..66d98d73 --- /dev/null +++ b/docs/Explanation/ADR/README.md @@ -0,0 +1,11 @@ +# Architecture Decision Records (ADR) + +Use this location to record all high-level architecture decisions in the farming module + +## Definitions + +## Rationale + +## Creating new ADR + +## ADR Table of Contents \ No newline at end of file diff --git a/docs/How-To/README.md b/docs/How-To/README.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..d7eb5d38 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,9 @@ +# Farming Module Documentation + +## Get Started + +## References + +## Other Resources + +## Contribute diff --git a/docs/Tutorials/README.md b/docs/Tutorials/README.md new file mode 100644 index 00000000..a390cfec --- /dev/null +++ b/docs/Tutorials/README.md @@ -0,0 +1 @@ +## Tutorials From e6aadfc06c29ab65370c0e6b11dc6f8141bf283a Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 22:21:37 +0900 Subject: [PATCH 30/39] add How-To farming_plans.md --- docs/How-To/farming_plans.md | 243 +++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 docs/How-To/farming_plans.md diff --git a/docs/How-To/farming_plans.md b/docs/How-To/farming_plans.md new file mode 100644 index 00000000..5e6fcb8c --- /dev/null +++ b/docs/How-To/farming_plans.md @@ -0,0 +1,243 @@ +# Farming Plans + +There are two different types of farming plans in the farming module. Where as a public farming plan can only be created through governance proposal, a private farming plan can be created with any account. The plan creator's account is used as distributing account FarmingPoolAddress that will be distributed to farmers automatically. + +In this documentation, there are sample data provided in JSON structure that are needed to test the functionality by using farming command line interfaces. + +## Table of Contetns + +- [Bootstrap Local Network](#Boostrap) +- [Public Farming Plan](#Public-Farming-Plan) + * [AddPublicFarmingFixedAmountPlan](#AddPublicFarmingFixedAmountPlan) + * [AddPublicFarmingRatioPlan](#AddPublicFarmingRatioPlan) + * [AddMultiplePublicPlans](#AddMultiplePublicPlans) + * [UpdatePublicFarmingFixedAmountPlan](#UpdatePublicFarmingFixedAmountPlan) + * [DeletePublicFarmingFixedAmountPlan](#DeletePublicFarmingFixedAmountPlan) +- [Private Farming Plan](#Private-Farming-Plan) + * [PrivateFarmingFixedAmountPlan](#PrivateFarmingFixedAmountPlan) + * [PrivateFarmingRatioPlan](#PrivateFarmingRatioPlan) + +# Bootstrap + +```bash +# Clone the project +git clone https://github.com/tendermint/farming.git +cd cosmos-sdk +make install + +# Configure variables +export BINARY=farmingd +export HOME_1=$HOME/.farmingapp +export CHAIN_ID=localnet +export VALIDATOR_1="struggle panic room apology luggage game screen wing want lazy famous eight robot picture wrap act uphold grab away proud music danger naive opinion" +export USER_1="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host" +export GENESIS_COINS=10000000000stake,10000000000uatom,10000000000uusd + +# Boostrap +$BINARY init $CHAIN_ID --chain-id $CHAIN_ID +echo $VALIDATOR_1 | $BINARY keys add val1 --keyring-backend test --recover +echo $USER_1 | $BINARY keys add user1 --keyring-backend test --recover +$BINARY add-genesis-account $($BINARY keys show val1 --keyring-backend test -a) $GENESIS_COINS +$BINARY add-genesis-account $($BINARY keys show user1 --keyring-backend test -a) $GENESIS_COINS +$BINARY gentx val1 100000000stake --chain-id $CHAIN_ID --keyring-backend test +$BINARY collect-gentxs + +# Modify app.toml +sed -i '' 's/enable = false/enable = true/g' $HOME_1/config/app.toml +sed -i '' 's/swagger = false/swagger = true/g' $HOME_1/config/app.toml + +# Modify governance proposal for testing purpose +sed -i '' 's%"amount": "10000000"%"amount": "1"%g' $HOME_1/config/genesis.json +sed -i '' 's%"quorum": "0.334000000000000000",%"quorum": "0.000000000000000001",%g' $HOME_1/config/genesis.json +sed -i '' 's%"threshold": "0.500000000000000000",%"threshold": "0.000000000000000001",%g' $HOME_1/config/genesis.json +sed -i '' 's%"voting_period": "172800s"%"voting_period": "60s"%g' $HOME_1/config/genesis.json + +# Start +$BINARY start +``` + +# Public Farming Plan + +## AddPublicFarmingFixedAmountPlan + +```json +{ + "title": "Public Farming Plan", + "description": "Are you ready to farm?", + "add_request_proposals": [ + { + "name": "First Public Farming Plan", + "farming_pool_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", + "termination_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", + "staking_coin_weights": [ + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] + } + ] +} +``` + +## AddPublicFarmingRatioPlan + +```json +{ + "title": "Public Farming Plan", + "description": "Are you ready to farm?", + "add_request_proposals": [ + { + "name": "First Public Farming Plan", + "farming_pool_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", + "termination_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", + "staking_coin_weights": [ + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_ratio": "1.000000000000000000" + } + ] +} +``` + +## AddMultiplePublicPlans + +```json +{ + "title": "Public Farming Plan", + "description": "Are you ready to farm?", + "add_request_proposals": [ + { + "name": "First Public Farming Plan", + "farming_pool_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", + "termination_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", + "staking_coin_weights": [ + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] + }, + { + "name": "First Public Farming Plan", + "farming_pool_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", + "termination_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", + "staking_coin_weights": [ + { + "denom": "PoolCoinDenom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_ratio": "1.000000000000000000" + } + ] +} +``` + +## UpdatePublicFarmingFixedAmountPlan + +```json +{ + "title": "Let's Update the Farming Plan 1", + "description": "FarmingPoolAddress needs to be changed", + "update_request_proposals": [ + { + "plan_id": 1, + "farming_pool_address": "cosmos13w4ueuk80d3kmwk7ntlhp84fk0arlm3mqf0w08", + "termination_address": "cosmos13w4ueuk80d3kmwk7ntlhp84fk0arlm3mqf0w08", + "staking_coin_weights": [ + { + "denom": "uatom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] + } + ] +} +``` + +## DeletePublicFarmingFixedAmountPlan + +```json +{ + "title": "Delete Public Farming Plan 1", + "description": "This plan is no longer needed", + "delete_request_proposals": [ + { + "plan_id": 1 + } + ] +} +``` + +# Private Farming Plan + +## PrivateFarmingFixedAmountPlan + +```json +{ + "name": "This Farming Plan intends to incentivize ATOM HODLERS!", + "staking_coin_weights": [ + { + "denom": "uatom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_amount": [ + { + "denom": "uatom", + "amount": "1" + } + ] +} +``` + +## PrivateFarmingRatioPlan + +```json +{ + "name": "This Farming Plan intends to incentivize ATOM HODLERS!", + "staking_coin_weights": [ + { + "denom": "uatom", + "amount": "1.000000000000000000" + } + ], + "start_time": "2021-07-15T08:41:21.662422Z", + "end_time": "2022-07-16T08:41:21.662422Z", + "epoch_ratio":"1.000000000000000000" +} +``` \ No newline at end of file From adc1b617ff64320055f67bdd0a7b4e8d3f0d0ad7 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 22:52:04 +0900 Subject: [PATCH 31/39] update comment --- x/farming/client/rest/rest.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/farming/client/rest/rest.go b/x/farming/client/rest/rest.go index 53a4b251..fdf6ddf9 100644 --- a/x/farming/client/rest/rest.go +++ b/x/farming/client/rest/rest.go @@ -7,10 +7,10 @@ import ( govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" ) -// TODO: not implemented yet; although this legacy REST API may not be needed, -// it needs for ProposalHandler; otherwise it throws panic when starting the chain +// TODO: not implemented yet; +// although this legacy REST API may not be needed, it needs for ProposalHandler; otherwise it throws panic when starting the chain -// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route. +// ProposalRESTHandler returns a ProposalRESTHandler that exposes the farming plan proposal (add/update/delete) REST handler with a given sub-route. func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { return govrest.ProposalRESTHandler{ SubRoute: "farming_plan", From 95044e1332ebe6e86705fb25e69d5228361e50b7 Mon Sep 17 00:00:00 2001 From: kogisin Date: Wed, 28 Jul 2021 22:52:10 +0900 Subject: [PATCH 32/39] add validation for duplicate plan name --- x/farming/keeper/proposal_handler.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 65e6ccd0..0532e770 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -37,6 +37,13 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP // AddPublicPlanProposal adds a new public plan once the governance proposal is passed. func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddRequestProposal) error { for _, p := range proposals { + plans := k.GetAllPlans(ctx) + for _, plan := range plans { + if plan.(*types.BasePlan).Name == p.Name { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", p.Name) + } + } + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { return err @@ -91,6 +98,13 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", proposal.GetPlanId()) } + plans := k.GetAllPlans(ctx) + for _, plan := range plans { + if plan.(*types.BasePlan).Name == proposal.Name { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", proposal.Name) + } + } + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetFarmingPoolAddress()) if err != nil { return err From dd77f217526362ec326f3cc909a04d5fca18843c Mon Sep 17 00:00:00 2001 From: kogisin Date: Thu, 29 Jul 2021 12:57:19 +0900 Subject: [PATCH 33/39] update date time format to RFC3339 --- x/farming/client/cli/utils_test.go | 20 ++++++++++---------- x/farming/types/msgs.go | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/x/farming/client/cli/utils_test.go b/x/farming/client/cli/utils_test.go index f057128d..6b115c6f 100644 --- a/x/farming/client/cli/utils_test.go +++ b/x/farming/client/cli/utils_test.go @@ -22,8 +22,8 @@ func TestParsePrivateFixedPlan(t *testing.T) { "amount": "1.000000000000000000" } ], - "start_time": "2021-07-15T08:41:21.662422Z", - "end_time": "2022-07-16T08:41:21.662422Z", + "start_time": "2021-07-15T08:41:21Z", + "end_time": "2022-07-16T08:41:21Z", "epoch_amount": [ { "denom": "uatom", @@ -38,8 +38,8 @@ func TestParsePrivateFixedPlan(t *testing.T) { require.Equal(t, "This plan intends to provide incentives for Cosmonauts!", plan.Name) require.Equal(t, "1.000000000000000000PoolCoinDenom", plan.StakingCoinWeights.String()) - require.Equal(t, "2021-07-15T08:41:21.662422Z", plan.StartTime.Format(time.RFC3339Nano)) - require.Equal(t, "2022-07-16T08:41:21.662422Z", plan.EndTime.Format(time.RFC3339Nano)) + require.Equal(t, "2021-07-15T08:41:21Z", plan.StartTime.Format(time.RFC3339)) + require.Equal(t, "2022-07-16T08:41:21Z", plan.EndTime.Format(time.RFC3339)) require.Equal(t, "1uatom", plan.EpochAmount.String()) } @@ -53,8 +53,8 @@ func TestParsePrivateRatioPlan(t *testing.T) { "amount": "1.000000000000000000" } ], - "start_time": "2021-07-15T08:41:21.662422Z", - "end_time": "2022-07-16T08:41:21.662422Z", + "start_time": "2021-07-15T08:41:21Z", + "end_time": "2022-07-16T08:41:21Z", "epoch_ratio": "1.000000000000000000" } `) @@ -64,8 +64,8 @@ func TestParsePrivateRatioPlan(t *testing.T) { require.Equal(t, "This plan intends to provide incentives for Cosmonauts!", plan.Name) require.Equal(t, "1.000000000000000000PoolCoinDenom", plan.StakingCoinWeights.String()) - require.Equal(t, "2021-07-15T08:41:21.662422Z", plan.StartTime.Format(time.RFC3339Nano)) - require.Equal(t, "2022-07-16T08:41:21.662422Z", plan.EndTime.Format(time.RFC3339Nano)) + require.Equal(t, "2021-07-15T08:41:21Z", plan.StartTime.Format(time.RFC3339)) + require.Equal(t, "2022-07-16T08:41:21Z", plan.EndTime.Format(time.RFC3339)) require.Equal(t, "1.000000000000000000", plan.EpochRatio.String()) } @@ -87,8 +87,8 @@ func TestParsePublicPlanProposal(t *testing.T) { "amount": "1.000000000000000000" } ], - "start_time": "2021-07-15T08:41:21.662422Z", - "end_time": "2022-07-16T08:41:21.662422Z", + "start_time": "2021-07-15T08:41:21Z", + "end_time": "2022-07-16T08:41:21Z", "epoch_amount": [ { "denom": "uatom", diff --git a/x/farming/types/msgs.go b/x/farming/types/msgs.go index fa11875b..c2de5b85 100644 --- a/x/farming/types/msgs.go +++ b/x/farming/types/msgs.go @@ -53,7 +53,7 @@ func (msg MsgCreateFixedAmountPlan) ValidateBasic() error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid farming pool address %q: %v", msg.FarmingPoolAddress, err) } if !msg.EndTime.After(msg.StartTime) { - return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", msg.EndTime.Format(time.RFC3339Nano), msg.StartTime.Format(time.RFC3339Nano)) + return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", msg.EndTime.Format(time.RFC3339), msg.StartTime.Format(time.RFC3339)) } if msg.StakingCoinWeights.Empty() { return ErrEmptyStakingCoinWeights @@ -118,7 +118,7 @@ func (msg MsgCreateRatioPlan) ValidateBasic() error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid farming pool address %q: %v", msg.FarmingPoolAddress, err) } if !msg.EndTime.After(msg.StartTime) { - return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", msg.EndTime.Format(time.RFC3339Nano), msg.StartTime.Format(time.RFC3339Nano)) + return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", msg.EndTime.Format(time.RFC3339), msg.StartTime.Format(time.RFC3339)) } if msg.StakingCoinWeights.Empty() { return ErrEmptyStakingCoinWeights From ee1cf1b3f1e392166c01886649f98c276ba0619c Mon Sep 17 00:00:00 2001 From: kogisin Date: Thu, 29 Jul 2021 14:51:40 +0900 Subject: [PATCH 34/39] feat: update public plan proposal --- .../tendermint/farming/v1beta1/proposal.proto | 7 +- x/farming/keeper/proposal_handler.go | 110 ++++++++---- x/farming/types/msgs.go | 3 + x/farming/types/proposal.go | 2 +- x/farming/types/proposal.pb.go | 168 ++++++++++-------- 5 files changed, 173 insertions(+), 117 deletions(-) diff --git a/proto/tendermint/farming/v1beta1/proposal.proto b/proto/tendermint/farming/v1beta1/proposal.proto index 7654a201..b6dee06c 100644 --- a/proto/tendermint/farming/v1beta1/proposal.proto +++ b/proto/tendermint/farming/v1beta1/proposal.proto @@ -12,7 +12,8 @@ option go_package = "github.com/tendermint/farming/x/farming/types"; // PublicPlanProposal defines a public farming plan governance proposal that receives one of the following requests: // A request that creates a public farming plan, a request that updates the plan, and a request that deletes the plan. -// For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed amount plan or ratio plan. +// For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed +// amount plan or ratio plan. message PublicPlanProposal { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; @@ -103,11 +104,11 @@ message UpdateRequestProposal { // start_time specifies the start time of the plan google.protobuf.Timestamp start_time = 6 - [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"start_time\""]; + [(gogoproto.stdtime) = true, (gogoproto.nullable) = true, (gogoproto.moretags) = "yaml:\"start_time\""]; // end_time specifies the end time of the plan google.protobuf.Timestamp end_time = 7 - [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"end_time\""]; + [(gogoproto.stdtime) = true, (gogoproto.nullable) = true, (gogoproto.moretags) = "yaml:\"end_time\""]; // epoch_amount specifies the distributing amount for each epoch repeated cosmos.base.v1beta1.Coin epoch_amount = 8 [ diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 0532e770..4e016e20 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -31,6 +31,8 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP } } + // TODO: ctx로 전체 플랜 가져온 후 동일한 farmer 주소의 epoch ratio 합이 1이 넘을경우 리턴 + return nil } @@ -93,11 +95,6 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq // UpdatePublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed. func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.UpdateRequestProposal) error { for _, proposal := range proposals { - plan, found := k.GetPlan(ctx, proposal.GetPlanId()) - if !found { - return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", proposal.GetPlanId()) - } - plans := k.GetAllPlans(ctx) for _, plan := range plans { if plan.(*types.BasePlan).Name == proposal.Name { @@ -105,35 +102,52 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd } } - farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetFarmingPoolAddress()) - if err != nil { - return err - } - - terminationAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetTerminationAddress()) - if err != nil { - return err + plan, found := k.GetPlan(ctx, proposal.GetPlanId()) + if !found { + return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", proposal.GetPlanId()) } switch p := plan.(type) { case *types.FixedAmountPlan: - if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { - return err + if proposal.GetFarmingPoolAddress() != "" { + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetFarmingPoolAddress()) + if err != nil { + return err + } + if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { + return err + } } - if err := p.SetTerminationAddress(terminationAddrAcc); err != nil { - return err + if proposal.GetTerminationAddress() != "" { + terminationAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetTerminationAddress()) + if err != nil { + return err + } + if err := p.SetTerminationAddress(terminationAddrAcc); err != nil { + return err + } } - if err := p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()); err != nil { - return err + if proposal.GetStakingCoinWeights() != nil { + if err := p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()); err != nil { + return err + } } - if err := p.SetStartTime(proposal.GetStartTime()); err != nil { - return err + if proposal.GetStartTime() != nil { + if err := p.SetStartTime(*proposal.GetStartTime()); err != nil { + return err + } } - if err := p.SetEndTime(proposal.GetStartTime()); err != nil { - return err + if proposal.GetEndTime() != nil { + if err := p.SetEndTime(*proposal.GetEndTime()); err != nil { + return err + } + } + if proposal.GetName() != "" { + p.Name = proposal.GetName() + } + if proposal.GetEpochAmount() != nil { + p.EpochAmount = proposal.GetEpochAmount() } - p.Name = proposal.GetName() - p.EpochAmount = proposal.GetEpochAmount() k.SetPlan(ctx, p) @@ -141,23 +155,45 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd logger.Info("updated public fixed amount plan", "fixed_amount_plan", plan) case *types.RatioPlan: - if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { - return err + if proposal.GetFarmingPoolAddress() != "" { + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetFarmingPoolAddress()) + if err != nil { + return err + } + if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { + return err + } } - if err := p.SetTerminationAddress(terminationAddrAcc); err != nil { - return err + if proposal.GetTerminationAddress() != "" { + terminationAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetTerminationAddress()) + if err != nil { + return err + } + if err := p.SetTerminationAddress(terminationAddrAcc); err != nil { + return err + } } - if err := p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()); err != nil { - return err + if proposal.GetStakingCoinWeights() != nil { + if err := p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()); err != nil { + return err + } } - if err := p.SetStartTime(proposal.GetStartTime()); err != nil { - return err + if proposal.GetStartTime() != nil { + if err := p.SetStartTime(*proposal.GetStartTime()); err != nil { + return err + } } - if err := p.SetEndTime(proposal.GetStartTime()); err != nil { - return err + if proposal.GetEndTime() != nil { + if err := p.SetEndTime(*proposal.GetEndTime()); err != nil { + return err + } + } + if proposal.GetName() != "" { + p.Name = proposal.GetName() + } + if !proposal.EpochRatio.IsNil() { + p.EpochRatio = proposal.EpochRatio } - p.Name = proposal.GetName() - p.EpochRatio = proposal.EpochRatio k.SetPlan(ctx, p) diff --git a/x/farming/types/msgs.go b/x/farming/types/msgs.go index c2de5b85..5ff5ffd9 100644 --- a/x/farming/types/msgs.go +++ b/x/farming/types/msgs.go @@ -129,6 +129,9 @@ func (msg MsgCreateRatioPlan) ValidateBasic() error { if !msg.EpochRatio.IsPositive() { return ErrInvalidPlanEpochRatio } + if msg.EpochRatio.GT(sdk.NewDec(1)) { + return ErrInvalidPlanEpochRatio + } return nil } diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 48e1ebd1..d5ca893c 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -109,7 +109,7 @@ func (p *UpdateRequestProposal) Validate() error { if err := p.StakingCoinWeights.Validate(); err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid staking coin weights: %v", err) } - if !p.EndTime.After(p.StartTime) { + if !p.EndTime.After(*p.StartTime) { return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", p.EndTime, p.StartTime) } if !p.EpochAmount.Empty() && !p.EpochRatio.IsZero() { diff --git a/x/farming/types/proposal.pb.go b/x/farming/types/proposal.pb.go index 57f8c3b6..404ad278 100644 --- a/x/farming/types/proposal.pb.go +++ b/x/farming/types/proposal.pb.go @@ -32,7 +32,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // PublicPlanProposal defines a public farming plan governance proposal that receives one of the following requests: // A request that creates a public farming plan, a request that updates the plan, and a request that deletes the plan. -// For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed amount plan or ratio plan. +// For public plan creation, depending on which field is passed, either epoch amount or epoch ratio, it creates a fixed +// amount plan or ratio plan. type PublicPlanProposal struct { // title specifies the title of the plan Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` @@ -197,9 +198,9 @@ type UpdateRequestProposal struct { // staking_coin_weights specifies coin weights for the plan StakingCoinWeights github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,5,rep,name=staking_coin_weights,json=stakingCoinWeights,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"staking_coin_weights" yaml:"staking_coin_weights"` // start_time specifies the start time of the plan - StartTime time.Time `protobuf:"bytes,6,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` + StartTime *time.Time `protobuf:"bytes,6,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time,omitempty" yaml:"start_time"` // end_time specifies the end time of the plan - EndTime time.Time `protobuf:"bytes,7,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"` + EndTime *time.Time `protobuf:"bytes,7,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time,omitempty" yaml:"end_time"` // epoch_amount specifies the distributing amount for each epoch EpochAmount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,8,rep,name=epoch_amount,json=epochAmount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"epoch_amount" yaml:"epoch_amount"` // epoch_ratio specifies the distributing amount by ratio @@ -274,18 +275,18 @@ func (m *UpdateRequestProposal) GetStakingCoinWeights() github_com_cosmos_cosmos return nil } -func (m *UpdateRequestProposal) GetStartTime() time.Time { +func (m *UpdateRequestProposal) GetStartTime() *time.Time { if m != nil { return m.StartTime } - return time.Time{} + return nil } -func (m *UpdateRequestProposal) GetEndTime() time.Time { +func (m *UpdateRequestProposal) GetEndTime() *time.Time { if m != nil { return m.EndTime } - return time.Time{} + return nil } func (m *UpdateRequestProposal) GetEpochAmount() github_com_cosmos_cosmos_sdk_types.Coins { @@ -353,55 +354,56 @@ func init() { } var fileDescriptor_4719b03c30c7910a = []byte{ - // 765 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4f, 0x4f, 0xdb, 0x3c, - 0x1c, 0x6e, 0xe8, 0x5f, 0xdc, 0x57, 0x7a, 0xf5, 0x9a, 0xc2, 0x5b, 0x0a, 0x4b, 0xaa, 0x4c, 0x9a, - 0x3a, 0x4d, 0x24, 0x83, 0xdd, 0xb8, 0xd1, 0x21, 0xa1, 0x9d, 0xd6, 0x45, 0x9b, 0x36, 0xed, 0x12, - 0xb9, 0xb5, 0x29, 0x11, 0x49, 0x9c, 0xc5, 0xee, 0x36, 0xce, 0xdb, 0xa4, 0x9d, 0x26, 0x8e, 0x3b, - 0xa2, 0x1d, 0xf9, 0x24, 0x1c, 0x39, 0x4e, 0x3b, 0x94, 0x09, 0xbe, 0x41, 0x3f, 0xc1, 0x14, 0xdb, - 0x29, 0xd5, 0x48, 0x81, 0x03, 0x48, 0x9c, 0xe2, 0x9f, 0xfd, 0x7b, 0x1e, 0x3f, 0x7e, 0xec, 0x07, - 0x0a, 0x1e, 0x72, 0x12, 0x62, 0x12, 0x07, 0x5e, 0xc8, 0xed, 0x6d, 0x94, 0x7c, 0xfb, 0xf6, 0xfb, - 0xd5, 0x2e, 0xe1, 0x68, 0xd5, 0x8e, 0x62, 0x1a, 0x51, 0x86, 0x7c, 0x2b, 0x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0x32, - 0x73, 0x8d, 0xb0, 0xe4, 0x6f, 0x3c, 0x2c, 0x85, 0x9b, 0x0f, 0x4b, 0xf1, 0xce, 0x86, 0xa5, 0x74, - 0x4b, 0x61, 0x29, 0xdf, 0x56, 0x58, 0x2a, 0x77, 0x22, 0x2c, 0xb3, 0xb7, 0x14, 0x96, 0xc7, 0x60, - 0x3e, 0xf3, 0xbf, 0xd3, 0xd4, 0xac, 0xb4, 0xb7, 0x8e, 0x4e, 0x75, 0xed, 0xf8, 0x54, 0xd7, 0x7e, - 0x9f, 0xea, 0xda, 0xfe, 0x99, 0x9e, 0x3b, 0x3e, 0xd3, 0x73, 0x3f, 0xcf, 0xf4, 0xdc, 0xdb, 0x95, - 0x09, 0x55, 0x19, 0xbf, 0x72, 0x3e, 0x8e, 0x47, 0x42, 0x60, 0xb7, 0x24, 0xee, 0xe8, 0xc9, 0x9f, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xf1, 0x6e, 0x1e, 0xce, 0xaa, 0x09, 0x00, 0x00, + // 773 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4f, 0x4f, 0xdb, 0x48, + 0x1c, 0x8d, 0xc9, 0x5f, 0x26, 0x2b, 0xad, 0x76, 0x08, 0x6c, 0x08, 0xac, 0x1d, 0x79, 0xa5, 0x55, + 0x56, 0x2b, 0xec, 0x85, 0xde, 0xb8, 0x91, 0x22, 0xa1, 0x9e, 0x9a, 0x5a, 0xad, 0x5a, 0xf5, 0x62, + 0x4d, 0x32, 0x43, 0xb0, 0xb0, 0x3d, 0xae, 0x67, 0xd2, 0x96, 0x73, 0x5b, 0xa9, 0xa7, 0x8a, 0x63, + 0x8f, 0xa8, 0x47, 0x3e, 0x09, 0x47, 0x8e, 0x55, 0x0f, 0xa1, 0x82, 0x6f, 0x90, 0x4f, 0x50, 0x79, + 0x66, 0x1c, 0xa2, 0xe2, 0x40, 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93, 0xb5, 0x85, 0xb1, 0x23, 0x71, + 0xa9, 0x8e, 0x76, 0x73, 0x34, 0x34, 0x56, 0x0f, 0x50, 0xe0, 0x6f, 0x9a, 0x99, 0xb4, 0xa6, 0xb3, + 0x80, 0xae, 0xa0, 0x18, 0x3c, 0xd4, 0x40, 0x7d, 0x10, 0x61, 0xc4, 0x49, 0x86, 0x92, 0x82, 0x50, + 0xb2, 0x7e, 0x9d, 0x92, 0x67, 0x02, 0xfb, 0xb3, 0x98, 0xbf, 0x47, 0x43, 0xc3, 0x90, 0x62, 0xa6, + 0x91, 0x9b, 0xce, 0xd2, 0x20, 0x0b, 0x2b, 0x25, 0x61, 0xe2, 0x93, 0x4c, 0x49, 0xc5, 0x9b, 0x25, + 0x6d, 0x0b, 0xec, 0x35, 0x92, 0xa6, 0x91, 0x9b, 0xce, 0x12, 0xce, 0xc2, 0xb2, 0xcd, 0xca, 0xc7, + 0x23, 0x23, 0xf7, 0xf9, 0xc8, 0xc8, 0x99, 0x9f, 0x4a, 0x00, 0x5e, 0x75, 0x1f, 0x42, 0x50, 0x08, + 0x51, 0x90, 0x3e, 0x02, 0x31, 0x86, 0x4f, 0x40, 0x4d, 0x49, 0x73, 0x23, 0x4a, 0x7d, 0x17, 0x61, + 0x1c, 0x13, 0xc6, 0xe4, 0x63, 0x68, 0x1b, 0xa3, 0xa1, 0xb1, 0x22, 0xf5, 0x64, 0x75, 0x99, 0x0e, + 0x54, 0xd3, 0x1d, 0x4a, 0xfd, 0x2d, 0x39, 0x09, 0x1f, 0x83, 0x05, 0x2e, 0x4e, 0x8d, 0x92, 0x37, + 0x34, 0x66, 0xcc, 0x0b, 0x46, 0x7d, 0x34, 0x34, 0x1a, 0x92, 0x31, 0xa3, 0xc9, 0x74, 0xe0, 0xc4, + 0x6c, 0x4a, 0xf8, 0x45, 0x03, 0x35, 0xc6, 0xd1, 0x7e, 0xb2, 0x7d, 0x12, 0x1b, 0xf7, 0x0d, 0xf1, + 0xfa, 0x7b, 0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fe, 0x99, 0xed, 0x4e, 0x46, 0x43, 0x03, 0x4e, + 0x8a, 0x12, 0x54, 0xa6, 0x03, 0x44, 0xe5, 0x88, 0xe2, 0xb8, 0x04, 0x16, 0x33, 0xff, 0x08, 0xc0, + 0x3f, 0x41, 0x39, 0xf2, 0x51, 0xe8, 0x7a, 0x58, 0xc4, 0xa2, 0xe0, 0x94, 0x92, 0xf2, 0x11, 0x1e, + 0x87, 0x65, 0x6e, 0x86, 0xb0, 0xe4, 0xef, 0x3c, 0x2c, 0x85, 0xbb, 0x0f, 0x4b, 0xf1, 0xde, 0x86, + 0xa5, 0x34, 0x53, 0x58, 0xb4, 0x5b, 0x87, 0xa5, 0x3c, 0x53, 0x58, 0xb4, 0xdb, 0x87, 0xa5, 0x72, + 0x2f, 0xc2, 0x32, 0xff, 0x8b, 0xc2, 0xf2, 0x3f, 0x58, 0xcc, 0xfc, 0xef, 0x34, 0x35, 0x2b, 0xed, + 0x9d, 0x93, 0x73, 0x5d, 0x3b, 0x3d, 0xd7, 0xb5, 0xef, 0xe7, 0xba, 0x76, 0x78, 0xa1, 0xe7, 0x4e, + 0x2f, 0xf4, 0xdc, 0xd7, 0x0b, 0x3d, 0xf7, 0x72, 0x6d, 0x42, 0x55, 0xc6, 0xaf, 0x9c, 0xb7, 0xe3, + 0x91, 0x10, 0xd8, 0x2d, 0x89, 0x3b, 0x7a, 0xf0, 0x23, 0x00, 0x00, 0xff, 0xff, 0x06, 0x3e, 0x94, + 0x84, 0xaa, 0x09, 0x00, 0x00, } func (m *PublicPlanProposal) Marshal() (dAtA []byte, err error) { @@ -625,22 +627,26 @@ func (m *UpdateRequestProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x42 } } - n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):]) - if err3 != nil { - return 0, err3 + if m.EndTime != nil { + n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(*m.EndTime):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintProposal(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x3a } - i -= n3 - i = encodeVarintProposal(dAtA, i, uint64(n3)) - i-- - dAtA[i] = 0x3a - n4, err4 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime):]) - if err4 != nil { - return 0, err4 + if m.StartTime != nil { + n4, err4 := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.StartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(*m.StartTime):]) + if err4 != nil { + return 0, err4 + } + i -= n4 + i = encodeVarintProposal(dAtA, i, uint64(n4)) + i-- + dAtA[i] = 0x32 } - i -= n4 - i = encodeVarintProposal(dAtA, i, uint64(n4)) - i-- - dAtA[i] = 0x32 if len(m.StakingCoinWeights) > 0 { for iNdEx := len(m.StakingCoinWeights) - 1; iNdEx >= 0; iNdEx-- { { @@ -824,10 +830,14 @@ func (m *UpdateRequestProposal) Size() (n int) { n += 1 + l + sovProposal(uint64(l)) } } - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.StartTime) - n += 1 + l + sovProposal(uint64(l)) - l = github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime) - n += 1 + l + sovProposal(uint64(l)) + if m.StartTime != nil { + l = github_com_gogo_protobuf_types.SizeOfStdTime(*m.StartTime) + n += 1 + l + sovProposal(uint64(l)) + } + if m.EndTime != nil { + l = github_com_gogo_protobuf_types.SizeOfStdTime(*m.EndTime) + n += 1 + l + sovProposal(uint64(l)) + } if len(m.EpochAmount) > 0 { for _, e := range m.EpochAmount { l = e.Size() @@ -1594,7 +1604,10 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.StartTime, dAtA[iNdEx:postIndex]); err != nil { + if m.StartTime == nil { + m.StartTime = new(time.Time) + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(m.StartTime, dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1627,7 +1640,10 @@ func (m *UpdateRequestProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.EndTime, dAtA[iNdEx:postIndex]); err != nil { + if m.EndTime == nil { + m.EndTime = new(time.Time) + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(m.EndTime, dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex From 0a48a98f19c2d46bf9123fcff4e48d1db4a89f98 Mon Sep 17 00:00:00 2001 From: kogisin Date: Thu, 29 Jul 2021 18:35:21 +0900 Subject: [PATCH 35/39] feat: adding validation logic for an epoch ratio must not exceed 1 with the same account --- x/farming/keeper/proposal_handler.go | 38 ++++++++++++++++++++-------- x/farming/types/plan.go | 22 ++++++++++++++++ x/farming/types/proposal.go | 3 +++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 4e016e20..3eed3baf 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -31,7 +31,12 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP } } - // TODO: ctx로 전체 플랜 가져온 후 동일한 farmer 주소의 epoch ratio 합이 1이 넘을경우 리턴 + // make sure that a single account cannot create plans that exceeds + // a total epoch ratio of 1 (100%) for farming distribution + plans := k.GetAllPlans(ctx) + if err := types.ValidatePlans(plans); err != nil { + return err + } return nil } @@ -39,11 +44,8 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP // AddPublicPlanProposal adds a new public plan once the governance proposal is passed. func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddRequestProposal) error { for _, p := range proposals { - plans := k.GetAllPlans(ctx) - for _, plan := range plans { - if plan.(*types.BasePlan).Name == p.Name { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", p.Name) - } + if err := k.ValidatePlanName(ctx, p.Name); err != nil { + return err } farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) @@ -95,11 +97,8 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq // UpdatePublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed. func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.UpdateRequestProposal) error { for _, proposal := range proposals { - plans := k.GetAllPlans(ctx) - for _, plan := range plans { - if plan.(*types.BasePlan).Name == proposal.Name { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", proposal.Name) - } + if err := k.ValidatePlanName(ctx, proposal.Name); err != nil { + return err } plan, found := k.GetPlan(ctx, proposal.GetPlanId()) @@ -224,3 +223,20 @@ func (k Keeper) DeletePublicPlanProposal(ctx sdk.Context, proposals []*types.Del return nil } + +func (k Keeper) ValidatePlanName(ctx sdk.Context, name string) error { + plans := k.GetAllPlans(ctx) + for _, plan := range plans { + if plan, ok := plan.(*types.FixedAmountPlan); ok { + if plan.Name == name { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", name) + } + } + if plan, ok := plan.(*types.RatioPlan); ok { + if plan.Name == name { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", name) + } + } + } + return nil +} diff --git a/x/farming/types/plan.go b/x/farming/types/plan.go index 90c57f0a..93be0c22 100644 --- a/x/farming/types/plan.go +++ b/x/farming/types/plan.go @@ -1,6 +1,7 @@ package types import ( + fmt "fmt" "strconv" "strings" "time" @@ -212,3 +213,24 @@ type PlanI interface { String() string } + +func ValidatePlans(plans []PlanI) error { + farmerEpochRatio := make(map[string]sdk.Dec) // farmingPoolAddr, epochRatio + + for i, plan := range plans { + if _, ok := plan.(*RatioPlan); ok { + farmingPoolAddr := plan.GetFarmingPoolAddress().String() + farmerEpochRatio[farmingPoolAddr] = plan.(*RatioPlan).EpochRatio + + fmt.Println(">>> i: ", i) + fmt.Println(">>> farmingPoolAddr: ", farmingPoolAddr) + fmt.Println(">>> farmerEpochRatio[farmingPoolAddr]: ", farmerEpochRatio[farmingPoolAddr]) + fmt.Println(">>> farmerEpochRatio: ", farmerEpochRatio) + + if farmerEpochRatio[farmingPoolAddr].GT(sdk.NewDec(1)) { + return sdkerrors.Wrapf(ErrInvalidPlanEpochRatio, "total epoch ratio for %s must be lower than 1", farmingPoolAddr) + } + } + } + return nil +} diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index d5ca893c..b446771f 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -43,16 +43,19 @@ func (p *PublicPlanProposal) ValidateBasic() error { if p.AddRequestProposals == nil && p.UpdateRequestProposals == nil && p.DeleteRequestProposals == nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proposal request must not be empty") } + for _, ap := range p.AddRequestProposals { if err := ap.Validate(); err != nil { return err } } + for _, up := range p.UpdateRequestProposals { if err := up.Validate(); err != nil { return err } } + for _, dp := range p.DeleteRequestProposals { if err := dp.Validate(); err != nil { return err From bfe2ece8a3e66d8fbe17121469cacceb56e08d45 Mon Sep 17 00:00:00 2001 From: kogisin Date: Fri, 30 Jul 2021 10:51:52 +0900 Subject: [PATCH 36/39] feat: add validation logic for overflow epoch ratio --- x/farming/keeper/proposal_handler.go | 128 +++++++++++++-------------- x/farming/types/plan.go | 49 +++++++--- 2 files changed, 99 insertions(+), 78 deletions(-) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 3eed3baf..c85f2ff1 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -31,20 +31,15 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP } } - // make sure that a single account cannot create plans that exceeds - // a total epoch ratio of 1 (100%) for farming distribution - plans := k.GetAllPlans(ctx) - if err := types.ValidatePlans(plans); err != nil { - return err - } - return nil } // AddPublicPlanProposal adds a new public plan once the governance proposal is passed. func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddRequestProposal) error { + plans := k.GetAllPlans(ctx) + for _, p := range proposals { - if err := k.ValidatePlanName(ctx, p.Name); err != nil { + if err := types.ValidatePlanName(plans, p.Name); err != nil { return err } @@ -72,6 +67,10 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq logger.Info("created public fixed amount plan", "fixed_amount_plan", plan) } else if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNil() && !p.EpochRatio.IsNegative() { + if err := types.ValidateOverflowEpochRatio(plans, p.FarmingPoolAddress, p.EpochRatio); err != nil { + return err + } + msg := types.NewMsgCreateRatioPlan( p.GetName(), farmingPoolAddrAcc, @@ -96,105 +95,123 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq // UpdatePublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed. func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.UpdateRequestProposal) error { - for _, proposal := range proposals { - if err := k.ValidatePlanName(ctx, proposal.Name); err != nil { + plans := k.GetAllPlans(ctx) + + for _, p := range proposals { + if err := types.ValidatePlanName(plans, p.Name); err != nil { return err } - plan, found := k.GetPlan(ctx, proposal.GetPlanId()) + plan, found := k.GetPlan(ctx, p.GetPlanId()) if !found { - return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", proposal.GetPlanId()) + return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", p.GetPlanId()) } - switch p := plan.(type) { + switch plan := plan.(type) { case *types.FixedAmountPlan: - if proposal.GetFarmingPoolAddress() != "" { - farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetFarmingPoolAddress()) + if p.GetFarmingPoolAddress() != "" { + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { return err } - if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { + if err := plan.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { return err } } - if proposal.GetTerminationAddress() != "" { - terminationAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetTerminationAddress()) + + if p.GetTerminationAddress() != "" { + terminationAddrAcc, err := sdk.AccAddressFromBech32(p.GetTerminationAddress()) if err != nil { return err } - if err := p.SetTerminationAddress(terminationAddrAcc); err != nil { + if err := plan.SetTerminationAddress(terminationAddrAcc); err != nil { return err } } - if proposal.GetStakingCoinWeights() != nil { - if err := p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()); err != nil { + + if p.GetStakingCoinWeights() != nil { + if err := plan.SetStakingCoinWeights(p.GetStakingCoinWeights()); err != nil { return err } } - if proposal.GetStartTime() != nil { - if err := p.SetStartTime(*proposal.GetStartTime()); err != nil { + + if p.GetStartTime() != nil { + if err := plan.SetStartTime(*p.GetStartTime()); err != nil { return err } } - if proposal.GetEndTime() != nil { - if err := p.SetEndTime(*proposal.GetEndTime()); err != nil { + + if p.GetEndTime() != nil { + if err := plan.SetEndTime(*p.GetEndTime()); err != nil { return err } } - if proposal.GetName() != "" { - p.Name = proposal.GetName() + + if p.GetName() != "" { + plan.Name = p.GetName() } - if proposal.GetEpochAmount() != nil { - p.EpochAmount = proposal.GetEpochAmount() + + if p.GetEpochAmount() != nil { + plan.EpochAmount = p.GetEpochAmount() } - k.SetPlan(ctx, p) + k.SetPlan(ctx, plan) logger := k.Logger(ctx) logger.Info("updated public fixed amount plan", "fixed_amount_plan", plan) case *types.RatioPlan: - if proposal.GetFarmingPoolAddress() != "" { - farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetFarmingPoolAddress()) + if err := types.ValidateOverflowEpochRatio(plans, p.FarmingPoolAddress, p.EpochRatio); err != nil { + return err + } + + if p.GetFarmingPoolAddress() != "" { + farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { return err } - if err := p.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { + if err := plan.SetFarmingPoolAddress(farmingPoolAddrAcc); err != nil { return err } } - if proposal.GetTerminationAddress() != "" { - terminationAddrAcc, err := sdk.AccAddressFromBech32(proposal.GetTerminationAddress()) + + if p.GetTerminationAddress() != "" { + terminationAddrAcc, err := sdk.AccAddressFromBech32(p.GetTerminationAddress()) if err != nil { return err } - if err := p.SetTerminationAddress(terminationAddrAcc); err != nil { + if err := plan.SetTerminationAddress(terminationAddrAcc); err != nil { return err } } - if proposal.GetStakingCoinWeights() != nil { - if err := p.SetStakingCoinWeights(proposal.GetStakingCoinWeights()); err != nil { + + if p.GetStakingCoinWeights() != nil { + if err := plan.SetStakingCoinWeights(p.GetStakingCoinWeights()); err != nil { return err } } - if proposal.GetStartTime() != nil { - if err := p.SetStartTime(*proposal.GetStartTime()); err != nil { + + if p.GetStartTime() != nil { + if err := plan.SetStartTime(*p.GetStartTime()); err != nil { return err } } - if proposal.GetEndTime() != nil { - if err := p.SetEndTime(*proposal.GetEndTime()); err != nil { + + if p.GetEndTime() != nil { + if err := plan.SetEndTime(*p.GetEndTime()); err != nil { return err } } - if proposal.GetName() != "" { - p.Name = proposal.GetName() + + if p.GetName() != "" { + plan.Name = p.GetName() } - if !proposal.EpochRatio.IsNil() { - p.EpochRatio = proposal.EpochRatio + + if !p.EpochRatio.IsZero() { + plan.EpochRatio = p.EpochRatio } - k.SetPlan(ctx, p) + k.SetPlan(ctx, plan) logger := k.Logger(ctx) logger.Info("updated public ratio plan", "ratio_plan", plan) @@ -223,20 +240,3 @@ func (k Keeper) DeletePublicPlanProposal(ctx sdk.Context, proposals []*types.Del return nil } - -func (k Keeper) ValidatePlanName(ctx sdk.Context, name string) error { - plans := k.GetAllPlans(ctx) - for _, plan := range plans { - if plan, ok := plan.(*types.FixedAmountPlan); ok { - if plan.Name == name { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", name) - } - } - if plan, ok := plan.(*types.RatioPlan); ok { - if plan.Name == name { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", name) - } - } - } - return nil -} diff --git a/x/farming/types/plan.go b/x/farming/types/plan.go index 93be0c22..7bda8b31 100644 --- a/x/farming/types/plan.go +++ b/x/farming/types/plan.go @@ -1,7 +1,6 @@ package types import ( - fmt "fmt" "strconv" "strings" "time" @@ -214,23 +213,45 @@ type PlanI interface { String() string } -func ValidatePlans(plans []PlanI) error { - farmerEpochRatio := make(map[string]sdk.Dec) // farmingPoolAddr, epochRatio +// ValidatePlanName validates if the plan name exists in store. +func ValidatePlanName(plans []PlanI, name string) error { + for _, plan := range plans { + switch p := plan.(type) { + case *FixedAmountPlan: + if p.Name == name { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", name) + } + case *RatioPlan: + if p.Name == name { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", name) + } + default: + return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized plan type: %T", p) + } + } + return nil +} - for i, plan := range plans { - if _, ok := plan.(*RatioPlan); ok { - farmingPoolAddr := plan.GetFarmingPoolAddress().String() - farmerEpochRatio[farmingPoolAddr] = plan.(*RatioPlan).EpochRatio +// ValidateOverflowEpochRatio validates that a single account cannot create ratio plans that exceeds +// a total epoch ratio of 1 (100%) because it will overflow the account's balance +func ValidateOverflowEpochRatio(plans []PlanI, farmingPoolAddr string, epochRatio sdk.Dec) error { + farmerEpochRatio := make(map[string]sdk.Dec) - fmt.Println(">>> i: ", i) - fmt.Println(">>> farmingPoolAddr: ", farmingPoolAddr) - fmt.Println(">>> farmerEpochRatio[farmingPoolAddr]: ", farmerEpochRatio[farmingPoolAddr]) - fmt.Println(">>> farmerEpochRatio: ", farmerEpochRatio) + for _, plan := range plans { + farmingPoolAddr := plan.GetFarmingPoolAddress().String() - if farmerEpochRatio[farmingPoolAddr].GT(sdk.NewDec(1)) { - return sdkerrors.Wrapf(ErrInvalidPlanEpochRatio, "total epoch ratio for %s must be lower than 1", farmingPoolAddr) - } + if plan, ok := plan.(*RatioPlan); ok { + farmerEpochRatio[farmingPoolAddr] = plan.EpochRatio + } + } + + if epochRatio, ok := farmerEpochRatio[farmingPoolAddr]; ok { + epochRatio = epochRatio.Add(epochRatio) + + if epochRatio.GT(sdk.NewDec(1)) { + return sdkerrors.Wrapf(ErrInvalidPlanEpochRatio, "total epoch ratio must be lower than 1") } } + return nil } From 8c7977936e87407f35a1448acf28ba0cdefc7d7e Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 2 Aug 2021 10:49:03 +0900 Subject: [PATCH 37/39] fix: add another if statement to check when both epoch amount and ratio are provided --- x/farming/types/proposal.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index b446771f..b4706bbc 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -90,8 +90,11 @@ func (p *AddRequestProposal) Validate() error { if !p.EndTime.After(p.StartTime) { return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", p.EndTime, p.StartTime) } - if !p.EpochAmount.Empty() && !p.EpochRatio.IsZero() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "epoch amount or epoch ratio must be provided") + if !p.EpochAmount.IsZero() && !p.EpochRatio.IsZero() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "either epoch amount or epoch ratio should be provided") + } + if p.EpochAmount.IsZero() && p.EpochRatio.IsZero() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "either epoch amount or epoch ratio must not be zero") } return nil } From f3abdf79f671fea160f563c7a2c76e27b0a184e9 Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 2 Aug 2021 14:24:35 +0900 Subject: [PATCH 38/39] chore: update public plan proposal logics - add validation logic for ratio plans - add test codes for the validation - clean up error messages --- x/farming/keeper/plan.go | 4 +- x/farming/keeper/proposal_handler.go | 28 ++++--------- x/farming/types/errors.go | 1 + x/farming/types/plan.go | 52 +++++++++++------------ x/farming/types/plan_test.go | 63 ++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 50 deletions(-) diff --git a/x/farming/keeper/plan.go b/x/farming/keeper/plan.go index 88b6c1f1..c5deec59 100644 --- a/x/farming/keeper/plan.go +++ b/x/farming/keeper/plan.go @@ -174,7 +174,7 @@ func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixed balances := k.bankKeeper.GetAllBalances(ctx, farmingPoolAddrAcc) diffs, hasNeg := balances.SafeSub(params.PrivatePlanCreationFee) if hasNeg { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s requires %s more coins to pay private plan createion fee", msg.FarmingPoolAddress, diffs.String()) + return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "lack of %s coins to pay private plan createion fee", diffs.String()) } farmingFeeCollectorAcc, err := sdk.AccAddressFromBech32(params.FarmingFeeCollector) @@ -229,7 +229,7 @@ func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, balances := k.bankKeeper.GetAllBalances(ctx, farmingPoolAddrAcc) diffs, hasNeg := balances.SafeSub(params.PrivatePlanCreationFee) if hasNeg { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s requires %s more coins to pay private plan createion fee", msg.FarmingPoolAddress, diffs.String()) + return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "lack of %s coins to pay private plan createion fee", diffs.String()) } farmingFeeCollectorAcc, err := sdk.AccAddressFromBech32(params.FarmingFeeCollector) diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 6ce998d2..61980b69 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -31,18 +31,17 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP } } + plans := k.GetAllPlans(ctx) + if err := types.ValidateRatioPlans(plans); err != nil { + return err + } + return nil } // AddPublicPlanProposal adds a new public plan once the governance proposal is passed. func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddRequestProposal) error { - plans := k.GetAllPlans(ctx) - for _, p := range proposals { - if err := types.ValidatePlanName(plans, p.Name); err != nil { - return err - } - farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { return err @@ -57,6 +56,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq p.GetEndTime(), p.EpochAmount, ) + plan, err := k.CreateFixedAmountPlan(ctx, msg, types.PlanTypePublic) if err != nil { return err @@ -65,11 +65,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq logger := k.Logger(ctx) logger.Info("created public fixed amount plan", "fixed_amount_plan", plan) - } else if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNil() && !p.EpochRatio.IsNegative() { - if err := types.ValidateOverflowEpochRatio(plans, p.FarmingPoolAddress, p.EpochRatio); err != nil { - return err - } - + } else if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNegative() && !p.EpochRatio.IsNil() { msg := types.NewMsgCreateRatioPlan( p.GetName(), farmingPoolAddrAcc, @@ -94,13 +90,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq // UpdatePublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed. func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.UpdateRequestProposal) error { - plans := k.GetAllPlans(ctx) - for _, p := range proposals { - if err := types.ValidatePlanName(plans, p.Name); err != nil { - return err - } - plan, found := k.GetPlan(ctx, p.GetPlanId()) if !found { return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", p.GetPlanId()) @@ -160,10 +150,6 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd logger.Info("updated public fixed amount plan", "fixed_amount_plan", plan) case *types.RatioPlan: - if err := types.ValidateOverflowEpochRatio(plans, p.FarmingPoolAddress, p.EpochRatio); err != nil { - return err - } - if p.GetFarmingPoolAddress() != "" { farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { diff --git a/x/farming/types/errors.go b/x/farming/types/errors.go index ace04131..e847d718 100644 --- a/x/farming/types/errors.go +++ b/x/farming/types/errors.go @@ -16,4 +16,5 @@ var ( ErrRewardNotExists = sdkerrors.Register(ModuleName, 9, "reward not exists") ErrFeeCollectionFailure = sdkerrors.Register(ModuleName, 10, "fee collection failure") ErrInvalidNameLength = sdkerrors.Register(ModuleName, 11, "invalid name length") + ErrDuplicatePlanName = sdkerrors.Register(ModuleName, 12, "duplicate plan name") ) diff --git a/x/farming/types/plan.go b/x/farming/types/plan.go index 7bda8b31..174af92c 100644 --- a/x/farming/types/plan.go +++ b/x/farming/types/plan.go @@ -213,43 +213,41 @@ type PlanI interface { String() string } -// ValidatePlanName validates if the plan name exists in store. -func ValidatePlanName(plans []PlanI, name string) error { - for _, plan := range plans { - switch p := plan.(type) { - case *FixedAmountPlan: - if p.Name == name { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", name) - } - case *RatioPlan: - if p.Name == name { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "plan name '%s' already exists", name) - } - default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized plan type: %T", p) - } +// ValidateRatioPlans validates a farmer's total epoch ratio and plan name. +// A total epoch ratio cannot be higher than 1 and plan name must not be duplicate. +func ValidateRatioPlans(i interface{}) error { + plans, ok := i.([]PlanI) + if !ok { + return sdkerrors.Wrapf(ErrInvalidPlanType, "invalid plan type %T", i) } - return nil -} -// ValidateOverflowEpochRatio validates that a single account cannot create ratio plans that exceeds -// a total epoch ratio of 1 (100%) because it will overflow the account's balance -func ValidateOverflowEpochRatio(plans []PlanI, farmingPoolAddr string, epochRatio sdk.Dec) error { - farmerEpochRatio := make(map[string]sdk.Dec) + totalEpochRatio := make(map[string]sdk.Dec) + names := make(map[string]bool) for _, plan := range plans { farmingPoolAddr := plan.GetFarmingPoolAddress().String() if plan, ok := plan.(*RatioPlan); ok { - farmerEpochRatio[farmingPoolAddr] = plan.EpochRatio + if err := plan.Validate(); err != nil { + return err + } + + if epochRatio, ok := totalEpochRatio[farmingPoolAddr]; ok { + totalEpochRatio[farmingPoolAddr] = epochRatio.Add(plan.EpochRatio) + } else { + totalEpochRatio[farmingPoolAddr] = plan.EpochRatio + } + + if _, ok := names[plan.Name]; ok { + return sdkerrors.Wrap(ErrDuplicatePlanName, plan.Name) + } + names[plan.Name] = true } } - if epochRatio, ok := farmerEpochRatio[farmingPoolAddr]; ok { - epochRatio = epochRatio.Add(epochRatio) - - if epochRatio.GT(sdk.NewDec(1)) { - return sdkerrors.Wrapf(ErrInvalidPlanEpochRatio, "total epoch ratio must be lower than 1") + for _, farmerRatio := range totalEpochRatio { + if farmerRatio.GT(sdk.NewDec(1)) { + return sdkerrors.Wrap(ErrInvalidPlanEpochRatio, "total epoch ratio must be lower than 1") } } diff --git a/x/farming/types/plan_test.go b/x/farming/types/plan_test.go index 41da5893..9e83aa93 100644 --- a/x/farming/types/plan_test.go +++ b/x/farming/types/plan_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/farming/x/farming/types" ) @@ -46,3 +47,65 @@ func TestGetPoolInformation(t *testing.T) { require.Equal(t, basePlan.RewardPoolAddress, rewardPoolAcc.String()) } } + +func TestRatioPlans(t *testing.T) { + name1 := "testPlan1" + name2 := "testPlan2" + farmingPoolAddr1 := sdk.AccAddress("farmingPoolAddr1") + terminationAddr1 := sdk.AccAddress("terminationAddr1") + stakingCoinWeights := sdk.NewDecCoins( + sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")}, + ) + startTime := time.Now().UTC() + endTime := startTime.AddDate(1, 0, 0) + + testCases := []struct { + plans []types.PlanI + expectedErr error + }{ + { + []types.PlanI{ + types.NewRatioPlan( + types.NewBasePlan(1, name1, 1, farmingPoolAddr1.String(), terminationAddr1.String(), stakingCoinWeights, startTime, endTime), + sdk.NewDec(1), + ), + }, + nil, + }, + { + []types.PlanI{ + types.NewRatioPlan( + types.NewBasePlan(1, name1, 1, farmingPoolAddr1.String(), terminationAddr1.String(), stakingCoinWeights, startTime, endTime), + sdk.NewDec(1), + ), + types.NewRatioPlan( + types.NewBasePlan(1, name1, 1, farmingPoolAddr1.String(), terminationAddr1.String(), stakingCoinWeights, startTime, endTime), + sdk.NewDec(1), + ), + }, + sdkerrors.Wrap(types.ErrDuplicatePlanName, name1), + }, + { + []types.PlanI{ + types.NewRatioPlan( + types.NewBasePlan(1, name1, 1, farmingPoolAddr1.String(), terminationAddr1.String(), stakingCoinWeights, startTime, endTime), + sdk.NewDec(1), + ), + types.NewRatioPlan( + types.NewBasePlan(1, name2, 1, farmingPoolAddr1.String(), terminationAddr1.String(), stakingCoinWeights, startTime, endTime), + sdk.NewDec(1), + ), + }, + sdkerrors.Wrap(types.ErrInvalidPlanEpochRatio, "total epoch ratio must be lower than 1"), + }, + } + + for _, tc := range testCases { + err := types.ValidateRatioPlans(tc.plans) + if tc.expectedErr == nil { + require.NoError(t, err) + } else { + require.Equal(t, tc.expectedErr.Error(), err.Error()) + } + } +} From d707cfd6a9cefb1e1724c37717ed4df8bff2be19 Mon Sep 17 00:00:00 2001 From: kogisin Date: Mon, 2 Aug 2021 15:12:39 +0900 Subject: [PATCH 39/39] docs: add command-line interfaces and update context --- docs/How-To/farming_plans.md | 173 +++++++++++++++++++++++++++++++---- 1 file changed, 153 insertions(+), 20 deletions(-) diff --git a/docs/How-To/farming_plans.md b/docs/How-To/farming_plans.md index 5e6fcb8c..754322f8 100644 --- a/docs/How-To/farming_plans.md +++ b/docs/How-To/farming_plans.md @@ -1,8 +1,8 @@ # Farming Plans -There are two different types of farming plans in the farming module. Where as a public farming plan can only be created through governance proposal, a private farming plan can be created with any account. The plan creator's account is used as distributing account FarmingPoolAddress that will be distributed to farmers automatically. +There are two different types of farming plans in the farming module. Whereas a public farming plan can only be created through governance proposal, a private farming plan can be created with any account or an entity. Read [spec](https://github.com/tendermint/farming/blob/master/x/farming/spec/01_concepts.md) documentation for more information about the plan types. -In this documentation, there are sample data provided in JSON structure that are needed to test the functionality by using farming command line interfaces. +In this tutorial, some sample data in JSON structure are provided. We will use command-line interfaces to test the functionality. ## Table of Contetns @@ -16,6 +16,7 @@ In this documentation, there are sample data provided in JSON structure that are - [Private Farming Plan](#Private-Farming-Plan) * [PrivateFarmingFixedAmountPlan](#PrivateFarmingFixedAmountPlan) * [PrivateFarmingRatioPlan](#PrivateFarmingRatioPlan) +- [REST APIs](#REST-APIs) # Bootstrap @@ -57,16 +58,17 @@ $BINARY start ``` # Public Farming Plan - ## AddPublicFarmingFixedAmountPlan +Create `public-fixed-plan-proposal.json` file in your local directory and copy the below json into the file. + ```json { "title": "Public Farming Plan", "description": "Are you ready to farm?", "add_request_proposals": [ { - "name": "First Public Farming Plan", + "name": "First Public Fixed Amount Plan", "farming_pool_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", "termination_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", "staking_coin_weights": [ @@ -88,15 +90,36 @@ $BINARY start } ``` +```bash +# Create public fixed amount plan through governance proposal +farmingd tx gov submit-proposal public-farming-plan public-fixed-plan-proposal.json \ +--chain-id localnet \ +--from user1 \ +--keyring-backend test \ +--deposit 100000stake \ +--broadcast-mode block \ +--yes + +# Vote +# Make sure to change proposal-id for the proposal +farmingd tx gov vote yes \ +--chain-id localnet \ +--from val1 \ +--keyring-backend test \ +--yes +``` + ## AddPublicFarmingRatioPlan +Create `public-ratio-plan-proposal.json` file in your local directory and copy the below json into the file. + ```json { "title": "Public Farming Plan", "description": "Are you ready to farm?", "add_request_proposals": [ { - "name": "First Public Farming Plan", + "name": "First Public Ratio Plan", "farming_pool_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", "termination_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", "staking_coin_weights": [ @@ -113,15 +136,36 @@ $BINARY start } ``` +```bash +# Create public ratio plan through governance proposal +farmingd tx gov submit-proposal public-farming-plan public-ratio-plan-proposal.json \ +--chain-id localnet \ +--from user1 \ +--keyring-backend test \ +--deposit 100000stake \ +--broadcast-mode block \ +--yes + +# Vote +# Make sure to change proposal-id for the proposal +farmingd tx gov vote yes \ +--chain-id localnet \ +--from val1 \ +--keyring-backend test \ +--yes +``` + ## AddMultiplePublicPlans +Create `public-multiple-plans-proposal.json` file in your local directory and copy the below json into the file. + ```json { "title": "Public Farming Plan", "description": "Are you ready to farm?", "add_request_proposals": [ { - "name": "First Public Farming Plan", + "name": "First Public Fixed Amount Plan", "farming_pool_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", "termination_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", "staking_coin_weights": [ @@ -140,7 +184,7 @@ $BINARY start ] }, { - "name": "First Public Farming Plan", + "name": "First Public Ratio Plan", "farming_pool_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", "termination_address": "cosmos1zaavvzxez0elundtn32qnk9lkm8kmcszzsv80v", "staking_coin_weights": [ @@ -157,11 +201,31 @@ $BINARY start } ``` +```bash +# Create public multiple plans through governance proposal +farmingd tx gov submit-proposal public-farming-plan public-multiple-plans-proposal.json \ +--chain-id localnet \ +--from user1 \ +--keyring-backend test \ +--deposit 100000stake \ +--broadcast-mode block \ +--yes + +# Vote +# Make sure to change proposal-id for the proposal +farmingd tx gov vote yes \ +--chain-id localnet \ +--from val1 \ +--keyring-backend test \ +--yes +``` ## UpdatePublicFarmingFixedAmountPlan +Create `update-plan-proposal.json` file in your local directory and copy the below json into the file. + ```json { - "title": "Let's Update the Farming Plan 1", + "title": "Update the Farming Plan 1", "description": "FarmingPoolAddress needs to be changed", "update_request_proposals": [ { @@ -187,8 +251,29 @@ $BINARY start } ``` +```bash +# Update public plan through governance proposal +farmingd tx gov submit-proposal public-farming-plan update-plan-proposal.json \ +--chain-id localnet \ +--from user1 \ +--keyring-backend test \ +--deposit 100000stake \ +--broadcast-mode block \ +--yes + +# Vote +# Make sure to change proposal-id for the proposal +farmingd tx gov vote yes \ +--chain-id localnet \ +--from val1 \ +--keyring-backend test \ +--yes +``` + ## DeletePublicFarmingFixedAmountPlan +Create `delete-plan-proposal.json` file in your local directory and copy the below json into the file. + ```json { "title": "Delete Public Farming Plan 1", @@ -201,18 +286,39 @@ $BINARY start } ``` +```bash +# Update public plan through governance proposal +farmingd tx gov submit-proposal public-farming-plan delete-plan-proposal.json \ +--chain-id localnet \ +--from user1 \ +--keyring-backend test \ +--deposit 100000stake \ +--broadcast-mode block \ +--yes + +# Vote +# Make sure to change proposal-id for the proposal +farmingd tx gov vote yes \ +--chain-id localnet \ +--from val1 \ +--keyring-backend test \ +--yes +``` + # Private Farming Plan +Create `create-private-fixed-plan.json` file in your local directory and copy the below json into the file. + ## PrivateFarmingFixedAmountPlan ```json { - "name": "This Farming Plan intends to incentivize ATOM HODLERS!", + "name": "This Farming Plan intends to incentivize ATOM HODLERS!", "staking_coin_weights": [ - { - "denom": "uatom", - "amount": "1.000000000000000000" - } + { + "denom": "uatom", + "amount": "1.000000000000000000" + } ], "start_time": "2021-07-15T08:41:21.662422Z", "end_time": "2022-07-16T08:41:21.662422Z", @@ -225,19 +331,46 @@ $BINARY start } ``` +```bash +# Create private fixed amount plan +farmingd tx farming create-private-fixed-plan create-private-fixed-plan.json \ +--chain-id localnet \ +--from user1 \ +--keyring-backend test \ +--yes +``` + ## PrivateFarmingRatioPlan +Create `create-private-ratio-plan.json` file in your local directory and copy the below json into the file. + ```json { - "name": "This Farming Plan intends to incentivize ATOM HODLERS!", + "name": "This Farming Plan intends to incentivize ATOM HODLERS!", "staking_coin_weights": [ - { - "denom": "uatom", - "amount": "1.000000000000000000" - } + { + "denom": "uatom", + "amount": "1.000000000000000000" + } ], "start_time": "2021-07-15T08:41:21.662422Z", "end_time": "2022-07-16T08:41:21.662422Z", - "epoch_ratio":"1.000000000000000000" + "epoch_ratio": "1.000000000000000000" } -``` \ No newline at end of file +``` + +```bash +# Create private ratio plan +farmingd tx farming create-private-fixed-plan create-private-ratio-plan.json \ +--chain-id localnet \ +--from user1 \ +--keyring-backend test \ +--yes +``` + +## REST APIs + +- http://localhost:1317/cosmos/bank/v1beta1/balances/{ADDRESS} +- http://localhost:1317/cosmos/gov/v1beta1/proposals +- http://localhost:1317/cosmos/farming/v1beta1/plans +- http://localhost:1317/cosmos/tx/v1beta1/txs/{TX_HASH} \ No newline at end of file