Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit c484430

Browse files
authored
fix legacy codecs and signbytes for amino. (#352)
* fix legacy codecs and signbytes for amino. * fix test
1 parent 2718161 commit c484430

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

x/lscosmos/module.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ func (AppModuleBasic) Name() string {
4444
return types.ModuleName
4545
}
4646

47-
func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) {
48-
types.RegisterCodec(cdc)
49-
}
50-
5147
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
52-
types.RegisterCodec(cdc)
48+
types.RegisterLegacyAminoCodec(cdc)
5349
}
5450

5551
// RegisterInterfaces registers the module's interface types

x/lscosmos/types/codec.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package types
33
import (
44
"github.com/cosmos/cosmos-sdk/codec"
55
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
6+
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
67
sdk "github.com/cosmos/cosmos-sdk/types"
78
"github.com/cosmos/cosmos-sdk/types/msgservice"
89
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
910
)
1011

11-
func RegisterCodec(cdc *codec.LegacyAmino) {
12+
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
1213
cdc.RegisterConcrete(&RegisterHostChainProposal{}, "cosmos/RegisterHostChainProposal", nil)
1314
cdc.RegisterConcrete(&MinDepositAndFeeChangeProposal{}, "cosmos/MinDepositAndFeeChangeProposal", nil)
1415
cdc.RegisterConcrete(&PstakeFeeAddressChangeProposal{}, "cosmos/PstakeFeeAddressChangeProposal", nil)
@@ -45,4 +46,11 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
4546
var (
4647
Amino = codec.NewLegacyAmino()
4748
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
49+
AminoCdc = codec.NewAminoCodec(Amino)
4850
)
51+
52+
func init() {
53+
RegisterLegacyAminoCodec(Amino)
54+
cryptocodec.RegisterCrypto(Amino)
55+
Amino.Seal()
56+
}

x/lscosmos/types/msgs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (m *MsgLiquidStake) ValidateBasic() error {
5151

5252
// GetSignBytes encodes the message for signing
5353
func (m *MsgLiquidStake) GetSignBytes() []byte {
54-
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
54+
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(m))
5555
}
5656

5757
// GetSigners defines whose signature is required
@@ -97,7 +97,7 @@ func (m *MsgJuice) ValidateBasic() error {
9797

9898
// GetSignBytes encodes the message for signing
9999
func (m *MsgJuice) GetSignBytes() []byte {
100-
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
100+
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(m))
101101
}
102102

103103
// GetSigners defines whose signature is required
@@ -139,7 +139,7 @@ func (m *MsgLiquidUnstake) ValidateBasic() error {
139139
}
140140

141141
func (m *MsgLiquidUnstake) GetSignBytes() []byte {
142-
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
142+
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(m))
143143

144144
}
145145

@@ -181,7 +181,7 @@ func (m *MsgRedeem) ValidateBasic() error {
181181
}
182182

183183
func (m *MsgRedeem) GetSignBytes() []byte {
184-
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
184+
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(m))
185185

186186
}
187187

@@ -219,7 +219,7 @@ func (m *MsgClaim) ValidateBasic() error {
219219

220220
// GetSignBytes encodes the message for signing
221221
func (m *MsgClaim) GetSignBytes() []byte {
222-
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
222+
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(m))
223223
}
224224

225225
// GetSigners defines whose signature is required
@@ -285,7 +285,7 @@ func (m *MsgJumpStart) ValidateBasic() error {
285285

286286
// GetSignBytes encodes the message for signing
287287
func (m *MsgJumpStart) GetSignBytes() []byte {
288-
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
288+
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(m))
289289
}
290290

291291
// GetSigners defines whose signature is required

x/lscosmos/types/msgs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestNewMsgLiquidStakeGetSignBytes(t *testing.T) {
6161
coin := sdk.NewInt64Coin("atom", 10)
6262
var msg = types.NewMsgLiquidStake(coin, addr)
6363
res := msg.GetSignBytes()
64-
excepted := `{"amount":{"amount":"10","denom":"atom"},"delegator_address":"persistence1d9h8qat5et0urd"}`
64+
excepted := `{"type":"cosmos/MsgLiquidStake","value":{"amount":{"amount":"10","denom":"atom"},"delegator_address":"persistence1d9h8qat5et0urd"}}`
6565
require.Equal(t, excepted, string(res))
6666

6767
}

0 commit comments

Comments
 (0)