From 8bd9f7713b2a50a4ed97bda95a48c214c014dd87 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 13 Feb 2018 20:54:51 -0800 Subject: [PATCH] waddrmgr: remove direct references to BIP 44 in struct/variable names In this commit, we remove all direct references to BIP 44 as upcoming changes will shift to a model that is no longer directly dependent on BIP 44 in favor of restoring a layer of abstraction and allowing users to manage multiple (purpose, coin type) scopes within the same database. --- waddrmgr/db.go | 58 +++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/waddrmgr/db.go b/waddrmgr/db.go index 017c2fe..0a177cc 100644 --- a/waddrmgr/db.go +++ b/waddrmgr/db.go @@ -76,7 +76,10 @@ type accountType uint8 // These constants define the various supported account types. const ( - actBIP0044 accountType = 0 // not iota as they need to be stable for db + // accountDefault is the current "default" account type within the + // database. This is an account that re-uses the key derivation schema + // of BIP0044-like accounts. + accountDefault accountType = 0 // not iota as they need to be stable ) // dbAccountRow houses information stored about an account in the database. @@ -85,9 +88,9 @@ type dbAccountRow struct { rawData []byte // Varies based on account type field. } -// dbBIP0044AccountRow houses additional information stored about a BIP0044 -// account in the database. -type dbBIP0044AccountRow struct { +// dbDefaultAccountRow houses additional information stored about a default +// BIP0044-like account in the database. +type dbDefaultAccountRow struct { dbAccountRow pubKeyEncrypted []byte privKeyEncrypted []byte @@ -284,8 +287,8 @@ func fetchMasterKeyParams(ns walletdb.ReadBucket) ([]byte, []byte, error) { return pubParams, privParams, nil } -// putMasterKeyParams stores the master key parameters needed to derive them -// to the database. Either parameter can be nil in which case no value is +// putMasterKeyParams stores the master key parameters needed to derive them to +// the database. Either parameter can be nil in which case no value is // written for the parameter. func putMasterKeyParams(ns walletdb.ReadWriteBucket, pubParams, privParams []byte) error { bucket := ns.NestedReadWriteBucket(mainBucketName) @@ -490,9 +493,9 @@ func serializeAccountRow(row *dbAccountRow) []byte { return buf } -// deserializeBIP0044AccountRow deserializes the raw data from the passed -// account row as a BIP0044 account. -func deserializeBIP0044AccountRow(accountID []byte, row *dbAccountRow) (*dbBIP0044AccountRow, error) { +// deserializeDefaultAccountRow deserializes the raw data from the passed +// account row as a BIP0044-like account. +func deserializeDefaultAccountRow(accountID []byte, row *dbAccountRow) (*dbDefaultAccountRow, error) { // The serialized BIP0044 account raw data format is: // // @@ -509,7 +512,7 @@ func deserializeBIP0044AccountRow(accountID []byte, row *dbAccountRow) (*dbBIP00 return nil, managerError(ErrDatabase, str, nil) } - retRow := dbBIP0044AccountRow{ + retRow := dbDefaultAccountRow{ dbAccountRow: *row, } @@ -533,11 +536,11 @@ func deserializeBIP0044AccountRow(accountID []byte, row *dbAccountRow) (*dbBIP00 return &retRow, nil } -// serializeBIP0044AccountRow returns the serialization of the raw data field -// for a BIP0044 account. -func serializeBIP0044AccountRow(encryptedPubKey, - encryptedPrivKey []byte, nextExternalIndex, nextInternalIndex uint32, - name string) []byte { +// serializeDefaultAccountRow returns the serialization of the raw data field +// for a BIP0044-like account. +func serializeDefaultAccountRow(encryptedPubKey, encryptedPrivKey []byte, + nextExternalIndex, nextInternalIndex uint32, name string) []byte { + // The serialized BIP0044 account raw data format is: // // @@ -749,7 +752,7 @@ func putAccountInfo(ns walletdb.ReadWriteBucket, account uint32, encryptedPubKey nextExternalIndex, nextInternalIndex, name) acctRow := dbAccountRow{ - acctType: actBIP0044, + acctType: accountDefault, rawData: rawData, } if err := putAccountRow(ns, account, &acctRow); err != nil { @@ -779,13 +782,9 @@ func putLastAccount(ns walletdb.ReadWriteBucket, account uint32) error { return nil } -// fetchAddressRow loads address information for the provided address id from -// the database. This is used as a common base for the various address types -// to load the common information. - -// deserializeAddressRow deserializes the passed serialized address information. -// This is used as a common base for the various address types to deserialize -// the common parts. +// deserializeAddressRow deserializes the passed serialized address +// information. This is used as a common base for the various address types to +// deserialize the common parts. func deserializeAddressRow(serializedAddress []byte) (*dbAddressRow, error) { // The serialized address format is: // @@ -991,10 +990,6 @@ func fetchAddressByHash(ns walletdb.ReadBucket, addrHash []byte) (interface{}, e } switch row.addrType { - case adtChainWitness: - fallthrough - case adtChainNestedWitness: - fallthrough case adtChain: return deserializeChainedAddress(row) case adtImport: @@ -1087,7 +1082,7 @@ func putChainedAddress(ns walletdb.ReadWriteBucket, addressID []byte, account ui if err != nil { return err } - arow, err := deserializeBIP0044AccountRow(accountID, row) + arow, err := deserializeDefaultAccountRow(accountID, row) if err != nil { return err } @@ -1103,9 +1098,10 @@ func putChainedAddress(ns walletdb.ReadWriteBucket, addressID []byte, account ui } // Reserialize the account with the updated index and store it. - row.rawData = serializeBIP0044AccountRow(arow.pubKeyEncrypted, - arow.privKeyEncrypted, nextExternalIndex, nextInternalIndex, - arow.name) + row.rawData = serializeDefaultAccountRow( + arow.pubKeyEncrypted, arow.privKeyEncrypted, nextExternalIndex, + nextInternalIndex, arow.name, + ) err = bucket.Put(accountID, serializeAccountRow(row)) if err != nil { str := fmt.Sprintf("failed to update next index for "+