-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/realiotech/realio-network/x/asset/types" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
) | ||
|
||
func NewCmdAddTokenManagerProposal() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add-token-manager [title] [description] [manager] [deposit]", | ||
Args: cobra.ExactArgs(4), | ||
Short: "Submit an add token manager proposal", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
from := clientCtx.GetFromAddress() | ||
content := types.NewAddTokenManager(args[0], args[1], args[2]) | ||
|
||
deposit, err := sdk.ParseCoinsNormalized(args[3]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, from) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func NewCmdRemoveTokenManagerProposal() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "remove-token-manager [title] [description] [manager] [deposit]", | ||
Args: cobra.ExactArgs(4), | ||
Short: "Submit an remove token manager proposal", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
from := clientCtx.GetFromAddress() | ||
content := types.NewRemoveTokenManager(args[0], args[1], args[2]) | ||
|
||
deposit, err := sdk.ParseCoinsNormalized(args[3]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, from) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,59 @@ | ||
package keeper | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/realiotech/realio-network/x/asset/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// AddTokenManager handles the proposals to add a new manager | ||
func (k Keeper) AddTokenManager( | ||
ctx sdk.Context, | ||
p *types.AddTokenManager, | ||
) error { | ||
managerAddress, err := sdk.AccAddressFromBech32(p.ManagerAddress) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ok := k.IsTokenManager(ctx, managerAddress) | ||
if ok { | ||
return fmt.Errorf("manager %s already exist", p.ManagerAddress) | ||
} | ||
|
||
k.SetTokenManager(ctx, managerAddress) | ||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
types.EventTypeAddTokenManager, | ||
sdk.NewAttribute(types.AttributeKeyAddress, p.ManagerAddress), | ||
), | ||
) | ||
return nil | ||
} | ||
|
||
// RemoveTokenManager handles the proposals to add a new manager | ||
func (k Keeper) RemoveTokenManager( | ||
ctx sdk.Context, | ||
p *types.RemoveTokenManager, | ||
) error { | ||
managerAddress, err := sdk.AccAddressFromBech32(p.ManagerAddress) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ok := k.IsTokenManager(ctx, managerAddress) | ||
if !ok { | ||
return fmt.Errorf("manager %s is not exist", p.ManagerAddress) | ||
} | ||
|
||
k.DeleteTokenManager(ctx, managerAddress) | ||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
types.EventTypeAddTokenManager, | ||
sdk.NewAttribute(types.AttributeKeyAddress, p.ManagerAddress), | ||
), | ||
) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package asset | ||
|
||
import ( | ||
"github.com/realiotech/realio-network/x/asset/client/cli" | ||
"github.com/realiotech/realio-network/x/asset/keeper" | ||
"github.com/realiotech/realio-network/x/asset/types" | ||
|
||
sdkerrors "cosmossdk.io/errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
errortypes "github.com/cosmos/cosmos-sdk/types/errors" | ||
govclient "github.com/cosmos/cosmos-sdk/x/gov/client" | ||
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
) | ||
|
||
var ( | ||
AddTokenManagerHandler = govclient.NewProposalHandler(cli.NewCmdAddTokenManagerProposal) | ||
RemoveTokenManagerHandler = govclient.NewProposalHandler(cli.NewCmdRemoveTokenManagerProposal) | ||
) | ||
|
||
// NewAssetProposalHandler creates a governance handler to manage asset proposals. | ||
func NewAssetProposalHandler(k *keeper.Keeper) govv1beta1.Handler { | ||
return func(ctx sdk.Context, content govv1beta1.Content) error { | ||
switch c := content.(type) { | ||
case *types.AddTokenManager: | ||
return k.AddTokenManager(ctx, c) | ||
case *types.RemoveTokenManager: | ||
return k.RemoveTokenManager(ctx, c) | ||
default: | ||
return sdkerrors.Wrapf(errortypes.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters