forked from decred/dcrwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
39 lines (31 loc) · 1.16 KB
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2017 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package udb
import (
"github.com/decred/dcrwallet/apperrors"
"github.com/decred/dcrwallet/walletdb"
)
type unifiedDBMetadata struct {
}
var metadataRootBucketKey = []byte("meta")
func (unifiedDBMetadata) rootBucketKey() []byte { return metadataRootBucketKey }
const unifiedDBMetadataVersionKey = "ver"
func (unifiedDBMetadata) putVersion(bucket walletdb.ReadWriteBucket, version uint32) error {
buf := make([]byte, 4)
byteOrder.PutUint32(buf, version)
err := bucket.Put([]byte(unifiedDBMetadataVersionKey), buf)
if err != nil {
const str = "failed to put unified database metadata bucket"
return apperrors.E{ErrorCode: apperrors.ErrDatabase, Description: str, Err: err}
}
return nil
}
func (unifiedDBMetadata) getVersion(bucket walletdb.ReadBucket) (uint32, error) {
v := bucket.Get([]byte(unifiedDBMetadataVersionKey))
if len(v) != 4 {
const str = "missing or incorrectly sized unified database version"
return 0, apperrors.E{ErrorCode: apperrors.ErrData, Description: str, Err: nil}
}
return byteOrder.Uint32(v), nil
}