Gofmt.
This commit is contained in:
parent
3bc401fed1
commit
fc11da9ca0
4 changed files with 28 additions and 31 deletions
|
@ -5,7 +5,7 @@
|
||||||
package ldb
|
package ldb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"fmt"
|
//"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InvalidateTxCache clear/release all cached transactions.
|
// InvalidateTxCache clear/release all cached transactions.
|
||||||
|
|
|
@ -23,7 +23,7 @@ func Test_dupTx(t *testing.T) {
|
||||||
_ = os.RemoveAll(dbnamever)
|
_ = os.RemoveAll(dbnamever)
|
||||||
db, err := btcdb.CreateDB("leveldb", dbname)
|
db, err := btcdb.CreateDB("leveldb", dbname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to open test database %v", err)
|
t.Errorf("Failed to open test database %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dbname)
|
defer os.RemoveAll(dbname)
|
||||||
|
@ -75,7 +75,6 @@ out:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
newheight, err := db.InsertBlock(block)
|
newheight, err := db.InsertBlock(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to insert block %v err %v", height, err)
|
t.Errorf("failed to insert block %v err %v", height, err)
|
||||||
|
@ -116,7 +115,7 @@ out:
|
||||||
|
|
||||||
hash, _ := btcwire.NewShaHashFromStr("df2b060fa2e5e9c8ed5eaf6a45c13753ec8c63282b2688322eba40cd98ea067a")
|
hash, _ := btcwire.NewShaHashFromStr("df2b060fa2e5e9c8ed5eaf6a45c13753ec8c63282b2688322eba40cd98ea067a")
|
||||||
|
|
||||||
po := btcwire.NewOutPoint(hash, 0)
|
po := btcwire.NewOutPoint(hash, 0)
|
||||||
txI := btcwire.NewTxIn(po, []byte("garbage"))
|
txI := btcwire.NewTxIn(po, []byte("garbage"))
|
||||||
txO := btcwire.NewTxOut(50000000, []byte("garbageout"))
|
txO := btcwire.NewTxOut(50000000, []byte("garbageout"))
|
||||||
|
|
||||||
|
@ -133,7 +132,7 @@ out:
|
||||||
for _, lr := range listReply {
|
for _, lr := range listReply {
|
||||||
if lr.Err != nil {
|
if lr.Err != nil {
|
||||||
t.Errorf("sha %v spent %v err %v\n", lr.Sha,
|
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 {
|
for _, lr := range listReply {
|
||||||
if lr.Err != btcdb.TxShaMissing {
|
if lr.Err != btcdb.TxShaMissing {
|
||||||
t.Errorf("sha %v spent %v err %v\n", lr.Sha,
|
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 {
|
} else {
|
||||||
for _, lr := range txReply {
|
for _, lr := range txReply {
|
||||||
if lr.Err != nil {
|
if lr.Err != nil {
|
||||||
fmt.Errorf("stx %v spent %v err %v\n", lr.Sha,
|
fmt.Errorf("stx %v spent %v err %v\n", lr.Sha,
|
||||||
lr.TxSpent, lr.Err)
|
lr.TxSpent, lr.Err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ type LevelDb struct {
|
||||||
lastBlkSha btcwire.ShaHash
|
lastBlkSha btcwire.ShaHash
|
||||||
lastBlkIdx int64
|
lastBlkIdx int64
|
||||||
|
|
||||||
txUpdateMap map[btcwire.ShaHash]*txUpdateObj
|
txUpdateMap map[btcwire.ShaHash]*txUpdateObj
|
||||||
txSpentUpdateMap map[btcwire.ShaHash]*spentTxUpdate
|
txSpentUpdateMap map[btcwire.ShaHash]*spentTxUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ func (db *LevelDb) InsertBlock(block *btcutil.Block) (height int64, rerr error)
|
||||||
}
|
}
|
||||||
if txsha.IsEqual(dupsha) {
|
if txsha.IsEqual(dupsha) {
|
||||||
// marking TxOut[0] as spent
|
// marking TxOut[0] as spent
|
||||||
po := btcwire.NewOutPoint(dupsha, 0)
|
po := btcwire.NewOutPoint(dupsha, 0)
|
||||||
txI := btcwire.NewTxIn(po, []byte("garbage"))
|
txI := btcwire.NewTxIn(po, []byte("garbage"))
|
||||||
|
|
||||||
var spendtx btcwire.MsgTx
|
var spendtx btcwire.MsgTx
|
||||||
|
@ -397,7 +397,7 @@ func (db *LevelDb) InsertBlock(block *btcutil.Block) (height int64, rerr error)
|
||||||
}
|
}
|
||||||
if txsha.IsEqual(dupsha) {
|
if txsha.IsEqual(dupsha) {
|
||||||
// marking TxOut[0] as spent
|
// marking TxOut[0] as spent
|
||||||
po := btcwire.NewOutPoint(dupsha, 0)
|
po := btcwire.NewOutPoint(dupsha, 0)
|
||||||
txI := btcwire.NewTxIn(po, []byte("garbage"))
|
txI := btcwire.NewTxIn(po, []byte("garbage"))
|
||||||
|
|
||||||
var spendtx btcwire.MsgTx
|
var spendtx btcwire.MsgTx
|
||||||
|
@ -501,13 +501,13 @@ func (db *LevelDb) setclearSpentData(txsha *btcwire.ShaHash, idx uint32, set boo
|
||||||
}
|
}
|
||||||
|
|
||||||
// need to reslice the list to exclude the most recent.
|
// need to reslice the list to exclude the most recent.
|
||||||
sTx := spentTxList [len(spentTxList) -1]
|
sTx := spentTxList[len(spentTxList)-1]
|
||||||
spentTxList [len(spentTxList) -1] = nil
|
spentTxList[len(spentTxList)-1] = nil
|
||||||
if len (spentTxList) == 1 {
|
if len(spentTxList) == 1 {
|
||||||
// write entry to delete tx from spent pool
|
// write entry to delete tx from spent pool
|
||||||
// XXX
|
// XXX
|
||||||
} else {
|
} else {
|
||||||
spentTxList = spentTxList [:len(spentTxList)-1]
|
spentTxList = spentTxList[:len(spentTxList)-1]
|
||||||
// XXX format sTxList and set update Table
|
// XXX format sTxList and set update Table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +551,7 @@ func (db *LevelDb) setclearSpentData(txsha *btcwire.ShaHash, idx uint32, set boo
|
||||||
if fullySpent {
|
if fullySpent {
|
||||||
var txSu *spentTxUpdate
|
var txSu *spentTxUpdate
|
||||||
// Look up Tx in fully spent table
|
// Look up Tx in fully spent table
|
||||||
if txSuOld, ok := db.txSpentUpdateMap[*txsha] ; ok {
|
if txSuOld, ok := db.txSpentUpdateMap[*txsha]; ok {
|
||||||
txSu = txSuOld
|
txSu = txSuOld
|
||||||
} else {
|
} else {
|
||||||
var txSuStore spentTxUpdate
|
var txSuStore spentTxUpdate
|
||||||
|
|
14
ldb/tx.go
14
ldb/tx.go
|
@ -9,8 +9,8 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
"github.com/conformal/goleveldb/leveldb"
|
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
|
"github.com/conformal/goleveldb/leveldb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type txUpdateObj struct {
|
type txUpdateObj struct {
|
||||||
|
@ -31,7 +31,7 @@ type spentTx struct {
|
||||||
delete bool
|
delete bool
|
||||||
}
|
}
|
||||||
type spentTxUpdate struct {
|
type spentTxUpdate struct {
|
||||||
txl []*spentTx
|
txl []*spentTx
|
||||||
delete bool
|
delete bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ func (db *LevelDb) getTxFullySpent(txsha *btcwire.ShaHash) ([]*spentTx, error) {
|
||||||
|
|
||||||
for i := range spentTxList {
|
for i := range spentTxList {
|
||||||
var sTx spentTx
|
var sTx spentTx
|
||||||
var blkHeight int64
|
var blkHeight int64
|
||||||
var txOff, txLen, numTxO int32
|
var txOff, txLen, numTxO int32
|
||||||
|
|
||||||
err := binary.Read(txR, binary.LittleEndian, &blkHeight)
|
err := binary.Read(txR, binary.LittleEndian, &blkHeight)
|
||||||
|
@ -275,7 +275,7 @@ func (db *LevelDb) FetchTxByShaList(txShaList []*btcwire.ShaHash) []*btcdb.TxLis
|
||||||
stx := sTxList[idx]
|
stx := sTxList[idx]
|
||||||
|
|
||||||
tx, blockSha, _, _, err = db.fetchTxDataByLoc(
|
tx, blockSha, _, _, err = db.fetchTxDataByLoc(
|
||||||
stx.blkHeight, stx.txoff, stx.txlen, []byte{})
|
stx.blkHeight, stx.txoff, stx.txlen, []byte{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
btxspent = make([]bool, len(tx.TxOut))
|
btxspent = make([]bool, len(tx.TxOut))
|
||||||
for i := range btxspent {
|
for i := range btxspent {
|
||||||
|
@ -384,13 +384,12 @@ func (db *LevelDb) FetchTxBySha(txsha *btcwire.ShaHash) ([]*btcdb.TxListReply, e
|
||||||
replylen += len(sTxList)
|
replylen += len(sTxList)
|
||||||
}
|
}
|
||||||
|
|
||||||
replies := make ([]*btcdb.TxListReply, replylen)
|
replies := make([]*btcdb.TxListReply, replylen)
|
||||||
|
|
||||||
|
|
||||||
if fSerr == nil {
|
if fSerr == nil {
|
||||||
for _, stx := range sTxList {
|
for _, stx := range sTxList {
|
||||||
tx, blksha, _, _, err := db.fetchTxDataByLoc(
|
tx, blksha, _, _, err := db.fetchTxDataByLoc(
|
||||||
stx.blkHeight, stx.txoff, stx.txlen, []byte{})
|
stx.blkHeight, stx.txoff, stx.txlen, []byte{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != leveldb.ErrNotFound {
|
if err != leveldb.ErrNotFound {
|
||||||
return []*btcdb.TxListReply{}, err
|
return []*btcdb.TxListReply{}, err
|
||||||
|
@ -419,4 +418,3 @@ func (db *LevelDb) FetchTxBySha(txsha *btcwire.ShaHash) ([]*btcdb.TxListReply, e
|
||||||
}
|
}
|
||||||
return replies, nil
|
return replies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue