From 1d8d5965b174e9059f69715d1ef8cb2bc6f9cbb7 Mon Sep 17 00:00:00 2001 From: StrathCole Date: Mon, 18 Nov 2024 11:33:38 +0100 Subject: [PATCH] - legacy message type compatibility with upstream types --- custom/auth/ante/fee_test.go | 59 ++++++++++++ custom/auth/types/codec.go | 52 ++++++++-- custom/authz/types/codec.go | 65 ++++++++++++- custom/bank/types/codec.go | 49 +++++++++- custom/crisis/types/codec.go | 18 +++- custom/distribution/types/codec.go | 77 ++++++++++++++- custom/evidence/types/codec.go | 36 ++++++- custom/feegrant/types/codec.go | 80 ++++++++++++++-- custom/params/types/codec.go | 22 ++++- custom/slashing/types/codec.go | 19 +++- custom/staking/types/codec.go | 94 +++++++++++++++++-- custom/upgrade/types/codec.go | 53 ++++++++++- ...d_burn_tax_exemption_address_proposal.json | 2 +- 13 files changed, 580 insertions(+), 46 deletions(-) diff --git a/custom/auth/ante/fee_test.go b/custom/auth/ante/fee_test.go index bb094edbc..5e55ae5e8 100644 --- a/custom/auth/ante/fee_test.go +++ b/custom/auth/ante/fee_test.go @@ -6,6 +6,8 @@ import ( "os" "time" + custombanktypes "github.com/classic-terra/core/v3/custom/bank/types" + "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -1057,3 +1059,60 @@ func (s *AnteTestSuite) TestOracleZeroFee() { balances = s.app.BankKeeper.GetAllBalances(s.ctx, s.app.AccountKeeper.GetModuleAddress(authtypes.FeeCollectorName)) s.Require().Equal(sdk.Coins{}, balances) } + +func (s *AnteTestSuite) TestLegacyAndUpstreamMsgSendCompatibility() { + // Setup the test environment + s.SetupTest(true) + + // Initialize the codec + amino := codec.NewLegacyAmino() + custombanktypes.RegisterLegacyAminoCodec(amino) // Your custom registration + amino.Seal() + + require := s.Require() + + // Test message + addr1 := "cosmos1addressfrom" + addr2 := "cosmos1addressto" + amount := sdk.NewCoins(sdk.NewInt64Coin("atom", 1000)) + + // Create messages + customMsg := custombanktypes.LegacyMsgSend{MsgSend: banktypes.MsgSend{FromAddress: addr1, ToAddress: addr2, Amount: amount}} + upstreamMsg := banktypes.MsgSend{FromAddress: addr1, ToAddress: addr2, Amount: amount} + + // Encode and decode using "bank/MsgSend" + bankJSON, err := amino.MarshalJSON(&customMsg) + require.NoError(err, "Failed to encode LegacyMsgSend with bank/MsgSend") + + var decodedCustomMsg custombanktypes.LegacyMsgSend + err = amino.UnmarshalJSON(bankJSON, &decodedCustomMsg) + require.NoError(err, "Failed to decode LegacyMsgSend with bank/MsgSend") + require.Equal(customMsg, decodedCustomMsg, "LegacyMsgSend (bank/MsgSend) mismatch after decoding") + + // construct a custom byte message + msg := json.RawMessage([]byte(`{"type":"bank/MsgSend","value":{"from_address":"cosmos1addressfrom","to_address":"cosmos1addressto","amount":[{"denom":"atom","amount":"1000"}]}}`)) + err = amino.UnmarshalJSON(msg, &decodedCustomMsg) + require.NoError(err, "Failed to decode LegacyMsgSend with bank/MsgSend") + require.Equal(customMsg, decodedCustomMsg, "LegacyMsgSend (bank/MsgSend) mismatch after decoding") + + // Encode and decode using "cosmos-sdk/MsgSend" + cosmosJSON, err := amino.MarshalJSON(&upstreamMsg) + require.NoError(err, "Failed to encode MsgSend with cosmos-sdk/MsgSend") + + var decodedUpstreamMsg banktypes.MsgSend + err = amino.UnmarshalJSON(cosmosJSON, &decodedUpstreamMsg) + require.NoError(err, "Failed to decode MsgSend with cosmos-sdk/MsgSend") + require.Equal(upstreamMsg, decodedUpstreamMsg, "MsgSend (cosmos-sdk/MsgSend) mismatch after decoding") + + // construct a custom upstream byte message + msg = json.RawMessage([]byte(`{"type":"cosmos-sdk/MsgSend","value":{"from_address":"cosmos1addressfrom","to_address":"cosmos1addressto","amount":[{"denom":"atom","amount":"1000"}]}}`)) + err = amino.UnmarshalJSON(msg, &decodedUpstreamMsg) + require.NoError(err, "Failed to decode MsgSend with cosmos-sdk/MsgSend") + require.Equal(upstreamMsg, decodedUpstreamMsg, "MsgSend (cosmos-sdk/MsgSend) mismatch after decoding") + + // Ensure TypeURLs match + customTypeURL := sdk.MsgTypeURL(&customMsg.MsgSend) + upstreamTypeURL := sdk.MsgTypeURL(&upstreamMsg) + require.Equal("/cosmos.bank.v1beta1.MsgSend", customTypeURL, "LegacyMsgSend TypeURL mismatch") + require.Equal("/cosmos.bank.v1beta1.MsgSend", upstreamTypeURL, "MsgSend TypeURL mismatch") +} diff --git a/custom/auth/types/codec.go b/custom/auth/types/codec.go index 8e700a89b..a8e5eabe6 100644 --- a/custom/auth/types/codec.go +++ b/custom/auth/types/codec.go @@ -1,21 +1,61 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/types" ) +// Wrapper type for backward compatibility +type LegacyStdTx struct { + legacytx.StdTx +} + +// Wrapper type for backward compatibility +type LegacyBaseAccount struct { + types.BaseAccount +} + +// Wrapper type for backward compatibility +type LegacyModuleAccount struct { + types.ModuleAccount +} + +func (l LegacyStdTx) MarshalJSON() ([]byte, error) { + return json.Marshal(l.StdTx) +} + +func (l *LegacyStdTx) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.StdTx) +} + +func (l LegacyBaseAccount) MarshalJSON() ([]byte, error) { + return json.Marshal(l.BaseAccount) +} + +func (l *LegacyBaseAccount) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.BaseAccount) +} + +func (l LegacyModuleAccount) MarshalJSON() ([]byte, error) { + return json.Marshal(l.ModuleAccount) +} + +func (l *LegacyModuleAccount) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.ModuleAccount) +} + // RegisterLegacyAminoCodec registers the account interfaces and concrete types on the // provided LegacyAmino codec. These types are used for Amino JSON serialization func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterInterface((*types.ModuleAccountI)(nil), nil) - cdc.RegisterInterface((*types.GenesisAccount)(nil), nil) - cdc.RegisterInterface((*types.AccountI)(nil), nil) - cdc.RegisterConcrete(&types.BaseAccount{}, "core/Account", nil) - cdc.RegisterConcrete(&types.ModuleAccount{}, "core/ModuleAccount", nil) - cdc.RegisterConcrete(legacytx.StdTx{}, "core/StdTx", nil) + types.RegisterLegacyAminoCodec(cdc) + + cdc.RegisterConcrete(&LegacyBaseAccount{}, "core/Account", nil) + cdc.RegisterConcrete(&LegacyModuleAccount{}, "core/ModuleAccount", nil) + cdc.RegisterConcrete(LegacyStdTx{}, "core/StdTx", nil) } var ( diff --git a/custom/authz/types/codec.go b/custom/authz/types/codec.go index 27363d543..1f3d2027a 100644 --- a/custom/authz/types/codec.go +++ b/custom/authz/types/codec.go @@ -1,18 +1,73 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/x/authz" ) +// Wrapper type for backward compatibility +type LegacyMsgGrant struct { + authz.MsgGrant +} + +// Wrapper type for backward compatibility +type LegacyMsgRevoke struct { + authz.MsgRevoke +} + +// Wrapper type for backward compatibility +type LegacyMsgExec struct { + authz.MsgExec +} + +// Wrapper type for backward compatibility +type LegacyGenericAuthorization struct { + authz.GenericAuthorization +} + +func (l LegacyMsgGrant) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgGrant) +} + +func (l *LegacyMsgGrant) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgGrant) +} + +func (l LegacyMsgRevoke) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgRevoke) +} + +func (l *LegacyMsgRevoke) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgRevoke) +} + +func (l LegacyMsgExec) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgExec) +} + +func (l *LegacyMsgExec) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgExec) +} + +func (l LegacyGenericAuthorization) MarshalJSON() ([]byte, error) { + return json.Marshal(l.GenericAuthorization) +} + +func (l *LegacyGenericAuthorization) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.GenericAuthorization) +} + // RegisterLegacyAminoCodec registers the necessary x/authz interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - legacy.RegisterAminoMsg(cdc, &authz.MsgGrant{}, "msgauth/MsgGrantAuthorization") - legacy.RegisterAminoMsg(cdc, &authz.MsgRevoke{}, "msgauth/MsgRevokeAuthorization") - legacy.RegisterAminoMsg(cdc, &authz.MsgExec{}, "msgauth/MsgExecAuthorized") + authz.RegisterLegacyAminoCodec(cdc) + + legacy.RegisterAminoMsg(cdc, &LegacyMsgGrant{}, "msgauth/MsgGrantAuthorization") + legacy.RegisterAminoMsg(cdc, &LegacyMsgRevoke{}, "msgauth/MsgRevokeAuthorization") + legacy.RegisterAminoMsg(cdc, &LegacyMsgExec{}, "msgauth/MsgExecAuthorized") - cdc.RegisterInterface((*authz.Authorization)(nil), nil) - cdc.RegisterConcrete(&authz.GenericAuthorization{}, "msgauth/GenericAuthorization", nil) + cdc.RegisterConcrete(&LegacyGenericAuthorization{}, "msgauth/GenericAuthorization", nil) } diff --git a/custom/bank/types/codec.go b/custom/bank/types/codec.go index e1742e68e..948ed8338 100644 --- a/custom/bank/types/codec.go +++ b/custom/bank/types/codec.go @@ -1,18 +1,61 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/x/bank/types" ) +// Wrapper type for backward compatibility +type LegacyMsgSend struct { + types.MsgSend +} + +// Wrapper type for backward compatibility +type LegacyMsgMultiSend struct { + types.MsgMultiSend +} + +type LegacySendAuthorization struct { + types.SendAuthorization +} + +func (m LegacyMsgSend) MarshalJSON() ([]byte, error) { + return json.Marshal(m.MsgSend) +} + +func (m *LegacyMsgSend) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &m.MsgSend) +} + +func (m LegacyMsgMultiSend) MarshalJSON() ([]byte, error) { + return json.Marshal(m.MsgMultiSend) +} + +func (m *LegacyMsgMultiSend) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &m.MsgMultiSend) +} + +func (m LegacySendAuthorization) MarshalJSON() ([]byte, error) { + return json.Marshal(m.SendAuthorization) +} + +func (m *LegacySendAuthorization) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &m.SendAuthorization) +} + // RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - legacy.RegisterAminoMsg(cdc, &types.MsgSend{}, "bank/MsgSend") - legacy.RegisterAminoMsg(cdc, &types.MsgMultiSend{}, "bank/MsgMultiSend") - cdc.RegisterConcrete(&types.SendAuthorization{}, "msgauth/SendAuthorization", nil) + // register the normal bank message types + types.RegisterLegacyAminoCodec(cdc) + + legacy.RegisterAminoMsg(cdc, &LegacyMsgSend{}, "bank/MsgSend") + legacy.RegisterAminoMsg(cdc, &LegacyMsgMultiSend{}, "bank/MsgMultiSend") + cdc.RegisterConcrete(&LegacySendAuthorization{}, "msgauth/SendAuthorization", nil) } var ( diff --git a/custom/crisis/types/codec.go b/custom/crisis/types/codec.go index 7fffd946e..00afe9bce 100644 --- a/custom/crisis/types/codec.go +++ b/custom/crisis/types/codec.go @@ -1,16 +1,32 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/x/crisis/types" ) +// Wrapper type for backward compatibility +type LegacyMsgVerifyInvariant struct { + types.MsgVerifyInvariant +} + +func (l LegacyMsgVerifyInvariant) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgVerifyInvariant) +} + +func (l *LegacyMsgVerifyInvariant) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgVerifyInvariant) +} + // RegisterLegacyAminoCodec registers the necessary x/crisis interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - legacy.RegisterAminoMsg(cdc, &types.MsgVerifyInvariant{}, "crisis/MsgVerifyInvariant") + types.RegisterLegacyAminoCodec(cdc) + legacy.RegisterAminoMsg(cdc, &LegacyMsgVerifyInvariant{}, "crisis/MsgVerifyInvariant") } var ( diff --git a/custom/distribution/types/codec.go b/custom/distribution/types/codec.go index ca563fcb1..6561b0911 100644 --- a/custom/distribution/types/codec.go +++ b/custom/distribution/types/codec.go @@ -1,6 +1,8 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -9,15 +11,82 @@ import ( govtypes "github.com/classic-terra/core/v3/custom/gov/types" ) +// Wrapper type for backward compatibility +type LegacyMsgSetWithdrawAddress struct { + types.MsgSetWithdrawAddress +} + +// Wrapper type for backward compatibility +type LegacyMsgFundCommunityPool struct { + types.MsgFundCommunityPool +} + +// Wrapper type for backward compatibility +type LegacyMsgWithdrawDelegatorReward struct { + types.MsgWithdrawDelegatorReward +} + +// Wrapper type for backward compatibility +type LegacyMsgWithdrawValidatorCommission struct { + types.MsgWithdrawValidatorCommission +} + +// Wrapper type for backward compatibility +type LegacyCommunityPoolSpendProposal struct { + types.CommunityPoolSpendProposal +} + +func (l LegacyMsgSetWithdrawAddress) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgSetWithdrawAddress) +} + +func (l *LegacyMsgSetWithdrawAddress) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgSetWithdrawAddress) +} + +func (l LegacyMsgFundCommunityPool) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgFundCommunityPool) +} + +func (l *LegacyMsgFundCommunityPool) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgFundCommunityPool) +} + +func (l LegacyMsgWithdrawDelegatorReward) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgWithdrawDelegatorReward) +} + +func (l *LegacyMsgWithdrawDelegatorReward) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgWithdrawDelegatorReward) +} + +func (l LegacyMsgWithdrawValidatorCommission) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgWithdrawValidatorCommission) +} + +func (l *LegacyMsgWithdrawValidatorCommission) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgWithdrawValidatorCommission) +} + +func (l LegacyCommunityPoolSpendProposal) MarshalJSON() ([]byte, error) { + return json.Marshal(l.CommunityPoolSpendProposal) +} + +func (l *LegacyCommunityPoolSpendProposal) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.CommunityPoolSpendProposal) +} + // RegisterLegacyAminoCodec registers the necessary x/distribution interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) + // distribution/MsgWithdrawDelegationReward and distribution/MsgWithdrawValidatorCommission // will not be supported by Ledger signing due to the overflow of length of the name - cdc.RegisterConcrete(&types.MsgWithdrawDelegatorReward{}, "distribution/MsgWithdrawDelegationReward", nil) - cdc.RegisterConcrete(&types.MsgWithdrawValidatorCommission{}, "distribution/MsgWithdrawValidatorCommission", nil) - legacy.RegisterAminoMsg(cdc, &types.MsgSetWithdrawAddress{}, "distribution/MsgModifyWithdrawAddress") - legacy.RegisterAminoMsg(cdc, &types.MsgFundCommunityPool{}, "distribution/MsgFundCommunityPool") + cdc.RegisterConcrete(&LegacyMsgWithdrawDelegatorReward{}, "distribution/MsgWithdrawDelegationReward", nil) + cdc.RegisterConcrete(&LegacyMsgWithdrawValidatorCommission{}, "distribution/MsgWithdrawValidatorCommission", nil) + legacy.RegisterAminoMsg(cdc, &LegacyMsgSetWithdrawAddress{}, "distribution/MsgModifyWithdrawAddress") + legacy.RegisterAminoMsg(cdc, &LegacyMsgFundCommunityPool{}, "distribution/MsgFundCommunityPool") cdc.RegisterConcrete(&types.CommunityPoolSpendProposal{}, "distribution/CommunityPoolSpendProposal", nil) } diff --git a/custom/evidence/types/codec.go b/custom/evidence/types/codec.go index b2727ef7c..9b9a091d1 100644 --- a/custom/evidence/types/codec.go +++ b/custom/evidence/types/codec.go @@ -1,19 +1,47 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/x/evidence/exported" "github.com/cosmos/cosmos-sdk/x/evidence/types" ) +// Wrapper type for backward compatibility +type LegacyMsgSubmitEvidence struct { + types.MsgSubmitEvidence +} + +// Wrapper type for backward compatibility +type LegacyEquivocation struct { + types.Equivocation +} + +func (l LegacyMsgSubmitEvidence) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgSubmitEvidence) +} + +func (l *LegacyMsgSubmitEvidence) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgSubmitEvidence) +} + +func (l LegacyEquivocation) MarshalJSON() ([]byte, error) { + return json.Marshal(l.Equivocation) +} + +func (l *LegacyEquivocation) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.Equivocation) +} + // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the // evidence module. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterInterface((*exported.Evidence)(nil), nil) - legacy.RegisterAminoMsg(cdc, &types.MsgSubmitEvidence{}, "evidence/MsgSubmitEvidence") - cdc.RegisterConcrete(&types.Equivocation{}, "evidence/Equivocation", nil) + types.RegisterLegacyAminoCodec(cdc) + + legacy.RegisterAminoMsg(cdc, &LegacyMsgSubmitEvidence{}, "evidence/MsgSubmitEvidence") + cdc.RegisterConcrete(&LegacyEquivocation{}, "evidence/Equivocation", nil) } var ( diff --git a/custom/feegrant/types/codec.go b/custom/feegrant/types/codec.go index 73e7047cb..3c3f1e83e 100644 --- a/custom/feegrant/types/codec.go +++ b/custom/feegrant/types/codec.go @@ -1,19 +1,87 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/x/feegrant" ) +// Wrapper type for backward compatibility +type LegacyMsgGrantAllowance struct { + feegrant.MsgGrantAllowance +} + +// Wrapper type for backward compatibility +type LegacyMsgRevokeAllowance struct { + feegrant.MsgRevokeAllowance +} + +// Wrapper type for backward compatibility +type LegacyBasicAllowance struct { + feegrant.BasicAllowance +} + +// Wrapper type for backward compatibility +type LegacyPeriodicAllowance struct { + feegrant.PeriodicAllowance +} + +// Wrapper type for backward compatibility +type LegacyAllowedMsgAllowance struct { + feegrant.AllowedMsgAllowance +} + +func (l LegacyMsgGrantAllowance) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgGrantAllowance) +} + +func (l *LegacyMsgGrantAllowance) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgGrantAllowance) +} + +func (l LegacyMsgRevokeAllowance) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgRevokeAllowance) +} + +func (l *LegacyMsgRevokeAllowance) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgRevokeAllowance) +} + +func (l LegacyBasicAllowance) MarshalJSON() ([]byte, error) { + return json.Marshal(l.BasicAllowance) +} + +func (l *LegacyBasicAllowance) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.BasicAllowance) +} + +func (l LegacyPeriodicAllowance) MarshalJSON() ([]byte, error) { + return json.Marshal(l.PeriodicAllowance) +} + +func (l *LegacyPeriodicAllowance) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.PeriodicAllowance) +} + +func (l LegacyAllowedMsgAllowance) MarshalJSON() ([]byte, error) { + return json.Marshal(l.AllowedMsgAllowance) +} + +func (l *LegacyAllowedMsgAllowance) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.AllowedMsgAllowance) +} + // RegisterLegacyAminoCodec registers the necessary x/authz interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - legacy.RegisterAminoMsg(cdc, &feegrant.MsgGrantAllowance{}, "feegrant/MsgGrantAllowance") - legacy.RegisterAminoMsg(cdc, &feegrant.MsgRevokeAllowance{}, "feegrant/MsgRevokeAllowance") + feegrant.RegisterLegacyAminoCodec(cdc) + + legacy.RegisterAminoMsg(cdc, &LegacyMsgGrantAllowance{}, "feegrant/MsgGrantAllowance") + legacy.RegisterAminoMsg(cdc, &LegacyMsgRevokeAllowance{}, "feegrant/MsgRevokeAllowance") - cdc.RegisterInterface((*feegrant.FeeAllowanceI)(nil), nil) - cdc.RegisterConcrete(&feegrant.BasicAllowance{}, "feegrant/BasicAllowance", nil) - cdc.RegisterConcrete(&feegrant.PeriodicAllowance{}, "feegrant/PeriodicAllowance", nil) - cdc.RegisterConcrete(&feegrant.AllowedMsgAllowance{}, "feegrant/AllowedMsgAllowance", nil) + cdc.RegisterConcrete(&LegacyBasicAllowance{}, "feegrant/BasicAllowance", nil) + cdc.RegisterConcrete(&LegacyPeriodicAllowance{}, "feegrant/PeriodicAllowance", nil) + cdc.RegisterConcrete(&LegacyAllowedMsgAllowance{}, "feegrant/AllowedMsgAllowance", nil) } diff --git a/custom/params/types/codec.go b/custom/params/types/codec.go index 8548a0b6e..552549c7f 100644 --- a/custom/params/types/codec.go +++ b/custom/params/types/codec.go @@ -1,17 +1,31 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" - - govtypes "github.com/classic-terra/core/v3/custom/gov/types" ) +// Wrapper type for backward compatibility +type LegacyParameterChangeProposal struct { + proposal.ParameterChangeProposal +} + +func (l LegacyParameterChangeProposal) MarshalJSON() ([]byte, error) { + return json.Marshal(l.ParameterChangeProposal) +} + +func (l *LegacyParameterChangeProposal) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.ParameterChangeProposal) +} + // RegisterLegacyAminoCodec registers all necessary param module types with a given LegacyAmino codec. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&proposal.ParameterChangeProposal{}, "params/ParameterChangeProposal", nil) + proposal.RegisterLegacyAminoCodec(cdc) + cdc.RegisterConcrete(&LegacyParameterChangeProposal{}, "params/ParameterChangeProposal", nil) } func init() { - govtypes.RegisterProposalTypeCodec(&proposal.ParameterChangeProposal{}, "params/ParameterChangeProposal") + // govtypes.RegisterProposalTypeCodec(&LegacyParameterChangeProposal{}, "params/ParameterChangeProposal") } diff --git a/custom/slashing/types/codec.go b/custom/slashing/types/codec.go index f002c7379..e9b9720f2 100644 --- a/custom/slashing/types/codec.go +++ b/custom/slashing/types/codec.go @@ -1,15 +1,32 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) +// Wrapper type for backward compatibility +type LegacyMsgUnjail struct { + types.MsgUnjail +} + +func (l LegacyMsgUnjail) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgUnjail) +} + +func (l *LegacyMsgUnjail) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgUnjail) +} + // RegisterLegacyAminoCodec registers concrete types on LegacyAmino codec func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - legacy.RegisterAminoMsg(cdc, &types.MsgUnjail{}, "slashing/MsgUnjail") + types.RegisterLegacyAminoCodec(cdc) + + legacy.RegisterAminoMsg(cdc, &LegacyMsgUnjail{}, "slashing/MsgUnjail") } var ( diff --git a/custom/staking/types/codec.go b/custom/staking/types/codec.go index 99c1b89e1..f0d176fa0 100644 --- a/custom/staking/types/codec.go +++ b/custom/staking/types/codec.go @@ -1,6 +1,8 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -8,16 +10,96 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" ) +// Wrapper type for backward compatibility +type LegacyMsgCreateValidator struct { + types.MsgCreateValidator +} + +// Wrapper type for backward compatibility +type LegacyMsgEditValidator struct { + types.MsgEditValidator +} + +// Wrapper type for backward compatibility +type LegacyMsgDelegate struct { + types.MsgDelegate +} + +// Wrapper type for backward compatibility +type LegacyMsgUndelegate struct { + types.MsgUndelegate +} + +// Wrapper type for backward compatibility +type LegacyMsgBeginRedelegate struct { + types.MsgBeginRedelegate +} + +// Wrapper type for backward compatibility +type LegacyStakeAuthorization struct { + types.StakeAuthorization +} + +func (l LegacyMsgCreateValidator) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgCreateValidator) +} + +func (l *LegacyMsgCreateValidator) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgCreateValidator) +} + +func (l LegacyMsgEditValidator) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgEditValidator) +} + +func (l *LegacyMsgEditValidator) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgEditValidator) +} + +func (l LegacyMsgDelegate) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgDelegate) +} + +func (l *LegacyMsgDelegate) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgDelegate) +} + +func (l LegacyMsgUndelegate) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgUndelegate) +} + +func (l *LegacyMsgUndelegate) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgUndelegate) +} + +func (l LegacyMsgBeginRedelegate) MarshalJSON() ([]byte, error) { + return json.Marshal(l.MsgBeginRedelegate) +} + +func (l *LegacyMsgBeginRedelegate) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.MsgBeginRedelegate) +} + +func (l LegacyStakeAuthorization) MarshalJSON() ([]byte, error) { + return json.Marshal(l.StakeAuthorization) +} + +func (l *LegacyStakeAuthorization) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.StakeAuthorization) +} + // RegisterLegacyAminoCodec registers the necessary x/staking interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - legacy.RegisterAminoMsg(cdc, &types.MsgCreateValidator{}, "staking/MsgCreateValidator") - legacy.RegisterAminoMsg(cdc, &types.MsgEditValidator{}, "staking/MsgEditValidator") - legacy.RegisterAminoMsg(cdc, &types.MsgDelegate{}, "staking/MsgDelegate") - legacy.RegisterAminoMsg(cdc, &types.MsgUndelegate{}, "staking/MsgUndelegate") - legacy.RegisterAminoMsg(cdc, &types.MsgBeginRedelegate{}, "staking/MsgBeginRedelegate") + types.RegisterLegacyAminoCodec(cdc) + + legacy.RegisterAminoMsg(cdc, &LegacyMsgCreateValidator{}, "staking/MsgCreateValidator") + legacy.RegisterAminoMsg(cdc, &LegacyMsgEditValidator{}, "staking/MsgEditValidator") + legacy.RegisterAminoMsg(cdc, &LegacyMsgDelegate{}, "staking/MsgDelegate") + legacy.RegisterAminoMsg(cdc, &LegacyMsgUndelegate{}, "staking/MsgUndelegate") + legacy.RegisterAminoMsg(cdc, &LegacyMsgBeginRedelegate{}, "staking/MsgBeginRedelegate") - cdc.RegisterConcrete(&types.StakeAuthorization{}, "msgauth/StakeAuthorization", nil) + cdc.RegisterConcrete(&LegacyStakeAuthorization{}, "msgauth/StakeAuthorization", nil) } var ( diff --git a/custom/upgrade/types/codec.go b/custom/upgrade/types/codec.go index bc63758e9..0660e8906 100644 --- a/custom/upgrade/types/codec.go +++ b/custom/upgrade/types/codec.go @@ -1,20 +1,63 @@ package types import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/upgrade/types" govtypes "github.com/classic-terra/core/v3/custom/gov/types" ) +// Wrapper type for backward compatibility +type LegacyPlan struct { + types.Plan +} + +// Wrapper type for backward compatibility +type LegacySoftwareUpgradeProposal struct { + types.SoftwareUpgradeProposal +} + +// Wrapper type for backward compatibility +type LegacyCancelSoftwareUpgradeProposal struct { + types.CancelSoftwareUpgradeProposal +} + +func (l LegacyPlan) MarshalJSON() ([]byte, error) { + return json.Marshal(l.Plan) +} + +func (l *LegacyPlan) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.Plan) +} + +func (l LegacySoftwareUpgradeProposal) MarshalJSON() ([]byte, error) { + return json.Marshal(l.SoftwareUpgradeProposal) +} + +func (l *LegacySoftwareUpgradeProposal) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.SoftwareUpgradeProposal) +} + +func (l LegacyCancelSoftwareUpgradeProposal) MarshalJSON() ([]byte, error) { + return json.Marshal(l.CancelSoftwareUpgradeProposal) +} + +func (l *LegacyCancelSoftwareUpgradeProposal) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &l.CancelSoftwareUpgradeProposal) +} + // RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(types.Plan{}, "upgrade/Plan", nil) - cdc.RegisterConcrete(&types.SoftwareUpgradeProposal{}, "upgrade/SoftwareUpgradeProposal", nil) - cdc.RegisterConcrete(&types.CancelSoftwareUpgradeProposal{}, "upgrade/CancelSoftwareUpgradeProposal", nil) + types.RegisterLegacyAminoCodec(cdc) + + cdc.RegisterConcrete(LegacyPlan{}, "upgrade/Plan", nil) + cdc.RegisterConcrete(&LegacySoftwareUpgradeProposal{}, "upgrade/SoftwareUpgradeProposal", nil) + cdc.RegisterConcrete(&LegacyCancelSoftwareUpgradeProposal{}, "upgrade/CancelSoftwareUpgradeProposal", nil) } func init() { - govtypes.RegisterProposalTypeCodec(&types.SoftwareUpgradeProposal{}, "upgrade/SoftwareUpgradeProposal") - govtypes.RegisterProposalTypeCodec(&types.CancelSoftwareUpgradeProposal{}, "upgrade/CancelSoftwareUpgradeProposal") + govtypes.RegisterProposalTypeCodec(&LegacySoftwareUpgradeProposal{}, "upgrade/SoftwareUpgradeProposal") + govtypes.RegisterProposalTypeCodec(&LegacyCancelSoftwareUpgradeProposal{}, "upgrade/CancelSoftwareUpgradeProposal") } diff --git a/tests/e2e/scripts/add_burn_tax_exemption_address_proposal.json b/tests/e2e/scripts/add_burn_tax_exemption_address_proposal.json index 9a4fe33da..7f44e6883 100644 --- a/tests/e2e/scripts/add_burn_tax_exemption_address_proposal.json +++ b/tests/e2e/scripts/add_burn_tax_exemption_address_proposal.json @@ -1 +1 @@ -{"title":"Add Burn Tax Exemption Address","description":"Add terra1pr327cmvezg8y35n67c0vexm6ayvuwktzdrfea,terra1emg70e3u4lyuspvh5k3u9fwrqqtxsw9zm29wxz to the burn tax exemption address list","addresses":["terra1pr327cmvezg8y35n67c0vexm6ayvuwktzdrfea","terra1emg70e3u4lyuspvh5k3u9fwrqqtxsw9zm29wxz"]} \ No newline at end of file +{"title":"Add Burn Tax Exemption Address","description":"Add terra1vz7lvukgxc5lca7he785jj0wa5uufgrphjsnnm,terra1t0qy682tnscfuckx5c67fqjzcqwxpd7uwh7fzn to the burn tax exemption address list","addresses":["terra1vz7lvukgxc5lca7he785jj0wa5uufgrphjsnnm","terra1t0qy682tnscfuckx5c67fqjzcqwxpd7uwh7fzn"]} \ No newline at end of file