Skip to content

Commit

Permalink
merge: royalty share & nfsw flag for onft & removed EditONFT Message (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 authored Feb 11, 2022
2 parents 6c3067a + 0f862ec commit 4638a53
Show file tree
Hide file tree
Showing 23 changed files with 404 additions and 1,609 deletions.
43 changes: 17 additions & 26 deletions client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import (
)

const (
FlagName = "name"
FlagDescription = "description"
FlagMediaURI = "media-uri"
FlagPreviewURI = "preview-uri"
FlagData = "data"
FlagTransferable = "transferable"
FlagExtensible = "extensible"
FlagRecipient = "recipient"
FlagOwner = "owner"
FlagDenomID = "denom-id"
FlagSchema = "schema"
FlagNsfw = "nsfw"
FlagName = "name"
FlagDescription = "description"
FlagMediaURI = "media-uri"
FlagPreviewURI = "preview-uri"
FlagData = "data"
FlagNonTransferable = "non-transferable"
FlagInExtensible = "inextensible"
FlagRecipient = "recipient"
FlagOwner = "owner"
FlagDenomID = "denom-id"
FlagSchema = "schema"
FlagNsfw = "nsfw"
FlagRoyaltyShare = "royalty-share"
)

var (
FsCreateDenom = flag.NewFlagSet("", flag.ContinueOnError)
FsUpdateDenom = flag.NewFlagSet("", flag.ContinueOnError)
FsTransferDenom = flag.NewFlagSet("", flag.ContinueOnError)
FsMintONFT = flag.NewFlagSet("", flag.ContinueOnError)
FsEditONFT = flag.NewFlagSet("", flag.ContinueOnError)
FsTransferONFT = flag.NewFlagSet("", flag.ContinueOnError)
FsQuerySupply = flag.NewFlagSet("", flag.ContinueOnError)
FsQueryOwner = flag.NewFlagSet("", flag.ContinueOnError)
Expand All @@ -48,19 +48,10 @@ func init() {
FsMintONFT.String(FlagName, "", "Name of onft")
FsMintONFT.String(FlagDescription, "", "Description of onft")
FsMintONFT.String(FlagData, "", "custom data of onft")

FsMintONFT.String(FlagTransferable, "yes", "transferability of onft (yes | no)")
FsMintONFT.String(FlagExtensible, "yes", "extensisbility of onft (yes | no)")
FsMintONFT.String(FlagNsfw, "no", "not safe for work flag for onft (yes | no)")

FsEditONFT.String(FlagMediaURI, "[do-not-modify]", "Media uri of onft")
FsEditONFT.String(FlagPreviewURI, "[do-not-modify]", "Preview uri of onft")
FsEditONFT.String(FlagName, "[do-not-modify]", "Name of nft")
FsEditONFT.String(FlagDescription, "[do-not-modify]", "Description of onft")
FsEditONFT.String(FlagTransferable, "[do-not-modify]", "transferability of onft")
FsEditONFT.String(FlagData, "[do-not-modify]", "custom data of onft")
FsEditONFT.String(FlagExtensible, "[do-not-modify]", "extensibility of onft (yes | no)")
FsEditONFT.String(FlagNsfw, "[do-not-modify]", "nsfw (not safe for work) flag of onft (yes | no)")
FsMintONFT.Bool(FlagNonTransferable, false, "To mint non-transferable onft")
FsMintONFT.Bool(FlagInExtensible, false, "To mint non-extensisble onft")
FsMintONFT.Bool(FlagNsfw, false, "not safe for work flag for onft")
FsMintONFT.String(FlagRoyaltyShare, "", "Royalty share value decimal value between 0 and 1")

FsTransferONFT.String(FlagRecipient, "", "Receiver of the onft. default value is sender address of transaction")
FsQuerySupply.String(FlagOwner, "", "The owner of a nft")
Expand Down
172 changes: 37 additions & 135 deletions client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package cli

import (
"fmt"
"strings"

"github.com/OmniFlix/onft/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"
"github.com/spf13/cobra"
"strings"
)

// NewTxCmd returns the transaction commands for this module
Expand All @@ -28,7 +27,6 @@ func NewTxCmd() *cobra.Command {
GetCmdUpdateDenom(),
GetCmdTransferDenom(),
GetCmdMintONFT(),
GetCmdEditONFT(),
GetCmdTransferONFT(),
GetCmdBurnONFT(),
)
Expand Down Expand Up @@ -101,8 +99,21 @@ func GetCmdMintONFT() *cobra.Command {
Long: strings.TrimSpace(
fmt.Sprintf(`Mint an oNFT.
Example:
$ %s tx onft mint [denom-id] --type <onft-type> --name <onft-name> --description <onft-descritpion> --media-uri=<uri> --preview-uri=<uri>
--transferable yes --extensible yes --recipient=<recipient> --from=<key-name> --chain-id=<chain-id> --fees=<fee>`,
$ %s tx onft mint [denom-id] \
--name <onft-name> \
--description <onft-descritpion> \
--media-uri=<uri> \
--preview-uri=<uri> \
--from=<key-name> \
--chain-id=<chain-id> \
--fees=<fee>
Additional Flags
--non-trasferable
--inextensible
--nsfw
--royalty-share="0.05"
`,
version.AppName,
),
),
Expand Down Expand Up @@ -166,44 +177,40 @@ $ %s tx onft mint [denom-id] --type <onft-type> --name <onft-name> --description
if err != nil {
return err
}

var transferable bool
transferability, err := cmd.Flags().GetString(FlagTransferable)
transferable := true
nonTransferable, err := cmd.Flags().GetBool(FlagNonTransferable)
if err != nil {
return err
}
transferability = strings.ToLower(transferability)
if transferability == "false" || transferability == "no" {
if nonTransferable {
transferable = false
} else if transferability == "true" || transferability == "yes" {
transferable = true
} else {
return fmt.Errorf("invalid option for transferable flag , valid options are true|false, yes|no")
}
var extensible bool
extensibility, err := cmd.Flags().GetString(FlagExtensible)
extensible := true
inExtensible, err := cmd.Flags().GetBool(FlagInExtensible)
if err != nil {
return err
}
if extensibility == "false" || extensibility == "no" {
if inExtensible {
extensible = false
} else if extensibility == "true" || extensibility == "yes" {
extensible = true
} else {
return fmt.Errorf("invalid option for extensible flag , valid options are yes|no")
}

var nsfw bool
nsfwFlag, err := cmd.Flags().GetString(FlagNsfw)
nsfw := false
nsfwFlag, err := cmd.Flags().GetBool(FlagNsfw)
if err != nil {
return err
}
if nsfwFlag == "false" || nsfwFlag == "no" {
nsfw = false
} else if nsfwFlag == "true" || nsfwFlag == "yes" {
if nsfwFlag {
nsfw = true
} else {
return fmt.Errorf("invalid option for nsfw flag , valid options are yes|no")
}
royaltyShareStr, err := cmd.Flags().GetString(FlagRoyaltyShare)
if err != nil {
return err
}
royaltyShare := sdk.NewDec(0)
if len(royaltyShareStr) > 0 {
royaltyShare, err = sdk.NewDecFromStr(royaltyShareStr)
if err != nil {
return err
}
}

msg := types.NewMsgMintONFT(
Expand All @@ -215,6 +222,7 @@ $ %s tx onft mint [denom-id] --type <onft-type> --name <onft-name> --description
transferable,
extensible,
nsfw,
royaltyShare,
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand All @@ -229,112 +237,6 @@ $ %s tx onft mint [denom-id] --type <onft-type> --name <onft-name> --description
return cmd
}

func GetCmdEditONFT() *cobra.Command {
cmd := &cobra.Command{
Use: "edit [denom-id] [onft-id]",
Long: strings.TrimSpace(
fmt.Sprintf(`Edit the data of an oNFT.
Example:
$ %s tx onft edit [denom-id] [onft-id] --name=<onft-name> --description=<onft-description> --media-uri=<uri>
--preview-uri=<uri> --type=<onft-type> --transferable=yes --extensible=yes --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
}
denomId := strings.ToLower(strings.TrimSpace(args[0]))
onftId := strings.ToLower(strings.TrimSpace(args[1]))

onftMetadata := types.Metadata{}
onftName, err := cmd.Flags().GetString(FlagName)
if err != nil {
return err
}
onftName = strings.TrimSpace(onftName)

onftDescription, err := cmd.Flags().GetString(FlagDescription)
if err != nil {
return err
}
onftDescription = strings.TrimSpace(onftDescription)

onftMediaURI, err := cmd.Flags().GetString(FlagMediaURI)
if err != nil {
return err
}
onftMediaURI = strings.TrimSpace(onftMediaURI)

onftPreviewURI, err := cmd.Flags().GetString(FlagPreviewURI)
if err != nil {
return err
}
onftPreviewURI = strings.TrimSpace(onftPreviewURI)

if len(onftName) > 0 {
onftMetadata.Name = onftName
}
if len(onftDescription) > 0 {
onftMetadata.Description = onftDescription
}
if len(onftMediaURI) > 0 {
onftMetadata.MediaURI = onftMediaURI
}
if len(onftPreviewURI) > 0 {
onftMetadata.PreviewURI = onftPreviewURI
}
data, err := cmd.Flags().GetString(FlagData)
if err != nil {
return err
}

transferable, err := cmd.Flags().GetString(FlagTransferable)
if err != nil {
return err
}
if !(len(transferable) > 0 && (transferable == "no" || transferable == "yes" ||
transferable == types.DoNotModify)) {
return fmt.Errorf("invalid option for transferable flag , valid options are yes | no")
}
extensible, err := cmd.Flags().GetString(FlagExtensible)
if err != nil {
return err
}
if !(len(extensible) > 0 && (extensible == "no" || extensible == "yes" || extensible == types.DoNotModify)) {
return fmt.Errorf("invalid option for extensible flag , valid options are yes|no")
}
nsfw, err := cmd.Flags().GetString(FlagNsfw)
if err != nil {
return err
}
if !(len(nsfw) > 0 && (nsfw == "no" || nsfw == "yes" || nsfw == types.DoNotModify)) {
return fmt.Errorf("invalid option for nsfw flag , valid options are yes|no")
}
msg := types.NewMsgEditONFT(
onftId,
denomId,
onftMetadata,
data,
transferable,
extensible,
nsfw,
clientCtx.GetFromAddress().String(),
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().AddFlagSet(FsEditONFT)
flags.AddTxFlagsToCmd(cmd)

return cmd
}

func GetCmdUpdateDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "update-denom [denom-id]",
Expand Down
20 changes: 4 additions & 16 deletions client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,10 @@ type mintONFTReq struct {
MediaURI string `json:"media_uri"`
PreviewURI string `json:"preview_uri"`
Data string `json:"data"`
Transferable string `json:"transferable"`
Extensible string `json:"extensible"`
Nsfw string `json:"nsfw"`
}

type editONFTReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Sender sdk.AccAddress `json:"sender"`
Name string `json:"name"`
Description string `json:"description"`
MediaURI string `json:"media_uri"`
PreviewURI string `json:"preview_uri"`
Data string `json:"data"`
Transferable string `json:"transferable"`
Extensible string `json:"extensible"`
Nsfw string `json:"nsfw"`
Transferable bool `json:"transferable"`
Extensible bool `json:"extensible"`
Nsfw bool `json:"nsfw"`
RoyaltyShare sdk.Dec `json:"royalty_share"`
}

type transferONFTReq struct {
Expand Down
Loading

0 comments on commit 4638a53

Please sign in to comment.