Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove gov keeper.MustMarshal #10373

Merged
merged 3 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Replace `baseapp.SetAnteHandler` with `baseapp.SetTxHandler`.
* Move Msg routers from BaseApp to middlewares.
* Move Baseapp panic recovery into a middleware.
* Rename simulation helper methods `baseapp.{Check,Deliver}` to `baseapp.Sim{Check,Deliver}`.
* Rename simulation helper methods `baseapp.{Check,Deliver}` to `baseapp.Sim{Check,Deliver}**.
* (x/gov) [\#10373](https://github.com/cosmos/cosmos-sdk/pull/10373) Removed gov `keeper.{MustMarshal, MustUnmarshal}`.


### Client Breaking Changes

Expand Down Expand Up @@ -132,7 +134,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (client) [#10226](https://github.com/cosmos/cosmos-sdk/pull/10226) Fix --home flag parsing.
* (client) [#10226](https://github.com/cosmos/cosmos-sdk/pull/10226) Fix --home flag parsing.
* [#10180](https://github.com/cosmos/cosmos-sdk/issues/10180) Documentation: make references to Cosmos SDK consistent
* (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly.
* [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasRemaining func to GasMeter.
Expand Down
39 changes: 16 additions & 23 deletions x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, content types.Content) (typ
return proposal, nil
}

// GetProposal get proposal from store by ProposalID
// GetProposal get proposal from store by ProposalID.
// Panics if can't unmarshal the proposal.
func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (types.Proposal, bool) {
store := ctx.KVStore(keeper.storeKey)

Expand All @@ -64,21 +65,27 @@ func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (types.Prop
}

var proposal types.Proposal
keeper.MustUnmarshalProposal(bz, &proposal)
if err := keeper.UnmarshalProposal(bz, &proposal); err != nil {
panic(err)
}

return proposal, true
}

// SetProposal set a proposal to store
// SetProposal set a proposal to store.
// Panics if can't marshal the proposal.
func (keeper Keeper) SetProposal(ctx sdk.Context, proposal types.Proposal) {
store := ctx.KVStore(keeper.storeKey)

bz := keeper.MustMarshalProposal(proposal)
bz, err := keeper.MarshalProposal(proposal)
if err != nil {
panic(err)
}

store := ctx.KVStore(keeper.storeKey)
store.Set(types.ProposalKey(proposal.ProposalId), bz)
}

// DeleteProposal deletes a proposal from store
// DeleteProposal deletes a proposal from store.
// Panics if the proposal doesn't exist.
func (keeper Keeper) DeleteProposal(ctx sdk.Context, proposalID uint64) {
store := ctx.KVStore(keeper.storeKey)
proposal, ok := keeper.GetProposal(ctx, proposalID)
Expand All @@ -90,7 +97,8 @@ func (keeper Keeper) DeleteProposal(ctx sdk.Context, proposalID uint64) {
store.Delete(types.ProposalKey(proposalID))
}

// IterateProposals iterates over the all the proposals and performs a callback function
// IterateProposals iterates over the all the proposals and performs a callback function.
// Panics when the iterator encounters a proposal which can't be unmarshaled.
func (keeper Keeper) IterateProposals(ctx sdk.Context, cb func(proposal types.Proposal) (stop bool)) {
store := ctx.KVStore(keeper.storeKey)

Expand Down Expand Up @@ -209,18 +217,3 @@ func (keeper Keeper) UnmarshalProposal(bz []byte, proposal *types.Proposal) erro
}
return nil
}

func (keeper Keeper) MustMarshalProposal(proposal types.Proposal) []byte {
bz, err := keeper.MarshalProposal(proposal)
if err != nil {
panic(err)
}
return bz
}

func (keeper Keeper) MustUnmarshalProposal(bz []byte, proposal *types.Proposal) {
err := keeper.UnmarshalProposal(bz, proposal)
if err != nil {
panic(err)
}
}