Skip to content

Commit

Permalink
declare proposal types
Browse files Browse the repository at this point in the history
  • Loading branch information
neitdung committed Sep 25, 2024
1 parent 1e28ef7 commit e7497aa
Show file tree
Hide file tree
Showing 5 changed files with 797 additions and 0 deletions.
31 changes: 31 additions & 0 deletions proto/realionetwork/asset/v1/proposal.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
syntax = "proto3";

package realionetwork.asset.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/realiotech/realio-network/x/asset/types";

message AddTokenManager {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";

string title = 1;
string description = 2;
string manager_address = 3;
}

message RemoveTokenManager {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";

string title = 1;
string description = 2;
string manager_address = 3;
}

1 change: 1 addition & 0 deletions x/asset/keeper/proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package keeper
2 changes: 2 additions & 0 deletions x/asset/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ var (
PrivilegedAccountsKey = []byte{0x02}
// PrivilegeStoreKey
PrivilegeStoreKey = []byte{0x03}
// PrivilegeStoreKey
ManagerStoreKey = []byte{0x04}
)
106 changes: 106 additions & 0 deletions x/asset/types/proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package types

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

// Proposal types
const (
ProposalTypeAddTokenManager string = "AddTokenManager"
ProposalTypeRemoveTokenManager string = "RemoveTokenManager"
)

var (
_ govv1beta1.Content = &AddTokenManager{}
_ govv1beta1.Content = &RemoveTokenManager{}
)

func init() {
govv1beta1.RegisterProposalType(ProposalTypeAddTokenManager)
govv1beta1.RegisterProposalType(ProposalTypeRemoveTokenManager)
}

// NewAddAddTokenManager returns new instance of AddTokenManager proposal
func NewAddTokenManager(title, description, manager string) govv1beta1.Content {
return &AddTokenManager{
Title: title,
Description: description,
ManagerAddress: manager,
}
}

// GetTitle returns the title of a AddTokenManager
func (atmp *AddTokenManager) GetTitle() string { return atmp.Title }

// GetDescription returns the description of a AddTokenManager
func (atmp *AddTokenManager) GetDescription() string { return atmp.Description }

// ProposalRoute returns router key for a AddTokenManager
func (*AddTokenManager) ProposalRoute() string { return RouterKey }

// ProposalType returns proposal type for a AddTokenManager
func (*AddTokenManager) ProposalType() string {
return ProposalTypeAddTokenManager
}

// ValidateBasic runs basic stateless validity checks
func (atmp *AddTokenManager) ValidateBasic() error {
err := govv1beta1.ValidateAbstract(atmp)
if err != nil {
return err
}
if _, err = sdk.AccAddressFromBech32(atmp.ManagerAddress); err != nil {
return err
}

return nil
}

// String implements the Stringer interface.
func (atmp AddTokenManager) String() string {
return fmt.Sprintf("AddTokenManager: Title: %s Description: %s Manager: %s", atmp.Title, atmp.Description, atmp.ManagerAddress)
}

// NewRemoveTokenManager returns new instance of RemoveTokenManager
func NewRemoveTokenManager(title, description, manager string) govv1beta1.Content {
return &RemoveTokenManager{
Title: title,
Description: description,
ManagerAddress: manager,
}
}

// GetTitle returns the title of a RemoveTokenManager
func (rtmp *RemoveTokenManager) GetTitle() string { return rtmp.Title }

// GetDescription returns the description of a RemoveTokenManager
func (rtmp *RemoveTokenManager) GetDescription() string { return rtmp.Description }

// ProposalRoute returns router key for a RemoveTokenManager
func (*RemoveTokenManager) ProposalRoute() string { return RouterKey }

// ProposalType returns proposal type for a RemoveTokenManager
func (*RemoveTokenManager) ProposalType() string {
return ProposalTypeRemoveTokenManager
}

// String implements the Stringer interface.
func (rtmp RemoveTokenManager) String() string {
return fmt.Sprintf("UpdateBondWeightProposal: Title: %s Description: %s Manager: %s", rtmp.Title, rtmp.Description, rtmp.ManagerAddress)
}

// ValidateBasic runs basic stateless validity checks
func (rtmp *RemoveTokenManager) ValidateBasic() error {
err := govv1beta1.ValidateAbstract(rtmp)
if err != nil {
return err
}
if _, err = sdk.AccAddressFromBech32(rtmp.ManagerAddress); err != nil {
return err
}

return nil
}
Loading

0 comments on commit e7497aa

Please sign in to comment.