Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
a2f2c92796
commit
9af83f4b92
@ -12,10 +12,10 @@ require (
|
||||
cosmossdk.io/math v1.1.3-rc.1
|
||||
cosmossdk.io/store v1.0.0-rc.0
|
||||
cosmossdk.io/tools/confix v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/circuit v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/nft v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f
|
||||
cosmossdk.io/x/upgrade v0.0.0-20230925151519-64e0e8980834
|
||||
github.com/cometbft/cometbft v0.38.0
|
||||
|
||||
@ -207,14 +207,14 @@ cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4=
|
||||
cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk=
|
||||
cosmossdk.io/tools/confix v0.0.0-20230925151519-64e0e8980834 h1:lOHFhmSC6phBBVeE/TbtV2MV7nDwclPnXdBEZsOEf3k=
|
||||
cosmossdk.io/tools/confix v0.0.0-20230925151519-64e0e8980834/go.mod h1:sJU9iqlZxilbg1Ik63S03QTZIYZZ9V+Uok/lu4px3XY=
|
||||
cosmossdk.io/x/circuit v0.0.0-20230925151519-64e0e8980834 h1:4HYvdHKJA4CUf86lql7a70/pVUtDRmN3f44P1hJ4ZSE=
|
||||
cosmossdk.io/x/circuit v0.0.0-20230925151519-64e0e8980834/go.mod h1:atLqPO4esHD8/5VSQYm3tem3u6Ul2Nhv+neBBDsE+zI=
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe h1:xcQTAlbv1l8PBHXI5/xv7AQLUe/tBvewH6JR2Zt1F4g=
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe/go.mod h1:syo6njNlaE1KLXRFd1gZQr/7pMstANp2zMqVUC+u4h4=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834 h1:h4ooSV3X5BxEfl3EUbOlXNFMnEc/mXTXF5mdl17CQLg=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834/go.mod h1:yUgv71a56ZEJu7c8BXWCliDrQ7Ag+FCZ//rYKw9S93U=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834 h1:hILr/Ve3CKlWwMC3oHFb1er9xWzxbx1UEZytTuGeI8o=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834/go.mod h1:C5DALk9amuP9nd/xCgaQxbn43q695zQ/tXH8b9ugzAs=
|
||||
cosmossdk.io/x/nft v0.0.0-20230925151519-64e0e8980834 h1:i+qcapUPVo5a9Q09/mUm1jMouyuWf67+fORAaNMPeTQ=
|
||||
cosmossdk.io/x/nft v0.0.0-20230925151519-64e0e8980834/go.mod h1:Q60Uu6/UsZlACzmGzSkGLSc/U8I6tbEusbqjTE40pvk=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe h1:xDWsbJp/9Tdwh2w8/KT7E0sxb52ASTn1M+UO4pq6kko=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe/go.mod h1:QQROAXjZWeJzH6dNHUNCPhs7zHrYjknH8gYynf0IvXs=
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f h1:Dkw1pM+jnjK9Pk0CM6JZKLLDaMXWDCHSlLJiHcSmPpg=
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f/go.mod h1:lRM7U4VkxFjWBKZp7Mo818azphiNixeMCV8h1ZofkhM=
|
||||
cosmossdk.io/x/upgrade v0.0.0-20230925151519-64e0e8980834 h1:M/yPP4g31SSgYEku5d5Xk+UGkjp47RKXFk1bYGnWJdY=
|
||||
|
||||
@ -13,7 +13,7 @@ require (
|
||||
cosmossdk.io/store v1.0.0-rc.0
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834
|
||||
cosmossdk.io/x/nft v0.0.0-20230925151519-64e0e8980834 // indirect
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe // indirect
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f
|
||||
cosmossdk.io/x/upgrade v0.0.0-20230925151519-64e0e8980834
|
||||
github.com/cometbft/cometbft v0.38.0
|
||||
@ -39,7 +39,7 @@ require (
|
||||
cloud.google.com/go/storage v1.30.1 // indirect
|
||||
cosmossdk.io/client/v2 v2.0.0-20231005134150-8334eefaaf7c // indirect
|
||||
cosmossdk.io/collections v0.4.0 // indirect
|
||||
cosmossdk.io/x/circuit v0.0.0-20230925151519-64e0e8980834 // indirect
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe // indirect
|
||||
filippo.io/edwards25519 v1.0.0 // indirect
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||
github.com/99designs/keyring v1.2.1 // indirect
|
||||
|
||||
@ -205,14 +205,14 @@ cosmossdk.io/math v1.1.3-rc.1 h1:NebCNWDqb1MJRNfvxr4YY7d8FSYgkuB3L75K6xvM+Zo=
|
||||
cosmossdk.io/math v1.1.3-rc.1/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
|
||||
cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4=
|
||||
cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk=
|
||||
cosmossdk.io/x/circuit v0.0.0-20230925151519-64e0e8980834 h1:4HYvdHKJA4CUf86lql7a70/pVUtDRmN3f44P1hJ4ZSE=
|
||||
cosmossdk.io/x/circuit v0.0.0-20230925151519-64e0e8980834/go.mod h1:atLqPO4esHD8/5VSQYm3tem3u6Ul2Nhv+neBBDsE+zI=
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe h1:xcQTAlbv1l8PBHXI5/xv7AQLUe/tBvewH6JR2Zt1F4g=
|
||||
cosmossdk.io/x/circuit v0.0.0-20231006095526-33390754f9fe/go.mod h1:syo6njNlaE1KLXRFd1gZQr/7pMstANp2zMqVUC+u4h4=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834 h1:h4ooSV3X5BxEfl3EUbOlXNFMnEc/mXTXF5mdl17CQLg=
|
||||
cosmossdk.io/x/evidence v0.0.0-20230925151519-64e0e8980834/go.mod h1:yUgv71a56ZEJu7c8BXWCliDrQ7Ag+FCZ//rYKw9S93U=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834 h1:hILr/Ve3CKlWwMC3oHFb1er9xWzxbx1UEZytTuGeI8o=
|
||||
cosmossdk.io/x/feegrant v0.0.0-20230925151519-64e0e8980834/go.mod h1:C5DALk9amuP9nd/xCgaQxbn43q695zQ/tXH8b9ugzAs=
|
||||
cosmossdk.io/x/nft v0.0.0-20230925151519-64e0e8980834 h1:i+qcapUPVo5a9Q09/mUm1jMouyuWf67+fORAaNMPeTQ=
|
||||
cosmossdk.io/x/nft v0.0.0-20230925151519-64e0e8980834/go.mod h1:Q60Uu6/UsZlACzmGzSkGLSc/U8I6tbEusbqjTE40pvk=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe h1:xDWsbJp/9Tdwh2w8/KT7E0sxb52ASTn1M+UO4pq6kko=
|
||||
cosmossdk.io/x/nft v0.0.0-20231006095526-33390754f9fe/go.mod h1:QQROAXjZWeJzH6dNHUNCPhs7zHrYjknH8gYynf0IvXs=
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f h1:Dkw1pM+jnjK9Pk0CM6JZKLLDaMXWDCHSlLJiHcSmPpg=
|
||||
cosmossdk.io/x/tx v0.10.1-0.20230920120022-6715b5afb59f/go.mod h1:lRM7U4VkxFjWBKZp7Mo818azphiNixeMCV8h1ZofkhM=
|
||||
cosmossdk.io/x/upgrade v0.0.0-20230925151519-64e0e8980834 h1:M/yPP4g31SSgYEku5d5Xk+UGkjp47RKXFk1bYGnWJdY=
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
package circuit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
circuitv1 "cosmossdk.io/api/cosmos/circuit/v1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
)
|
||||
|
||||
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
@ -29,7 +33,41 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
},
|
||||
},
|
||||
Tx: &autocliv1.ServiceCommandDescriptor{
|
||||
Service: circuitv1.Query_ServiceDesc.ServiceName,
|
||||
Service: circuitv1.Msg_ServiceDesc.ServiceName,
|
||||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
|
||||
{
|
||||
RpcMethod: "AuthorizeCircuitBreaker",
|
||||
Use: "authorize [grantee] [permissions_json] --from [granter]",
|
||||
Short: "Authorize an account to trip the circuit breaker.",
|
||||
Long: `Authorize an account to trip the circuit breaker.
|
||||
"SOME_MSGS" = 1,
|
||||
"ALL_MSGS" = 2,
|
||||
"SUPER_ADMIN" = 3,`,
|
||||
Example: fmt.Sprintf(`%s circuit authorize [address] '{"level":1,"limit_type_urls":["cosmos.bank.v1beta1.MsgSend,cosmos.bank.v1beta1.MsgMultiSend"]}'"`, version.AppName),
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "grantee"},
|
||||
{ProtoField: "permissions"}, // TODO(@julienrbrt) Support flattening msg for setting each field as a positional arg
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "TripCircuitBreaker",
|
||||
Use: "disable [msg_type_urls]",
|
||||
Short: "Disable a message from being executed",
|
||||
Example: fmt.Sprintf(`%s circuit disable "cosmos.bank.v1beta1.MsgSend cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName),
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "msg_type_urls", Varargs: true},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "ResetCircuitBreaker",
|
||||
Use: "reset [msg_type_urls]",
|
||||
Short: "Enable a message to be executed",
|
||||
Example: fmt.Sprintf(`%s circuit reset "cosmos.bank.v1beta1.MsgSend cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName),
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "msg_type_urls", Varargs: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,140 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"cosmossdk.io/x/circuit/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
)
|
||||
|
||||
// NewTxCmd returns a root CLI command handler for all x/circuit transaction commands.
|
||||
func NewTxCmd() *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Circuit transaction subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
txCmd.AddCommand(
|
||||
AuthorizeCircuitBreakerCmd(),
|
||||
TripCircuitBreakerCmd(),
|
||||
)
|
||||
|
||||
return txCmd
|
||||
}
|
||||
|
||||
// AuthorizeCircuitBreakerCmd returns a CLI command handler for creating a MsgAuthorizeCircuitBreaker transaction.
|
||||
func AuthorizeCircuitBreakerCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "authorize [grantee] [permission_level] [limit_type_urls] --from [granter]",
|
||||
Short: "Authorize an account to trip the circuit breaker.",
|
||||
Long: `Authorize an account to trip the circuit breaker.
|
||||
"SOME_MSGS" = 1,
|
||||
"ALL_MSGS" = 2,
|
||||
"SUPER_ADMIN" = 3,`,
|
||||
Example: fmt.Sprintf(`%s circuit authorize [address] 0 "cosmos.bank.v1beta1.MsgSend,cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName),
|
||||
Args: cobra.RangeArgs(2, 3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
grantee, err := sdk.AccAddressFromBech32(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lvl, err := math.ParseUint(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var typeUrls []string
|
||||
if len(args) == 3 {
|
||||
typeUrls = strings.Split(args[2], ",")
|
||||
}
|
||||
|
||||
permission := types.Permissions{Level: types.Permissions_Level(lvl.Uint64()), LimitTypeUrls: typeUrls}
|
||||
|
||||
msg := &types.MsgAuthorizeCircuitBreaker{
|
||||
Granter: clientCtx.GetFromAddress().String(),
|
||||
Grantee: grantee.String(),
|
||||
Permissions: &permission,
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// TripCircuitBreakerCmd returns a CLI command handler for creating a MsgTripCircuitBreaker transaction.
|
||||
func TripCircuitBreakerCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "disable [type_url]",
|
||||
Short: "disable a message from being executed",
|
||||
Example: fmt.Sprintf(`%s circuit disable "cosmos.bank.v1beta1.MsgSend,cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := &types.MsgTripCircuitBreaker{
|
||||
Authority: clientCtx.GetFromAddress().String(),
|
||||
MsgTypeUrls: strings.Split(args[0], ","),
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// ResetCircuitBreakerCmd returns a CLI command handler for creating a MsgRestCircuitBreaker transaction.
|
||||
func ResetCircuitBreakerCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "reset [type_url]",
|
||||
Short: "Enable a message to be executed",
|
||||
Example: fmt.Sprintf(`%s circuit reset "cosmos.bank.v1beta1.MsgSend,cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msgTypeUrls := strings.Split(args[0], ",")
|
||||
|
||||
msg := &types.MsgResetCircuitBreaker{
|
||||
Authority: clientCtx.GetFromAddress().String(),
|
||||
MsgTypeUrls: msgTypeUrls,
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
@ -8,7 +8,6 @@ require (
|
||||
cosmossdk.io/core v0.11.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.4
|
||||
cosmossdk.io/errors v1.0.0
|
||||
cosmossdk.io/math v1.1.3-rc.1
|
||||
cosmossdk.io/store v1.0.0-rc.0
|
||||
github.com/cockroachdb/errors v1.11.1
|
||||
github.com/cometbft/cometbft v0.38.0
|
||||
@ -16,7 +15,6 @@ require (
|
||||
github.com/cosmos/gogoproto v1.4.11
|
||||
github.com/golang/protobuf v1.5.3
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
||||
github.com/spf13/cobra v1.7.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e
|
||||
google.golang.org/grpc v1.58.1
|
||||
@ -24,6 +22,7 @@ require (
|
||||
|
||||
require (
|
||||
cosmossdk.io/log v1.2.1 // indirect
|
||||
cosmossdk.io/math v1.1.3-rc.1 // indirect
|
||||
cosmossdk.io/x/tx v0.10.0 // indirect
|
||||
filippo.io/edwards25519 v1.0.0 // indirect
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||
@ -123,6 +122,7 @@ require (
|
||||
github.com/sasha-s/go-deadlock v0.3.1 // indirect
|
||||
github.com/spf13/afero v1.9.5 // indirect
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/spf13/cobra v1.7.0 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.16.0 // indirect
|
||||
|
||||
@ -37,6 +37,10 @@ func (srv msgServer) AuthorizeCircuitBreaker(ctx context.Context, msg *types.Msg
|
||||
// Check that the authorizer has the permission level of "super admin"
|
||||
perms, err := srv.Permissions.Get(ctx, address)
|
||||
if err != nil {
|
||||
if errorsmod.IsOf(err, collections.ErrNotFound) {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "only super admins can authorize users")
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@ -7,14 +7,12 @@ import (
|
||||
"time"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
modulev1 "cosmossdk.io/api/cosmos/circuit/module/v1"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/store"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/x/circuit/client/cli"
|
||||
"cosmossdk.io/x/circuit/keeper"
|
||||
"cosmossdk.io/x/circuit/types"
|
||||
|
||||
@ -75,11 +73,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g
|
||||
}
|
||||
}
|
||||
|
||||
// GetTxCmd returns the root tx command for the circuit module.
|
||||
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
return cli.NewTxCmd()
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers interfaces and implementations of the circuit module.
|
||||
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
types.RegisterInterfaces(registry)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user