Skip to content

Commit

Permalink
Add upgrade method to intialized address used flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Feb 12, 2015
1 parent d09ce1d commit 65369d2
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions waddrmgr/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

const (
// LatestMgrVersion is the most recent manager version.
LatestMgrVersion = 1
LatestMgrVersion = 2
)

const (
Expand Down Expand Up @@ -1320,8 +1320,37 @@ func upgradeManager(namespace walletdb.Namespace) error {

// Upgrade the manager as needed.
if version < LatestMgrVersion {
// No upgrades yet.
// Upgrade addresses used flag
upgradeVersion1to2(namespace)
}

return nil
}

// upgradeVersion1to2 upgrades the database from version 1 to version 2
// dbAddressRow field 'used', a flag for marking addresses used, is initialized
// and it will be updated on the next rescan
func upgradeVersion1to2(namespace walletdb.Namespace) error {
err := namespace.Update(func(tx walletdb.Tx) error {
bucket := tx.RootBucket().Bucket(addrBucketName)
return bucket.ForEach(func(k, v []byte) error {
// Skip buckets.
if v == nil {
return nil
}

row, err := deserializeAddressRow(k, v)
if err != nil {
return err
}
row.used = false
return putAddress(tx, k, row)
})

})
if err != nil {
str := "failed to upgrade version 1 to version 2"
return managerError(ErrDatabase, str, err)
}
return nil
}

0 comments on commit 65369d2

Please sign in to comment.