Skip to content

Commit bc8f971

Browse files
committed
dcrstakepool: move vars into config struct for fewer globals
1 parent 481b7bb commit bc8f971

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ var (
5353
dcrstakepoolHomeDir = dcrutil.AppDataDir("dcrstakepool", false)
5454
defaultConfigFile = filepath.Join(dcrstakepoolHomeDir, defaultConfigFilename)
5555
defaultLogDir = filepath.Join(dcrstakepoolHomeDir, defaultLogDirname)
56-
coldWalletFeeKey *hdkeychain.ExtendedKey
57-
votingWalletVoteKey *hdkeychain.ExtendedKey
5856
)
5957

6058
// runServiceCommand is only set to a real function on Windows. It is used
@@ -106,6 +104,9 @@ type config struct {
106104
MaxVotedTickets int `long:"maxvotedtickets" description:"Maximum number of voted tickets to show on tickets page."`
107105
Description string `long:"description" description:"Operators own description of their VSP"`
108106
Designation string `long:"designation" description:"VSP designation (eg. Alpha, Bravo, etc)"`
107+
108+
coldWalletFeeKey *hdkeychain.ExtendedKey
109+
votingWalletVoteKey *hdkeychain.ExtendedKey
109110
}
110111

111112
// serviceOptions defines the configuration options for the daemon as a service
@@ -260,12 +261,12 @@ func fileExists(name string) bool {
260261
func (c *config) parsePubKeys(params *chaincfg.Params) error {
261262
// Parse the extended public key and the pool fees.
262263
var err error
263-
coldWalletFeeKey, err = hdkeychain.NewKeyFromString(c.ColdWalletExtPub, params)
264+
c.coldWalletFeeKey, err = hdkeychain.NewKeyFromString(c.ColdWalletExtPub, params)
264265
if err != nil {
265266
return fmt.Errorf("cold wallet extended public key: %v", err)
266267
}
267268
// Parse the extended public key for the voting addresses.
268-
votingWalletVoteKey, err = hdkeychain.NewKeyFromString(c.VotingWalletExtPub, params)
269+
c.votingWalletVoteKey, err = hdkeychain.NewKeyFromString(c.VotingWalletExtPub, params)
269270
if err != nil {
270271
return fmt.Errorf("voting wallet extended public key: %v", err)
271272
}

config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ func TestParsePubKeys(t *testing.T) {
7878
//testing func
7979
err := cfg.parsePubKeys(test.params)
8080
//err if expected output key strings and real output key strings don't match or expected error status is different
81-
if strFromHd(test.keysOut.coldFeeWallet) != strFromHd(coldWalletFeeKey) || strFromHd(test.keysOut.voteWallet) != strFromHd(votingWalletVoteKey) || (err != nil) != test.isError {
82-
t.Error("for", test.keysIn, "expected", strFromHd(test.keysOut.coldFeeWallet), strFromHd(test.keysOut.voteWallet), "and is error=", test.isError, "got", strFromHd(coldWalletFeeKey), strFromHd(votingWalletVoteKey), "and is error=", err != nil)
81+
if strFromHd(test.keysOut.coldFeeWallet) != strFromHd(cfg.coldWalletFeeKey) || strFromHd(test.keysOut.voteWallet) != strFromHd(cfg.votingWalletVoteKey) || (err != nil) != test.isError {
82+
t.Error("for", test.keysIn, "expected", strFromHd(test.keysOut.coldFeeWallet), strFromHd(test.keysOut.voteWallet), "and is error=", test.isError, "got", strFromHd(cfg.coldWalletFeeKey), strFromHd(cfg.votingWalletVoteKey), "and is error=", err != nil)
8383
}
8484
}
8585
}

server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ func runMain(ctx context.Context) error {
115115
Designation: cfg.Designation,
116116

117117
APIVersionsSupported: APIVersionsSupported,
118-
FeeXpub: coldWalletFeeKey,
118+
FeeXpub: cfg.coldWalletFeeKey,
119119
StakepooldServers: stakepooldConnMan,
120120
EmailSender: sender,
121-
VotingXpub: votingWalletVoteKey,
121+
VotingXpub: cfg.votingWalletVoteKey,
122122
NetParams: activeNetParams.Params,
123123
}
124124

0 commit comments

Comments
 (0)