-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathtx.go
60 lines (51 loc) · 1.57 KB
/
tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cli
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"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/cosmos/cosmos-sdk/x/nft"
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
nftTxCmd := &cobra.Command{
Use: nft.ModuleName,
Short: "nft transactions subcommands",
Long: "Provides the most common nft logic for upper-level applications, compatible with Ethereum's erc721 contract",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
nftTxCmd.AddCommand(
NewCmdSend(),
)
return nftTxCmd
}
func NewCmdSend() *cobra.Command {
cmd := &cobra.Command{
Use: "send [class-id] [nft-id] [receiver] --from [sender]",
Args: cobra.ExactArgs(3),
Short: "transfer ownership of nft",
Long: strings.TrimSpace(fmt.Sprintf(`
$ %s tx %s send <class-id> <nft-id> <receiver> --from <sender> --chain-id <chain-id>`, version.AppName, nft.ModuleName),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := nft.MsgSend{
ClassId: args[0],
Id: args[1],
Sender: clientCtx.GetFromAddress().String(),
Receiver: args[2],
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}