From 92651c6d138cd0dc19824de7d54bed0cb2145e4f Mon Sep 17 00:00:00 2001 From: Dale Rahn Date: Thu, 18 Jul 2013 16:43:36 -0400 Subject: [PATCH] Fix spent computation on a multiple of 8 txout tx. --- sqlite3/sqlite.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sqlite3/sqlite.go b/sqlite3/sqlite.go index 6e16d70a..8807c0ae 100644 --- a/sqlite3/sqlite.go +++ b/sqlite3/sqlite.go @@ -678,8 +678,10 @@ func (db *SqliteDb) InsertBlock(block *btcutil.Block) (height int64, err error) } spentbuflen := (len(tx.TxOut) + 7) / 8 spentbuf := make([]byte, spentbuflen, spentbuflen) - for i := uint(len(tx.TxOut) % 8); i < 8; i++ { - spentbuf[spentbuflen-1] |= (byte(1) << i) + if len(tx.TxOut)%8 != 0 { + for i := uint(len(tx.TxOut) % 8); i < 8; i++ { + spentbuf[spentbuflen-1] |= (byte(1) << i) + } } err = db.insertTx(&txsha, newheight, txloc[txidx].TxStart, txloc[txidx].TxLen, spentbuf)