From fba9fe5b0a72d09d3ccb59bb0da6e8e644ac7297 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Mon, 28 Mar 2022 13:43:11 +0100 Subject: [PATCH] Move database encoding helpers. --- database/database.go | 33 --------------------------------- database/helpers.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/database/database.go b/database/database.go index e9b8881..e56cbf0 100644 --- a/database/database.go +++ b/database/database.go @@ -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). diff --git a/database/helpers.go b/database/helpers.go index 099d46e..a000757 100644 --- a/database/helpers.go +++ b/database/helpers.go @@ -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} +}