Update for latest btcutil and btcwire changes.
This commit updates the calls into btcutil and btcwire for the latest API changes which remove the need for the protocol version for serialization and deserialization of blocks and transactions.
This commit is contained in:
parent
3b743e4cfc
commit
8062889d04
6 changed files with 16 additions and 27 deletions
|
@ -31,8 +31,7 @@ change.
|
|||
|
||||
|
||||
// Insert the main network genesis block.
|
||||
pver := btcwire.ProtocolVersion
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock, pver)
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
newHeight, err := db.InsertBlock(genesis)
|
||||
if err != nil {
|
||||
// Log and handle the error
|
||||
|
|
3
doc.go
3
doc.go
|
@ -49,8 +49,7 @@ referenced parent block to already exist. In a more concrete example:
|
|||
|
||||
|
||||
// Insert the main network genesis block.
|
||||
pver := btcwire.ProtocolVersion
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock, pver)
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
newHeight, err := db.InsertBlock(genesis)
|
||||
if err != nil {
|
||||
// Log and handle the error
|
||||
|
|
|
@ -101,7 +101,7 @@ endtest:
|
|||
}
|
||||
|
||||
}
|
||||
txshaname, _ := tx.TxSha(block.ProtocolVersion())
|
||||
txshaname, _ := tx.TxSha()
|
||||
txlookupList = append(txlookupList, &txshaname)
|
||||
txOutList = append(txOutList, &txshaname)
|
||||
}
|
||||
|
|
|
@ -281,7 +281,7 @@ func testBackout(t *testing.T, mode int) {
|
|||
|
||||
block := blocks[110]
|
||||
mblock := block.MsgBlock()
|
||||
txsha, err := mblock.Transactions[0].TxSha(block.ProtocolVersion())
|
||||
txsha, err := mblock.Transactions[0].TxSha()
|
||||
exists := db.ExistsTxSha(&txsha)
|
||||
if exists {
|
||||
t.Errorf("tx %v exists in db, failure expected", txsha)
|
||||
|
@ -292,7 +292,7 @@ func testBackout(t *testing.T, mode int) {
|
|||
|
||||
block = blocks[99]
|
||||
mblock = block.MsgBlock()
|
||||
txsha, err = mblock.Transactions[0].TxSha(block.ProtocolVersion())
|
||||
txsha, err = mblock.Transactions[0].TxSha()
|
||||
oldused, err := db.FetchTxUsedBySha(&txsha)
|
||||
err = db.InsertTx(&txsha, 99, 1024, 1048, oldused)
|
||||
if err == nil {
|
||||
|
@ -324,7 +324,7 @@ func loadBlocks(t *testing.T, file string) (blocks []*btcutil.Block, err error)
|
|||
}()
|
||||
|
||||
// Set the first block as the genesis block.
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock, btcwire.ProtocolVersion)
|
||||
genesis := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
blocks = append(blocks, genesis)
|
||||
|
||||
var block *btcutil.Block
|
||||
|
@ -355,14 +355,7 @@ func loadBlocks(t *testing.T, file string) (blocks []*btcutil.Block, err error)
|
|||
// read block
|
||||
dr.Read(rbytes)
|
||||
|
||||
var pver uint32
|
||||
switch {
|
||||
case height < 200000:
|
||||
pver = 1
|
||||
case height >= 200000:
|
||||
pver = 2
|
||||
}
|
||||
block, err = btcutil.NewBlockFromBytes(rbytes, pver)
|
||||
block, err = btcutil.NewBlockFromBytes(rbytes)
|
||||
if err != nil {
|
||||
t.Errorf("failed to parse block %v", height)
|
||||
return
|
||||
|
|
|
@ -550,14 +550,12 @@ func (db *SqliteDb) DropAfterBlockBySha(sha *btcwire.ShaHash) (err error) {
|
|||
}
|
||||
|
||||
var buf []byte
|
||||
var pver uint32
|
||||
|
||||
buf, pver, _, err = db.fetchSha(*sha)
|
||||
buf, _, _, err = db.fetchSha(*sha)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
blk, err = btcutil.NewBlockFromBytes(buf, pver)
|
||||
blk, err = btcutil.NewBlockFromBytes(buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -624,7 +622,7 @@ func (db *SqliteDb) InsertBlock(block *btcutil.Block) (int64, error) {
|
|||
}
|
||||
|
||||
mblock := block.MsgBlock()
|
||||
rawMsg, pver, err := block.Bytes()
|
||||
rawMsg, err := block.Bytes()
|
||||
if err != nil {
|
||||
log.Warnf("Failed to obtain raw block sha %v", blocksha)
|
||||
return -1, err
|
||||
|
@ -637,7 +635,7 @@ func (db *SqliteDb) InsertBlock(block *btcutil.Block) (int64, error) {
|
|||
|
||||
// Insert block into database
|
||||
newheight, err := db.insertBlockData(blocksha, &mblock.Header.PrevBlock,
|
||||
pver, rawMsg)
|
||||
0, rawMsg)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to insert block %v %v %v", blocksha,
|
||||
&mblock.Header.PrevBlock, err)
|
||||
|
@ -672,7 +670,7 @@ func (db *SqliteDb) InsertBlock(block *btcutil.Block) (int64, error) {
|
|||
// detect this condition and 'accept' the block.
|
||||
for txidx, tx := range mblock.Transactions {
|
||||
var txsha btcwire.ShaHash
|
||||
txsha, err = tx.TxSha(pver)
|
||||
txsha, err = tx.TxSha()
|
||||
if err != nil {
|
||||
log.Warnf("failed to compute tx name block %v idx %v err %v", blocksha, txidx, err)
|
||||
return -1, err
|
||||
|
|
|
@ -62,12 +62,12 @@ func (db *SqliteDb) fetchBlockBySha(sha *btcwire.ShaHash) (blk *btcutil.Block, e
|
|||
return blkcache.blk, nil
|
||||
}
|
||||
|
||||
buf, pver, height, err := db.fetchSha(*sha)
|
||||
buf, _, height, err := db.fetchSha(*sha)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blk, err = btcutil.NewBlockFromBytes(buf, pver)
|
||||
blk, err = btcutil.NewBlockFromBytes(buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ func (db *SqliteDb) fetchTxDataBySha(txsha *btcwire.ShaHash) (rtx *btcwire.MsgTx
|
|||
return
|
||||
}
|
||||
|
||||
blkbuf, pver, err = blk.Bytes()
|
||||
blkbuf, err = blk.Bytes()
|
||||
if err != nil {
|
||||
log.Warnf("unable to decode block %v %v", height, &blksha)
|
||||
return
|
||||
|
@ -264,7 +264,7 @@ func (db *SqliteDb) FetchTxAllBySha(txsha *btcwire.ShaHash) (rtx *btcwire.MsgTx,
|
|||
return
|
||||
}
|
||||
|
||||
blkbuf, pver, err = blk.Bytes()
|
||||
blkbuf, err = blk.Bytes()
|
||||
if err != nil {
|
||||
log.Warnf("unable to decode block %v %v", height, &blksha)
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue