Update for latest btcutil, btcscript, and btcwire.
This commit updates the calls into btcutil, btcscript, 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
c00de3ffd5
commit
10a62a37a3
8 changed files with 14 additions and 18 deletions
|
@ -105,8 +105,7 @@ intentionally causes an error by attempting to process a duplicate block.
|
|||
// Insert the main network genesis block. This is part of the initial
|
||||
// database setup. Like above, this typically would not be needed when
|
||||
// opening an existing database.
|
||||
pver := btcwire.ProtocolVersion
|
||||
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock, pver)
|
||||
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
_, err = db.InsertBlock(genesisBlock)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to insert genesis block: %v\n", err)
|
||||
|
|
3
doc.go
3
doc.go
|
@ -98,8 +98,7 @@ intentionally causes an error by attempting to process a duplicate block.
|
|||
// Insert the main network genesis block. This is part of the initial
|
||||
// database setup. Like above, this typically would not be needed when
|
||||
// opening an existing database.
|
||||
pver := btcwire.ProtocolVersion
|
||||
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock, pver)
|
||||
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||
_, err = db.InsertBlock(genesisBlock)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to insert genesis block: %v\n", err)
|
||||
|
|
|
@ -7,13 +7,12 @@ package btcchain_test
|
|||
import (
|
||||
"github.com/conformal/btcchain"
|
||||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMerkle tests the BuildMerkleTreeStore API.
|
||||
func TestMerkle(t *testing.T) {
|
||||
block := btcutil.NewBlock(&Block100000, btcwire.ProtocolVersion)
|
||||
block := btcutil.NewBlock(&Block100000)
|
||||
merkles := btcchain.BuildMerkleTreeStore(block)
|
||||
calculatedMerkleRoot := merkles[len(merkles)-1]
|
||||
wantMerkle := &Block100000.Header.MerkleRoot
|
||||
|
|
|
@ -122,7 +122,7 @@ func loadBlocks(filename string) (blocks []*btcutil.Block, err error) {
|
|||
// read block
|
||||
dr.Read(rbytes)
|
||||
|
||||
block, err = btcutil.NewBlockFromBytes(rbytes, btcwire.ProtocolVersion)
|
||||
block, err = btcutil.NewBlockFromBytes(rbytes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
11
scriptval.go
11
scriptval.go
|
@ -29,7 +29,7 @@ type txProcessList struct {
|
|||
// validateTxIn validates a the script pair for the passed spending transaction
|
||||
// (along with the specific input index) and origin transaction (with the
|
||||
// specific output index).
|
||||
func validateTxIn(txInIdx int, txin *btcwire.TxIn, txSha *btcwire.ShaHash, tx *btcwire.MsgTx, pver uint32, timestamp time.Time, originTx *btcwire.MsgTx) error {
|
||||
func validateTxIn(txInIdx int, txin *btcwire.TxIn, txSha *btcwire.ShaHash, tx *btcwire.MsgTx, timestamp time.Time, originTx *btcwire.MsgTx) error {
|
||||
// If the input transaction has no previous input, there is nothing
|
||||
// to check.
|
||||
originTxIdx := txin.PreviousOutpoint.Index
|
||||
|
@ -46,7 +46,7 @@ func validateTxIn(txInIdx int, txin *btcwire.TxIn, txSha *btcwire.ShaHash, tx *b
|
|||
sigScript := txin.SignatureScript
|
||||
pkScript := originTx.TxOut[originTxIdx].PkScript
|
||||
engine, err := btcscript.NewScript(sigScript, pkScript, txInIdx, tx,
|
||||
pver, timestamp.After(btcscript.Bip16Activation))
|
||||
timestamp.After(btcscript.Bip16Activation))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func validateTxIn(txInIdx int, txin *btcwire.TxIn, txSha *btcwire.ShaHash, tx *b
|
|||
|
||||
// validateAllTxIn validates the scripts for all of the passed transaction
|
||||
// inputs using multiple goroutines.
|
||||
func validateAllTxIn(txsha *btcwire.ShaHash, txValidator *btcwire.MsgTx, pver uint32, timestamp time.Time, job []*btcwire.TxIn, txStore map[btcwire.ShaHash]*txData) (err error) {
|
||||
func validateAllTxIn(txsha *btcwire.ShaHash, txValidator *btcwire.MsgTx, timestamp time.Time, job []*btcwire.TxIn, txStore map[btcwire.ShaHash]*txData) (err error) {
|
||||
c := make(chan txValidate)
|
||||
resultErrors := make([]error, len(job))
|
||||
|
||||
|
@ -87,7 +87,7 @@ func validateAllTxIn(txsha *btcwire.ShaHash, txValidator *btcwire.MsgTx, pver ui
|
|||
originTx = txInfo.tx
|
||||
}
|
||||
err := validateTxIn(txInIdx, job[txInIdx], txsha, txValidator,
|
||||
pver, timestamp, originTx)
|
||||
timestamp, originTx)
|
||||
r := txValidate{txInIdx, err}
|
||||
c <- r
|
||||
}
|
||||
|
@ -122,11 +122,10 @@ func validateAllTxIn(txsha *btcwire.ShaHash, txValidator *btcwire.MsgTx, pver ui
|
|||
// checkBlockScripts executes and validates the scripts for all transactions in
|
||||
// the passed block.
|
||||
func checkBlockScripts(block *btcutil.Block, txStore map[btcwire.ShaHash]*txData) error {
|
||||
pver := block.ProtocolVersion()
|
||||
timestamp := block.MsgBlock().Header.Timestamp
|
||||
for i, tx := range block.MsgBlock().Transactions {
|
||||
txHash, _ := block.TxSha(i)
|
||||
err := validateAllTxIn(txHash, tx, pver, timestamp, tx.TxIn, txStore)
|
||||
err := validateAllTxIn(txHash, tx, timestamp, tx.TxIn, txStore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ type txData struct {
|
|||
}
|
||||
|
||||
// connectTransactions updates the passed map by applying transaction and
|
||||
// spend information for all the transactions in the passed block. Only
|
||||
// spend information for all the transactions in the passed block. Only
|
||||
// transactions in the passed map are updated.
|
||||
func connectTransactions(txStore map[btcwire.ShaHash]*txData, block *btcutil.Block) error {
|
||||
// Loop through all of the transactions in the block to see if any of
|
||||
|
@ -243,7 +243,7 @@ func (b *BlockChain) fetchInputTransactions(node *blockNode, block *btcutil.Bloc
|
|||
}
|
||||
}
|
||||
|
||||
// Request the input transaction from the point of view of the node.
|
||||
// Request the input transactions from the point of view of the node.
|
||||
txNeededStore, err := b.fetchTxList(node, txNeededList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -334,7 +334,7 @@ func countP2SHSigOps(msgTx *btcwire.MsgTx, isCoinBaseTx bool, txStore map[btcwir
|
|||
}
|
||||
|
||||
// TODO(davec): Need to pass the cached version in.
|
||||
txHash, err := msgTx.TxSha(btcwire.ProtocolVersion)
|
||||
txHash, err := msgTx.TxSha()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -593,7 +593,7 @@ func checkTransactionInputs(tx *btcwire.MsgTx, txHeight int64, txStore map[btcwi
|
|||
}
|
||||
|
||||
// TODO(davec): Need to pass the cached version in.
|
||||
txHash, err := tx.TxSha(btcwire.ProtocolVersion)
|
||||
txHash, err := tx.TxSha()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ func TestCheckBlockSanity(t *testing.T) {
|
|||
// the main bitcoin network and ignore notifications.
|
||||
chain := btcchain.New(db, btcwire.MainNet, nil)
|
||||
|
||||
block := btcutil.NewBlock(&Block100000, btcwire.ProtocolVersion)
|
||||
block := btcutil.NewBlock(&Block100000)
|
||||
err = chain.TstCheckBlockSanity(block)
|
||||
if err != nil {
|
||||
t.Errorf("CheckBlockSanity: %v", err)
|
||||
|
|
Loading…
Reference in a new issue