golinted waddrmgr package

This commit is contained in:
Manan Patel 2015-04-02 11:52:06 -07:00 committed by Dave Collins
parent dfe617e05d
commit 3940e853f8
2 changed files with 15 additions and 15 deletions

View file

@ -169,12 +169,12 @@ var (
// and id changes e.g. RenameAccount // and id changes e.g. RenameAccount
acctNameIdxBucketName = []byte("acctnameidx") acctNameIdxBucketName = []byte("acctnameidx")
// acctIdIdxBucketName is used to create an index // acctIDIdxBucketName is used to create an index
// mapping an account id to the corresponding // mapping an account id to the corresponding
// account name string. // account name string.
// The index needs to be updated whenever the account name // The index needs to be updated whenever the account name
// and id changes e.g. RenameAccount // and id changes e.g. RenameAccount
acctIdIdxBucketName = []byte("acctididx") acctIDIdxBucketName = []byte("acctididx")
// meta is used to store meta-data about the address manager // meta is used to store meta-data about the address manager
// e.g. last account number // e.g. last account number
@ -613,7 +613,7 @@ func fetchLastAccount(tx walletdb.Tx) (uint32, error) {
// fetchAccountName retreives the account name given an account number from // fetchAccountName retreives the account name given an account number from
// the database. // the database.
func fetchAccountName(tx walletdb.Tx, account uint32) (string, error) { func fetchAccountName(tx walletdb.Tx, account uint32) (string, error) {
bucket := tx.RootBucket().Bucket(acctIdIdxBucketName) bucket := tx.RootBucket().Bucket(acctIDIdxBucketName)
val := bucket.Get(uint32ToBytes(account)) val := bucket.Get(uint32ToBytes(account))
if val == nil { if val == nil {
@ -681,8 +681,8 @@ func deleteAccountNameIndex(tx walletdb.Tx, name string) error {
} }
// deleteAccounIdIndex deletes the given key from the account id index of the database. // deleteAccounIdIndex deletes the given key from the account id index of the database.
func deleteAccountIdIndex(tx walletdb.Tx, account uint32) error { func deleteAccountIDIndex(tx walletdb.Tx, account uint32) error {
bucket := tx.RootBucket().Bucket(acctIdIdxBucketName) bucket := tx.RootBucket().Bucket(acctIDIdxBucketName)
// Delete the account id key // Delete the account id key
err := bucket.Delete(uint32ToBytes(account)) err := bucket.Delete(uint32ToBytes(account))
@ -706,9 +706,9 @@ func putAccountNameIndex(tx walletdb.Tx, account uint32, name string) error {
return nil return nil
} }
// putAccountIdIndex stores the given key to the account id index of the database. // putAccountIDIndex stores the given key to the account id index of the database.
func putAccountIdIndex(tx walletdb.Tx, account uint32, name string) error { func putAccountIDIndex(tx walletdb.Tx, account uint32, name string) error {
bucket := tx.RootBucket().Bucket(acctIdIdxBucketName) bucket := tx.RootBucket().Bucket(acctIDIdxBucketName)
// Write the account number keyed by the account id. // Write the account number keyed by the account id.
err := bucket.Put(uint32ToBytes(account), stringToBytes(name)) err := bucket.Put(uint32ToBytes(account), stringToBytes(name))
@ -772,7 +772,7 @@ func putAccountInfo(tx walletdb.Tx, account uint32, encryptedPubKey,
return err return err
} }
// Update account id index // Update account id index
if err := putAccountIdIndex(tx, account, name); err != nil { if err := putAccountIDIndex(tx, account, name); err != nil {
return err return err
} }
// Update account name index // Update account name index
@ -1599,7 +1599,7 @@ func createManagerNS(namespace walletdb.Namespace) error {
return managerError(ErrDatabase, str, err) return managerError(ErrDatabase, str, err)
} }
_, err = rootBucket.CreateBucket(acctIdIdxBucketName) _, err = rootBucket.CreateBucket(acctIDIdxBucketName)
if err != nil { if err != nil {
str := "failed to create an account id index bucket" str := "failed to create an account id index bucket"
return managerError(ErrDatabase, str, err) return managerError(ErrDatabase, str, err)
@ -1757,7 +1757,7 @@ func upgradeManager(namespace walletdb.Namespace, pubPassPhrase []byte, config *
// upgradeToVersion3 upgrades the database from version 2 to version 3 // upgradeToVersion3 upgrades the database from version 2 to version 3
// The following buckets were introduced in version 3 to support account names: // The following buckets were introduced in version 3 to support account names:
// * acctNameIdxBucketName // * acctNameIdxBucketName
// * acctIdIdxBucketName // * acctIDIdxBucketName
// * metaBucketName // * metaBucketName
func upgradeToVersion3(namespace walletdb.Namespace, seed, privPassPhrase, pubPassPhrase []byte) error { func upgradeToVersion3(namespace walletdb.Namespace, seed, privPassPhrase, pubPassPhrase []byte) error {
err := namespace.Update(func(tx walletdb.Tx) error { err := namespace.Update(func(tx walletdb.Tx) error {
@ -1820,7 +1820,7 @@ func upgradeToVersion3(namespace walletdb.Namespace, seed, privPassPhrase, pubPa
return managerError(ErrDatabase, str, err) return managerError(ErrDatabase, str, err)
} }
_, err = rootBucket.CreateBucket(acctIdIdxBucketName) _, err = rootBucket.CreateBucket(acctIDIdxBucketName)
if err != nil { if err != nil {
str := "failed to create an account id index bucket" str := "failed to create an account id index bucket"
return managerError(ErrDatabase, str, err) return managerError(ErrDatabase, str, err)
@ -1838,14 +1838,14 @@ func upgradeToVersion3(namespace walletdb.Namespace, seed, privPassPhrase, pubPa
} }
// Update default account indexes // Update default account indexes
if err := putAccountIdIndex(tx, DefaultAccountNum, DefaultAccountName); err != nil { if err := putAccountIDIndex(tx, DefaultAccountNum, DefaultAccountName); err != nil {
return err return err
} }
if err := putAccountNameIndex(tx, DefaultAccountNum, DefaultAccountName); err != nil { if err := putAccountNameIndex(tx, DefaultAccountNum, DefaultAccountName); err != nil {
return err return err
} }
// Update imported account indexes // Update imported account indexes
if err := putAccountIdIndex(tx, ImportedAddrAccount, ImportedAddrAccountName); err != nil { if err := putAccountIDIndex(tx, ImportedAddrAccount, ImportedAddrAccountName); err != nil {
return err return err
} }
if err := putAccountNameIndex(tx, ImportedAddrAccount, ImportedAddrAccountName); err != nil { if err := putAccountNameIndex(tx, ImportedAddrAccount, ImportedAddrAccountName); err != nil {

View file

@ -1756,7 +1756,7 @@ func (m *Manager) RenameAccount(account uint32, name string) error {
err = managerError(ErrDatabase, str, nil) err = managerError(ErrDatabase, str, nil)
} }
// Remove the old name key from the accout id index // Remove the old name key from the accout id index
if err = deleteAccountIdIndex(tx, account); err != nil { if err = deleteAccountIDIndex(tx, account); err != nil {
return err return err
} }
// Remove the old name key from the accout name index // Remove the old name key from the accout name index