2020-08-17 17:09:02 +00:00
package cli
import (
"fmt"
"github.com/spf13/cobra"
2022-01-08 00:39:27 +00:00
"github.com/cosmos/cosmos-sdk/client"
2020-08-17 17:09:02 +00:00
"github.com/cosmos/cosmos-sdk/client/flags"
2022-01-08 00:39:27 +00:00
"github.com/cosmos/cosmos-sdk/client/tx"
2020-08-17 17:09:02 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/kava-labs/kava/x/issuance/types"
)
// GetTxCmd returns the transaction cli commands for the issuance module
2022-01-08 00:39:27 +00:00
func GetTxCmd ( ) * cobra . Command {
2020-08-17 17:09:02 +00:00
issuanceTxCmd := & cobra . Command {
Use : types . ModuleName ,
Short : "transaction commands for the issuance module" ,
}
2022-01-08 00:39:27 +00:00
cmds := [ ] * cobra . Command {
GetCmdIssueTokens ( ) ,
GetCmdRedeemTokens ( ) ,
GetCmdBlockAddress ( ) ,
GetCmdUnblockAddress ( ) ,
GetCmdPauseAsset ( ) ,
}
for _ , cmd := range cmds {
flags . AddTxFlagsToCmd ( cmd )
}
issuanceTxCmd . AddCommand ( cmds ... )
2020-08-17 17:09:02 +00:00
return issuanceTxCmd
}
2022-01-08 00:39:27 +00:00
func GetCmdIssueTokens ( ) * cobra . Command {
2020-08-17 17:09:02 +00:00
return & cobra . Command {
Use : "issue [tokens] [receiver]" ,
Short : "issue new tokens to the receiver address" ,
Long : "The asset owner issues new tokens that will be credited to the receiver address" ,
Example : fmt . Sprintf ( ` $ % s tx % s issue 20000000 usdtoken kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw
2022-01-08 00:39:27 +00:00
` , version . AppName , types . ModuleName ) ,
2020-08-17 17:09:02 +00:00
Args : cobra . ExactArgs ( 2 ) ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-01-08 00:39:27 +00:00
cliCtx , err := client . GetClientTxContext ( cmd )
if err != nil {
return err
}
tokens , err := sdk . ParseCoinNormalized ( args [ 0 ] )
2020-08-17 17:09:02 +00:00
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
// We use the string later but here validate the acc address
2020-08-17 17:09:02 +00:00
receiver , err := sdk . AccAddressFromBech32 ( args [ 1 ] )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
msg := types . NewMsgIssueTokens ( cliCtx . GetFromAddress ( ) . String ( ) , tokens , receiver . String ( ) )
2020-08-17 17:09:02 +00:00
err = msg . ValidateBasic ( )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
return tx . GenerateOrBroadcastTxCLI ( cliCtx , cmd . Flags ( ) , msg )
2020-08-17 17:09:02 +00:00
} ,
}
}
2022-01-08 00:39:27 +00:00
func GetCmdRedeemTokens ( ) * cobra . Command {
2020-08-17 17:09:02 +00:00
return & cobra . Command {
Use : "redeem [tokens]" ,
Short : "redeem tokens" ,
Long : "The asset owner redeems (burns) tokens, removing them from the circulating supply" ,
Example : fmt . Sprintf ( ` $ % s tx % s redeem 20000000 usdtoken
2022-01-08 00:39:27 +00:00
` , version . AppName , types . ModuleName ) ,
2020-08-17 17:09:02 +00:00
Args : cobra . ExactArgs ( 1 ) ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-01-08 00:39:27 +00:00
cliCtx , err := client . GetClientTxContext ( cmd )
if err != nil {
return err
}
tokens , err := sdk . ParseCoinNormalized ( args [ 0 ] )
2020-08-17 17:09:02 +00:00
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
msg := types . NewMsgRedeemTokens ( cliCtx . GetFromAddress ( ) . String ( ) , tokens )
2020-08-17 17:09:02 +00:00
err = msg . ValidateBasic ( )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
return tx . GenerateOrBroadcastTxCLI ( cliCtx , cmd . Flags ( ) , msg )
2020-08-17 17:09:02 +00:00
} ,
}
}
2022-01-08 00:39:27 +00:00
func GetCmdBlockAddress ( ) * cobra . Command {
2020-08-17 17:09:02 +00:00
return & cobra . Command {
Use : "block [address] [denom]" ,
Short : "block an address for the input denom" ,
Long : "The asset owner blocks an address from holding coins of that denomination. Any tokens of the input denomination held by the address will be sent to the owner address" ,
Example : fmt . Sprintf ( ` $ % s tx % s block kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw usdtoken
2022-01-08 00:39:27 +00:00
` , version . AppName , types . ModuleName ) ,
2020-08-17 17:09:02 +00:00
Args : cobra . ExactArgs ( 2 ) ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-01-08 00:39:27 +00:00
cliCtx , err := client . GetClientTxContext ( cmd )
if err != nil {
return err
}
2020-08-17 17:09:02 +00:00
address , err := sdk . AccAddressFromBech32 ( args [ 0 ] )
if err != nil {
return err
}
err = sdk . ValidateDenom ( args [ 1 ] )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
msg := types . NewMsgBlockAddress ( cliCtx . GetFromAddress ( ) . String ( ) , args [ 1 ] , address . String ( ) )
2020-08-17 17:09:02 +00:00
err = msg . ValidateBasic ( )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
return tx . GenerateOrBroadcastTxCLI ( cliCtx , cmd . Flags ( ) , msg )
2020-08-17 17:09:02 +00:00
} ,
}
}
2022-01-08 00:39:27 +00:00
func GetCmdUnblockAddress ( ) * cobra . Command {
2020-08-17 17:09:02 +00:00
return & cobra . Command {
Use : "unblock [address] [denom]" ,
Short : "unblock an address for the input denom" ,
Long : "The asset owner unblocks an address from holding coins of that denomination." ,
Example : fmt . Sprintf ( ` $ % s tx % s unblock kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw usdtoken
2022-01-08 00:39:27 +00:00
` , version . AppName , types . ModuleName ) ,
2020-08-17 17:09:02 +00:00
Args : cobra . ExactArgs ( 2 ) ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-01-08 00:39:27 +00:00
cliCtx , err := client . GetClientTxContext ( cmd )
if err != nil {
return err
}
2020-08-17 17:09:02 +00:00
address , err := sdk . AccAddressFromBech32 ( args [ 0 ] )
if err != nil {
return err
}
err = sdk . ValidateDenom ( args [ 1 ] )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
msg := types . NewMsgUnblockAddress ( cliCtx . GetFromAddress ( ) . String ( ) , args [ 1 ] , address . String ( ) )
2020-08-17 17:09:02 +00:00
err = msg . ValidateBasic ( )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
return tx . GenerateOrBroadcastTxCLI ( cliCtx , cmd . Flags ( ) , msg )
2020-08-17 17:09:02 +00:00
} ,
}
}
2022-01-08 00:39:27 +00:00
func GetCmdPauseAsset ( ) * cobra . Command {
2020-08-17 17:09:02 +00:00
return & cobra . Command {
Use : "set-pause-status [denom] [status]" ,
Short : "pause or unpause an asset" ,
2020-08-21 22:56:20 +00:00
Long : "The asset owner pauses or un-pauses the input asset, halting new issuance and redemption" ,
2020-08-17 17:09:02 +00:00
Example : fmt . Sprintf ( ` $ % s tx % s pause usdtoken true
2022-01-08 00:39:27 +00:00
` , version . AppName , types . ModuleName ) ,
2020-08-17 17:09:02 +00:00
Args : cobra . ExactArgs ( 2 ) ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-01-08 00:39:27 +00:00
cliCtx , err := client . GetClientTxContext ( cmd )
if err != nil {
return err
}
err = sdk . ValidateDenom ( args [ 0 ] )
2020-08-17 17:09:02 +00:00
if err != nil {
return err
}
var status bool
if args [ 1 ] == "true" {
status = true
} else if args [ 1 ] == "false" {
status = false
} else {
return fmt . Errorf ( fmt . Sprintf ( "status must be true or false, got %s" , args [ 1 ] ) )
}
2022-01-08 00:39:27 +00:00
msg := types . NewMsgSetPauseStatus ( cliCtx . GetFromAddress ( ) . String ( ) , args [ 0 ] , status )
2020-08-17 17:09:02 +00:00
err = msg . ValidateBasic ( )
if err != nil {
return err
}
2022-01-08 00:39:27 +00:00
return tx . GenerateOrBroadcastTxCLI ( cliCtx , cmd . Flags ( ) , msg )
2020-08-17 17:09:02 +00:00
} ,
}
}