mirror of
https://github.com/btcsuite/btcd.git
synced 2025-03-10 17:26:07 +01:00
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
|
// Insert the main network genesis block. This is part of the initial
|
||||||
// database setup. Like above, this typically would not be needed when
|
// database setup. Like above, this typically would not be needed when
|
||||||
// opening an existing database.
|
// opening an existing database.
|
||||||
pver := btcwire.ProtocolVersion
|
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||||
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock, pver)
|
|
||||||
_, err = db.InsertBlock(genesisBlock)
|
_, err = db.InsertBlock(genesisBlock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to insert genesis block: %v\n", err)
|
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
|
// Insert the main network genesis block. This is part of the initial
|
||||||
// database setup. Like above, this typically would not be needed when
|
// database setup. Like above, this typically would not be needed when
|
||||||
// opening an existing database.
|
// opening an existing database.
|
||||||
pver := btcwire.ProtocolVersion
|
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock)
|
||||||
genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock, pver)
|
|
||||||
_, err = db.InsertBlock(genesisBlock)
|
_, err = db.InsertBlock(genesisBlock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to insert genesis block: %v\n", err)
|
fmt.Printf("Failed to insert genesis block: %v\n", err)
|
||||||
|
|
|
@ -7,13 +7,12 @@ package btcchain_test
|
||||||
import (
|
import (
|
||||||
"github.com/conformal/btcchain"
|
"github.com/conformal/btcchain"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwire"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestMerkle tests the BuildMerkleTreeStore API.
|
// TestMerkle tests the BuildMerkleTreeStore API.
|
||||||
func TestMerkle(t *testing.T) {
|
func TestMerkle(t *testing.T) {
|
||||||
block := btcutil.NewBlock(&Block100000, btcwire.ProtocolVersion)
|
block := btcutil.NewBlock(&Block100000)
|
||||||
merkles := btcchain.BuildMerkleTreeStore(block)
|
merkles := btcchain.BuildMerkleTreeStore(block)
|
||||||
calculatedMerkleRoot := merkles[len(merkles)-1]
|
calculatedMerkleRoot := merkles[len(merkles)-1]
|
||||||
wantMerkle := &Block100000.Header.MerkleRoot
|
wantMerkle := &Block100000.Header.MerkleRoot
|
||||||
|
|
|
@ -122,7 +122,7 @@ func loadBlocks(filename string) (blocks []*btcutil.Block, err error) {
|
||||||
// read block
|
// read block
|
||||||
dr.Read(rbytes)
|
dr.Read(rbytes)
|
||||||
|
|
||||||
block, err = btcutil.NewBlockFromBytes(rbytes, btcwire.ProtocolVersion)
|
block, err = btcutil.NewBlockFromBytes(rbytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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
|
// validateTxIn validates a the script pair for the passed spending transaction
|
||||||
// (along with the specific input index) and origin transaction (with the
|
// (along with the specific input index) and origin transaction (with the
|
||||||
// specific output index).
|
// 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
|
// If the input transaction has no previous input, there is nothing
|
||||||
// to check.
|
// to check.
|
||||||
originTxIdx := txin.PreviousOutpoint.Index
|
originTxIdx := txin.PreviousOutpoint.Index
|
||||||
|
@ -46,7 +46,7 @@ func validateTxIn(txInIdx int, txin *btcwire.TxIn, txSha *btcwire.ShaHash, tx *b
|
||||||
sigScript := txin.SignatureScript
|
sigScript := txin.SignatureScript
|
||||||
pkScript := originTx.TxOut[originTxIdx].PkScript
|
pkScript := originTx.TxOut[originTxIdx].PkScript
|
||||||
engine, err := btcscript.NewScript(sigScript, pkScript, txInIdx, tx,
|
engine, err := btcscript.NewScript(sigScript, pkScript, txInIdx, tx,
|
||||||
pver, timestamp.After(btcscript.Bip16Activation))
|
timestamp.After(btcscript.Bip16Activation))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// validateAllTxIn validates the scripts for all of the passed transaction
|
||||||
// inputs using multiple goroutines.
|
// 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)
|
c := make(chan txValidate)
|
||||||
resultErrors := make([]error, len(job))
|
resultErrors := make([]error, len(job))
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ func validateAllTxIn(txsha *btcwire.ShaHash, txValidator *btcwire.MsgTx, pver ui
|
||||||
originTx = txInfo.tx
|
originTx = txInfo.tx
|
||||||
}
|
}
|
||||||
err := validateTxIn(txInIdx, job[txInIdx], txsha, txValidator,
|
err := validateTxIn(txInIdx, job[txInIdx], txsha, txValidator,
|
||||||
pver, timestamp, originTx)
|
timestamp, originTx)
|
||||||
r := txValidate{txInIdx, err}
|
r := txValidate{txInIdx, err}
|
||||||
c <- r
|
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
|
// checkBlockScripts executes and validates the scripts for all transactions in
|
||||||
// the passed block.
|
// the passed block.
|
||||||
func checkBlockScripts(block *btcutil.Block, txStore map[btcwire.ShaHash]*txData) error {
|
func checkBlockScripts(block *btcutil.Block, txStore map[btcwire.ShaHash]*txData) error {
|
||||||
pver := block.ProtocolVersion()
|
|
||||||
timestamp := block.MsgBlock().Header.Timestamp
|
timestamp := block.MsgBlock().Header.Timestamp
|
||||||
for i, tx := range block.MsgBlock().Transactions {
|
for i, tx := range block.MsgBlock().Transactions {
|
||||||
txHash, _ := block.TxSha(i)
|
txHash, _ := block.TxSha(i)
|
||||||
err := validateAllTxIn(txHash, tx, pver, timestamp, tx.TxIn, txStore)
|
err := validateAllTxIn(txHash, tx, timestamp, tx.TxIn, txStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
txNeededStore, err := b.fetchTxList(node, txNeededList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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.
|
// TODO(davec): Need to pass the cached version in.
|
||||||
txHash, err := msgTx.TxSha(btcwire.ProtocolVersion)
|
txHash, err := msgTx.TxSha()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
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.
|
// TODO(davec): Need to pass the cached version in.
|
||||||
txHash, err := tx.TxSha(btcwire.ProtocolVersion)
|
txHash, err := tx.TxSha()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ func TestCheckBlockSanity(t *testing.T) {
|
||||||
// the main bitcoin network and ignore notifications.
|
// the main bitcoin network and ignore notifications.
|
||||||
chain := btcchain.New(db, btcwire.MainNet, nil)
|
chain := btcchain.New(db, btcwire.MainNet, nil)
|
||||||
|
|
||||||
block := btcutil.NewBlock(&Block100000, btcwire.ProtocolVersion)
|
block := btcutil.NewBlock(&Block100000)
|
||||||
err = chain.TstCheckBlockSanity(block)
|
err = chain.TstCheckBlockSanity(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("CheckBlockSanity: %v", err)
|
t.Errorf("CheckBlockSanity: %v", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue