/
cointype.go
61 lines (51 loc) · 1.78 KB
/
cointype.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
// Copyright (c) 2017 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package wallet
import (
"context"
"decred.org/dcrwallet/errors"
"decred.org/dcrwallet/wallet/udb"
"decred.org/dcrwallet/wallet/walletdb"
"github.com/decred/dcrd/hdkeychain/v3"
)
// UpgradeToSLIP0044CoinType upgrades the wallet from the legacy BIP0044 coin
// type to one of the coin types assigned to Decred in SLIP0044. This should be
// called after a new wallet is created with a random (not imported) seed.
//
// This function does not register addresses from the new account 0 with the
// wallet's network backend. This is intentional as it allows offline
// activities, such as wallet creation, to perform this upgrade.
func (w *Wallet) UpgradeToSLIP0044CoinType(ctx context.Context) error {
const op errors.Op = "wallet.UpgradeToSLIP0044CoinType"
var acctXpub, extBranchXpub, intBranchXpub *hdkeychain.ExtendedKey
err := walletdb.Update(ctx, w.db, func(dbtx walletdb.ReadWriteTx) error {
err := w.manager.UpgradeToSLIP0044CoinType(dbtx)
if err != nil {
return err
}
acctXpub, err = w.manager.AccountExtendedPubKey(dbtx, 0)
if err != nil {
return err
}
extBranchXpub, err = w.manager.AccountBranchExtendedPubKey(dbtx, 0,
udb.ExternalBranch)
if err != nil {
return err
}
intBranchXpub, err = w.manager.AccountBranchExtendedPubKey(dbtx, 0,
udb.InternalBranch)
return err
})
if err != nil {
return errors.E(op, err)
}
w.addressBuffersMu.Lock()
w.addressBuffers[0] = &bip0044AccountData{
xpub: acctXpub,
albExternal: addressBuffer{branchXpub: extBranchXpub, lastUsed: ^uint32(0)},
albInternal: addressBuffer{branchXpub: intBranchXpub, lastUsed: ^uint32(0)},
}
w.addressBuffersMu.Unlock()
return nil
}