-
Notifications
You must be signed in to change notification settings - Fork 30
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
1 parent
3634423
commit 4149361
Showing
17 changed files
with
547 additions
and
137 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
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,188 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/cosmos/cosmos-sdk/version" | ||
"github.com/irisnet/irismod/modules/nft/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Tx Command for rental plugin | ||
|
||
// GetCmdRental is the CLI tx command for NFT rental plugin. | ||
func GetCmdRental() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "rental", | ||
Long: "NFT rental plugin tx subcommands", | ||
DisableFlagParsing: true, | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
cmd.AddCommand( | ||
GetCmdRentalSetUser(), | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
// GetCmdRentalSetUser is the CLI command for setting user for a rentable NFT. | ||
func GetCmdRentalSetUser() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "set-user [denom-id] [nft-id]", | ||
Long: "Set user and expiry for an NFT.", | ||
Example: fmt.Sprintf( | ||
"$ %s tx nft rental set-user <denom-id> <nft-id> "+ | ||
"--user=<user> "+ | ||
"--expiry=<expiry> "+ | ||
"--from=<key-name> "+ | ||
"--chain-id=<chain-id> "+ | ||
"--fees=<fee>", | ||
version.AppName), | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sender := clientCtx.GetFromAddress().String() | ||
|
||
user, err := cmd.Flags().GetString(FlagRentalUser) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
expiry, err := cmd.Flags().GetInt64(FlagRentalExpiry) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgSetUser( | ||
args[0], | ||
args[1], | ||
user, | ||
expiry, | ||
sender, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
cmd.Flags().AddFlagSet(FsRental) | ||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// Query Command for rental plugin | ||
|
||
// GetCmdQueryRental is the CLI query command for NFT rental plugin. | ||
func GetCmdQueryRental() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "rental", | ||
Long: "NFT rental plugin query subcommands", | ||
DisableFlagParsing: true, | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
cmd.AddCommand( | ||
GetCmdQueryRentalUserOf(), | ||
GetCmdQueryRentalUserExpires(), | ||
GetCmdQueryRentalHasUser(), | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
// GetCmdQueryRentalUserOf is the CLI command for query user of a rentable NFT. | ||
func GetCmdQueryRentalUserOf() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "user [denom-id] [nft-id]", | ||
Long: "user of a rented nft", | ||
Example: fmt.Sprintf("$ %s query nft rental user <denom-id> <nft-id>", version.AppName), | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
resp, err := queryClient.UserOf(context.Background(), &types.QueryUserOfRequest{ | ||
DenomId: args[0], | ||
NftId: args[1], | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(resp) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
return cmd | ||
} | ||
|
||
// GetCmdQueryRentalUserExpires is the CLI command for query expiry of a rentable NFT. | ||
func GetCmdQueryRentalUserExpires() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "user [denom-id] [nft-id]", | ||
Long: "expiry of a rented nft", | ||
Example: fmt.Sprintf("$ %s query nft rental user <denom-id> <nft-id>", version.AppName), | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
resp, err := queryClient.UserExpires(context.Background(), &types.QueryUserExpiresRequest{ | ||
DenomId: args[0], | ||
NftId: args[1], | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(resp) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
return cmd | ||
} | ||
|
||
// GetCmdQueryRentalHasUser is the CLI command for query does an NFT have a user. | ||
func GetCmdQueryRentalHasUser() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "user [denom-id] [nft-id]", | ||
Long: "does an nft have a user", | ||
Example: fmt.Sprintf("$ %s query nft rental user <denom-id> <nft-id>", version.AppName), | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
resp, err := queryClient.HasUser(context.Background(), &types.QueryHasUserRequest{ | ||
DenomId: args[0], | ||
NftId: args[1], | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(resp) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package cli_test | ||
|
||
// | ||
//import ( | ||
// "fmt" | ||
// | ||
// "github.com/cosmos/cosmos-sdk/client/flags" | ||
// sdk "github.com/cosmos/cosmos-sdk/types" | ||
// "github.com/gogo/protobuf/proto" | ||
// "github.com/irisnet/irismod/modules/nft/client/cli" | ||
// "github.com/irisnet/irismod/modules/nft/client/testutil" | ||
//) | ||
// | ||
//func (s *IntegrationTestSuite) TestRental() { | ||
// owner := s.network.Validators[0] | ||
// user := s.network.Validators[1] | ||
// | ||
// // 1. issue a denom with rental enabled. | ||
// denomID := "denom" | ||
// denomName := "denomName" | ||
// denomSchema := "denomSchema" | ||
// denomSymbol := "dsb" | ||
// mintRestricted := false | ||
// updateRestricted := true | ||
// denomDescription := "denom description" | ||
// denomURI := "denomURI" | ||
// denomURIHash := "denomURIHash" | ||
// denomData := "denomData" | ||
// rentable := true | ||
// | ||
// args := []string{ | ||
// fmt.Sprintf("--%s=%s", cli.FlagDenomName, denomName), | ||
// fmt.Sprintf("--%s=%s", cli.FlagSchema, denomSchema), | ||
// fmt.Sprintf("--%s=%s", cli.FlagSymbol, denomSymbol), | ||
// fmt.Sprintf("--%s=%s", cli.FlagURI, denomURI), | ||
// fmt.Sprintf("--%s=%s", cli.FlagURIHash, denomURIHash), | ||
// fmt.Sprintf("--%s=%s", cli.FlagDescription, denomDescription), | ||
// fmt.Sprintf("--%s=%s", cli.FlagData, denomData), | ||
// fmt.Sprintf("--%s=%t", cli.FlagMintRestricted, mintRestricted), | ||
// fmt.Sprintf("--%s=%t", cli.FlagUpdateRestricted, updateRestricted), | ||
// fmt.Sprintf("--%s=%t", cli.FlagRentable, rentable), | ||
// | ||
// fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
// fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
// fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
// } | ||
// | ||
// respType := proto.Message(&sdk.TxResponse{}) | ||
// expectedCode := uint32(0) | ||
// | ||
// bz, err := testutil.IssueDenomExec(owner.ClientCtx, owner.Address.String(), denomID, args...) | ||
// s.Require().NoError(err) | ||
// s.Require().NoError(owner.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
// txResp := respType.(*sdk.TxResponse) | ||
// s.Require().Equal(expectedCode, txResp.Code) | ||
// | ||
// // 2. mint an nft | ||
// tokenID := "token" | ||
// tokenName := "tokenName" | ||
// tokenURI := "tokenURI" | ||
// tokenURIHash := "tokenURIHash" | ||
// tokenData := "tokenData" | ||
// | ||
// args = []string{ | ||
// fmt.Sprintf("--%s=%s", cli.FlagData, tokenData), | ||
// fmt.Sprintf("--%s=%s", cli.FlagRecipient, owner.Address.String()), | ||
// fmt.Sprintf("--%s=%s", cli.FlagURI, tokenURI), | ||
// fmt.Sprintf("--%s=%s", cli.FlagURIHash, tokenURIHash), | ||
// fmt.Sprintf("--%s=%s", cli.FlagTokenName, tokenName), | ||
// | ||
// fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
// fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
// fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
// } | ||
// | ||
// respType = proto.Message(&sdk.TxResponse{}) | ||
// | ||
// bz, err = testutil.MintNFTExec(owner.ClientCtx, owner.Address.String(), denomID, tokenID, args...) | ||
// s.Require().NoError(err) | ||
// s.Require().NoError(owner.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
// txResp = respType.(*sdk.TxResponse) | ||
// s.Require().Equal(expectedCode, txResp.Code) | ||
// | ||
// // 3. set user for that nft | ||
// | ||
// expiry := "2524579200" // 2050-01-01-00:00:00 | ||
// | ||
// args = []string{ | ||
// fmt.Sprintf("--%s=%s", cli.FlagRentalUser, user.Address.String()), | ||
// fmt.Sprintf("--%s=%s", cli.FlagRentalExpiry, expiry), | ||
// } | ||
// | ||
// respType = proto.Message(&sdk.TxResponse{}) | ||
// | ||
// bz, err = testutil.RentalSetUser(owner.ClientCtx, owner.Address.String(), denomID, tokenID, args...) | ||
// //s.Require().NoError(err) | ||
// // s.Require().NoError(owner.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
// owner.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType) | ||
// fmt.Print(respType) | ||
// //txResp = respType.(*sdk.TxResponse) | ||
// //s.Require().Equal(expectedCode, txResp.Code) | ||
// | ||
// // 4. get rental info | ||
//} |
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
Oops, something went wrong.