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.
This commit is contained in:
parent
ea82d184bf
commit
8bd9f7713b
1 changed files with 27 additions and 31 deletions
|
@ -76,7 +76,10 @@ type accountType uint8
|
||||||
|
|
||||||
// These constants define the various supported account types.
|
// These constants define the various supported account types.
|
||||||
const (
|
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.
|
// 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.
|
rawData []byte // Varies based on account type field.
|
||||||
}
|
}
|
||||||
|
|
||||||
// dbBIP0044AccountRow houses additional information stored about a BIP0044
|
// dbDefaultAccountRow houses additional information stored about a default
|
||||||
// account in the database.
|
// BIP0044-like account in the database.
|
||||||
type dbBIP0044AccountRow struct {
|
type dbDefaultAccountRow struct {
|
||||||
dbAccountRow
|
dbAccountRow
|
||||||
pubKeyEncrypted []byte
|
pubKeyEncrypted []byte
|
||||||
privKeyEncrypted []byte
|
privKeyEncrypted []byte
|
||||||
|
@ -284,8 +287,8 @@ func fetchMasterKeyParams(ns walletdb.ReadBucket) ([]byte, []byte, error) {
|
||||||
return pubParams, privParams, nil
|
return pubParams, privParams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// putMasterKeyParams stores the master key parameters needed to derive them
|
// putMasterKeyParams stores the master key parameters needed to derive them to
|
||||||
// to the database. Either parameter can be nil in which case no value is
|
// the database. Either parameter can be nil in which case no value is
|
||||||
// written for the parameter.
|
// written for the parameter.
|
||||||
func putMasterKeyParams(ns walletdb.ReadWriteBucket, pubParams, privParams []byte) error {
|
func putMasterKeyParams(ns walletdb.ReadWriteBucket, pubParams, privParams []byte) error {
|
||||||
bucket := ns.NestedReadWriteBucket(mainBucketName)
|
bucket := ns.NestedReadWriteBucket(mainBucketName)
|
||||||
|
@ -490,9 +493,9 @@ func serializeAccountRow(row *dbAccountRow) []byte {
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
// deserializeBIP0044AccountRow deserializes the raw data from the passed
|
// deserializeDefaultAccountRow deserializes the raw data from the passed
|
||||||
// account row as a BIP0044 account.
|
// account row as a BIP0044-like account.
|
||||||
func deserializeBIP0044AccountRow(accountID []byte, row *dbAccountRow) (*dbBIP0044AccountRow, error) {
|
func deserializeDefaultAccountRow(accountID []byte, row *dbAccountRow) (*dbDefaultAccountRow, error) {
|
||||||
// The serialized BIP0044 account raw data format is:
|
// The serialized BIP0044 account raw data format is:
|
||||||
// <encpubkeylen><encpubkey><encprivkeylen><encprivkey><nextextidx>
|
// <encpubkeylen><encpubkey><encprivkeylen><encprivkey><nextextidx>
|
||||||
// <nextintidx><namelen><name>
|
// <nextintidx><namelen><name>
|
||||||
|
@ -509,7 +512,7 @@ func deserializeBIP0044AccountRow(accountID []byte, row *dbAccountRow) (*dbBIP00
|
||||||
return nil, managerError(ErrDatabase, str, nil)
|
return nil, managerError(ErrDatabase, str, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
retRow := dbBIP0044AccountRow{
|
retRow := dbDefaultAccountRow{
|
||||||
dbAccountRow: *row,
|
dbAccountRow: *row,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,11 +536,11 @@ func deserializeBIP0044AccountRow(accountID []byte, row *dbAccountRow) (*dbBIP00
|
||||||
return &retRow, nil
|
return &retRow, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// serializeBIP0044AccountRow returns the serialization of the raw data field
|
// serializeDefaultAccountRow returns the serialization of the raw data field
|
||||||
// for a BIP0044 account.
|
// for a BIP0044-like account.
|
||||||
func serializeBIP0044AccountRow(encryptedPubKey,
|
func serializeDefaultAccountRow(encryptedPubKey, encryptedPrivKey []byte,
|
||||||
encryptedPrivKey []byte, nextExternalIndex, nextInternalIndex uint32,
|
nextExternalIndex, nextInternalIndex uint32, name string) []byte {
|
||||||
name string) []byte {
|
|
||||||
// The serialized BIP0044 account raw data format is:
|
// The serialized BIP0044 account raw data format is:
|
||||||
// <encpubkeylen><encpubkey><encprivkeylen><encprivkey><nextextidx>
|
// <encpubkeylen><encpubkey><encprivkeylen><encprivkey><nextextidx>
|
||||||
// <nextintidx><namelen><name>
|
// <nextintidx><namelen><name>
|
||||||
|
@ -749,7 +752,7 @@ func putAccountInfo(ns walletdb.ReadWriteBucket, account uint32, encryptedPubKey
|
||||||
nextExternalIndex, nextInternalIndex, name)
|
nextExternalIndex, nextInternalIndex, name)
|
||||||
|
|
||||||
acctRow := dbAccountRow{
|
acctRow := dbAccountRow{
|
||||||
acctType: actBIP0044,
|
acctType: accountDefault,
|
||||||
rawData: rawData,
|
rawData: rawData,
|
||||||
}
|
}
|
||||||
if err := putAccountRow(ns, account, &acctRow); err != nil {
|
if err := putAccountRow(ns, account, &acctRow); err != nil {
|
||||||
|
@ -779,13 +782,9 @@ func putLastAccount(ns walletdb.ReadWriteBucket, account uint32) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchAddressRow loads address information for the provided address id from
|
// deserializeAddressRow deserializes the passed serialized address
|
||||||
// the database. This is used as a common base for the various address types
|
// information. This is used as a common base for the various address types to
|
||||||
// to load the common information.
|
// 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) {
|
func deserializeAddressRow(serializedAddress []byte) (*dbAddressRow, error) {
|
||||||
// The serialized address format is:
|
// The serialized address format is:
|
||||||
// <addrType><account><addedTime><syncStatus><rawdata>
|
// <addrType><account><addedTime><syncStatus><rawdata>
|
||||||
|
@ -991,10 +990,6 @@ func fetchAddressByHash(ns walletdb.ReadBucket, addrHash []byte) (interface{}, e
|
||||||
}
|
}
|
||||||
|
|
||||||
switch row.addrType {
|
switch row.addrType {
|
||||||
case adtChainWitness:
|
|
||||||
fallthrough
|
|
||||||
case adtChainNestedWitness:
|
|
||||||
fallthrough
|
|
||||||
case adtChain:
|
case adtChain:
|
||||||
return deserializeChainedAddress(row)
|
return deserializeChainedAddress(row)
|
||||||
case adtImport:
|
case adtImport:
|
||||||
|
@ -1087,7 +1082,7 @@ func putChainedAddress(ns walletdb.ReadWriteBucket, addressID []byte, account ui
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
arow, err := deserializeBIP0044AccountRow(accountID, row)
|
arow, err := deserializeDefaultAccountRow(accountID, row)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.
|
// Reserialize the account with the updated index and store it.
|
||||||
row.rawData = serializeBIP0044AccountRow(arow.pubKeyEncrypted,
|
row.rawData = serializeDefaultAccountRow(
|
||||||
arow.privKeyEncrypted, nextExternalIndex, nextInternalIndex,
|
arow.pubKeyEncrypted, arow.privKeyEncrypted, nextExternalIndex,
|
||||||
arow.name)
|
nextInternalIndex, arow.name,
|
||||||
|
)
|
||||||
err = bucket.Put(accountID, serializeAccountRow(row))
|
err = bucket.Put(accountID, serializeAccountRow(row))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
str := fmt.Sprintf("failed to update next index for "+
|
str := fmt.Sprintf("failed to update next index for "+
|
||||||
|
|
Loading…
Reference in a new issue