Move database encoding helpers.
This commit is contained in:
parent
3b1812e98f
commit
fba9fe5b0a
@ -8,7 +8,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -89,38 +88,6 @@ func writeHotBackupFile(db *bolt.DB) error {
|
|||||||
return err
|
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
|
// CreateNew intializes a new bbolt database with all of the necessary vspd
|
||||||
// buckets, and inserts:
|
// buckets, and inserts:
|
||||||
// - the provided extended pubkey (to be used for deriving fee addresses).
|
// - the provided extended pubkey (to be used for deriving fee addresses).
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,3 +27,35 @@ func bytesToStringMap(bytes []byte) (map[string]string, error) {
|
|||||||
|
|
||||||
return stringMap, nil
|
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}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user