Skip to content

Commit

Permalink
fix: ledger support (#48)
Browse files Browse the repository at this point in the history
(cherry picked from commit f019618)
  • Loading branch information
johnletey authored and mergify[bot] committed May 15, 2023
1 parent a48a9b6 commit 969441b
Show file tree
Hide file tree
Showing 31 changed files with 415 additions and 237 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

### Bug Fixes

- [#48](https://github.com/KYVENetwork/chain/pull/48) Register amino types for full Ledger support.
- (`x/team`) [#45](https://github.com/KYVENetwork/chain/pull/45) Adjust vesting schedules of multiple KYVE Core Team members.

### API Breaking
Expand Down
2 changes: 1 addition & 1 deletion x/bundles/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (AppModuleBasic) Name() string {

// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
types.RegisterLegacyAminoCodec(cdc)
}

// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message
Expand Down
20 changes: 16 additions & 4 deletions x/bundles/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ package types

import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
codecTypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptoCodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func RegisterCodec(_ *codec.LegacyAmino) {}
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgSubmitBundleProposal{}, "kyve/bundles/MsgSubmitBundleProposal", nil)
cdc.RegisterConcrete(&MsgVoteBundleProposal{}, "kyve/bundles/MsgVoteBundleProposal", nil)
cdc.RegisterConcrete(&MsgClaimUploaderRole{}, "kyve/bundles/MsgClaimUploaderRole", nil)
cdc.RegisterConcrete(&MsgSkipUploaderRole{}, "kyve/bundles/MsgSkipUploaderRole", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
func RegisterInterfaces(registry codecTypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSubmitBundleProposal{})
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgVoteBundleProposal{})
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgClaimUploaderRole{})
Expand All @@ -18,5 +24,11 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
ModuleCdc = codec.NewAminoCodec(Amino)
)

func init() {
RegisterLegacyAminoCodec(Amino)
cryptoCodec.RegisterCrypto(Amino)
sdk.RegisterLegacyAminoCodec(Amino)
}
27 changes: 15 additions & 12 deletions x/bundles/types/message_claim_uploader_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errorsTypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

const TypeMsgClaimUploaderRole = "claim_uploader_role"

var _ sdk.Msg = &MsgClaimUploaderRole{}
var (
_ legacytx.LegacyMsg = &MsgClaimUploaderRole{}
_ sdk.Msg = &MsgClaimUploaderRole{}
)

func NewMsgClaimUploaderRole(creator string, staker string, poolId uint64) *MsgClaimUploaderRole {
return &MsgClaimUploaderRole{
Expand All @@ -18,25 +20,26 @@ func NewMsgClaimUploaderRole(creator string, staker string, poolId uint64) *MsgC
}
}

func (msg *MsgClaimUploaderRole) Route() string {
return RouterKey
}

func (msg *MsgClaimUploaderRole) Type() string {
return TypeMsgClaimUploaderRole
func (msg *MsgClaimUploaderRole) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgClaimUploaderRole) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}

return []sdk.AccAddress{creator}
}

func (msg *MsgClaimUploaderRole) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
func (msg *MsgClaimUploaderRole) Route() string {
return RouterKey
}

func (msg *MsgClaimUploaderRole) Type() string {
return "kyve/bundles/MsgClaimUploaderRole"
}

func (msg *MsgClaimUploaderRole) ValidateBasic() error {
Expand Down
27 changes: 15 additions & 12 deletions x/bundles/types/message_skip_uploader_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errorsTypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

const TypeMsgSkipUploaderRole = "skip_uploader_role"

var _ sdk.Msg = &MsgSkipUploaderRole{}
var (
_ legacytx.LegacyMsg = &MsgSkipUploaderRole{}
_ sdk.Msg = &MsgSkipUploaderRole{}
)

func NewMsgSkipUploaderRole(creator string, staker string, poolId uint64, fromIndex uint64) *MsgSkipUploaderRole {
return &MsgSkipUploaderRole{
Expand All @@ -19,25 +21,26 @@ func NewMsgSkipUploaderRole(creator string, staker string, poolId uint64, fromIn
}
}

func (msg *MsgSkipUploaderRole) Route() string {
return RouterKey
}

func (msg *MsgSkipUploaderRole) Type() string {
return TypeMsgSkipUploaderRole
func (msg *MsgSkipUploaderRole) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgSkipUploaderRole) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}

return []sdk.AccAddress{creator}
}

func (msg *MsgSkipUploaderRole) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
func (msg *MsgSkipUploaderRole) Route() string {
return RouterKey
}

func (msg *MsgSkipUploaderRole) Type() string {
return "kyve/bundles/MsgSkipUploaderRole"
}

