Skip to content

Commit 717dcdf

Browse files
refactor!: remove gov keeper.MustMarshal (#10373)
* chore: remove gov keeper.MustMarshal * added changelog and comments * Update CHANGELOG.md Co-authored-by: Amaury <[email protected]> Co-authored-by: Amaury <[email protected]>
1 parent 3c85944 commit 717dcdf

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
9797
* Replace `baseapp.SetAnteHandler` with `baseapp.SetTxHandler`.
9898
* Move Msg routers from BaseApp to middlewares.
9999
* Move Baseapp panic recovery into a middleware.
100-
* Rename simulation helper methods `baseapp.{Check,Deliver}` to `baseapp.Sim{Check,Deliver}`.
100+
* Rename simulation helper methods `baseapp.{Check,Deliver}` to `baseapp.Sim{Check,Deliver}**.
101+
* (x/gov) [\#10373](https://github.com/cosmos/cosmos-sdk/pull/10373) Removed gov `keeper.{MustMarshal, MustUnmarshal}`.
102+
101103

102104
### Client Breaking Changes
103105

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

133135
### Bug Fixes
134136

135-
* (client) [#10226](https://github.com/cosmos/cosmos-sdk/pull/10226) Fix --home flag parsing.
137+
* (client) [#10226](https://github.com/cosmos/cosmos-sdk/pull/10226) Fix --home flag parsing.
136138
* [#10180](https://github.com/cosmos/cosmos-sdk/issues/10180) Documentation: make references to Cosmos SDK consistent
137139
* (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly.
138140
* [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasRemaining func to GasMeter.

x/gov/keeper/proposal.go

+16-23
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, content types.Content) (typ
5454
return proposal, nil
5555
}
5656

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

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

6667
var proposal types.Proposal
67-
keeper.MustUnmarshalProposal(bz, &proposal)
68+
if err := keeper.UnmarshalProposal(bz, &proposal); err != nil {
69+
panic(err)
70+
}
6871

6972
return proposal, true
7073
}
7174

72-
// SetProposal set a proposal to store
75+
// SetProposal set a proposal to store.
76+
// Panics if can't marshal the proposal.
7377
func (keeper Keeper) SetProposal(ctx sdk.Context, proposal types.Proposal) {
74-
store := ctx.KVStore(keeper.storeKey)
75-
76-
bz := keeper.MustMarshalProposal(proposal)
78+
bz, err := keeper.MarshalProposal(proposal)
79+
if err != nil {
80+
panic(err)
81+
}
7782

83+
store := ctx.KVStore(keeper.storeKey)
7884
store.Set(types.ProposalKey(proposal.ProposalId), bz)
7985
}
8086

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

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

@@ -209,18 +217,3 @@ func (keeper Keeper) UnmarshalProposal(bz []byte, proposal *types.Proposal) erro
209217
}
210218
return nil
211219
}
212-
213-
func (keeper Keeper) MustMarshalProposal(proposal types.Proposal) []byte {
214-
bz, err := keeper.MarshalProposal(proposal)
215-
if err != nil {
216-
panic(err)
217-
}
218-
return bz
219-
}
220-
221-
func (keeper Keeper) MustUnmarshalProposal(bz []byte, proposal *types.Proposal) {
222-
err := keeper.UnmarshalProposal(bz, proposal)
223-
if err != nil {
224-
panic(err)
225-
}
226-
}

0 commit comments

Comments
 (0)