-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.go
71 lines (60 loc) · 2.65 KB
/
wallet.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
package pfcharness
import (
"github.com/jfixby/coinharness"
"github.com/jfixby/pin"
"github.com/jfixby/pin/commandline"
)
// ConsoleWalletFactory produces a new ConsoleWallet-instance upon request
type ConsoleWalletFactory struct {
// WalletExecutablePathProvider returns path to the btcd executable
WalletExecutablePathProvider commandline.ExecutablePathProvider
ConsoleCommandCook WalletConsoleCommandCook
RPCClientFactory RPCClientFactory
}
// NewWallet creates and returns a fully initialized instance of the ConsoleWallet.
func (factory *ConsoleWalletFactory) NewWallet(config *coinharness.TestWalletConfig) coinharness.Wallet {
pin.AssertNotNil("ActiveNet", config.ActiveNet)
pin.AssertNotNil("WorkingDir", config.WorkingDir)
pin.AssertNotEmpty("WorkingDir", config.WorkingDir)
pin.AssertNotEmpty("NodeUser", config.NodeUser)
pin.AssertNotEmpty("NodePassword", config.NodePassword)
pin.AssertNotEmpty("WalletUser", config.WalletUser)
pin.AssertNotEmpty("WalletPassword", config.WalletPassword)
args := &coinharness.NewConsoleWalletArgs{
ClientFac: &factory.RPCClientFactory,
ConsoleCommandCook: &factory.ConsoleCommandCook,
WalletExecutablePathProvider: factory.WalletExecutablePathProvider,
WalletUser: config.WalletUser,
WalletPass: config.WalletPassword,
NodeUser: config.NodeUser,
NodePass: config.NodePassword,
AppDir: config.WorkingDir,
NodeRPCHost: config.NodeRPCHost,
NodeRPCPort: config.NodeRPCPort,
WalletRPCHost: config.WalletRPCHost,
WalletRPCPort: config.WalletRPCPort,
ActiveNet: config.ActiveNet,
}
return coinharness.NewConsoleWallet(args)
}
type WalletConsoleCommandCook struct {
}
// cookArguments prepares arguments for the command-line call
func (cook *WalletConsoleCommandCook) CookArguments(par *coinharness.ConsoleCommandWalletParams) map[string]interface{} {
result := make(map[string]interface{})
result["pfcdusername"] = par.NodeRpcUser
result["pfcdpassword"] = par.NodeRpcPass
result["username"] = par.WalletRpcUser
result["password"] = par.WalletRpcPass
result["rpcconnect"] = par.RpcConnect
result["rpclisten"] = par.RpcListen
result["appdata"] = par.AppDir
result["debuglevel"] = par.DebugLevel
result["cafile"] = par.NodeCertFile
result["rpccert"] = par.CertFile
result["rpckey"] = par.KeyFile
result["nogrpc"] = commandline.NoArgumentValue
result[NetworkFor(par.Network)] = commandline.NoArgumentValue
commandline.ArgumentsCopyTo(par.ExtraArguments, result)
return result
}