diff --git a/common/coords.go b/common/coords.go index 8b33b33..dce9b46 100644 --- a/common/coords.go +++ b/common/coords.go @@ -4,9 +4,17 @@ package common -import "strconv" +import ( + "fmt" + "strconv" +) // Constructs a database key out of byte slice. func DecodePosFromBytes(key []byte) (pos int64, err error) { return strconv.ParseInt(string(key), 10, 64) } + +// Encode a block pos to byte slice. +func EncodePosToBytes(key int64) []byte { + return []byte(fmt.Sprintf("%d", key)) +} diff --git a/sqlite.go b/sqlite.go index 2984eb0..4f4cc6d 100644 --- a/sqlite.go +++ b/sqlite.go @@ -242,12 +242,12 @@ func (ss *SqliteSession) AllKeys(hash []byte) (keys chan []byte, n int, err erro defer rows.Close() defer close(keys) for rows.Next() { - var key []byte + var key int64 if err := rows.Scan(&key); err != nil { log.Printf("WARN: %s", err) break } - keys <- key + keys <- common.EncodePosToBytes(key) } }()