Skip to content

Commit

Permalink
use proto type proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
likesToEatFish committed Oct 1, 2024
1 parent ffcfe5c commit 2b21e8e
Show file tree
Hide file tree
Showing 5 changed files with 448 additions and 10 deletions.
21 changes: 21 additions & 0 deletions proto/reserve/vaults/proposal.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";
package reserve.vaults;

import "gogoproto/gogo.proto";
import "reserve/vaults/tx.proto";
import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";


option go_package = "github.com/onomyprotocol/reserve/x/vaults/types";


message ActiveCollateralProposal {
option (gogoproto.goproto_getters) = false;
option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content";
option (amino.name) = "reserve/ActiveCollateralProposal";

string title = 1;
string description = 2;
MsgActiveCollateral active_collateral = 3 [(gogoproto.nullable) = false];
}
4 changes: 2 additions & 2 deletions x/vaults/module/proposal_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
func NewVaultsProposalHandler(k *keeper.Keeper) govtypes.Handler {
return func(ctx sdk.Context, content govtypes.Content) error {
switch c := content.(type) {
case *types.MsgActiveCollateral:
return k.ActiveCollateralAsset(ctx, c.Denom, c.MinCollateralRatio, c.LiquidationRatio, c.MaxDebt)
case *types.ActiveCollateralProposal:
return k.ActiveCollateralAsset(ctx, c.ActiveCollateral.Denom, c.ActiveCollateral.MinCollateralRatio, c.ActiveCollateral.LiquidationRatio, c.ActiveCollateral.MaxDebt)
default:
return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c)
}
Expand Down
8 changes: 7 additions & 1 deletion x/vaults/types/codec.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package types

import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

// RegisterLegacyAminoCodec registers all necessary param module types with a given LegacyAmino codec.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&ActiveCollateralProposal{}, "reserve/ActiveCollateralProposal", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
// this line is used by starport scaffolding # 3

Expand All @@ -23,7 +29,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {

registry.RegisterImplementations(
(*govtypes.Content)(nil),
&MsgActiveCollateral{},
&ActiveCollateralProposal{},
)

}
15 changes: 8 additions & 7 deletions x/vaults/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ var (
)

const (
ProposalTypeActiveCollateral string = "MsgActiveCollateral"
ProposalTypeActiveCollateralProposal string = "ActiveCollateralProposal"
)

func (m *MsgActiveCollateral) GetDescription() string {
func (m *ActiveCollateralProposal) GetDescription() string {
return " "
}

func (m *MsgActiveCollateral) GetTitle() string {
func (m *ActiveCollateralProposal) GetTitle() string {
return " "
}

func (m *MsgActiveCollateral) ProposalRoute() string {
func (m *ActiveCollateralProposal) ProposalRoute() string {
return RouterKey
}

func (m *MsgActiveCollateral) ProposalType() string {
return ProposalTypeActiveCollateral
func (m *ActiveCollateralProposal) ProposalType() string {
return ProposalTypeActiveCollateralProposal
}

func (a *MsgActiveCollateral) ValidateBasic() error {
func (m *ActiveCollateralProposal) ValidateBasic() error {
a := m.ActiveCollateral
if a.Denom == "" {
return sdkerrors.Wrap(ErrInvalidActiveCollateralProposal, "empty denom")
}
Expand Down
Loading

0 comments on commit 2b21e8e

Please sign in to comment.