Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ST-365: Fix tx msg decode #371

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
889 changes: 889 additions & 0 deletions api/stratos/register/v1_1/register.pulsar.go

Large diffs are not rendered by default.

3,553 changes: 3,553 additions & 0 deletions api/stratos/register/v1_1/tx.pulsar.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stratosnet/stratos-chain/api v0.0.0-20240318144156-bf3328f863f6
github.com/stratosnet/stratos-chain/api v0.0.0-20240716160341-ec9024ef5de0
github.com/stretchr/testify v1.9.0
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/crypto v0.21.0
Expand Down Expand Up @@ -243,7 +243,7 @@ replace (
// use stratos fork of cometbft: fork/v0.37.5
github.com/cometbft/cometbft => github.com/stratosnet/cometbft v0.37.6-0.20240620154138-dc955d478115
// use stratos fork of cosmos-sdk: v0.47.x-stratos
github.com/cosmos/cosmos-sdk => github.com/stratosnet/cosmos-sdk v0.47.12-0.20240521173001-c32cdc9a1e54
github.com/cosmos/cosmos-sdk => github.com/stratosnet/cosmos-sdk v0.47.12-0.20240711204239-ae99645b490a
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1038,12 +1038,12 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stratosnet/cometbft v0.37.6-0.20240620154138-dc955d478115 h1:Mc90IpZrL2Wd6zLMhK342kRysRbb0vMMKnO5ptDc5Yw=
github.com/stratosnet/cometbft v0.37.6-0.20240620154138-dc955d478115/go.mod h1:QC+mU0lBhKn8r9qvmnq53Dmf3DWBt4VtkcKw2C81wxY=
github.com/stratosnet/cosmos-sdk v0.47.12-0.20240521173001-c32cdc9a1e54 h1:8uIe3hXJaPg/cgd6FqHSdiy8ntQQtzuA2C+3aFZTtkI=
github.com/stratosnet/cosmos-sdk v0.47.12-0.20240521173001-c32cdc9a1e54/go.mod h1:c7xno1ENztUrUOqZ70W5gi0pTh3pT/3C6O0y1WzHSwU=
github.com/stratosnet/cosmos-sdk v0.47.12-0.20240711204239-ae99645b490a h1:2wf/13Pu9ZYf7tlaVF1x8rvQisPbMOAqgbeH6WWavbo=
github.com/stratosnet/cosmos-sdk v0.47.12-0.20240711204239-ae99645b490a/go.mod h1:c7xno1ENztUrUOqZ70W5gi0pTh3pT/3C6O0y1WzHSwU=
github.com/stratosnet/ledger-stratos-go v0.0.0-20230728214905-432bf09f4b6c h1:EuJdqCo1DYeKjkXaIYNnU7WIFmu+FzJwJtzYhY3sQpQ=
github.com/stratosnet/ledger-stratos-go v0.0.0-20230728214905-432bf09f4b6c/go.mod h1:9T0Ii/AMWWnJRtvKYKB4kDdraaOP76J+K5/IbRXQgyc=
github.com/stratosnet/stratos-chain/api v0.0.0-20240318144156-bf3328f863f6 h1:xrwEM+1tq/DEuHQCKr83C40SX61DEUALaWq7YEpR/uM=
github.com/stratosnet/stratos-chain/api v0.0.0-20240318144156-bf3328f863f6/go.mod h1:FN6crwtoVjf2errz8Nsj0y/zRxuIRtxs5w8qLHKVBqA=
github.com/stratosnet/stratos-chain/api v0.0.0-20240716160341-ec9024ef5de0 h1:WtXepCWm3FFya8L19INO/0bSxlsNqYNgkn5v5d+XHQQ=
github.com/stratosnet/stratos-chain/api v0.0.0-20240716160341-ec9024ef5de0/go.mod h1:FN6crwtoVjf2errz8Nsj0y/zRxuIRtxs5w8qLHKVBqA=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down
1 change: 1 addition & 0 deletions proto/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ deps:
- buf.build/cosmos/gogo-proto
- buf.build/cosmos/ibc
- buf.build/googleapis/googleapis
- buf.build/stratosnet/stratos-chain
lint:
use:
- DEFAULT
Expand Down
6 changes: 3 additions & 3 deletions proto/stratos/register/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ message MsgUpdateResourceNode {
option (cosmos.msg.v1.signer) = "owner_address";
option (amino.name) = "stratos/MsgUpdateResourceNode";

Description description = 1 [
Description description = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "description",
Expand Down Expand Up @@ -206,7 +206,7 @@ message MsgUpdateMetaNode {
option (cosmos.msg.v1.signer) = "owner_address";
option (amino.name) = "stratos/MsgUpdateMetaNode";

Description description = 1 [
Description description = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "description",
Expand All @@ -217,7 +217,7 @@ message MsgUpdateMetaNode {
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
];
string network_address = 3 [
string network_address = 3 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "network_address",
(gogoproto.moretags) = "yaml:\"network_address\""
Expand Down
34 changes: 34 additions & 0 deletions proto/stratos/register/v1_1/register.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";
package stratos.register.v1_1;

import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "cosmos_proto/cosmos.proto";
import "amino/amino.proto";

option (gogoproto.equal_all) = true;
option go_package = "github.com/stratosnet/stratos-chain/x/register/types/v1_1";


message Description {
option (gogoproto.goproto_stringer) = true;

string moniker = 1 [
(gogoproto.jsontag) = "moniker",
(gogoproto.moretags) = "yaml:\"moniker\""
];
string identity = 2 [
(gogoproto.jsontag) = "identity",
(gogoproto.moretags) = "yaml:\"identity\",omitempty"
];
string website = 3 [
(gogoproto.jsontag) = "website",
(gogoproto.moretags) = "yaml:\"website\",omitempty"
];
string security_contact = 4 [
(gogoproto.jsontag) = "security_contact",
(gogoproto.moretags) = "yaml:\"security_contact\",omitempty"];
string details = 5 [
(gogoproto.jsontag) = "details",
(gogoproto.moretags) = "yaml:\"details\",omitempty"];
}
156 changes: 156 additions & 0 deletions proto/stratos/register/v1_1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
syntax = "proto3";
package stratos.register.v1_1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "amino/amino.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/any.proto";
import "stratos/register/v1_1/register.proto";

option (gogoproto.equal_all) = true;
option go_package = "github.com/stratosnet/stratos-chain/x/register/types/v1_1";

// MsgCreateResourceNode encapsulates an MsgCreateResourceNodeTx transaction as an SDK message.
message MsgCreateResourceNode {
option (cosmos.msg.v1.signer) = "owner_address";
option (amino.name) = "stratos/MsgCreateResourceNode";

string network_address = 1 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "network_address",
(gogoproto.moretags) = "yaml:\"network_address\""
];
google.protobuf.Any pubkey = 2 [
(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey",
(gogoproto.jsontag) = "pubkey",
(gogoproto.moretags) = "yaml:\"pubkey\""
];
cosmos.base.v1beta1.Coin value = 3 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "value",
(gogoproto.moretags) = "yaml:\"value\""
];
string owner_address = 4 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 5 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
uint32 node_type = 6 [
(gogoproto.jsontag) = "node_type",
(gogoproto.moretags) = "yaml:\"node_type\""
];
string beneficiary_address = 7 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
];
}

// MsgCreateMetaNode encapsulates an MsgCreateMetaNodeTx transaction as an SDK message.
message MsgCreateMetaNode {
option (cosmos.msg.v1.signer) = "owner_address";
option (amino.name) = "stratos/MsgCreateMetaNode";

string network_address = 1 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "network_address",
(gogoproto.moretags) = "yaml:\"network_address\""
];
google.protobuf.Any pubkey = 2 [
(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey",
(gogoproto.jsontag) = "pubkey",
(gogoproto.moretags) = "yaml:\"pubkey\""
];
cosmos.base.v1beta1.Coin value = 3 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "value",
(gogoproto.moretags) = "yaml:\"value\""
];
string owner_address = 4 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 5 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
string beneficiary_address = 6 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
];
}

// MsgUpdateResourceNode defines a SDK message for updating an existing resource node.
message MsgUpdateResourceNode {
option (cosmos.msg.v1.signer) = "owner_address";
option (amino.name) = "stratos/MsgUpdateResourceNode";

Description description = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
string network_address = 2 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "network_address",
(gogoproto.moretags) = "yaml:\"network_address\""
];
string owner_address = 3 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
];
uint32 node_type = 4 [
(gogoproto.jsontag) = "node_type",
(gogoproto.moretags) = "yaml:\"node_type\""
];
string beneficiary_address = 5 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
];
}

// MsgUpdateMetaNode defines a SDK message for updating an existing meta node.
message MsgUpdateMetaNode {
option (cosmos.msg.v1.signer) = "owner_address";
option (amino.name) = "stratos/MsgUpdateMetaNode";

Description description = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
string network_address = 2 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "network_address",
(gogoproto.moretags) = "yaml:\"network_address\""
];
string owner_address = 3 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
];
string beneficiary_address = 4 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
];
}

3 changes: 3 additions & 0 deletions testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func SetupWithGenesisNodeSet(t *testing.T,
initRemainingOzoneLimit,
make([]registertypes.Slashing, 0),
registertypes.DefaultDepositNozRate,
make([]registertypes.MetaNodeRegistrationVotePool, 0),
make([]registertypes.UnbondingNode, 0),
make([]registertypes.KickMetaNodeVotePool, 0),
)
genesisState[registertypes.ModuleName] = app.AppCodec().MustMarshalJSON(registerGenesis)

Expand Down
5 changes: 5 additions & 0 deletions x/register/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
"github.com/stratosnet/stratos-chain/x/register/types/v1_1"
)

// RegisterLegacyAminoCodec registers concrete types on codec
Expand Down Expand Up @@ -41,6 +42,10 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgUpdateMetaNodeDeposit{},
&MsgMetaNodeRegistrationVote{},
&MsgUpdateParams{},
&v1_1.MsgCreateResourceNode{},
&v1_1.MsgUpdateResourceNode{},
&v1_1.MsgCreateMetaNode{},
&v1_1.MsgUpdateMetaNode{},
)
registry.RegisterImplementations(
(*authz.Authorization)(nil),
Expand Down
82 changes: 82 additions & 0 deletions x/register/types/v1_1/msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package v1_1

import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
_ sdk.Msg = &MsgCreateResourceNode{}
_ sdk.Msg = &MsgUpdateResourceNode{}
_ sdk.Msg = &MsgCreateMetaNode{}
_ sdk.Msg = &MsgUpdateMetaNode{}
)

