wtxmgr/db: add new createBuckets and deleteBuckets methods
This commit is contained in:
parent
de4662e5df
commit
a0a5e46177
1 changed files with 54 additions and 23 deletions
77
wtxmgr/db.go
77
wtxmgr/db.go
|
@ -1311,50 +1311,42 @@ func createStore(ns walletdb.ReadWriteBucket) error {
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ns.CreateBucket(bucketBlocks)
|
// Finally, create all of our required descendant buckets.
|
||||||
if err != nil {
|
return createBuckets(ns)
|
||||||
|
}
|
||||||
|
|
||||||
|
// createBuckets creates all of the descendants buckets required for the
|
||||||
|
// transaction store to properly carry its duties.
|
||||||
|
func createBuckets(ns walletdb.ReadWriteBucket) error {
|
||||||
|
if _, err := ns.CreateBucket(bucketBlocks); err != nil {
|
||||||
str := "failed to create blocks bucket"
|
str := "failed to create blocks bucket"
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
if _, err := ns.CreateBucket(bucketTxRecords); err != nil {
|
||||||
_, err = ns.CreateBucket(bucketTxRecords)
|
|
||||||
if err != nil {
|
|
||||||
str := "failed to create tx records bucket"
|
str := "failed to create tx records bucket"
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
if _, err := ns.CreateBucket(bucketCredits); err != nil {
|
||||||
_, err = ns.CreateBucket(bucketCredits)
|
|
||||||
if err != nil {
|
|
||||||
str := "failed to create credits bucket"
|
str := "failed to create credits bucket"
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
if _, err := ns.CreateBucket(bucketDebits); err != nil {
|
||||||
_, err = ns.CreateBucket(bucketDebits)
|
|
||||||
if err != nil {
|
|
||||||
str := "failed to create debits bucket"
|
str := "failed to create debits bucket"
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
if _, err := ns.CreateBucket(bucketUnspent); err != nil {
|
||||||
_, err = ns.CreateBucket(bucketUnspent)
|
|
||||||
if err != nil {
|
|
||||||
str := "failed to create unspent bucket"
|
str := "failed to create unspent bucket"
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
if _, err := ns.CreateBucket(bucketUnmined); err != nil {
|
||||||
_, err = ns.CreateBucket(bucketUnmined)
|
|
||||||
if err != nil {
|
|
||||||
str := "failed to create unmined bucket"
|
str := "failed to create unmined bucket"
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
if _, err := ns.CreateBucket(bucketUnminedCredits); err != nil {
|
||||||
_, err = ns.CreateBucket(bucketUnminedCredits)
|
|
||||||
if err != nil {
|
|
||||||
str := "failed to create unmined credits bucket"
|
str := "failed to create unmined credits bucket"
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
if _, err := ns.CreateBucket(bucketUnminedInputs); err != nil {
|
||||||
_, err = ns.CreateBucket(bucketUnminedInputs)
|
|
||||||
if err != nil {
|
|
||||||
str := "failed to create unmined inputs bucket"
|
str := "failed to create unmined inputs bucket"
|
||||||
return storeError(ErrDatabase, str, err)
|
return storeError(ErrDatabase, str, err)
|
||||||
}
|
}
|
||||||
|
@ -1362,6 +1354,45 @@ func createStore(ns walletdb.ReadWriteBucket) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deleteBuckets deletes all of the descendants buckets required for the
|
||||||
|
// transaction store to properly carry its duties.
|
||||||
|
func deleteBuckets(ns walletdb.ReadWriteBucket) error {
|
||||||
|
if err := ns.DeleteNestedBucket(bucketBlocks); err != nil {
|
||||||
|
str := "failed to delete blocks bucket"
|
||||||
|
return storeError(ErrDatabase, str, err)
|
||||||
|
}
|
||||||
|
if err := ns.DeleteNestedBucket(bucketTxRecords); err != nil {
|
||||||
|
str := "failed to delete tx records bucket"
|
||||||
|
return storeError(ErrDatabase, str, err)
|
||||||
|
}
|
||||||
|
if err := ns.DeleteNestedBucket(bucketCredits); err != nil {
|
||||||
|
str := "failed to delete credits bucket"
|
||||||
|
return storeError(ErrDatabase, str, err)
|
||||||
|
}
|
||||||
|
if err := ns.DeleteNestedBucket(bucketDebits); err != nil {
|
||||||
|
str := "failed to delete debits bucket"
|
||||||
|
return storeError(ErrDatabase, str, err)
|
||||||
|
}
|
||||||
|
if err := ns.DeleteNestedBucket(bucketUnspent); err != nil {
|
||||||
|
str := "failed to delete unspent bucket"
|
||||||
|
return storeError(ErrDatabase, str, err)
|
||||||
|
}
|
||||||
|
if err := ns.DeleteNestedBucket(bucketUnmined); err != nil {
|
||||||
|
str := "failed to delete unmined bucket"
|
||||||
|
return storeError(ErrDatabase, str, err)
|
||||||
|
}
|
||||||
|
if err := ns.DeleteNestedBucket(bucketUnminedCredits); err != nil {
|
||||||
|
str := "failed to delete unmined credits bucket"
|
||||||
|
return storeError(ErrDatabase, str, err)
|
||||||
|
}
|
||||||
|
if err := ns.DeleteNestedBucket(bucketUnminedInputs); err != nil {
|
||||||
|
str := "failed to delete unmined inputs bucket"
|
||||||
|
return storeError(ErrDatabase, str, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// putVersion modifies the version of the store to reflect the given version
|
// putVersion modifies the version of the store to reflect the given version
|
||||||
// number.
|
// number.
|
||||||
func putVersion(ns walletdb.ReadWriteBucket, version uint32) error {
|
func putVersion(ns walletdb.ReadWriteBucket, version uint32) error {
|
||||||
|
|
Loading…
Reference in a new issue