Skip to content

Commit

Permalink
uspv: update to new upstream btcd api to fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed May 23, 2016
1 parent 566bf47 commit 6eaf490
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion shell.go
Expand Up @@ -30,7 +30,7 @@ const (
)

var (
Params = &chaincfg.SegNetParams
Params = &chaincfg.SegNet4Params
SCon uspv.SPVCon // global here for now
)

Expand Down
2 changes: 1 addition & 1 deletion uspv/hardmode.go
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion uspv/msghandler.go
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions uspv/sortsignsend.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions uspv/txstore.go
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"sync"

"github.com/roasbeef/btcd/blockchain"
"github.com/roasbeef/btcd/chaincfg"

"github.com/boltdb/bolt"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion uspv/utxodb.go
Expand Up @@ -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
Expand Down

0 comments on commit 6eaf490

Please sign in to comment.