-
Notifications
You must be signed in to change notification settings - Fork 12
/
tx.go
77 lines (62 loc) · 2.09 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package cli
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"
"github.com/allinbits/cosmos-cash/v2/x/verifiable-credential/types"
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
// this line is used by starport scaffolding # 1
cmd.AddCommand(
NewDeleteVerifiableCredentialCmd(),
NewRevokeCredentialCmd(),
)
return cmd
}
// NewDeleteVerifiableCredentialCmd defines the command to delete a verifiable credential.
// TODO: to me moved to the issuer module
func NewDeleteVerifiableCredentialCmd() *cobra.Command {
cmd := &cobra.Command{
Use: `delete-verifiable-credential [cred_id] [issuer_did]`,
Short: "delete a decentralized verifiable-credential",
Example: "deletes a license verifiable credential for issuers",
Args: cobra.ExactArgs(2),
RunE: revokeCredential,
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// NewRevokeCredentialCmd defines the command to create a new license verifiable credential.
// This is used by regulators to define issuers and issuer permissions
func NewRevokeCredentialCmd() *cobra.Command {
cmd := &cobra.Command{
Use: `revoke-credential [cred_id]`,
Short: "revoke a verifiable credential",
Example: "",
Args: cobra.ExactArgs(1),
RunE: revokeCredential,
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
func revokeCredential(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
accAddr := clientCtx.GetFromAddress()
accAddrBech32 := accAddr.String()
credentialID := args[0]
msg := types.NewMsgRevokeVerifiableCredential(credentialID, accAddrBech32)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
}