/
listokens.go
47 lines (38 loc) · 1.06 KB
/
listokens.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package token
import (
"github.com/hyperledger/fabric/cmd/common"
"github.com/pkg/errors"
)
type ListTokensCmd struct {
*BaseCmd
clientConfigPath *string
stub Stub
parser ResponseParser
}
func NewListTokensCmd(stub Stub, parser ResponseParser) *ListTokensCmd {
return &ListTokensCmd{BaseCmd: &BaseCmd{}, stub: stub, parser: parser}
}
// SetRecipient sets the recipient
func (cmd *ListTokensCmd) SetClientConfigPath(clientConfigPath *string) {
cmd.clientConfigPath = clientConfigPath
}
func (cmd *ListTokensCmd) Execute(conf common.Config) error {
if cmd.clientConfigPath == nil || len(*cmd.clientConfigPath) == 0 {
return errors.New("no client config path specified")
}
clientConfigPath := *cmd.clientConfigPath
channel, mspPath, mspID := cmd.BaseCmd.GetArgs()
err := cmd.stub.Setup(clientConfigPath, channel, mspPath, mspID)
if err != nil {
return err
}
response, err := cmd.stub.ListTokens()
if err != nil {
return err
}
return cmd.parser.ParseResponse(response)
}