waddrmgr: store block timestamp in BlockStamp
This commit is contained in:
parent
ab4ccacbb9
commit
f4ef7cdd29
2 changed files with 16 additions and 7 deletions
|
@ -1376,11 +1376,11 @@ func fetchSyncedTo(ns walletdb.ReadBucket) (*BlockStamp, error) {
|
||||||
bucket := ns.NestedReadBucket(syncBucketName)
|
bucket := ns.NestedReadBucket(syncBucketName)
|
||||||
|
|
||||||
// The serialized synced to format is:
|
// The serialized synced to format is:
|
||||||
// <blockheight><blockhash>
|
// <blockheight><blockhash><timestamp>
|
||||||
//
|
//
|
||||||
// 4 bytes block height + 32 bytes hash length
|
// 4 bytes block height + 32 bytes hash length
|
||||||
buf := bucket.Get(syncedToName)
|
buf := bucket.Get(syncedToName)
|
||||||
if len(buf) != 36 {
|
if len(buf) < 36 {
|
||||||
str := "malformed sync information stored in database"
|
str := "malformed sync information stored in database"
|
||||||
return nil, managerError(ErrDatabase, str, nil)
|
return nil, managerError(ErrDatabase, str, nil)
|
||||||
}
|
}
|
||||||
|
@ -1388,6 +1388,13 @@ func fetchSyncedTo(ns walletdb.ReadBucket) (*BlockStamp, error) {
|
||||||
var bs BlockStamp
|
var bs BlockStamp
|
||||||
bs.Height = int32(binary.LittleEndian.Uint32(buf[0:4]))
|
bs.Height = int32(binary.LittleEndian.Uint32(buf[0:4]))
|
||||||
copy(bs.Hash[:], buf[4:36])
|
copy(bs.Hash[:], buf[4:36])
|
||||||
|
|
||||||
|
if len(buf) == 40 {
|
||||||
|
bs.Timestamp = time.Unix(
|
||||||
|
int64(binary.LittleEndian.Uint32(buf[36:])), 0,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return &bs, nil
|
return &bs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1415,12 +1422,13 @@ func putSyncedTo(ns walletdb.ReadWriteBucket, bs *BlockStamp) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The serialized synced to format is:
|
// The serialized synced to format is:
|
||||||
// <blockheight><blockhash>
|
// <blockheight><blockhash><timestamp>
|
||||||
//
|
//
|
||||||
// 4 bytes block height + 32 bytes hash length
|
// 4 bytes block height + 32 bytes hash length + 4 byte timestamp length
|
||||||
buf := make([]byte, 36)
|
buf := make([]byte, 40)
|
||||||
binary.LittleEndian.PutUint32(buf[0:4], uint32(bs.Height))
|
binary.LittleEndian.PutUint32(buf[0:4], uint32(bs.Height))
|
||||||
copy(buf[4:36], bs.Hash[0:32])
|
copy(buf[4:36], bs.Hash[0:32])
|
||||||
|
binary.LittleEndian.PutUint32(buf[36:], uint32(bs.Timestamp.Unix()))
|
||||||
|
|
||||||
err = bucket.Put(syncedToName, buf)
|
err = bucket.Put(syncedToName, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -15,8 +15,9 @@ import (
|
||||||
// used to mark a point in the blockchain that an address manager element is
|
// used to mark a point in the blockchain that an address manager element is
|
||||||
// synced to.
|
// synced to.
|
||||||
type BlockStamp struct {
|
type BlockStamp struct {
|
||||||
Height int32
|
Height int32
|
||||||
Hash chainhash.Hash
|
Hash chainhash.Hash
|
||||||
|
Timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncState houses the sync state of the manager. It consists of the recently
|
// syncState houses the sync state of the manager. It consists of the recently
|
||||||
|
|
Loading…
Add table
Reference in a new issue