Skip to content

Commit

Permalink
refactor!: remove gov keeper.MustMarshal (#10373)
Browse files Browse the repository at this point in the history
* chore: remove gov keeper.MustMarshal

* added changelog and comments

* Update CHANGELOG.md

Co-authored-by: Amaury <[email protected]>

Co-authored-by: Amaury <[email protected]>
  • Loading branch information
robert-zaremba and amaury1093 authored Oct 15, 2021
1 parent 3c85944 commit 717dcdf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
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)
}
}

0 comments on commit 717dcdf

Please sign in to comment.