diff --git a/incubator/group/codec.go b/incubator/group/codec.go index 5d680e7..df6117f 100644 --- a/incubator/group/codec.go +++ b/incubator/group/codec.go @@ -29,7 +29,7 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(MsgVote{}, "cosmos-sdk/group/MsgVote", nil) cdc.RegisterConcrete(MsgExec{}, "cosmos-sdk/group/MsgExec", nil) - // oh man... this is for amino + // oh man... amino cdc.RegisterConcrete(StdDecisionPolicy{}, "cosmos-sdk/StdDecisionPolicy", nil) cdc.RegisterConcrete(&StdDecisionPolicy_Threshold{}, "cosmos-sdk/StdDecisionPolicy_Threshold", nil) cdc.RegisterConcrete(ThresholdDecisionPolicy{}, "cosmos-sdk/ThresholdDecisionPolicy", nil) diff --git a/incubator/group/integration_test.go b/incubator/group/integration_test.go index e53b63e..2bff2d8 100644 --- a/incubator/group/integration_test.go +++ b/incubator/group/integration_test.go @@ -115,14 +115,15 @@ func TestFullProposalWorkflow(t *testing.T) { }, }, // submit proposal - testdata.MsgProposeA{ + testdata.MsgPropose{ Base: group.MsgProposeBase{ GroupAccount: make([]byte, sdk.AddrLen), Proposers: []sdk.AccAddress{myAddr}, Comment: "ok", }, + Msgs: []testdata.MyAppMsg{{Sum: &testdata.MyAppMsg_A{A: &testdata.MyAppProposalPayloadMsgA{}}}}, }, - testdata.MsgProposeB{ + testdata.MsgPropose{ Base: group.MsgProposeBase{ GroupAccount: make([]byte, sdk.AddrLen), Proposers: []sdk.AccAddress{myAddr}, diff --git a/incubator/group/keeper.go b/incubator/group/keeper.go index ee453ed..b2eec3e 100644 --- a/incubator/group/keeper.go +++ b/incubator/group/keeper.go @@ -40,31 +40,16 @@ const ( ) type ProposalI interface { + orm.Persistent GetBase() ProposalBase SetBase(ProposalBase) -} - -type ProposalModel interface { - orm.Persistent - GetProposalI() ProposalI -} -type ExecRouter map[string]func(ctx sdk.Context, p ProposalI) error - -func (e ExecRouter) Add(k interface{}, f func(ctx sdk.Context, p ProposalI) error) { - key := reflect.TypeOf(k).String() - if _, exists := e[key]; exists { - panic(errors.Wrapf(ErrDuplicate, "%q already registered: %T", key, k)) - } - e[key] = f + GetMsg() []sdk.Msg } type Keeper struct { key sdk.StoreKey proposalModelType reflect.Type - // todo: not mutable - ExecRouter ExecRouter - // Group Table groupTable orm.Table groupByAdminIndex orm.Index @@ -91,9 +76,10 @@ type Keeper struct { groupSeq orm.Sequence paramSpace params.Subspace + router sdk.Router } -func NewGroupKeeper(storeKey sdk.StoreKey, paramSpace params.Subspace, proposalModel ProposalModel) Keeper { +func NewGroupKeeper(storeKey sdk.StoreKey, paramSpace params.Subspace, router sdk.Router, proposalModel ProposalI) Keeper { // set KeyTable if it has not already been set if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(params.NewKeyTable().RegisterParamSet(&Params{})) @@ -105,12 +91,15 @@ func NewGroupKeeper(storeKey sdk.StoreKey, paramSpace params.Subspace, proposalM if proposalModel == nil { panic("proposalModel must not be nil") } + if router == nil { + panic("router must not be nil") + } tp := reflect.TypeOf(proposalModel) if tp.Kind() == reflect.Ptr { tp = tp.Elem() } - k := Keeper{key: storeKey, paramSpace: paramSpace, proposalModelType: tp, ExecRouter: make(ExecRouter)} + k := Keeper{key: storeKey, paramSpace: paramSpace, proposalModelType: tp, router: router} // // Group Table @@ -153,12 +142,12 @@ func NewGroupKeeper(storeKey sdk.StoreKey, paramSpace params.Subspace, proposalM // Proposal Table proposalTableBuilder := orm.NewAutoUInt64TableBuilder(ProposalBaseTablePrefix, ProposalBaseTableSeqPrefix, storeKey, proposalModel) k.ProposalGroupAccountIndex = orm.NewIndex(proposalTableBuilder, ProposalBaseByGroupAccountIndexPrefix, func(value interface{}) ([]orm.RowID, error) { - account := value.(ProposalModel).GetProposalI().GetBase().GroupAccount + account := value.(ProposalI).GetBase().GroupAccount return []orm.RowID{account.Bytes()}, nil }) k.ProposalByProposerIndex = orm.NewIndex(proposalTableBuilder, ProposalBaseByProposerIndexPrefix, func(value interface{}) ([]orm.RowID, error) { - proposers := value.(ProposalModel).GetProposalI().GetBase().Proposers + proposers := value.(ProposalI).GetBase().Proposers r := make([]orm.RowID, len(proposers)) for i := range proposers { r[i] = proposers[i].Bytes() @@ -312,15 +301,15 @@ func (k Keeper) Vote(ctx sdk.Context, id ProposalID, voters []sdk.AccAddress, ch if err != nil { return err } - proposalModel, err := k.getProposalModel(ctx, id) + proposal, err := k.GetProposal(ctx, id) if err != nil { return err } - proposal := proposalModel.GetProposalI().GetBase() - if proposal.Status != ProposalBase_Submitted { + base := proposal.GetBase() + if base.Status != ProposalBase_Submitted { return errors.Wrap(ErrInvalid, "proposal not open") } - votingPeriodEnd, err := types.TimestampFromProto(&proposal.VotingEndTime) + votingPeriodEnd, err := types.TimestampFromProto(&base.VotingEndTime) if err != nil { return err } @@ -328,11 +317,11 @@ func (k Keeper) Vote(ctx sdk.Context, id ProposalID, voters []sdk.AccAddress, ch if end.Before(ctx.BlockTime()) || end.Equal(ctx.BlockTime()) { return errors.Wrap(ErrExpired, "voting period has ended already") } - electorate, err := k.GetGroupByGroupAccount(ctx, proposal.GroupAccount) + electorate, err := k.GetGroupByGroupAccount(ctx, base.GroupAccount) if err != nil { return err } - if electorate.Version != proposal.GroupVersion { + if electorate.Version != base.GroupVersion { // todo: this is not the voters fault. return errors.Wrap(ErrModified, "group was modified") } @@ -360,11 +349,11 @@ func (k Keeper) Vote(ctx sdk.Context, id ProposalID, voters []sdk.AccAddress, ch case err != nil: return errors.Wrap(err, "load old vote") default: // it is an update - if err := proposal.VoteState.Sub(oldVote, member.Weight); err != nil { + if err := base.VoteState.Sub(oldVote, member.Weight); err != nil { return errors.Wrap(err, "previous vote") } } - if err := proposal.VoteState.Add(newVote, member.Weight); err != nil { + if err := base.VoteState.Add(newVote, member.Weight); err != nil { return errors.Wrap(err, "new vote") } @@ -379,41 +368,40 @@ func (k Keeper) Vote(ctx sdk.Context, id ProposalID, voters []sdk.AccAddress, ch } } } - proposalModel.GetProposalI().SetBase(proposal) - return k.proposalTable.Save(ctx, id.Uint64(), proposalModel) + proposal.SetBase(base) + return k.proposalTable.Save(ctx, id.Uint64(), proposal) } func (k Keeper) ExecProposal(ctx sdk.Context, id ProposalID) error { - proposalModel, err := k.getProposalModel(ctx, id) + proposal, err := k.GetProposal(ctx, id) if err != nil { return err } - proposal := proposalModel.GetProposalI() - proposalBase := proposal.GetBase() + base := proposal.GetBase() - if proposalBase.Status != ProposalBase_Submitted { + if base.Status != ProposalBase_Submitted { return errors.Wrap(ErrInvalid, "proposal not open") } var accountMetadata StdGroupAccountMetadata - if err := k.groupAccountTable.GetOne(ctx, proposalBase.GroupAccount.Bytes(), &accountMetadata); err != nil { + if err := k.groupAccountTable.GetOne(ctx, base.GroupAccount.Bytes(), &accountMetadata); err != nil { return errors.Wrap(err, "load group account") } - electorate, err := k.GetGroupByGroupAccount(ctx, proposalBase.GroupAccount) + electorate, err := k.GetGroupByGroupAccount(ctx, base.GroupAccount) if err != nil { return err } - if electorate.Version != proposalBase.GroupVersion { - proposalBase.Status = ProposalBase_Aborted + if electorate.Version != base.GroupVersion { + base.Status = ProposalBase_Aborted return nil // todo: or error? //return errors.Wrap(ErrModified, "group was modified") } // todo: validate - votingPeriodEnd, err := types.TimestampFromProto(&proposalBase.VotingEndTime) + votingPeriodEnd, err := types.TimestampFromProto(&base.VotingEndTime) if err != nil { return err } @@ -421,7 +409,7 @@ func (k Keeper) ExecProposal(ctx sdk.Context, id ProposalID) error { return errors.Wrap(ErrExpired, "voting period not ended yet") } - proposalBase.Status = ProposalBase_Closed + base.Status = ProposalBase_Closed // run decision policy policy := accountMetadata.DecisionPolicy.GetThreshold() @@ -429,54 +417,70 @@ func (k Keeper) ExecProposal(ctx sdk.Context, id ProposalID) error { return errors.Wrap(ErrInvalid, "unknown decision policy") } - submittedAt, err := types.TimestampFromProto(&proposalBase.SubmittedAt) + submittedAt, err := types.TimestampFromProto(&base.SubmittedAt) if err != nil { return errors.Wrap(err, "from proto time") } - switch accepted, err := policy.Allow(proposalBase.VoteState, electorate.TotalWeight, ctx.BlockTime().Sub(submittedAt)); { + switch accepted, err := policy.Allow(base.VoteState, electorate.TotalWeight, ctx.BlockTime().Sub(submittedAt)); { case err != nil: return errors.Wrap(err, "policy execution") case accepted: - proposalBase.Result = ProposalBase_Accepted + base.Result = ProposalBase_Accepted logger := ctx.Logger().With("module", fmt.Sprintf("x/%s", ModuleName)) proposalType := reflect.TypeOf(proposal).String() - if exec, ok := k.ExecRouter[proposalType]; !ok { - logger.Error("no executor for proposal", "type", proposalType, "proposalID", id) - proposalBase.ExecutorResult = ProposalBase_Failure - } else { - // execute proposal in a nested TX and only flush on non error - cacheCtx, writeCache := ctx.CacheContext() - if err := exec(cacheCtx, proposal); err != nil { - proposalBase.ExecutorResult = ProposalBase_Failure - logger.Error("executor failed for proposal", "cause", err, "proposalID", id) - } else { - writeCache() - proposalBase.ExecutorResult = ProposalBase_Success + + msgs := proposal.GetMsg() + results := make([]sdk.Result, len(msgs)) + for i, msg := range msgs { + for _, acct := range msg.GetSigners() { + _ = acct + if !accountMetadata.Base.GroupAccount.Equals(acct) { + return errors.Wrap(errors.ErrUnauthorized, "proposal msg does not have permission") + } + } + + handler := k.router.Route(ctx, msg.Route()) + if handler == nil { + logger.Debug("no handler found", "type", proposalType, "proposalID", id, "route", msg.Route(), "pos", i) + return errors.Wrap(ErrInvalid, "no message handler found") } + r, err := handler(ctx, msg) + if err != nil { + return errors.Wrapf(err, "message %q at position %d", msg.Type(), i) + } + results[i] = *r } + _ = results // todo: merge results + //if exec, ok := k.ExecRouter[proposalType]; !ok { + // logger.Error("no executor for proposal", "type", proposalType, "proposalID", id) + // base.ExecutorResult = ProposalBase_Failure + //} else { + // // execute proposal in a nested TX and only flush on non error + // cacheCtx, writeCache := ctx.CacheContext() + // if err := exec(cacheCtx, proposal); err != nil { + // base.ExecutorResult = ProposalBase_Failure + // logger.Error("executor failed for proposal", "cause", err, "proposalID", id) + // } else { + // writeCache() + // base.ExecutorResult = ProposalBase_Success + // } + //} default: - proposalBase.Result = ProposalBase_Rejected + base.Result = ProposalBase_Rejected } - proposal.SetBase(proposalBase) - return k.proposalTable.Save(ctx, id.Uint64(), proposalModel) + proposal.SetBase(base) + return k.proposalTable.Save(ctx, id.Uint64(), proposal) } -func (k Keeper) getProposalModel(ctx sdk.Context, id ProposalID) (ProposalModel, error) { - loaded := reflect.New(k.proposalModelType).Interface().(ProposalModel) +func (k Keeper) GetProposal(ctx sdk.Context, id ProposalID) (ProposalI, error) { + loaded := reflect.New(k.proposalModelType).Interface().(ProposalI) if _, err := k.proposalTable.GetOne(ctx, id.Uint64(), loaded); err != nil { return nil, errors.Wrap(err, "load proposal source") } return loaded, nil } -func (k Keeper) GetProposal(ctx sdk.Context, id ProposalID) (ProposalI, error) { - s, err := k.getProposalModel(ctx, id) - if err != nil { - return nil, err - } - return s.GetProposalI(), nil -} -func (k Keeper) CreateProposal(ctx sdk.Context, p ProposalModel) (ProposalID, error) { +func (k Keeper) CreateProposal(ctx sdk.Context, p ProposalI) (ProposalID, error) { id, err := k.proposalTable.Create(ctx, p) if err != nil { return 0, errors.Wrap(err, "create proposal") diff --git a/incubator/group/keeper_test.go b/incubator/group/keeper_test.go index 28fc59d..55ca0eb 100644 --- a/incubator/group/keeper_test.go +++ b/incubator/group/keeper_test.go @@ -3,6 +3,7 @@ package group import ( "testing" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/params/subspace" @@ -16,7 +17,7 @@ func TestCreateGroup(t *testing.T) { paramSpace := subspace.NewSubspace(ModuleCdc.amino, pKey, pTKey, DefaultParamspace) groupKey := sdk.NewKVStoreKey(StoreKeyName) - k := NewGroupKeeper(groupKey, paramSpace, &MockProposalModel{}) + k := NewGroupKeeper(groupKey, paramSpace, baseapp.NewRouter(), &MockProposalI{}) ctx := NewContext(pKey, pTKey, groupKey) k.setParams(ctx, DefaultParams()) @@ -61,7 +62,7 @@ func TestLoadParam(t *testing.T) { paramSpace := subspace.NewSubspace(ModuleCdc.amino, pKey, pTKey, DefaultParamspace) groupKey := sdk.NewKVStoreKey(StoreKeyName) - k := NewGroupKeeper(groupKey, paramSpace, &MockProposalModel{}) + k := NewGroupKeeper(groupKey, paramSpace, baseapp.NewRouter(), &MockProposalI{}) ctx := NewContext(pKey, pTKey, groupKey) diff --git a/incubator/group/testdata/codec.go b/incubator/group/testdata/codec.go index 413c11e..2fcca12 100644 --- a/incubator/group/testdata/codec.go +++ b/incubator/group/testdata/codec.go @@ -21,8 +21,13 @@ func NewCodec(amino *codec.Codec) *Codec { // RegisterCodec registers all the necessary crisis module concrete types and // interfaces with the provided codec reference. func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgProposeA{}, "testdata/MsgProposeA", nil) - cdc.RegisterConcrete(MsgProposeB{}, "testdata/MsgProposeB", nil) + cdc.RegisterConcrete(MsgPropose{}, "testdata/MsgPropose", nil) + // oh man... amino + cdc.RegisterInterface((*isMyAppMsg_Sum)(nil), nil) + cdc.RegisterConcrete(&MyAppProposalPayloadMsgA{}, "testdata/MyAppProposalPayloadMsgA", nil) + cdc.RegisterConcrete(&MyAppProposalPayloadMsgB{}, "testdata/MyAppProposalPayloadMsgB", nil) + cdc.RegisterConcrete(&MyAppMsg_A{}, "testdata/MyAppMsg_A", nil) + cdc.RegisterConcrete(&MyAppMsg_B{}, "testdata/MyAppMsg_B", nil) } // generic sealed codec to be used throughout module diff --git a/incubator/group/testdata/handler.go b/incubator/group/testdata/handler.go index 4f22dc2..8aceeed 100644 --- a/incubator/group/testdata/handler.go +++ b/incubator/group/testdata/handler.go @@ -1,6 +1,7 @@ package testdata import ( + "errors" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,35 +12,30 @@ import ( func NewHandler(k Keeper) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) + logger := ctx.Logger().With("module", fmt.Sprintf("x/%s", ModuleName)) switch msg := msg.(type) { - case MsgProposeA: - return handleMsgProposeA(ctx, k, msg) - case MsgProposeB: - return handleMsgProposeB(ctx, k, msg) + case MsgPropose: + return handleMsgPropose(ctx, k, msg) + case *MyAppProposalPayloadMsgA: + logger.Info("executed MyAppProposalPayloadMsgA msg") + return &sdk.Result{ + Data: nil, + Log: "MyAppProposalPayloadMsgA executed", + Events: ctx.EventManager().Events(), + }, nil + case *MyAppProposalPayloadMsgB: + logger.Info("executed MyAppProposalPayloadMsgB msg") + return nil, errors.New("execution of MyAppProposalPayloadMsgB testdata always fails") default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message type: %T", msg) } } } -func handleMsgProposeA(ctx sdk.Context, k Keeper, msg MsgProposeA) (*sdk.Result, error) { +func handleMsgPropose(ctx sdk.Context, k Keeper, msg MsgPropose) (*sdk.Result, error) { // todo: vaidate // check execNow - id, err := k.CreateProposalA(ctx, msg.Base.GroupAccount, msg.Base.Proposers, msg.Base.Comment) - if err != nil { - return nil, err - } - return &sdk.Result{ - Data: orm.EncodeSequence(id), - Log: fmt.Sprintf("Proposal created :%d", id), - Events: ctx.EventManager().Events(), - }, nil -} - -func handleMsgProposeB(ctx sdk.Context, k Keeper, msg MsgProposeB) (*sdk.Result, error) { - // todo: vaidate - // check execNow - id, err := k.CreateProposalB(ctx, msg.Base.GroupAccount, msg.Base.Proposers, msg.Base.Comment) + id, err := k.CreateProposalA(ctx, msg.Base.GroupAccount, msg.Base.Proposers, msg.Base.Comment, msg.Msgs) if err != nil { return nil, err } diff --git a/incubator/group/testdata/keeper.go b/incubator/group/testdata/keeper.go index 1cdec68..4c4301c 100644 --- a/incubator/group/testdata/keeper.go +++ b/incubator/group/testdata/keeper.go @@ -1,8 +1,6 @@ package testdata import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/modules/incubator/group" "github.com/gogo/protobuf/types" @@ -19,67 +17,14 @@ func NewTestdataKeeper(storeKey sdk.StoreKey, groupKeeper group.Keeper) Keeper { groupKeeper: groupKeeper, key: storeKey, } - // register all proposals with an executor - groupKeeper.ExecRouter.Add(&AMyAppProposal{}, ProposalAExecutor(k)) - groupKeeper.ExecRouter.Add(&BMyAppProposal{}, k.ProposalExecutor) return k } -func (k Keeper) CreateProposalA(ctx sdk.Context, accountAddress sdk.AccAddress, proposers []sdk.AccAddress, comment string) (uint64, error) { - return CreateProposalA(k, ctx, accountAddress, comment, proposers) -} - -func CreateProposalA(k Keeper, ctx sdk.Context, accountAddress sdk.AccAddress, comment string, proposers []sdk.AccAddress) (uint64, error) { - // todo: validate - account, err := k.groupKeeper.GetGroupAccount(ctx, accountAddress.Bytes()) - if err != nil { - return 0, errors.Wrap(err, "load group account") - } - - g, err := k.groupKeeper.GetGroupByGroupAccount(ctx, accountAddress) - if err != nil { - return 0, errors.Wrap(err, "get group by account") - } - blockTime, err := types.TimestampProto(ctx.BlockTime()) - if err != nil { - return 0, errors.Wrap(err, "block time conversion") - } - policy := account.GetDecisionPolicy() - window, err := types.DurationFromProto(&policy.GetThreshold().MaxVotingWindow) - if err != nil { - return 0, errors.Wrap(err, "maxVotingWindow time conversion") - } - endTime, err := types.TimestampProto(ctx.BlockTime().Add(window)) - if err != nil { - return 0, errors.Wrap(err, "end time conversion") - } - block := ctx.BlockHeight() - _ = block - m := &MyAppProposal{ - Sum: &MyAppProposal_A{A: &AMyAppProposal{ - Base: group.ProposalBase{ - GroupAccount: accountAddress, - Comment: comment, - Proposers: proposers, - SubmittedAt: *blockTime, - GroupVersion: g.Version, - GroupAccountVersion: account.Base.Version, - Result: group.ProposalBase_Undefined, - Status: group.ProposalBase_Submitted, - ExecutorResult: group.ProposalBase_NotRun, - VotingEndTime: *endTime, - }, - }, - }, - } - id, err := k.groupKeeper.CreateProposal(ctx, m) - if err != nil { - return 0, errors.Wrap(err, "create proposal") - } - return id.Uint64(), nil +func (k Keeper) CreateProposalA(ctx sdk.Context, accountAddress sdk.AccAddress, proposers []sdk.AccAddress, comment string, msgs []MyAppMsg) (uint64, error) { + return CreateProposal(k, ctx, accountAddress, comment, proposers, msgs) } -func (k Keeper) CreateProposalB(ctx sdk.Context, accountAddress sdk.AccAddress, proposers []sdk.AccAddress, comment string) (uint64, error) { +func CreateProposal(k Keeper, ctx sdk.Context, accountAddress sdk.AccAddress, comment string, proposers []sdk.AccAddress, msgs []MyAppMsg) (uint64, error) { // todo: validate account, err := k.groupKeeper.GetGroupAccount(ctx, accountAddress.Bytes()) if err != nil { @@ -106,56 +51,23 @@ func (k Keeper) CreateProposalB(ctx sdk.Context, accountAddress sdk.AccAddress, block := ctx.BlockHeight() _ = block m := &MyAppProposal{ - Sum: &MyAppProposal_B{B: &BMyAppProposal{ - Base: group.ProposalBase{ - GroupAccount: accountAddress, - Comment: comment, - Proposers: proposers, - SubmittedAt: *blockTime, - GroupVersion: g.Version, - GroupAccountVersion: account.Base.Version, - Result: group.ProposalBase_Undefined, - Status: group.ProposalBase_Submitted, - ExecutorResult: group.ProposalBase_NotRun, - VotingEndTime: *endTime, - }, - }, + Base: group.ProposalBase{ + GroupAccount: accountAddress, + Comment: comment, + Proposers: proposers, + SubmittedAt: *blockTime, + GroupVersion: g.Version, + GroupAccountVersion: account.Base.Version, + Result: group.ProposalBase_Undefined, + Status: group.ProposalBase_Submitted, + ExecutorResult: group.ProposalBase_NotRun, + VotingEndTime: *endTime, }, + Msgs:msgs, } id, err := k.groupKeeper.CreateProposal(ctx, m) if err != nil { return 0, errors.Wrap(err, "create proposal") } return id.Uint64(), nil -} - -// within a keeper -func (k Keeper) ProposalExecutor(ctx sdk.Context, proposalI group.ProposalI) error { - logger := ctx.Logger().With("module", fmt.Sprintf("x/%s", ModuleName)) - - switch proposalI.(type) { - case *AMyAppProposal: - logger.Info("executing AMyAppProposal") - return nil - case *BMyAppProposal: - logger.Info("executing BMyAppProposal") - return errors.New("exec should fail by intention") - default: - return errors.Wrapf(group.ErrType, "%T", proposalI) - } -} - -// or as standalone function -func ProposalAExecutor(k Keeper) func(ctx sdk.Context, proposalI group.ProposalI) error { - return func(ctx sdk.Context, proposalI group.ProposalI) error { - logger := ctx.Logger().With("module", fmt.Sprintf("x/%s", ModuleName)) - switch p := proposalI.(type) { - case *AMyAppProposal: - _ = p - default: - return errors.Wrapf(group.ErrType, "got %T", proposalI) - } - logger.Info("executing AMyAppProposal") - return nil - } -} +} \ No newline at end of file diff --git a/incubator/group/testdata/msg.go b/incubator/group/testdata/msg.go index 9ec24b4..bcd72a9 100644 --- a/incubator/group/testdata/msg.go +++ b/incubator/group/testdata/msg.go @@ -4,27 +4,29 @@ import ( "bytes" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" "github.com/gogo/protobuf/jsonpb" ) const ( - msgTypeCreateProposalA = "create_proposal_a" - msgTypeCreateProposalB = "create_proposal_B" + msgTypeCreateProposal = "create_proposal" + msgTypeMyMsgA = "my_msg_a" + msgTypeMyMsgB = "my_msg_b" ) -var _ sdk.Msg = &MsgProposeA{} +var _ sdk.Msg = &MsgPropose{} -func (m MsgProposeA) Route() string { return ModuleName } +func (m MsgPropose) Route() string { return ModuleName } -func (m MsgProposeA) Type() string { return msgTypeCreateProposalA } +func (m MsgPropose) Type() string { return msgTypeMyMsgA } // GetSigners returns the addresses that must sign over msg.GetSignBytes() -func (m MsgProposeA) GetSigners() []sdk.AccAddress { +func (m MsgPropose) GetSigners() []sdk.AccAddress { return m.Base.Proposers } // GetSignBytes returns the bytes for the message signer to sign on -func (m MsgProposeA) GetSignBytes() []byte { +func (m MsgPropose) GetSignBytes() []byte { var buf bytes.Buffer enc := jsonpb.Marshaler{} if err := enc.Marshal(&buf, &m); err != nil { @@ -34,23 +36,57 @@ func (m MsgProposeA) GetSignBytes() []byte { } // ValidateBasic does a sanity check on the provided data -func (m MsgProposeA) ValidateBasic() error { - return m.Base.ValidateBasic() +func (m MsgPropose) ValidateBasic() error { + if err := m.Base.ValidateBasic(); err != nil { + return err + } + for i, v := range m.Msgs { + if err := v.GetMsg().ValidateBasic(); err != nil { + return errors.Wrapf(err, "msg %d", i) + } + } + return nil } -var _ sdk.Msg = &MsgProposeB{} +var _ sdk.Msg = &MyAppProposalPayloadMsgA{} -func (m MsgProposeB) Route() string { return ModuleName } +func (m MyAppProposalPayloadMsgA) Route() string { return ModuleName } -func (m MsgProposeB) Type() string { return msgTypeCreateProposalB } +func (m MyAppProposalPayloadMsgA) Type() string { return msgTypeMyMsgA } // GetSigners returns the addresses that must sign over msg.GetSignBytes() -func (m MsgProposeB) GetSigners() []sdk.AccAddress { - return m.Base.Proposers +func (m MyAppProposalPayloadMsgA) GetSigners() []sdk.AccAddress { + return nil // nothing to do +} + +// GetSignBytes returns the bytes for the message signer to sign on +func (m MyAppProposalPayloadMsgA) GetSignBytes() []byte { + var buf bytes.Buffer + enc := jsonpb.Marshaler{} + if err := enc.Marshal(&buf, &m); err != nil { + panic(err) + } + return sdk.MustSortJSON(buf.Bytes()) +} + +// ValidateBasic does a sanity check on the provided data +func (m MyAppProposalPayloadMsgA) ValidateBasic() error { + return nil +} + +var _ sdk.Msg = &MyAppProposalPayloadMsgB{} + +func (m MyAppProposalPayloadMsgB) Route() string { return ModuleName } + +func (m MyAppProposalPayloadMsgB) Type() string { return msgTypeMyMsgB } + +// GetSigners returns the addresses that must sign over msg.GetSignBytes() +func (m MyAppProposalPayloadMsgB) GetSigners() []sdk.AccAddress { + return nil } // GetSignBytes returns the bytes for the message signer to sign on -func (m MsgProposeB) GetSignBytes() []byte { +func (m MyAppProposalPayloadMsgB) GetSignBytes() []byte { var buf bytes.Buffer enc := jsonpb.Marshaler{} if err := enc.Marshal(&buf, &m); err != nil { @@ -60,6 +96,6 @@ func (m MsgProposeB) GetSignBytes() []byte { } // ValidateBasic does a sanity check on the provided data -func (m MsgProposeB) ValidateBasic() error { - return m.Base.ValidateBasic() +func (m MyAppProposalPayloadMsgB) ValidateBasic() error { + return nil } diff --git a/incubator/group/testdata/sim_app.go b/incubator/group/testdata/sim_app.go index fdcc844..1af2769 100644 --- a/incubator/group/testdata/sim_app.go +++ b/incubator/group/testdata/sim_app.go @@ -204,7 +204,7 @@ func NewSimApp( evidenceKeeper := evidence.NewKeeper( app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &app.StakingKeeper, app.SlashingKeeper, ) - app.GroupKeeper = group.NewGroupKeeper(keys[group.StoreKeyName], app.subspaces[group.ModuleName], &MyAppProposal{}) + app.GroupKeeper = group.NewGroupKeeper(keys[group.StoreKeyName], app.subspaces[group.ModuleName], app.Router(), &MyAppProposal{} ) app.TestdataKeeper = NewTestdataKeeper(keys[ModuleName], app.GroupKeeper) evidenceRouter := evidence.NewRouter() // TODO: Register evidence routes. diff --git a/incubator/group/testdata/types.go b/incubator/group/testdata/types.go index 98b4e98..d3a0781 100644 --- a/incubator/group/testdata/types.go +++ b/incubator/group/testdata/types.go @@ -1,14 +1,18 @@ package testdata import ( + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/modules/incubator/group" ) -func (m *AMyAppProposal) SetBase(new group.ProposalBase) { - m.Base = new -} - -func (m *BMyAppProposal) SetBase(new group.ProposalBase) { - m.Base = new +func (m *MyAppProposal) SetBase(b group.ProposalBase) { + m.Base = b } +func (m *MyAppProposal) GetMsg() []sdk.Msg { + r := make([]sdk.Msg, len(m.Msgs)) + for i := range m.Msgs { + r[i] = m.Msgs[i].GetMsg() + } + return r +} \ No newline at end of file diff --git a/incubator/group/testdata/types.pb.go b/incubator/group/testdata/types.pb.go index 8547dd0..19cc09b 100644 --- a/incubator/group/testdata/types.pb.go +++ b/incubator/group/testdata/types.pb.go @@ -5,7 +5,7 @@ package testdata import ( fmt "fmt" - github_com_cosmos_modules_incubator_group "github.com/cosmos/modules/incubator/group" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" group "github.com/cosmos/modules/incubator/group" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" @@ -26,25 +26,26 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type MyAppProposal struct { +// MyAppMsg is the payload stored with a proposal and executed on success +type MyAppMsg struct { // Types that are valid to be assigned to Sum: - // *MyAppProposal_A - // *MyAppProposal_B - Sum isMyAppProposal_Sum `protobuf_oneof:"sum"` + // *MyAppMsg_A + // *MyAppMsg_B + Sum isMyAppMsg_Sum `protobuf_oneof:"sum"` } -func (m *MyAppProposal) Reset() { *m = MyAppProposal{} } -func (m *MyAppProposal) String() string { return proto.CompactTextString(m) } -func (*MyAppProposal) ProtoMessage() {} -func (*MyAppProposal) Descriptor() ([]byte, []int) { +func (m *MyAppMsg) Reset() { *m = MyAppMsg{} } +func (m *MyAppMsg) String() string { return proto.CompactTextString(m) } +func (*MyAppMsg) ProtoMessage() {} +func (*MyAppMsg) Descriptor() ([]byte, []int) { return fileDescriptor_2447ab8d7bf628b8, []int{0} } -func (m *MyAppProposal) XXX_Unmarshal(b []byte) error { +func (m *MyAppMsg) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MyAppProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MyAppMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MyAppProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_MyAppMsg.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -54,79 +55,81 @@ func (m *MyAppProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error return b[:n], nil } } -func (m *MyAppProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_MyAppProposal.Merge(m, src) +func (m *MyAppMsg) XXX_Merge(src proto.Message) { + xxx_messageInfo_MyAppMsg.Merge(m, src) } -func (m *MyAppProposal) XXX_Size() int { +func (m *MyAppMsg) XXX_Size() int { return m.Size() } -func (m *MyAppProposal) XXX_DiscardUnknown() { - xxx_messageInfo_MyAppProposal.DiscardUnknown(m) +func (m *MyAppMsg) XXX_DiscardUnknown() { + xxx_messageInfo_MyAppMsg.DiscardUnknown(m) } -var xxx_messageInfo_MyAppProposal proto.InternalMessageInfo +var xxx_messageInfo_MyAppMsg proto.InternalMessageInfo -type isMyAppProposal_Sum interface { - isMyAppProposal_Sum() +type isMyAppMsg_Sum interface { + isMyAppMsg_Sum() MarshalTo([]byte) (int, error) Size() int } -type MyAppProposal_A struct { - A *AMyAppProposal `protobuf:"bytes,1,opt,name=A,proto3,oneof" json:"A,omitempty"` +type MyAppMsg_A struct { + A *MyAppProposalPayloadMsgA `protobuf:"bytes,1,opt,name=A,proto3,oneof" json:"A,omitempty"` } -type MyAppProposal_B struct { - B *BMyAppProposal `protobuf:"bytes,2,opt,name=B,proto3,oneof" json:"B,omitempty"` +type MyAppMsg_B struct { + B *MyAppProposalPayloadMsgB `protobuf:"bytes,2,opt,name=B,proto3,oneof" json:"B,omitempty"` } -func (*MyAppProposal_A) isMyAppProposal_Sum() {} -func (*MyAppProposal_B) isMyAppProposal_Sum() {} +func (*MyAppMsg_A) isMyAppMsg_Sum() {} +func (*MyAppMsg_B) isMyAppMsg_Sum() {} -func (m *MyAppProposal) GetSum() isMyAppProposal_Sum { +func (m *MyAppMsg) GetSum() isMyAppMsg_Sum { if m != nil { return m.Sum } return nil } -func (m *MyAppProposal) GetA() *AMyAppProposal { - if x, ok := m.GetSum().(*MyAppProposal_A); ok { +func (m *MyAppMsg) GetA() *MyAppProposalPayloadMsgA { + if x, ok := m.GetSum().(*MyAppMsg_A); ok { return x.A } return nil } -func (m *MyAppProposal) GetB() *BMyAppProposal { - if x, ok := m.GetSum().(*MyAppProposal_B); ok { +func (m *MyAppMsg) GetB() *MyAppProposalPayloadMsgB { + if x, ok := m.GetSum().(*MyAppMsg_B); ok { return x.B } return nil } // XXX_OneofWrappers is for the internal use of the proto package. -func (*MyAppProposal) XXX_OneofWrappers() []interface{} { +func (*MyAppMsg) XXX_OneofWrappers() []interface{} { return []interface{}{ - (*MyAppProposal_A)(nil), - (*MyAppProposal_B)(nil), + (*MyAppMsg_A)(nil), + (*MyAppMsg_B)(nil), } } -type AMyAppProposal struct { +type MyAppProposal struct { Base group.ProposalBase `protobuf:"bytes,1,opt,name=base,proto3" json:"base"` + // option (cosmos_proto.interface_type) = "*github.com/cosmos/modules/incubator/group.ProposalI"; + Msgs []MyAppMsg `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs"` } -func (m *AMyAppProposal) Reset() { *m = AMyAppProposal{} } -func (m *AMyAppProposal) String() string { return proto.CompactTextString(m) } -func (*AMyAppProposal) ProtoMessage() {} -func (*AMyAppProposal) Descriptor() ([]byte, []int) { +func (m *MyAppProposal) Reset() { *m = MyAppProposal{} } +func (m *MyAppProposal) String() string { return proto.CompactTextString(m) } +func (*MyAppProposal) ProtoMessage() {} +func (*MyAppProposal) Descriptor() ([]byte, []int) { return fileDescriptor_2447ab8d7bf628b8, []int{1} } -func (m *AMyAppProposal) XXX_Unmarshal(b []byte) error { +func (m *MyAppProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *AMyAppProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MyAppProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_AMyAppProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_MyAppProposal.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -136,41 +139,47 @@ func (m *AMyAppProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro return b[:n], nil } } -func (m *AMyAppProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_AMyAppProposal.Merge(m, src) +func (m *MyAppProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_MyAppProposal.Merge(m, src) } -func (m *AMyAppProposal) XXX_Size() int { +func (m *MyAppProposal) XXX_Size() int { return m.Size() } -func (m *AMyAppProposal) XXX_DiscardUnknown() { - xxx_messageInfo_AMyAppProposal.DiscardUnknown(m) +func (m *MyAppProposal) XXX_DiscardUnknown() { + xxx_messageInfo_MyAppProposal.DiscardUnknown(m) } -var xxx_messageInfo_AMyAppProposal proto.InternalMessageInfo +var xxx_messageInfo_MyAppProposal proto.InternalMessageInfo -func (m *AMyAppProposal) GetBase() group.ProposalBase { +func (m *MyAppProposal) GetBase() group.ProposalBase { if m != nil { return m.Base } return group.ProposalBase{} } -type BMyAppProposal struct { - Base group.ProposalBase `protobuf:"bytes,1,opt,name=base,proto3" json:"base"` +func (m *MyAppProposal) GetMsgs() []MyAppMsg { + if m != nil { + return m.Msgs + } + return nil +} + +type MyAppProposalPayloadMsgA struct { } -func (m *BMyAppProposal) Reset() { *m = BMyAppProposal{} } -func (m *BMyAppProposal) String() string { return proto.CompactTextString(m) } -func (*BMyAppProposal) ProtoMessage() {} -func (*BMyAppProposal) Descriptor() ([]byte, []int) { +func (m *MyAppProposalPayloadMsgA) Reset() { *m = MyAppProposalPayloadMsgA{} } +func (m *MyAppProposalPayloadMsgA) String() string { return proto.CompactTextString(m) } +func (*MyAppProposalPayloadMsgA) ProtoMessage() {} +func (*MyAppProposalPayloadMsgA) Descriptor() ([]byte, []int) { return fileDescriptor_2447ab8d7bf628b8, []int{2} } -func (m *BMyAppProposal) XXX_Unmarshal(b []byte) error { +func (m *MyAppProposalPayloadMsgA) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *BMyAppProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MyAppProposalPayloadMsgA) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_BMyAppProposal.Marshal(b, m, deterministic) + return xxx_messageInfo_MyAppProposalPayloadMsgA.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -180,41 +189,33 @@ func (m *BMyAppProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, erro return b[:n], nil } } -func (m *BMyAppProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_BMyAppProposal.Merge(m, src) +func (m *MyAppProposalPayloadMsgA) XXX_Merge(src proto.Message) { + xxx_messageInfo_MyAppProposalPayloadMsgA.Merge(m, src) } -func (m *BMyAppProposal) XXX_Size() int { +func (m *MyAppProposalPayloadMsgA) XXX_Size() int { return m.Size() } -func (m *BMyAppProposal) XXX_DiscardUnknown() { - xxx_messageInfo_BMyAppProposal.DiscardUnknown(m) +func (m *MyAppProposalPayloadMsgA) XXX_DiscardUnknown() { + xxx_messageInfo_MyAppProposalPayloadMsgA.DiscardUnknown(m) } -var xxx_messageInfo_BMyAppProposal proto.InternalMessageInfo +var xxx_messageInfo_MyAppProposalPayloadMsgA proto.InternalMessageInfo -func (m *BMyAppProposal) GetBase() group.ProposalBase { - if m != nil { - return m.Base - } - return group.ProposalBase{} -} - -type MsgProposeA struct { - Base group.MsgProposeBase `protobuf:"bytes,1,opt,name=base,proto3" json:"base"` +type MyAppProposalPayloadMsgB struct { } -func (m *MsgProposeA) Reset() { *m = MsgProposeA{} } -func (m *MsgProposeA) String() string { return proto.CompactTextString(m) } -func (*MsgProposeA) ProtoMessage() {} -func (*MsgProposeA) Descriptor() ([]byte, []int) { +func (m *MyAppProposalPayloadMsgB) Reset() { *m = MyAppProposalPayloadMsgB{} } +func (m *MyAppProposalPayloadMsgB) String() string { return proto.CompactTextString(m) } +func (*MyAppProposalPayloadMsgB) ProtoMessage() {} +func (*MyAppProposalPayloadMsgB) Descriptor() ([]byte, []int) { return fileDescriptor_2447ab8d7bf628b8, []int{3} } -func (m *MsgProposeA) XXX_Unmarshal(b []byte) error { +func (m *MyAppProposalPayloadMsgB) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgProposeA) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MyAppProposalPayloadMsgB) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgProposeA.Marshal(b, m, deterministic) + return xxx_messageInfo_MyAppProposalPayloadMsgB.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -224,41 +225,35 @@ func (m *MsgProposeA) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } -func (m *MsgProposeA) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgProposeA.Merge(m, src) +func (m *MyAppProposalPayloadMsgB) XXX_Merge(src proto.Message) { + xxx_messageInfo_MyAppProposalPayloadMsgB.Merge(m, src) } -func (m *MsgProposeA) XXX_Size() int { +func (m *MyAppProposalPayloadMsgB) XXX_Size() int { return m.Size() } -func (m *MsgProposeA) XXX_DiscardUnknown() { - xxx_messageInfo_MsgProposeA.DiscardUnknown(m) +func (m *MyAppProposalPayloadMsgB) XXX_DiscardUnknown() { + xxx_messageInfo_MyAppProposalPayloadMsgB.DiscardUnknown(m) } -var xxx_messageInfo_MsgProposeA proto.InternalMessageInfo +var xxx_messageInfo_MyAppProposalPayloadMsgB proto.InternalMessageInfo -func (m *MsgProposeA) GetBase() group.MsgProposeBase { - if m != nil { - return m.Base - } - return group.MsgProposeBase{} -} - -type MsgProposeB struct { +type MsgPropose struct { Base group.MsgProposeBase `protobuf:"bytes,1,opt,name=base,proto3" json:"base"` + Msgs []MyAppMsg `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs"` } -func (m *MsgProposeB) Reset() { *m = MsgProposeB{} } -func (m *MsgProposeB) String() string { return proto.CompactTextString(m) } -func (*MsgProposeB) ProtoMessage() {} -func (*MsgProposeB) Descriptor() ([]byte, []int) { +func (m *MsgPropose) Reset() { *m = MsgPropose{} } +func (m *MsgPropose) String() string { return proto.CompactTextString(m) } +func (*MsgPropose) ProtoMessage() {} +func (*MsgPropose) Descriptor() ([]byte, []int) { return fileDescriptor_2447ab8d7bf628b8, []int{4} } -func (m *MsgProposeB) XXX_Unmarshal(b []byte) error { +func (m *MsgPropose) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgProposeB) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgPropose) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgProposeB.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgPropose.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -268,37 +263,44 @@ func (m *MsgProposeB) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } -func (m *MsgProposeB) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgProposeB.Merge(m, src) +func (m *MsgPropose) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPropose.Merge(m, src) } -func (m *MsgProposeB) XXX_Size() int { +func (m *MsgPropose) XXX_Size() int { return m.Size() } -func (m *MsgProposeB) XXX_DiscardUnknown() { - xxx_messageInfo_MsgProposeB.DiscardUnknown(m) +func (m *MsgPropose) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPropose.DiscardUnknown(m) } -var xxx_messageInfo_MsgProposeB proto.InternalMessageInfo +var xxx_messageInfo_MsgPropose proto.InternalMessageInfo -func (m *MsgProposeB) GetBase() group.MsgProposeBase { +func (m *MsgPropose) GetBase() group.MsgProposeBase { if m != nil { return m.Base } return group.MsgProposeBase{} } +func (m *MsgPropose) GetMsgs() []MyAppMsg { + if m != nil { + return m.Msgs + } + return nil +} + func init() { + proto.RegisterType((*MyAppMsg)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.MyAppMsg") proto.RegisterType((*MyAppProposal)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.MyAppProposal") - proto.RegisterType((*AMyAppProposal)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.AMyAppProposal") - proto.RegisterType((*BMyAppProposal)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.BMyAppProposal") - proto.RegisterType((*MsgProposeA)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.MsgProposeA") - proto.RegisterType((*MsgProposeB)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.MsgProposeB") + proto.RegisterType((*MyAppProposalPayloadMsgA)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.MyAppProposalPayloadMsgA") + proto.RegisterType((*MyAppProposalPayloadMsgB)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.MyAppProposalPayloadMsgB") + proto.RegisterType((*MsgPropose)(nil), "cosmos_modules.incubator.group.v1_alpha.testdata.MsgPropose") } func init() { proto.RegisterFile("testdata/types.proto", fileDescriptor_2447ab8d7bf628b8) } var fileDescriptor_2447ab8d7bf628b8 = []byte{ - // 335 bytes of a gzipped FileDescriptorProto + // 379 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x29, 0x49, 0x2d, 0x2e, 0x49, 0x49, 0x2c, 0x49, 0xd4, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x32, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x8e, 0xcf, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x2d, @@ -306,23 +308,26 @@ var fileDescriptor_2447ab8d7bf628b8 = []byte{ 0xd0, 0x2b, 0x33, 0x8c, 0x4f, 0xcc, 0x29, 0xc8, 0x48, 0xd4, 0x83, 0xe9, 0x96, 0xd2, 0x2e, 0xc9, 0xc8, 0x2c, 0x4a, 0x89, 0x2f, 0x48, 0x2c, 0x2a, 0xa9, 0xd4, 0x07, 0x1b, 0xa2, 0x0f, 0x31, 0x43, 0x17, 0x99, 0x03, 0x31, 0x5e, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0x22, 0x0e, 0x62, 0x41, 0x45, - 0x05, 0xc1, 0x66, 0x23, 0xbb, 0x43, 0xe9, 0x0b, 0x23, 0x17, 0xaf, 0x6f, 0xa5, 0x63, 0x41, 0x41, - 0x40, 0x51, 0x7e, 0x41, 0x7e, 0x71, 0x62, 0x8e, 0x50, 0x00, 0x17, 0xa3, 0xa3, 0x04, 0xa3, 0x02, - 0xa3, 0x06, 0xb7, 0x91, 0x83, 0x1e, 0xa9, 0xae, 0xd4, 0x73, 0x44, 0x31, 0xcc, 0x83, 0x21, 0x88, - 0xd1, 0x11, 0x64, 0xa2, 0x93, 0x04, 0x13, 0xb9, 0x26, 0x3a, 0x61, 0x98, 0xe8, 0x64, 0x65, 0x71, - 0x6a, 0x8b, 0xae, 0x89, 0x56, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0xd4, - 0xf3, 0xfa, 0x50, 0x53, 0xf5, 0xe1, 0xa6, 0xea, 0x43, 0x4c, 0x85, 0xe9, 0xf6, 0x74, 0x62, 0xe5, - 0x62, 0x2e, 0x2e, 0xcd, 0x55, 0x4a, 0xe4, 0xe2, 0x43, 0x75, 0xa9, 0x90, 0x3f, 0x17, 0x4b, 0x52, - 0x62, 0x71, 0x2a, 0xd4, 0xe7, 0xa6, 0x44, 0xbb, 0x13, 0x66, 0x80, 0x53, 0x62, 0x71, 0xaa, 0x13, - 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x60, 0x83, 0x40, 0x56, 0x38, 0xd1, 0xd8, 0x8a, 0x04, 0x2e, - 0x6e, 0xdf, 0xe2, 0x74, 0x88, 0x74, 0xaa, 0xa3, 0x50, 0x20, 0x8a, 0xf9, 0xe6, 0x44, 0x9b, 0x8f, - 0x30, 0x03, 0xbf, 0x0d, 0x4e, 0x34, 0xb0, 0xc1, 0xc9, 0xe7, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, - 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, - 0x8f, 0xe5, 0x18, 0xa2, 0x8c, 0x88, 0x8e, 0x5f, 0x7d, 0x58, 0x62, 0x49, 0x62, 0x03, 0xa7, 0x6a, - 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd0, 0xdb, 0x8f, 0x0f, 0x75, 0x03, 0x00, 0x00, -} - -func (this *MyAppProposal) GetProposalI() github_com_cosmos_modules_incubator_group.ProposalI { + 0x05, 0xc1, 0x66, 0x23, 0xbb, 0x43, 0xe9, 0x1b, 0x23, 0x17, 0x87, 0x6f, 0xa5, 0x63, 0x41, 0x81, + 0x6f, 0x71, 0xba, 0x50, 0x14, 0x17, 0xa3, 0xa3, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x97, + 0x1e, 0xa9, 0x0e, 0xd4, 0x03, 0x1b, 0x13, 0x50, 0x94, 0x5f, 0x90, 0x5f, 0x9c, 0x98, 0x13, 0x90, + 0x58, 0x99, 0x93, 0x9f, 0x98, 0xe2, 0x5b, 0x9c, 0xee, 0xe8, 0xc1, 0x10, 0xc4, 0xe8, 0x08, 0x32, + 0xdb, 0x49, 0x82, 0x89, 0xca, 0x66, 0x3b, 0x81, 0xcc, 0x76, 0xb2, 0xd2, 0x3e, 0xb5, 0x45, 0x57, + 0x5d, 0x2b, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x17, 0x1a, 0x16, 0xb0, 0xf0, + 0x29, 0x4e, 0xc9, 0x86, 0xfa, 0x19, 0xa4, 0x85, 0x95, 0x8b, 0xb9, 0xb8, 0x34, 0x57, 0x69, 0x1b, + 0x23, 0x17, 0x2f, 0x8a, 0xa9, 0x42, 0xfe, 0x5c, 0x2c, 0x49, 0x89, 0xc5, 0xa9, 0xd0, 0x00, 0x30, + 0x25, 0xda, 0x91, 0x30, 0x03, 0x9c, 0x12, 0x8b, 0x53, 0x9d, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, + 0x02, 0x1b, 0x24, 0x14, 0xc2, 0xc5, 0x92, 0x5b, 0x9c, 0x5e, 0x2c, 0xc1, 0xa4, 0xc0, 0xac, 0xc1, + 0x6d, 0x64, 0x45, 0xa6, 0xaf, 0x41, 0x6e, 0x86, 0x9a, 0x0a, 0x32, 0x4d, 0x49, 0x8a, 0x4b, 0x02, + 0x57, 0x48, 0xe3, 0x91, 0x73, 0x52, 0xda, 0xca, 0xc8, 0xc5, 0xe5, 0x5b, 0x9c, 0x0e, 0x91, 0x4a, + 0x15, 0x0a, 0x44, 0xf1, 0xad, 0x39, 0xd1, 0x8e, 0x43, 0x18, 0x41, 0x1f, 0xff, 0x3a, 0xf9, 0x9c, + 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, + 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x11, 0x66, 0x8c, 0x43, 0xed, 0xd2, + 0x87, 0xdb, 0xa5, 0x0f, 0x4d, 0xf2, 0x50, 0x2b, 0x92, 0xd8, 0xc0, 0xc9, 0xde, 0x18, 0x10, 0x00, + 0x00, 0xff, 0xff, 0xc5, 0x03, 0xe5, 0x0c, 0x96, 0x03, 0x00, 0x00, +} + +func (this *MyAppMsg) GetMsg() github_com_cosmos_cosmos_sdk_types.Msg { if x := this.GetA(); x != nil { return x } @@ -332,23 +337,23 @@ func (this *MyAppProposal) GetProposalI() github_com_cosmos_modules_incubator_gr return nil } -func (this *MyAppProposal) SetProposalI(value github_com_cosmos_modules_incubator_group.ProposalI) error { +func (this *MyAppMsg) SetMsg(value github_com_cosmos_cosmos_sdk_types.Msg) error { if value == nil { this.Sum = nil return nil } switch vt := value.(type) { - case *AMyAppProposal: - this.Sum = &MyAppProposal_A{vt} + case *MyAppProposalPayloadMsgA: + this.Sum = &MyAppMsg_A{vt} return nil - case *BMyAppProposal: - this.Sum = &MyAppProposal_B{vt} + case *MyAppProposalPayloadMsgB: + this.Sum = &MyAppMsg_B{vt} return nil } - return fmt.Errorf("can't encode value of type %T as message MyAppProposal", value) + return fmt.Errorf("can't encode value of type %T as message MyAppMsg", value) } -func (m *MyAppProposal) Marshal() (dAtA []byte, err error) { +func (m *MyAppMsg) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -358,12 +363,12 @@ func (m *MyAppProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MyAppProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *MyAppMsg) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MyAppProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MyAppMsg) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -380,12 +385,12 @@ func (m *MyAppProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MyAppProposal_A) MarshalTo(dAtA []byte) (int, error) { +func (m *MyAppMsg_A) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MyAppProposal_A) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MyAppMsg_A) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) if m.A != nil { { @@ -401,12 +406,12 @@ func (m *MyAppProposal_A) MarshalToSizedBuffer(dAtA []byte) (int, error) { } return len(dAtA) - i, nil } -func (m *MyAppProposal_B) MarshalTo(dAtA []byte) (int, error) { +func (m *MyAppMsg_B) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MyAppProposal_B) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MyAppMsg_B) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) if m.B != nil { { @@ -422,7 +427,7 @@ func (m *MyAppProposal_B) MarshalToSizedBuffer(dAtA []byte) (int, error) { } return len(dAtA) - i, nil } -func (m *AMyAppProposal) Marshal() (dAtA []byte, err error) { +func (m *MyAppProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -432,16 +437,30 @@ func (m *AMyAppProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *AMyAppProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *MyAppProposal) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *AMyAppProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MyAppProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + if len(m.Msgs) > 0 { + for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } { size, err := m.Base.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -455,7 +474,7 @@ func (m *AMyAppProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *BMyAppProposal) Marshal() (dAtA []byte, err error) { +func (m *MyAppProposalPayloadMsgA) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -465,30 +484,20 @@ func (m *BMyAppProposal) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *BMyAppProposal) MarshalTo(dAtA []byte) (int, error) { +func (m *MyAppProposalPayloadMsgA) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *BMyAppProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MyAppProposalPayloadMsgA) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - { - size, err := m.Base.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } -func (m *MsgProposeA) Marshal() (dAtA []byte, err error) { +func (m *MyAppProposalPayloadMsgB) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -498,30 +507,20 @@ func (m *MsgProposeA) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgProposeA) MarshalTo(dAtA []byte) (int, error) { +func (m *MyAppProposalPayloadMsgB) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgProposeA) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MyAppProposalPayloadMsgB) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - { - size, err := m.Base.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } -func (m *MsgProposeB) Marshal() (dAtA []byte, err error) { +func (m *MsgPropose) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -531,16 +530,30 @@ func (m *MsgProposeB) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgProposeB) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgPropose) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgProposeB) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgPropose) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + if len(m.Msgs) > 0 { + for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } { size, err := m.Base.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -565,7 +578,7 @@ func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MyAppProposal) Size() (n int) { +func (m *MyAppMsg) Size() (n int) { if m == nil { return 0 } @@ -577,7 +590,7 @@ func (m *MyAppProposal) Size() (n int) { return n } -func (m *MyAppProposal_A) Size() (n int) { +func (m *MyAppMsg_A) Size() (n int) { if m == nil { return 0 } @@ -589,7 +602,7 @@ func (m *MyAppProposal_A) Size() (n int) { } return n } -func (m *MyAppProposal_B) Size() (n int) { +func (m *MyAppMsg_B) Size() (n int) { if m == nil { return 0 } @@ -601,7 +614,7 @@ func (m *MyAppProposal_B) Size() (n int) { } return n } -func (m *AMyAppProposal) Size() (n int) { +func (m *MyAppProposal) Size() (n int) { if m == nil { return 0 } @@ -609,32 +622,34 @@ func (m *AMyAppProposal) Size() (n int) { _ = l l = m.Base.Size() n += 1 + l + sovTypes(uint64(l)) + if len(m.Msgs) > 0 { + for _, e := range m.Msgs { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } return n } -func (m *BMyAppProposal) Size() (n int) { +func (m *MyAppProposalPayloadMsgA) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = m.Base.Size() - n += 1 + l + sovTypes(uint64(l)) return n } -func (m *MsgProposeA) Size() (n int) { +func (m *MyAppProposalPayloadMsgB) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = m.Base.Size() - n += 1 + l + sovTypes(uint64(l)) return n } -func (m *MsgProposeB) Size() (n int) { +func (m *MsgPropose) Size() (n int) { if m == nil { return 0 } @@ -642,6 +657,12 @@ func (m *MsgProposeB) Size() (n int) { _ = l l = m.Base.Size() n += 1 + l + sovTypes(uint64(l)) + if len(m.Msgs) > 0 { + for _, e := range m.Msgs { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } return n } @@ -651,7 +672,7 @@ func sovTypes(x uint64) (n int) { func sozTypes(x uint64) (n int) { return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MyAppProposal) Unmarshal(dAtA []byte) error { +func (m *MyAppMsg) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -674,10 +695,10 @@ func (m *MyAppProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MyAppProposal: wiretype end group for non-group") + return fmt.Errorf("proto: MyAppMsg: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MyAppProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MyAppMsg: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -709,11 +730,11 @@ func (m *MyAppProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - v := &AMyAppProposal{} + v := &MyAppProposalPayloadMsgA{} if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } - m.Sum = &MyAppProposal_A{v} + m.Sum = &MyAppMsg_A{v} iNdEx = postIndex case 2: if wireType != 2 { @@ -744,11 +765,11 @@ func (m *MyAppProposal) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - v := &BMyAppProposal{} + v := &MyAppProposalPayloadMsgB{} if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } - m.Sum = &MyAppProposal_B{v} + m.Sum = &MyAppMsg_B{v} iNdEx = postIndex default: iNdEx = preIndex @@ -774,7 +795,7 @@ func (m *MyAppProposal) Unmarshal(dAtA []byte) error { } return nil } -func (m *AMyAppProposal) Unmarshal(dAtA []byte) error { +func (m *MyAppProposal) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -797,10 +818,10 @@ func (m *AMyAppProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: AMyAppProposal: wiretype end group for non-group") + return fmt.Errorf("proto: MyAppProposal: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: AMyAppProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MyAppProposal: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -836,6 +857,40 @@ func (m *AMyAppProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msgs = append(m.Msgs, MyAppMsg{}) + if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -860,7 +915,7 @@ func (m *AMyAppProposal) Unmarshal(dAtA []byte) error { } return nil } -func (m *BMyAppProposal) Unmarshal(dAtA []byte) error { +func (m *MyAppProposalPayloadMsgA) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -883,45 +938,12 @@ func (m *BMyAppProposal) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: BMyAppProposal: wiretype end group for non-group") + return fmt.Errorf("proto: MyAppProposalPayloadMsgA: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: BMyAppProposal: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MyAppProposalPayloadMsgA: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Base", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Base.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -946,7 +968,7 @@ func (m *BMyAppProposal) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgProposeA) Unmarshal(dAtA []byte) error { +func (m *MyAppProposalPayloadMsgB) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -969,45 +991,12 @@ func (m *MsgProposeA) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgProposeA: wiretype end group for non-group") + return fmt.Errorf("proto: MyAppProposalPayloadMsgB: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgProposeA: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MyAppProposalPayloadMsgB: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Base", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Base.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) @@ -1032,7 +1021,7 @@ func (m *MsgProposeA) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgProposeB) Unmarshal(dAtA []byte) error { +func (m *MsgPropose) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1055,10 +1044,10 @@ func (m *MsgProposeB) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgProposeB: wiretype end group for non-group") + return fmt.Errorf("proto: MsgPropose: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgProposeB: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgPropose: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1094,6 +1083,40 @@ func (m *MsgProposeB) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msgs = append(m.Msgs, MyAppMsg{}) + if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) diff --git a/incubator/group/testdata/types.proto b/incubator/group/testdata/types.proto index 18f89a4..d735070 100644 --- a/incubator/group/testdata/types.proto +++ b/incubator/group/testdata/types.proto @@ -7,27 +7,29 @@ import "third_party/proto/cosmos-proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "group/types.proto"; - - -message MyAppProposal { - option (cosmos_proto.interface_type) = "*github.com/cosmos/modules/incubator/group.ProposalI"; +// MyAppMsg is the payload stored with a proposal and executed on success +message MyAppMsg { + option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/types.Msg"; oneof sum { - AMyAppProposal A = 1; - BMyAppProposal B = 2; + MyAppProposalPayloadMsgA A = 1; + MyAppProposalPayloadMsgB B = 2; } } -message AMyAppProposal { + +message MyAppProposal { cosmos_modules.incubator.group.v1_alpha.ProposalBase base = 1 [(gogoproto.nullable) = false]; + // option (cosmos_proto.interface_type) = "*github.com/cosmos/modules/incubator/group.ProposalI"; + repeated MyAppMsg msgs = 2 [(gogoproto.nullable) = false]; } -message BMyAppProposal { - cosmos_modules.incubator.group.v1_alpha.ProposalBase base = 1 [(gogoproto.nullable) = false]; +message MyAppProposalPayloadMsgA { } -message MsgProposeA { - cosmos_modules.incubator.group.v1_alpha.MsgProposeBase base = 1 [(gogoproto.nullable) = false]; +message MyAppProposalPayloadMsgB { } -message MsgProposeB { + +message MsgPropose { cosmos_modules.incubator.group.v1_alpha.MsgProposeBase base = 1 [(gogoproto.nullable) = false]; + repeated MyAppMsg msgs = 2 [(gogoproto.nullable) = false]; } \ No newline at end of file diff --git a/incubator/group/testsupport.go b/incubator/group/testsupport.go index 095305d..447a668 100644 --- a/incubator/group/testsupport.go +++ b/incubator/group/testsupport.go @@ -1,6 +1,7 @@ package group import ( + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/store/rootmulti" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params" @@ -29,24 +30,31 @@ func createGroupKeeper() (Keeper, sdk.Context) { paramSpace := subspace.NewSubspace(ModuleCdc.amino, pKey, pTKey, DefaultParamspace) groupKey := sdk.NewKVStoreKey(StoreKeyName) - k := NewGroupKeeper(groupKey, paramSpace, &MockProposalModel{}) + k := NewGroupKeeper(groupKey, paramSpace, baseapp.NewRouter(), &MockProposalI{}) ctx := NewContext(pKey, pTKey, groupKey) k.setParams(ctx, DefaultParams()) return k, ctx } -type MockProposalModel struct { - Proposal ProposalI +type MockProposalI struct { } -func (f MockProposalModel) Marshal() ([]byte, error) { +func (m MockProposalI) Marshal() ([]byte, error) { panic("implement me") } -func (f MockProposalModel) Unmarshal([]byte) error { +func (m MockProposalI) Unmarshal([]byte) error { panic("implement me") } -func (f MockProposalModel) GetProposalI() ProposalI { - return f.Proposal +func (m MockProposalI) GetBase() ProposalBase { + panic("implement me") +} + +func (m MockProposalI) SetBase(ProposalBase) { + panic("implement me") +} + +func (m MockProposalI) GetMsg() []sdk.Msg { + panic("implement me") }