Skip to content

Commit a968d6f

Browse files
committed
ethwallet: switch package level var to func
1 parent 4dc0484 commit a968d6f

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

ethwallet/ethwallet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func NewWalletFromPrivateKey(key string) (*Wallet, error) {
4444

4545
func NewWalletFromHDNode(hdnode *HDNode, optPath ...accounts.DerivationPath) (*Wallet, error) {
4646
var err error
47-
derivationPath := DefaultBaseDerivationPath
47+
derivationPath := DefaultBaseDerivationPath()
4848
if len(optPath) > 0 {
4949
derivationPath = optPath[0]
5050
}
@@ -82,7 +82,7 @@ func NewWalletFromRandomEntropy(options ...WalletOptions) (*Wallet, error) {
8282

8383
func NewWalletFromMnemonic(mnemonic string, optPath ...string) (*Wallet, error) {
8484
var err error
85-
derivationPath := DefaultBaseDerivationPath
85+
derivationPath := DefaultBaseDerivationPath()
8686
if len(optPath) > 0 {
8787
derivationPath, err = ParseDerivationPath(optPath[0])
8888
if err != nil {

ethwallet/hdnode.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@ import (
1414
"github.com/tyler-smith/go-bip39"
1515
)
1616

17-
// DefaultBaseDerivationPath is the base path from which custom derivation endpoints
18-
// are incremented. As such, the first account will be at m/44'/60'/0'/0/0, the second
19-
// at m/44'/60'/0'/0/1, etc.
20-
var DefaultBaseDerivationPath = accounts.DefaultBaseDerivationPath
21-
2217
// Entropy bit size constants for 12 and 24 word mnemonics
2318
const (
2419
EntropyBitSize12WordMnemonic = 128
2520
EntropyBitSize24WordMnemonic = 256
2621
)
2722

23+
// DefaultBaseDerivationPath is the base path from which custom derivation endpoints
24+
// are incremented. As such, the first account will be at m/44'/60'/0'/0/0, the second
25+
// at m/44'/60'/0'/0/1, etc.
26+
var defaultBaseDerivationPath = accounts.DefaultBaseDerivationPath
27+
28+
func DefaultBaseDerivationPath() accounts.DerivationPath {
29+
derivationPath := make(accounts.DerivationPath, len(defaultBaseDerivationPath))
30+
copy(derivationPath, defaultBaseDerivationPath)
31+
return derivationPath
32+
}
33+
2834
type HDNode struct {
2935
masterKey *hdkeychain.ExtendedKey
3036
privateKey *ecdsa.PrivateKey
@@ -82,7 +88,7 @@ func NewHDNodeFromEntropy(entropy []byte, path *accounts.DerivationPath) (*HDNod
8288

8389
var derivationPath accounts.DerivationPath
8490
if path == nil {
85-
derivationPath = DefaultBaseDerivationPath
91+
derivationPath = DefaultBaseDerivationPath()
8692
} else {
8793
derivationPath = *path
8894
}

0 commit comments

Comments
 (0)