// ValidateBasic validity check for the CreateResourceNode
func (msg MsgCreateResourceNode) ValidateBasic() error {
return nil
}

func (msg MsgCreateResourceNode) GetSigners() []sdk.AccAddress {
// Owner pays the tx fees
addr, err := sdk.AccAddressFromBech32(msg.GetOwnerAddress())
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr.Bytes()}
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (msg MsgCreateResourceNode) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var pk cryptotypes.PubKey
return unpacker.UnpackAny(msg.Pubkey, &pk)
}

// ValidateBasic implements the sdk.Msg interface.
func (msg MsgUpdateResourceNode) ValidateBasic() error {
return nil
}

// GetSigners implements the sdk.Msg interface.
func (msg MsgUpdateResourceNode) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.OwnerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr.Bytes()}
}

func (msg MsgCreateMetaNode) ValidateBasic() error {
return nil
}

func (msg MsgCreateMetaNode) GetSigners() []sdk.AccAddress {
// Owner pays the tx fees
addr, err := sdk.AccAddressFromBech32(msg.GetOwnerAddress())
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr.Bytes()}

}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (msg MsgCreateMetaNode) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var pk cryptotypes.PubKey
return unpacker.UnpackAny(msg.Pubkey, &pk)
}

// GetSigners implements the sdk.Msg interface.
func (msg MsgUpdateMetaNode) GetSigners() []sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msg.OwnerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{addr.Bytes()}
}

// ValidateBasic implements the sdk.Msg interface.
func (msg MsgUpdateMetaNode) ValidateBasic() error {
return nil
}
Loading