-
Notifications
You must be signed in to change notification settings - Fork 1
/
accountservice.go
91 lines (77 loc) · 2.3 KB
/
accountservice.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package service
import (
"encoding/json"
"github.com/drep-project/drepcli/common"
"gopkg.in/urfave/cli.v1"
path2 "path"
accountCommponent "github.com/drep-project/drepcli/accounts/component"
accountTypes "github.com/drep-project/drepcli/accounts/types"
"github.com/drep-project/drepcli/app"
)
var (
KeyStoreDirFlag = common.DirectoryFlag{
Name: "keystore",
Usage: "Directory for the keystore (default = inside the homedir)",
}
)
// CliService provides an interactive command line window
type AccountService struct {
config *accountTypes.Config
wallet *accountCommponent.Wallet
apis []app.API
}
// Name name
func (accountService *AccountService) Name() string {
return "account"
}
// Api api none
func (accountService *AccountService) Api() []app.API {
return accountService.apis
}
// Flags flags enable load js and execute before run
func (accountService *AccountService) Flags() []cli.Flag {
return []cli.Flag{KeyStoreDirFlag}
}
// Init set console config
func (accountService *AccountService) Init(executeContext *app.ExecuteContext) error {
accountService.config = &accountTypes.Config{}
config := executeContext.GetConfig(accountService.Name())
if config != nil {
err := json.Unmarshal(config, accountService.config)
if err != nil {
return err
}
}
if executeContext.CliContext.IsSet(KeyStoreDirFlag.Name) {
accountService.config.KeyStoreDir = executeContext.CliContext.GlobalString(KeyStoreDirFlag.Name)
}
if !path2.IsAbs(accountService.config.KeyStoreDir) {
if accountService.config.KeyStoreDir == "" {
accountService.config.KeyStoreDir = path2.Join(executeContext.CommonConfig.HomeDir, "KeyStore")
} else {
accountService.config.KeyStoreDir = path2.Join(executeContext.CommonConfig.HomeDir, accountService.config.KeyStoreDir)
}
}
var err error
accountService.wallet, err = accountCommponent.NewWallet(accountService.config, accountTypes.RootChain)
if err != nil {
return err
}
accountService.apis = []app.API{
app.API{
Namespace: "account",
Version: "1.0",
Service: &AccountApi{
Wallet: accountService.wallet,
},
Public: true,
},
}
return nil
}
func (accountService *AccountService) Start(executeContext *app.ExecuteContext) error {
return nil
}
func (accountService *AccountService) Stop(executeContext *app.ExecuteContext) error {
return nil
}