diff --git a/ldb/dbcache.go b/ldb/dbcache.go index 6f9e3883..24fb2856 100644 --- a/ldb/dbcache.go +++ b/ldb/dbcache.go @@ -5,7 +5,7 @@ package ldb import ( - //"fmt" +//"fmt" ) // InvalidateTxCache clear/release all cached transactions. diff --git a/ldb/dup_test.go b/ldb/dup_test.go index 4fa8a6f4..e1621408 100644 --- a/ldb/dup_test.go +++ b/ldb/dup_test.go @@ -23,7 +23,7 @@ func Test_dupTx(t *testing.T) { _ = os.RemoveAll(dbnamever) db, err := btcdb.CreateDB("leveldb", dbname) if err != nil { - t.Errorf("Failed to open test database %v", err) + t.Errorf("Failed to open test database %v", err) return } defer os.RemoveAll(dbname) @@ -75,7 +75,6 @@ out: } } - newheight, err := db.InsertBlock(block) if err != nil { t.Errorf("failed to insert block %v err %v", height, err) @@ -116,7 +115,7 @@ out: hash, _ := btcwire.NewShaHashFromStr("df2b060fa2e5e9c8ed5eaf6a45c13753ec8c63282b2688322eba40cd98ea067a") - po := btcwire.NewOutPoint(hash, 0) + po := btcwire.NewOutPoint(hash, 0) txI := btcwire.NewTxIn(po, []byte("garbage")) txO := btcwire.NewTxOut(50000000, []byte("garbageout")) @@ -133,7 +132,7 @@ out: for _, lr := range listReply { if lr.Err != nil { t.Errorf("sha %v spent %v err %v\n", lr.Sha, - lr.TxSpent, lr.Err) + lr.TxSpent, lr.Err) } } @@ -148,7 +147,7 @@ out: for _, lr := range listReply { if lr.Err != btcdb.TxShaMissing { t.Errorf("sha %v spent %v err %v\n", lr.Sha, - lr.TxSpent, lr.Err) + lr.TxSpent, lr.Err) } } @@ -160,8 +159,8 @@ out: } else { for _, lr := range txReply { if lr.Err != nil { - fmt.Errorf("stx %v spent %v err %v\n", lr.Sha, - lr.TxSpent, lr.Err) + fmt.Errorf("stx %v spent %v err %v\n", lr.Sha, + lr.TxSpent, lr.Err) } } } diff --git a/ldb/leveldb.go b/ldb/leveldb.go index 0f88ed5a..ea7f882a 100644 --- a/ldb/leveldb.go +++ b/ldb/leveldb.go @@ -51,7 +51,7 @@ type LevelDb struct { lastBlkSha btcwire.ShaHash lastBlkIdx int64 - txUpdateMap map[btcwire.ShaHash]*txUpdateObj + txUpdateMap map[btcwire.ShaHash]*txUpdateObj txSpentUpdateMap map[btcwire.ShaHash]*spentTxUpdate } @@ -379,10 +379,10 @@ func (db *LevelDb) InsertBlock(block *btcutil.Block) (height int64, rerr error) } if txsha.IsEqual(dupsha) { // marking TxOut[0] as spent - po := btcwire.NewOutPoint(dupsha, 0) + po := btcwire.NewOutPoint(dupsha, 0) txI := btcwire.NewTxIn(po, []byte("garbage")) - var spendtx btcwire.MsgTx + var spendtx btcwire.MsgTx spendtx.AddTxIn(txI) err = db.doSpend(&spendtx) if err != nil { @@ -397,10 +397,10 @@ func (db *LevelDb) InsertBlock(block *btcutil.Block) (height int64, rerr error) } if txsha.IsEqual(dupsha) { // marking TxOut[0] as spent - po := btcwire.NewOutPoint(dupsha, 0) + po := btcwire.NewOutPoint(dupsha, 0) txI := btcwire.NewTxIn(po, []byte("garbage")) - var spendtx btcwire.MsgTx + var spendtx btcwire.MsgTx spendtx.AddTxIn(txI) err = db.doSpend(&spendtx) if err != nil { @@ -501,20 +501,20 @@ func (db *LevelDb) setclearSpentData(txsha *btcwire.ShaHash, idx uint32, set boo } // need to reslice the list to exclude the most recent. - sTx := spentTxList [len(spentTxList) -1] - spentTxList [len(spentTxList) -1] = nil - if len (spentTxList) == 1 { + sTx := spentTxList[len(spentTxList)-1] + spentTxList[len(spentTxList)-1] = nil + if len(spentTxList) == 1 { // write entry to delete tx from spent pool // XXX } else { - spentTxList = spentTxList [:len(spentTxList)-1] + spentTxList = spentTxList[:len(spentTxList)-1] // XXX format sTxList and set update Table } // Create 'new' Tx update data. blkHeight = sTx.blkHeight txOff = sTx.txoff - txLen = sTx.txlen + txLen = sTx.txlen spentbuflen := (sTx.numTxO + 7) / 8 spentData = make([]byte, spentbuflen, spentbuflen) for i := range spentData { @@ -542,7 +542,7 @@ func (db *LevelDb) setclearSpentData(txsha *btcwire.ShaHash, idx uint32, set boo // check for fully spent Tx fullySpent := true - for _, val := range txUo.spentData { + for _, val := range txUo.spentData { if val != ^byte(0) { fullySpent = false break @@ -551,11 +551,11 @@ func (db *LevelDb) setclearSpentData(txsha *btcwire.ShaHash, idx uint32, set boo if fullySpent { var txSu *spentTxUpdate // Look up Tx in fully spent table - if txSuOld, ok := db.txSpentUpdateMap[*txsha] ; ok { + if txSuOld, ok := db.txSpentUpdateMap[*txsha]; ok { txSu = txSuOld } else { var txSuStore spentTxUpdate - txSu = &txSuStore + txSu = &txSuStore txSuOld, err := db.getTxFullySpent(txsha) if err == nil { @@ -568,8 +568,8 @@ func (db *LevelDb) setclearSpentData(txsha *btcwire.ShaHash, idx uint32, set boo sTx.blkHeight = txUo.blkHeight sTx.txoff = txUo.txoff sTx.txlen = txUo.txlen - // XXX -- there is no way to comput the real TxOut - // from the spent array. + // XXX -- there is no way to comput the real TxOut + // from the spent array. sTx.numTxO = 8 * len(txUo.spentData) // append this txdata to fully spent txlist diff --git a/ldb/tx.go b/ldb/tx.go index 61883846..cf99a6a5 100644 --- a/ldb/tx.go +++ b/ldb/tx.go @@ -9,8 +9,8 @@ import ( "encoding/binary" "fmt" "github.com/conformal/btcdb" - "github.com/conformal/goleveldb/leveldb" "github.com/conformal/btcwire" + "github.com/conformal/goleveldb/leveldb" ) type txUpdateObj struct { @@ -31,7 +31,7 @@ type spentTx struct { delete bool } type spentTxUpdate struct { - txl []*spentTx + txl []*spentTx delete bool } @@ -154,7 +154,7 @@ func (db *LevelDb) getTxFullySpent(txsha *btcwire.ShaHash) ([]*spentTx, error) { for i := range spentTxList { var sTx spentTx - var blkHeight int64 + var blkHeight int64 var txOff, txLen, numTxO int32 err := binary.Read(txR, binary.LittleEndian, &blkHeight) @@ -275,7 +275,7 @@ func (db *LevelDb) FetchTxByShaList(txShaList []*btcwire.ShaHash) []*btcdb.TxLis stx := sTxList[idx] tx, blockSha, _, _, err = db.fetchTxDataByLoc( - stx.blkHeight, stx.txoff, stx.txlen, []byte{}) + stx.blkHeight, stx.txoff, stx.txlen, []byte{}) if err == nil { btxspent = make([]bool, len(tx.TxOut)) for i := range btxspent { @@ -384,13 +384,12 @@ func (db *LevelDb) FetchTxBySha(txsha *btcwire.ShaHash) ([]*btcdb.TxListReply, e replylen += len(sTxList) } - replies := make ([]*btcdb.TxListReply, replylen) - + replies := make([]*btcdb.TxListReply, replylen) if fSerr == nil { for _, stx := range sTxList { tx, blksha, _, _, err := db.fetchTxDataByLoc( - stx.blkHeight, stx.txoff, stx.txlen, []byte{}) + stx.blkHeight, stx.txoff, stx.txlen, []byte{}) if err != nil { if err != leveldb.ErrNotFound { return []*btcdb.TxListReply{}, err @@ -419,4 +418,3 @@ func (db *LevelDb) FetchTxBySha(txsha *btcwire.ShaHash) ([]*btcdb.TxListReply, e } return replies, nil } -