From 6eaf4908fb15f3f4727d63af0f37a040ff9099ae Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 22 May 2016 22:04:05 -0700 Subject: [PATCH] uspv: update to new upstream btcd api to fix compile errors --- shell.go | 2 +- uspv/hardmode.go | 2 +- uspv/msghandler.go | 2 +- uspv/sortsignsend.go | 11 ++++++----- uspv/txstore.go | 7 ++++--- uspv/utxodb.go | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/shell.go b/shell.go index b42d5d012..ebf8cea25 100644 --- a/shell.go +++ b/shell.go @@ -30,7 +30,7 @@ const ( ) var ( - Params = &chaincfg.SegNetParams + Params = &chaincfg.SegNet4Params SCon uspv.SPVCon // global here for now ) diff --git a/uspv/hardmode.go b/uspv/hardmode.go index 8f6d2465e..12ddab5de 100644 --- a/uspv/hardmode.go +++ b/uspv/hardmode.go @@ -26,7 +26,7 @@ func BlockOK(blk wire.MsgBlock) bool { for _, tx := range blk.Transactions { // make slice of (w)/txids txid := tx.TxSha() - wtxid := tx.WTxSha() + wtxid := tx.WitnessHash() if !witMode && !txid.IsEqual(&wtxid) { witMode = true } diff --git a/uspv/msghandler.go b/uspv/msghandler.go index 922612765..fc6f92caf 100644 --- a/uspv/msghandler.go +++ b/uspv/msghandler.go @@ -203,7 +203,7 @@ func (s *SPVCon) GetDataHandler(m *wire.MsgGetData) { log.Printf("error getting tx %s: %s", thing.Hash.String(), err.Error()) } - tx.Flags = 0x00 // dewitnessify + //tx.Flags = 0x00 // dewitnessify s.outMsgQueue <- tx sent++ continue diff --git a/uspv/sortsignsend.go b/uspv/sortsignsend.go index be208a52f..9e324b5dd 100644 --- a/uspv/sortsignsend.go +++ b/uspv/sortsignsend.go @@ -6,6 +6,7 @@ import ( "log" "sort" + "github.com/roasbeef/btcd/blockchain" "github.com/roasbeef/btcd/txscript" "github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcutil" @@ -124,7 +125,7 @@ func (s *SPVCon) SendOne(u Utxo, adr btcutil.Address) error { var prevPKs []byte if u.IsWit { - tx.Flags = 0x01 + //tx.Flags = 0x01 wa, err := btcutil.NewAddressWitnessPubKeyHash( s.TS.Adrs[u.KeyIdx].PkhAdr.ScriptAddress(), s.TS.Param) prevPKs, err = txscript.PayToAddrScript(wa) @@ -143,7 +144,7 @@ func (s *SPVCon) SendOne(u Utxo, adr btcutil.Address) error { var sig []byte var wit [][]byte - hCache := txscript.CalcHashCache(tx, 0, txscript.SigHashAll) + hCache := txscript.NewTxSigHashes(tx) child, err := s.TS.rootPrivKey.Child(u.KeyIdx + hdkeychain.HardenedKeyStart) @@ -251,7 +252,7 @@ func (s *SPVCon) SendCoins(adrs []btcutil.Address, sendAmts []int64) error { // these are all zeroed out during signing but it's an easy way to keep track var prevPKs []byte if utxo.IsWit { - tx.Flags = 0x01 + //tx.Flags = 0x01 wa, err := btcutil.NewAddressWitnessPubKeyHash( s.TS.Adrs[utxo.KeyIdx].PkhAdr.ScriptAddress(), s.TS.Param) prevPKs, err = txscript.PayToAddrScript(wa) @@ -315,7 +316,7 @@ func (s *SPVCon) SendCoins(adrs []btcutil.Address, sendAmts []int64) error { // generate tx-wide hashCache for segwit stuff // middle index number doesn't matter for sighashAll. - hCache := txscript.CalcHashCache(tx, 0, txscript.SigHashAll) + hCache := txscript.NewTxSigHashes(tx) for i, txin := range tx.TxIn { // pick key @@ -408,7 +409,7 @@ func EstFee(otx *wire.MsgTx, spB int64) int64 { } } fmt.Printf(TxToString(tx)) - size := int64(tx.VirtualSize()) + size := int64(blockchain.GetTxVirtualSize(btcutil.NewTx(tx))) fmt.Printf("%d spB, est vsize %d, fee %d\n", spB, size, size*spB) return size * spB } diff --git a/uspv/txstore.go b/uspv/txstore.go index 0fa9dce00..239db0ca3 100644 --- a/uspv/txstore.go +++ b/uspv/txstore.go @@ -7,6 +7,7 @@ import ( "log" "sync" + "github.com/roasbeef/btcd/blockchain" "github.com/roasbeef/btcd/chaincfg" "github.com/boltdb/bolt" @@ -139,9 +140,9 @@ func CheckDoubleSpends( // TxToString prints out some info about a transaction. for testing / debugging func TxToString(tx *wire.MsgTx) string { - str := fmt.Sprintf("size %d vsize %d wsize %d locktime %d flag %x txid %s\n", - tx.SerializeSize(), tx.VirtualSize(), tx.SerializeSizeWitness(), - tx.LockTime, tx.Flags, tx.TxSha().String()) + str := fmt.Sprintf("size %d vsize %d wsize %d locktime %d txid %s\n", + tx.SerializeSize(), blockchain.GetTxVirtualSize(btcutil.NewTx(tx)), + tx.SerializeSize(), tx.LockTime, tx.TxSha().String()) for i, in := range tx.TxIn { str += fmt.Sprintf("Input %d spends %s\n", i, in.PreviousOutPoint.String()) str += fmt.Sprintf("\tSigScript: %x\n", in.SignatureScript) diff --git a/uspv/utxodb.go b/uspv/utxodb.go index d9a037f38..4d20635c7 100644 --- a/uspv/utxodb.go +++ b/uspv/utxodb.go @@ -486,7 +486,7 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx, height int32) (uint32, error) { // if hits is nonzero it's a relevant tx and we should store it var buf bytes.Buffer - tx.SerializeWitness(&buf) // always store witness version + tx.Serialize(&buf) err = txns.Put(cachedSha.Bytes(), buf.Bytes()) if err != nil { return err