func (msg *MsgSkipUploaderRole) ValidateBasic() error {
Expand Down
27 changes: 15 additions & 12 deletions x/bundles/types/message_submit_bundle_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errorsTypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

const TypeMsgSubmitBundleProposal = "submit_bundle_proposal"

var _ sdk.Msg = &MsgSubmitBundleProposal{}
var (
_ legacytx.LegacyMsg = &MsgSubmitBundleProposal{}
_ sdk.Msg = &MsgSubmitBundleProposal{}
)

func NewMsgSubmitBundleProposal(creator string, staker string, poolId uint64, storageId string, dataSize uint64, dataHash string, fromIndex uint64, bundleSize uint64, fromKey string, toKey string, bundleSummary string) *MsgSubmitBundleProposal {
return &MsgSubmitBundleProposal{
Expand All @@ -26,25 +28,26 @@ func NewMsgSubmitBundleProposal(creator string, staker string, poolId uint64, st
}
}

func (msg *MsgSubmitBundleProposal) Route() string {
return RouterKey
}

func (msg *MsgSubmitBundleProposal) Type() string {
return TypeMsgSubmitBundleProposal
func (msg *MsgSubmitBundleProposal) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgSubmitBundleProposal) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}

return []sdk.AccAddress{creator}
}

func (msg *MsgSubmitBundleProposal) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
func (msg *MsgSubmitBundleProposal) Route() string {
return RouterKey
}

func (msg *MsgSubmitBundleProposal) Type() string {
return "kyve/bundles/MsgSubmitBundleProposal"
}

func (msg *MsgSubmitBundleProposal) ValidateBasic() error {
Expand Down
27 changes: 15 additions & 12 deletions x/bundles/types/message_vote_bundle_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errorsTypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

const TypeMsgVoteBundleProposal = "vote_bundle_proposal"

var _ sdk.Msg = &MsgVoteBundleProposal{}
var (
_ legacytx.LegacyMsg = &MsgVoteBundleProposal{}
_ sdk.Msg = &MsgVoteBundleProposal{}
)

func NewMsgVoteBundleProposal(creator string, staker string, poolId uint64, storageId string, vote VoteType) *MsgVoteBundleProposal {
return &MsgVoteBundleProposal{
Expand All @@ -20,25 +22,26 @@ func NewMsgVoteBundleProposal(creator string, staker string, poolId uint64, stor
}
}

func (msg *MsgVoteBundleProposal) Route() string {
return RouterKey
}

func (msg *MsgVoteBundleProposal) Type() string {
return TypeMsgVoteBundleProposal
func (msg *MsgVoteBundleProposal) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgVoteBundleProposal) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}

return []sdk.AccAddress{creator}
}

func (msg *MsgVoteBundleProposal) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
func (msg *MsgVoteBundleProposal) Route() string {
return RouterKey
}

func (msg *MsgVoteBundleProposal) Type() string {
return "kyve/bundles/MsgVoteBundleProposal"
}

func (msg *MsgVoteBundleProposal) ValidateBasic() error {
Expand Down
2 changes: 1 addition & 1 deletion x/delegation/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (AppModuleBasic) Name() string {

// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
types.RegisterLegacyAminoCodec(cdc)
}

// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message
Expand Down
20 changes: 16 additions & 4 deletions x/delegation/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ package types

import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
codecTypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptoCodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func RegisterCodec(_ *codec.LegacyAmino) {}
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgDelegate{}, "kyve/delegation/MsgDelegate", nil)
cdc.RegisterConcrete(&MsgWithdrawRewards{}, "kyve/delegation/MsgWithdrawRewards", nil)
cdc.RegisterConcrete(&MsgUndelegate{}, "kyve/delegation/MsgUndelegate", nil)
cdc.RegisterConcrete(&MsgRedelegate{}, "kyve/delegation/MsgRedelegate", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
func RegisterInterfaces(registry codecTypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgDelegate{})
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgWithdrawRewards{})
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgUndelegate{})
Expand All @@ -18,5 +24,11 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
ModuleCdc = codec.NewAminoCodec(Amino)
)

func init() {
RegisterLegacyAminoCodec(Amino)
cryptoCodec.RegisterCrypto(Amino)
sdk.RegisterLegacyAminoCodec(Amino)
}
33 changes: 18 additions & 15 deletions x/delegation/types/message_delegate.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
package types

import (
sdkErrors "cosmossdk.io/errors"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errorsTypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

const TypeMsgDelegate = "delegate"

var _ sdk.Msg = &MsgDelegate{}

func (msg *MsgDelegate) Route() string {
return RouterKey
}
var (
_ legacytx.LegacyMsg = &MsgDelegate{}
_ sdk.Msg = &MsgDelegate{}
)

func (msg *MsgDelegate) Type() string {
return TypeMsgDelegate
func (msg *MsgDelegate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgDelegate) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}

return []sdk.AccAddress{creator}
}

func (msg *MsgDelegate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
func (msg *MsgDelegate) Route() string {
return RouterKey
}

func (msg *MsgDelegate) Type() string {
return "kyve/delegation/MsgDelegate"
}

func (msg *MsgDelegate) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkErrors.Wrapf(errorsTypes.ErrInvalidAddress, "invalid creator address (%s)", err)
return errors.Wrapf(errorsTypes.ErrInvalidAddress, "invalid creator address (%s)", err)
}

_, err = sdk.AccAddressFromBech32(msg.Staker)
if err != nil {
return sdkErrors.Wrapf(errorsTypes.ErrInvalidAddress, "invalid staker address (%s)", err)
return errors.Wrapf(errorsTypes.ErrInvalidAddress, "invalid staker address (%s)", err)
}
return nil
}
Loading

0 comments on commit 969441b

Please sign in to comment.