Skip to content

Commit

Permalink
[1752]: Clean up codec.go by getting rid of the amino codec stuff and…
Browse files Browse the repository at this point in the history
… switching to the allRequestMsgs pattern used in other modules.
  • Loading branch information
SpicyLemon committed Nov 20, 2023
1 parent 0c2ac07 commit 77e8535
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
33 changes: 7 additions & 26 deletions x/quarantine/codec.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
package quarantine

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/gogo/protobuf/proto"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgOptIn{},
&MsgOptOut{},
&MsgAccept{},
&MsgDecline{},
&MsgUpdateAutoResponses{},
)
messages := make([]proto.Message, len(allRequestMsgs))
for i, msg := range allRequestMsgs {
messages[i] = msg
}
registry.RegisterImplementations((*sdk.Msg)(nil), messages...)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

var (
amino = codec.NewLegacyAmino()

// ModuleCdc references the global x/quarantine module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
// still used for that purpose.
//
// The actual codec used for serialization should be provided to x/quarantine and
// defined at the application level.
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
cryptocodec.RegisterCrypto(amino)
sdk.RegisterLegacyAminoCodec(amino)
}
16 changes: 7 additions & 9 deletions x/quarantine/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import (
qerrors "github.com/provenance-io/provenance/x/quarantine/errors"
)

var _ sdk.Msg = &MsgOptIn{}
var allRequestMsgs = []sdk.Msg{
(*MsgOptIn)(nil),
(*MsgOptOut)(nil),
(*MsgAccept)(nil),
(*MsgDecline)(nil),
(*MsgUpdateAutoResponses)(nil),
}

// NewMsgOptIn creates a new msg to opt in to account quarantine.
func NewMsgOptIn(toAddr sdk.AccAddress) *MsgOptIn {
Expand All @@ -32,8 +38,6 @@ func (msg MsgOptIn) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{addr}
}

var _ sdk.Msg = &MsgOptOut{}

// NewMsgOptOut creates a new msg to opt out of account quarantine.
func NewMsgOptOut(toAddr sdk.AccAddress) *MsgOptOut {
return &MsgOptOut{
Expand All @@ -55,8 +59,6 @@ func (msg MsgOptOut) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{addr}
}

var _ sdk.Msg = &MsgAccept{}

// NewMsgAccept creates a new msg to accept quarantined funds.
func NewMsgAccept(toAddr sdk.AccAddress, fromAddrsStrs []string, permanent bool) *MsgAccept {
return &MsgAccept{
Expand Down Expand Up @@ -88,8 +90,6 @@ func (msg MsgAccept) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{addr}
}

var _ sdk.Msg = &MsgDecline{}

// NewMsgDecline creates a new msg to decline quarantined funds.
func NewMsgDecline(toAddr sdk.AccAddress, fromAddrsStrs []string, permanent bool) *MsgDecline {
return &MsgDecline{
Expand Down Expand Up @@ -121,8 +121,6 @@ func (msg MsgDecline) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{addr}
}

var _ sdk.Msg = &MsgUpdateAutoResponses{}

// NewMsgUpdateAutoResponses creates a new msg to update quarantined auto-responses.
func NewMsgUpdateAutoResponses(toAddr sdk.AccAddress, updates []*AutoResponseUpdate) *MsgUpdateAutoResponses {
return &MsgUpdateAutoResponses{
Expand Down

0 comments on commit 77e8535

Please sign in to comment.