refactor!: remove gov keeper.MustMarshal (#10373)
* chore: remove gov keeper.MustMarshal * added changelog and comments * Update CHANGELOG.md Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
This commit is contained in:
parent
3c85944061
commit
717dcdfa8f
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
@ -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) {
|
||||
bz, err := keeper.MarshalProposal(proposal)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
store := ctx.KVStore(keeper.storeKey)
|
||||
|
||||
bz := keeper.MustMarshalProposal(proposal)
|
||||
|
||||
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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue