Move database encoding helpers.

This commit is contained in:
jholdstock 2022-03-28 13:43:11 +01:00 committed by Jamie Holdstock
parent 3b1812e98f
commit fba9fe5b0a
2 changed files with 33 additions and 33 deletions

View File

@ -8,7 +8,6 @@ import (
"context"
"crypto/ed25519"
"crypto/rand"
"encoding/binary"
"fmt"
"io"
"net/http"
@ -89,38 +88,6 @@ func writeHotBackupFile(db *bolt.DB) error {
return err
}
func int64ToBytes(i int64) []byte {
bytes := make([]byte, 8)
binary.LittleEndian.PutUint64(bytes, uint64(i))
return bytes
}
func bytesToInt64(bytes []byte) int64 {
return int64(binary.LittleEndian.Uint64(bytes))
}
func uint32ToBytes(i uint32) []byte {
bytes := make([]byte, 4)
binary.LittleEndian.PutUint32(bytes, i)
return bytes
}
func bytesToUint32(bytes []byte) uint32 {
return binary.LittleEndian.Uint32(bytes)
}
func bytesToBool(bytes []byte) bool {
return bytes[0] == 1
}
func boolToBytes(b bool) []byte {
if b {
return []byte{1}
}
return []byte{0}
}
// CreateNew intializes a new bbolt database with all of the necessary vspd
// buckets, and inserts:
// - the provided extended pubkey (to be used for deriving fee addresses).

View File

@ -5,6 +5,7 @@
package database
import (
"encoding/binary"
"encoding/json"
)
@ -26,3 +27,35 @@ func bytesToStringMap(bytes []byte) (map[string]string, error) {
return stringMap, nil
}
func int64ToBytes(i int64) []byte {
bytes := make([]byte, 8)
binary.LittleEndian.PutUint64(bytes, uint64(i))
return bytes
}
func bytesToInt64(bytes []byte) int64 {
return int64(binary.LittleEndian.Uint64(bytes))
}
func uint32ToBytes(i uint32) []byte {
bytes := make([]byte, 4)
binary.LittleEndian.PutUint32(bytes, i)
return bytes
}
func bytesToUint32(bytes []byte) uint32 {
return binary.LittleEndian.Uint32(bytes)
}
func bytesToBool(bytes []byte) bool {
return bytes[0] == 1
}
func boolToBytes(b bool) []byte {
if b {
return []byte{1}
}
return []byte{0}
}