mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-23 17:47:29 +00:00
Update btcwire path import paths to new location.
This commit is contained in:
parent
1b7cd45029
commit
23c9dc423e
19 changed files with 191 additions and 191 deletions
|
@ -21,12 +21,12 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcrpcclient"
|
"github.com/btcsuite/btcrpcclient"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/keystore"
|
"github.com/btcsuite/btcwallet/keystore"
|
||||||
"github.com/btcsuite/btcwallet/txstore"
|
"github.com/btcsuite/btcwallet/txstore"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
"github.com/btcsuite/btcws"
|
"github.com/btcsuite/btcws"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -162,12 +162,12 @@ type (
|
||||||
Block *txstore.Block // nil if unmined
|
Block *txstore.Block // nil if unmined
|
||||||
}
|
}
|
||||||
RescanProgress struct {
|
RescanProgress struct {
|
||||||
Hash *btcwire.ShaHash
|
Hash *wire.ShaHash
|
||||||
Height int32
|
Height int32
|
||||||
Time time.Time
|
Time time.Time
|
||||||
}
|
}
|
||||||
RescanFinished struct {
|
RescanFinished struct {
|
||||||
Hash *btcwire.ShaHash
|
Hash *wire.ShaHash
|
||||||
Height int32
|
Height int32
|
||||||
Time time.Time
|
Time time.Time
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ func parseBlock(block *btcws.BlockDetails) (blk *txstore.Block, idx int, err err
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil, btcutil.TxIndexUnknown, nil
|
return nil, btcutil.TxIndexUnknown, nil
|
||||||
}
|
}
|
||||||
blksha, err := btcwire.NewShaHashFromStr(block.Hash)
|
blksha, err := wire.NewShaHashFromStr(block.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, btcutil.TxIndexUnknown, err
|
return nil, btcutil.TxIndexUnknown, err
|
||||||
}
|
}
|
||||||
|
@ -197,11 +197,11 @@ func (c *Client) onClientConnect() {
|
||||||
c.notifyConnected(true)
|
c.notifyConnected(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) onBlockConnected(hash *btcwire.ShaHash, height int32) {
|
func (c *Client) onBlockConnected(hash *wire.ShaHash, height int32) {
|
||||||
c.enqueueNotification <- BlockConnected{Hash: hash, Height: height}
|
c.enqueueNotification <- BlockConnected{Hash: hash, Height: height}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) onBlockDisconnected(hash *btcwire.ShaHash, height int32) {
|
func (c *Client) onBlockDisconnected(hash *wire.ShaHash, height int32) {
|
||||||
c.enqueueNotification <- BlockDisconnected{Hash: hash, Height: height}
|
c.enqueueNotification <- BlockDisconnected{Hash: hash, Height: height}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,11 +237,11 @@ func (c *Client) onRedeemingTx(tx *btcutil.Tx, block *btcws.BlockDetails) {
|
||||||
c.enqueueNotification <- RedeemingTx{tx, blk}
|
c.enqueueNotification <- RedeemingTx{tx, blk}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) onRescanProgress(hash *btcwire.ShaHash, height int32, blkTime time.Time) {
|
func (c *Client) onRescanProgress(hash *wire.ShaHash, height int32, blkTime time.Time) {
|
||||||
c.enqueueNotification <- &RescanProgress{hash, height, blkTime}
|
c.enqueueNotification <- &RescanProgress{hash, height, blkTime}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) onRescanFinished(hash *btcwire.ShaHash, height int32, blkTime time.Time) {
|
func (c *Client) onRescanFinished(hash *wire.ShaHash, height int32, blkTime time.Time) {
|
||||||
c.enqueueNotification <- &RescanFinished{hash, height, blkTime}
|
c.enqueueNotification <- &RescanFinished{hash, height, blkTime}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,15 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
flags "github.com/btcsuite/go-flags"
|
flags "github.com/btcsuite/go-flags"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultCAFilename = "btcd.cert"
|
defaultCAFilename = "btcd.cert"
|
||||||
defaultConfigFilename = "btcwallet.conf"
|
defaultConfigFilename = "btcwallet.conf"
|
||||||
defaultBtcNet = btcwire.TestNet3
|
defaultBtcNet = wire.TestNet3
|
||||||
defaultLogLevel = "info"
|
defaultLogLevel = "info"
|
||||||
defaultLogDirname = "logs"
|
defaultLogDirname = "logs"
|
||||||
defaultLogFilename = "btcwallet.log"
|
defaultLogFilename = "btcwallet.log"
|
||||||
|
|
24
createtx.go
24
createtx.go
|
@ -25,10 +25,10 @@ import (
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/blockchain"
|
"github.com/btcsuite/btcd/blockchain"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/keystore"
|
"github.com/btcsuite/btcwallet/keystore"
|
||||||
"github.com/btcsuite/btcwallet/txstore"
|
"github.com/btcsuite/btcwallet/txstore"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -163,7 +163,7 @@ func createTx(
|
||||||
changeAddress func(*keystore.BlockStamp) (btcutil.Address, error)) (
|
changeAddress func(*keystore.BlockStamp) (btcutil.Address, error)) (
|
||||||
*CreatedTx, error) {
|
*CreatedTx, error) {
|
||||||
|
|
||||||
msgtx := btcwire.NewMsgTx()
|
msgtx := wire.NewMsgTx()
|
||||||
minAmount, err := addOutputs(msgtx, outputs)
|
minAmount, err := addOutputs(msgtx, outputs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -184,7 +184,7 @@ func createTx(
|
||||||
}
|
}
|
||||||
input, eligible = eligible[0], eligible[1:]
|
input, eligible = eligible[0], eligible[1:]
|
||||||
inputs = append(inputs, input)
|
inputs = append(inputs, input)
|
||||||
msgtx.AddTxIn(btcwire.NewTxIn(input.OutPoint(), nil))
|
msgtx.AddTxIn(wire.NewTxIn(input.OutPoint(), nil))
|
||||||
totalAdded += input.Amount()
|
totalAdded += input.Amount()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ func createTx(
|
||||||
}
|
}
|
||||||
input, eligible = eligible[0], eligible[1:]
|
input, eligible = eligible[0], eligible[1:]
|
||||||
inputs = append(inputs, input)
|
inputs = append(inputs, input)
|
||||||
msgtx.AddTxIn(btcwire.NewTxIn(input.OutPoint(), nil))
|
msgtx.AddTxIn(wire.NewTxIn(input.OutPoint(), nil))
|
||||||
szEst += txInEstimate
|
szEst += txInEstimate
|
||||||
totalAdded += input.Amount()
|
totalAdded += input.Amount()
|
||||||
feeEst = minimumFee(feeIncrement, szEst, msgtx.TxOut, inputs, bs.Height)
|
feeEst = minimumFee(feeIncrement, szEst, msgtx.TxOut, inputs, bs.Height)
|
||||||
|
@ -253,7 +253,7 @@ func createTx(
|
||||||
}
|
}
|
||||||
input, eligible = eligible[0], eligible[1:]
|
input, eligible = eligible[0], eligible[1:]
|
||||||
inputs = append(inputs, input)
|
inputs = append(inputs, input)
|
||||||
msgtx.AddTxIn(btcwire.NewTxIn(input.OutPoint(), nil))
|
msgtx.AddTxIn(wire.NewTxIn(input.OutPoint(), nil))
|
||||||
szEst += txInEstimate
|
szEst += txInEstimate
|
||||||
totalAdded += input.Amount()
|
totalAdded += input.Amount()
|
||||||
feeEst = minimumFee(feeIncrement, szEst, msgtx.TxOut, inputs, bs.Height)
|
feeEst = minimumFee(feeIncrement, szEst, msgtx.TxOut, inputs, bs.Height)
|
||||||
|
@ -274,12 +274,12 @@ func createTx(
|
||||||
|
|
||||||
// addChange adds a new output with the given amount and address, and
|
// addChange adds a new output with the given amount and address, and
|
||||||
// randomizes the index (and returns it) of the newly added output.
|
// randomizes the index (and returns it) of the newly added output.
|
||||||
func addChange(msgtx *btcwire.MsgTx, change btcutil.Amount, changeAddr btcutil.Address) (int, error) {
|
func addChange(msgtx *wire.MsgTx, change btcutil.Amount, changeAddr btcutil.Address) (int, error) {
|
||||||
pkScript, err := txscript.PayToAddrScript(changeAddr)
|
pkScript, err := txscript.PayToAddrScript(changeAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("cannot create txout script: %s", err)
|
return 0, fmt.Errorf("cannot create txout script: %s", err)
|
||||||
}
|
}
|
||||||
msgtx.AddTxOut(btcwire.NewTxOut(int64(change), pkScript))
|
msgtx.AddTxOut(wire.NewTxOut(int64(change), pkScript))
|
||||||
|
|
||||||
// Randomize index of the change output.
|
// Randomize index of the change output.
|
||||||
rng := badrand.New(badrand.NewSource(time.Now().UnixNano()))
|
rng := badrand.New(badrand.NewSource(time.Now().UnixNano()))
|
||||||
|
@ -308,7 +308,7 @@ func (w *Wallet) changeAddress(bs *keystore.BlockStamp) (btcutil.Address, error)
|
||||||
|
|
||||||
// addOutputs adds the given address/amount pairs as outputs to msgtx,
|
// addOutputs adds the given address/amount pairs as outputs to msgtx,
|
||||||
// returning their total amount.
|
// returning their total amount.
|
||||||
func addOutputs(msgtx *btcwire.MsgTx, pairs map[string]btcutil.Amount) (btcutil.Amount, error) {
|
func addOutputs(msgtx *wire.MsgTx, pairs map[string]btcutil.Amount) (btcutil.Amount, error) {
|
||||||
var minAmount btcutil.Amount
|
var minAmount btcutil.Amount
|
||||||
for addrStr, amt := range pairs {
|
for addrStr, amt := range pairs {
|
||||||
if amt <= 0 {
|
if amt <= 0 {
|
||||||
|
@ -325,7 +325,7 @@ func addOutputs(msgtx *btcwire.MsgTx, pairs map[string]btcutil.Amount) (btcutil.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return minAmount, fmt.Errorf("cannot create txout script: %s", err)
|
return minAmount, fmt.Errorf("cannot create txout script: %s", err)
|
||||||
}
|
}
|
||||||
txout := btcwire.NewTxOut(int64(amt), pkScript)
|
txout := wire.NewTxOut(int64(amt), pkScript)
|
||||||
msgtx.AddTxOut(txout)
|
msgtx.AddTxOut(txout)
|
||||||
}
|
}
|
||||||
return minAmount, nil
|
return minAmount, nil
|
||||||
|
@ -370,7 +370,7 @@ func (w *Wallet) findEligibleOutputs(minconf int, bs *keystore.BlockStamp) ([]tx
|
||||||
// signMsgTx sets the SignatureScript for every item in msgtx.TxIn.
|
// signMsgTx sets the SignatureScript for every item in msgtx.TxIn.
|
||||||
// It must be called every time a msgtx is changed.
|
// It must be called every time a msgtx is changed.
|
||||||
// Only P2PKH outputs are supported at this point.
|
// Only P2PKH outputs are supported at this point.
|
||||||
func signMsgTx(msgtx *btcwire.MsgTx, prevOutputs []txstore.Credit, store *keystore.Store) error {
|
func signMsgTx(msgtx *wire.MsgTx, prevOutputs []txstore.Credit, store *keystore.Store) error {
|
||||||
if len(prevOutputs) != len(msgtx.TxIn) {
|
if len(prevOutputs) != len(msgtx.TxIn) {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Number of prevOutputs (%d) does not match number of tx inputs (%d)",
|
"Number of prevOutputs (%d) does not match number of tx inputs (%d)",
|
||||||
|
@ -410,7 +410,7 @@ func signMsgTx(msgtx *btcwire.MsgTx, prevOutputs []txstore.Credit, store *keysto
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateMsgTx(msgtx *btcwire.MsgTx, prevOutputs []txstore.Credit) error {
|
func validateMsgTx(msgtx *wire.MsgTx, prevOutputs []txstore.Credit) error {
|
||||||
flags := txscript.ScriptCanonicalSignatures | txscript.ScriptStrictMultiSig
|
flags := txscript.ScriptCanonicalSignatures | txscript.ScriptStrictMultiSig
|
||||||
bip16 := time.Now().After(txscript.Bip16Activation)
|
bip16 := time.Now().After(txscript.Bip16Activation)
|
||||||
if bip16 {
|
if bip16 {
|
||||||
|
@ -434,7 +434,7 @@ func validateMsgTx(msgtx *btcwire.MsgTx, prevOutputs []txstore.Credit) error {
|
||||||
// s less than 1 kilobyte and none of the outputs contain a value
|
// s less than 1 kilobyte and none of the outputs contain a value
|
||||||
// less than 1 bitcent. Otherwise, the fee will be calculated using
|
// less than 1 bitcent. Otherwise, the fee will be calculated using
|
||||||
// incr, incrementing the fee for each kilobyte of transaction.
|
// incr, incrementing the fee for each kilobyte of transaction.
|
||||||
func minimumFee(incr btcutil.Amount, txLen int, outputs []*btcwire.TxOut, prevOutputs []txstore.Credit, height int32) btcutil.Amount {
|
func minimumFee(incr btcutil.Amount, txLen int, outputs []*wire.TxOut, prevOutputs []txstore.Credit, height int32) btcutil.Amount {
|
||||||
allowFree := false
|
allowFree := false
|
||||||
if !cfg.DisallowFree {
|
if !cfg.DisallowFree {
|
||||||
allowFree = allowNoFeeTx(height, prevOutputs, txLen)
|
allowFree = allowNoFeeTx(height, prevOutputs, txLen)
|
||||||
|
|
|
@ -7,10 +7,10 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/keystore"
|
"github.com/btcsuite/btcwallet/keystore"
|
||||||
"github.com/btcsuite/btcwallet/txstore"
|
"github.com/btcsuite/btcwallet/txstore"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// This is a tx that transfers funds (0.371 BTC) to addresses of known privKeys.
|
// This is a tx that transfers funds (0.371 BTC) to addresses of known privKeys.
|
||||||
|
@ -41,7 +41,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_addOutputs(t *testing.T) {
|
func Test_addOutputs(t *testing.T) {
|
||||||
msgtx := btcwire.NewMsgTx()
|
msgtx := wire.NewMsgTx()
|
||||||
pairs := map[string]btcutil.Amount{outAddr1: 10, outAddr2: 1}
|
pairs := map[string]btcutil.Amount{outAddr1: 10, outAddr2: 1}
|
||||||
if _, err := addOutputs(msgtx, pairs); err != nil {
|
if _, err := addOutputs(msgtx, pairs); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -126,7 +126,7 @@ func TestCreateTxInsufficientFundsError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkOutputsMatch checks that the outputs in the tx match the expected ones.
|
// checkOutputsMatch checks that the outputs in the tx match the expected ones.
|
||||||
func checkOutputsMatch(t *testing.T, msgtx *btcwire.MsgTx, expected map[string]btcutil.Amount) {
|
func checkOutputsMatch(t *testing.T, msgtx *wire.MsgTx, expected map[string]btcutil.Amount) {
|
||||||
// This is a bit convoluted because the index of the change output is randomized.
|
// This is a bit convoluted because the index of the change output is randomized.
|
||||||
for addrStr, v := range expected {
|
for addrStr, v := range expected {
|
||||||
addr, err := btcutil.DecodeAddress(addrStr, activeNet.Params)
|
addr, err := btcutil.DecodeAddress(addrStr, activeNet.Params)
|
||||||
|
|
|
@ -13,9 +13,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/tx"
|
"github.com/btcsuite/btcwallet/tx"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -83,14 +83,14 @@ func TestAllowFree(t *testing.T) {
|
||||||
func TestFakeTxs(t *testing.T) {
|
func TestFakeTxs(t *testing.T) {
|
||||||
// First we need a wallet.
|
// First we need a wallet.
|
||||||
w, err := keystore.NewStore("banana wallet", "", []byte("banana"),
|
w, err := keystore.NewStore("banana wallet", "", []byte("banana"),
|
||||||
btcwire.MainNet, &keystore.BlockStamp{}, 100)
|
wire.MainNet, &keystore.BlockStamp{}, 100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can not create encrypted wallet: %s", err)
|
t.Errorf("Can not create encrypted wallet: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
a := &Wallet{
|
a := &Wallet{
|
||||||
Wallet: w,
|
Wallet: w,
|
||||||
lockedOutpoints: map[btcwire.OutPoint]struct{}{},
|
lockedOutpoints: map[wire.OutPoint]struct{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Unlock([]byte("banana"))
|
w.Unlock([]byte("banana"))
|
||||||
|
@ -106,10 +106,10 @@ func TestFakeTxs(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
copy(utxo.AddrHash[:], addr.ScriptAddress())
|
copy(utxo.AddrHash[:], addr.ScriptAddress())
|
||||||
ophash := (btcwire.ShaHash)([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
ophash := (wire.ShaHash)([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||||
28, 29, 30, 31, 32})
|
28, 29, 30, 31, 32})
|
||||||
out := btcwire.NewOutPoint(&ophash, 0)
|
out := wire.NewOutPoint(&ophash, 0)
|
||||||
utxo.Out = tx.OutPoint(*out)
|
utxo.Out = tx.OutPoint(*out)
|
||||||
ss, err := txscript.PayToAddrScript(addr)
|
ss, err := txscript.PayToAddrScript(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -37,11 +37,11 @@ import (
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcec"
|
"github.com/btcsuite/btcec"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/rename"
|
"github.com/btcsuite/btcwallet/rename"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -202,7 +202,7 @@ func chainedPrivKey(privkey, pubkey, chaincode []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xorbytes := make([]byte, 32)
|
xorbytes := make([]byte, 32)
|
||||||
chainMod := btcwire.DoubleSha256(pubkey)
|
chainMod := wire.DoubleSha256(pubkey)
|
||||||
for i := range xorbytes {
|
for i := range xorbytes {
|
||||||
xorbytes[i] = chainMod[i] ^ chaincode[i]
|
xorbytes[i] = chainMod[i] ^ chaincode[i]
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ func chainedPubKey(pubkey, chaincode []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
xorbytes := make([]byte, 32)
|
xorbytes := make([]byte, 32)
|
||||||
chainMod := btcwire.DoubleSha256(pubkey)
|
chainMod := wire.DoubleSha256(pubkey)
|
||||||
for i := range xorbytes {
|
for i := range xorbytes {
|
||||||
xorbytes[i] = chainMod[i] ^ chaincode[i]
|
xorbytes[i] = chainMod[i] ^ chaincode[i]
|
||||||
}
|
}
|
||||||
|
@ -487,12 +487,12 @@ func (net *netParams) ReadFrom(r io.Reader) (int64, error) {
|
||||||
return n64, err
|
return n64, err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch btcwire.BitcoinNet(binary.LittleEndian.Uint32(uint32Bytes)) {
|
switch wire.BitcoinNet(binary.LittleEndian.Uint32(uint32Bytes)) {
|
||||||
case btcwire.MainNet:
|
case wire.MainNet:
|
||||||
*net = (netParams)(btcnet.MainNetParams)
|
*net = (netParams)(btcnet.MainNetParams)
|
||||||
case btcwire.TestNet3:
|
case wire.TestNet3:
|
||||||
*net = (netParams)(btcnet.TestNet3Params)
|
*net = (netParams)(btcnet.TestNet3Params)
|
||||||
case btcwire.SimNet:
|
case wire.SimNet:
|
||||||
*net = (netParams)(btcnet.SimNetParams)
|
*net = (netParams)(btcnet.SimNetParams)
|
||||||
default:
|
default:
|
||||||
return n64, errors.New("unknown network")
|
return n64, errors.New("unknown network")
|
||||||
|
@ -601,7 +601,7 @@ func New(dir string, desc string, passphrase []byte, net *btcnet.Params,
|
||||||
kdfParams: *kdfp,
|
kdfParams: *kdfp,
|
||||||
recent: recentBlocks{
|
recent: recentBlocks{
|
||||||
lastHeight: createdAt.Height,
|
lastHeight: createdAt.Height,
|
||||||
hashes: []*btcwire.ShaHash{
|
hashes: []*wire.ShaHash{
|
||||||
createdAt.Hash,
|
createdAt.Hash,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1354,7 +1354,7 @@ func (s *Store) SetSyncedWith(bs *BlockStamp) {
|
||||||
// NOTE: If the hash of the synced block is not known, hash will be nil, and
|
// NOTE: If the hash of the synced block is not known, hash will be nil, and
|
||||||
// must be obtained from elsewhere. This must be explicitly checked before
|
// must be obtained from elsewhere. This must be explicitly checked before
|
||||||
// dereferencing the pointer.
|
// dereferencing the pointer.
|
||||||
func (s *Store) SyncedTo() (hash *btcwire.ShaHash, height int32) {
|
func (s *Store) SyncedTo() (hash *wire.ShaHash, height int32) {
|
||||||
s.mtx.RLock()
|
s.mtx.RLock()
|
||||||
defer s.mtx.RUnlock()
|
defer s.mtx.RUnlock()
|
||||||
|
|
||||||
|
@ -1541,7 +1541,7 @@ func (s *Store) ExportWatchingWallet() (*Store, error) {
|
||||||
kgwc := s.keyGenerator.watchingCopy(ws)
|
kgwc := s.keyGenerator.watchingCopy(ws)
|
||||||
ws.keyGenerator = *(kgwc.(*btcAddress))
|
ws.keyGenerator = *(kgwc.(*btcAddress))
|
||||||
if len(s.recent.hashes) != 0 {
|
if len(s.recent.hashes) != 0 {
|
||||||
ws.recent.hashes = make([]*btcwire.ShaHash, 0, len(s.recent.hashes))
|
ws.recent.hashes = make([]*wire.ShaHash, 0, len(s.recent.hashes))
|
||||||
for _, hash := range s.recent.hashes {
|
for _, hash := range s.recent.hashes {
|
||||||
hashCpy := *hash
|
hashCpy := *hash
|
||||||
ws.recent.hashes = append(ws.recent.hashes, &hashCpy)
|
ws.recent.hashes = append(ws.recent.hashes, &hashCpy)
|
||||||
|
@ -1796,7 +1796,7 @@ func (af *addrFlags) WriteTo(w io.Writer) (int64, error) {
|
||||||
// recentBlocks holds at most the last 20 seen block hashes as well as
|
// recentBlocks holds at most the last 20 seen block hashes as well as
|
||||||
// the block height of the most recently seen block.
|
// the block height of the most recently seen block.
|
||||||
type recentBlocks struct {
|
type recentBlocks struct {
|
||||||
hashes []*btcwire.ShaHash
|
hashes []*wire.ShaHash
|
||||||
lastHeight int32
|
lastHeight int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1828,14 +1828,14 @@ func (rb *recentBlocks) readFromVersion(v version, r io.Reader) (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read block hash.
|
// Read block hash.
|
||||||
var syncedBlockHash btcwire.ShaHash
|
var syncedBlockHash wire.ShaHash
|
||||||
n, err = io.ReadFull(r, syncedBlockHash[:])
|
n, err = io.ReadFull(r, syncedBlockHash[:])
|
||||||
read += int64(n)
|
read += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return read, err
|
return read, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rb.hashes = []*btcwire.ShaHash{
|
rb.hashes = []*wire.ShaHash{
|
||||||
&syncedBlockHash,
|
&syncedBlockHash,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1879,9 +1879,9 @@ func (rb *recentBlocks) ReadFrom(r io.Reader) (int64, error) {
|
||||||
// Read nBlocks block hashes. Hashes are expected to be in
|
// Read nBlocks block hashes. Hashes are expected to be in
|
||||||
// order of oldest to newest, but there's no way to check
|
// order of oldest to newest, but there's no way to check
|
||||||
// that here.
|
// that here.
|
||||||
rb.hashes = make([]*btcwire.ShaHash, 0, nBlocks)
|
rb.hashes = make([]*wire.ShaHash, 0, nBlocks)
|
||||||
for i := uint32(0); i < nBlocks; i++ {
|
for i := uint32(0); i < nBlocks; i++ {
|
||||||
var blockSha btcwire.ShaHash
|
var blockSha wire.ShaHash
|
||||||
n, err := io.ReadFull(r, blockSha[:])
|
n, err := io.ReadFull(r, blockSha[:])
|
||||||
read += int64(n)
|
read += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3040,7 +3040,7 @@ func (sa *scriptAddress) watchingCopy(s *Store) walletAddress {
|
||||||
}
|
}
|
||||||
|
|
||||||
func walletHash(b []byte) uint32 {
|
func walletHash(b []byte) uint32 {
|
||||||
sum := btcwire.DoubleSha256(b)
|
sum := wire.DoubleSha256(b)
|
||||||
return binary.LittleEndian.Uint32(sum)
|
return binary.LittleEndian.Uint32(sum)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3247,6 +3247,6 @@ func (e *scriptEntry) ReadFrom(r io.Reader) (n int64, err error) {
|
||||||
// used to mark a point in the blockchain that a key store element is
|
// used to mark a point in the blockchain that a key store element is
|
||||||
// synced to.
|
// synced to.
|
||||||
type BlockStamp struct {
|
type BlockStamp struct {
|
||||||
Hash *btcwire.ShaHash
|
Hash *wire.ShaHash
|
||||||
Height int32
|
Height int32
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,10 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcec"
|
"github.com/btcsuite/btcec"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
|
@ -38,7 +38,7 @@ var tstNetParams = &btcnet.MainNetParams
|
||||||
|
|
||||||
func makeBS(height int32) *BlockStamp {
|
func makeBS(height int32) *BlockStamp {
|
||||||
return &BlockStamp{
|
return &BlockStamp{
|
||||||
Hash: new(btcwire.ShaHash),
|
Hash: new(wire.ShaHash),
|
||||||
Height: height,
|
Height: height,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ type params struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// mainNetParams contains parameters specific running btcwallet and
|
// mainNetParams contains parameters specific running btcwallet and
|
||||||
// btcd on the main network (btcwire.MainNet).
|
// btcd on the main network (wire.MainNet).
|
||||||
var mainNetParams = params{
|
var mainNetParams = params{
|
||||||
Params: &btcnet.MainNetParams,
|
Params: &btcnet.MainNetParams,
|
||||||
connect: "localhost:8334",
|
connect: "localhost:8334",
|
||||||
|
@ -41,7 +41,7 @@ var mainNetParams = params{
|
||||||
}
|
}
|
||||||
|
|
||||||
// testNet3Params contains parameters specific running btcwallet and
|
// testNet3Params contains parameters specific running btcwallet and
|
||||||
// btcd on the test network (version 3) (btcwire.TestNet3).
|
// btcd on the test network (version 3) (wire.TestNet3).
|
||||||
var testNet3Params = params{
|
var testNet3Params = params{
|
||||||
Params: &btcnet.TestNet3Params,
|
Params: &btcnet.TestNet3Params,
|
||||||
connect: "localhost:18334",
|
connect: "localhost:18334",
|
||||||
|
@ -50,7 +50,7 @@ var testNet3Params = params{
|
||||||
}
|
}
|
||||||
|
|
||||||
// simNetParams contains parameters specific to the simulation test network
|
// simNetParams contains parameters specific to the simulation test network
|
||||||
// (btcwire.SimNet).
|
// (wire.SimNet).
|
||||||
var simNetParams = params{
|
var simNetParams = params{
|
||||||
Params: &btcnet.SimNetParams,
|
Params: &btcnet.SimNetParams,
|
||||||
connect: "localhost:18556",
|
connect: "localhost:18556",
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/chain"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/btcsuite/btcwallet/keystore"
|
"github.com/btcsuite/btcwallet/keystore"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RescanProgressMsg reports the current progress made by a rescan for a
|
// RescanProgressMsg reports the current progress made by a rescan for a
|
||||||
|
@ -46,7 +46,7 @@ type RescanFinishedMsg struct {
|
||||||
type RescanJob struct {
|
type RescanJob struct {
|
||||||
InitialSync bool
|
InitialSync bool
|
||||||
Addrs []btcutil.Address
|
Addrs []btcutil.Address
|
||||||
OutPoints []*btcwire.OutPoint
|
OutPoints []*wire.OutPoint
|
||||||
BlockStamp keystore.BlockStamp
|
BlockStamp keystore.BlockStamp
|
||||||
err chan error
|
err chan error
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ type RescanJob struct {
|
||||||
type rescanBatch struct {
|
type rescanBatch struct {
|
||||||
initialSync bool
|
initialSync bool
|
||||||
addrs []btcutil.Address
|
addrs []btcutil.Address
|
||||||
outpoints []*btcwire.OutPoint
|
outpoints []*wire.OutPoint
|
||||||
bs keystore.BlockStamp
|
bs keystore.BlockStamp
|
||||||
errChans []chan error
|
errChans []chan error
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ func (w *Wallet) RescanActiveAddresses() (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
outpoints := make([]*btcwire.OutPoint, len(unspents))
|
outpoints := make([]*wire.OutPoint, len(unspents))
|
||||||
for i, output := range unspents {
|
for i, output := range unspents {
|
||||||
outpoints[i] = output.OutPoint()
|
outpoints[i] = output.OutPoint()
|
||||||
}
|
}
|
||||||
|
|
26
rpcserver.go
26
rpcserver.go
|
@ -38,6 +38,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcec"
|
"github.com/btcsuite/btcec"
|
||||||
"github.com/btcsuite/btcjson"
|
"github.com/btcsuite/btcjson"
|
||||||
"github.com/btcsuite/btcrpcclient"
|
"github.com/btcsuite/btcrpcclient"
|
||||||
|
@ -45,7 +46,6 @@ import (
|
||||||
"github.com/btcsuite/btcwallet/chain"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/btcsuite/btcwallet/keystore"
|
"github.com/btcsuite/btcwallet/keystore"
|
||||||
"github.com/btcsuite/btcwallet/txstore"
|
"github.com/btcsuite/btcwallet/txstore"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
"github.com/btcsuite/btcws"
|
"github.com/btcsuite/btcws"
|
||||||
"github.com/btcsuite/websocket"
|
"github.com/btcsuite/websocket"
|
||||||
)
|
)
|
||||||
|
@ -1922,7 +1922,7 @@ func GetReceivedByAddress(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (
|
||||||
func GetTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface{}, error) {
|
func GetTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface{}, error) {
|
||||||
cmd := icmd.(*btcjson.GetTransactionCmd)
|
cmd := icmd.(*btcjson.GetTransactionCmd)
|
||||||
|
|
||||||
txSha, err := btcwire.NewShaHashFromStr(cmd.Txid)
|
txSha, err := wire.NewShaHashFromStr(cmd.Txid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, btcjson.ErrDecodeHexString
|
return nil, btcjson.ErrDecodeHexString
|
||||||
}
|
}
|
||||||
|
@ -2184,7 +2184,7 @@ func ListSinceBlock(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interf
|
||||||
|
|
||||||
height := int32(-1)
|
height := int32(-1)
|
||||||
if cmd.BlockHash != "" {
|
if cmd.BlockHash != "" {
|
||||||
hash, err := btcwire.NewShaHashFromStr(cmd.BlockHash)
|
hash, err := wire.NewShaHashFromStr(cmd.BlockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, DeserializationError{err}
|
return nil, DeserializationError{err}
|
||||||
}
|
}
|
||||||
|
@ -2328,11 +2328,11 @@ func LockUnspent(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface
|
||||||
w.ResetLockedOutpoints()
|
w.ResetLockedOutpoints()
|
||||||
default:
|
default:
|
||||||
for _, input := range cmd.Transactions {
|
for _, input := range cmd.Transactions {
|
||||||
txSha, err := btcwire.NewShaHashFromStr(input.Txid)
|
txSha, err := wire.NewShaHashFromStr(input.Txid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ParseError{err}
|
return nil, ParseError{err}
|
||||||
}
|
}
|
||||||
op := btcwire.OutPoint{Hash: *txSha, Index: input.Vout}
|
op := wire.OutPoint{Hash: *txSha, Index: input.Vout}
|
||||||
if cmd.Unlock {
|
if cmd.Unlock {
|
||||||
w.UnlockOutpoint(op)
|
w.UnlockOutpoint(op)
|
||||||
} else {
|
} else {
|
||||||
|
@ -2506,7 +2506,7 @@ func SignMessage(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interface
|
||||||
|
|
||||||
fullmsg := "Bitcoin Signed Message:\n" + cmd.Message
|
fullmsg := "Bitcoin Signed Message:\n" + cmd.Message
|
||||||
sigbytes, err := btcec.SignCompact(btcec.S256(), privKey,
|
sigbytes, err := btcec.SignCompact(btcec.S256(), privKey,
|
||||||
btcwire.DoubleSha256([]byte(fullmsg)), ainfo.Compressed())
|
wire.DoubleSha256([]byte(fullmsg)), ainfo.Compressed())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2594,7 +2594,7 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, btcjson.ErrDecodeHexString
|
return nil, btcjson.ErrDecodeHexString
|
||||||
}
|
}
|
||||||
msgTx := btcwire.NewMsgTx()
|
msgTx := wire.NewMsgTx()
|
||||||
err = msgTx.Deserialize(bytes.NewBuffer(serializedTx))
|
err = msgTx.Deserialize(bytes.NewBuffer(serializedTx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := errors.New("TX decode failed")
|
e := errors.New("TX decode failed")
|
||||||
|
@ -2604,10 +2604,10 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in
|
||||||
// First we add the stuff we have been given.
|
// First we add the stuff we have been given.
|
||||||
// TODO(oga) really we probably should look these up with btcd anyway
|
// TODO(oga) really we probably should look these up with btcd anyway
|
||||||
// to make sure that they match the blockchain if present.
|
// to make sure that they match the blockchain if present.
|
||||||
inputs := make(map[btcwire.OutPoint][]byte)
|
inputs := make(map[wire.OutPoint][]byte)
|
||||||
scripts := make(map[string][]byte)
|
scripts := make(map[string][]byte)
|
||||||
for _, rti := range cmd.Inputs {
|
for _, rti := range cmd.Inputs {
|
||||||
inputSha, err := btcwire.NewShaHashFromStr(rti.Txid)
|
inputSha, err := wire.NewShaHashFromStr(rti.Txid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, DeserializationError{err}
|
return nil, DeserializationError{err}
|
||||||
}
|
}
|
||||||
|
@ -2636,7 +2636,7 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in
|
||||||
}
|
}
|
||||||
scripts[addr.String()] = redeemScript
|
scripts[addr.String()] = redeemScript
|
||||||
}
|
}
|
||||||
inputs[btcwire.OutPoint{
|
inputs[wire.OutPoint{
|
||||||
Hash: *inputSha,
|
Hash: *inputSha,
|
||||||
Index: rti.Vout,
|
Index: rti.Vout,
|
||||||
}] = script
|
}] = script
|
||||||
|
@ -2646,7 +2646,7 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in
|
||||||
// querying btcd with getrawtransaction. We queue up a bunch of async
|
// querying btcd with getrawtransaction. We queue up a bunch of async
|
||||||
// requests and will wait for replies after we have checked the rest of
|
// requests and will wait for replies after we have checked the rest of
|
||||||
// the arguments.
|
// the arguments.
|
||||||
requested := make(map[btcwire.ShaHash]*pendingTx)
|
requested := make(map[wire.ShaHash]*pendingTx)
|
||||||
for _, txIn := range msgTx.TxIn {
|
for _, txIn := range msgTx.TxIn {
|
||||||
// Did we get this txin from the arguments?
|
// Did we get this txin from the arguments?
|
||||||
if _, ok := inputs[txIn.PreviousOutPoint]; ok {
|
if _, ok := inputs[txIn.PreviousOutPoint]; ok {
|
||||||
|
@ -2740,7 +2740,7 @@ func SignRawTransaction(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (in
|
||||||
return nil, InvalidParameterError{e}
|
return nil, InvalidParameterError{e}
|
||||||
}
|
}
|
||||||
|
|
||||||
inputs[btcwire.OutPoint{
|
inputs[wire.OutPoint{
|
||||||
Hash: txid,
|
Hash: txid,
|
||||||
Index: input,
|
Index: input,
|
||||||
}] = tx.MsgTx().TxOut[input].PkScript
|
}] = tx.MsgTx().TxOut[input].PkScript
|
||||||
|
@ -2933,7 +2933,7 @@ func VerifyMessage(w *Wallet, chainSvr *chain.Client, icmd btcjson.Cmd) (interfa
|
||||||
// Validate the signature - this just shows that it was valid at all.
|
// Validate the signature - this just shows that it was valid at all.
|
||||||
// we will compare it with the key next.
|
// we will compare it with the key next.
|
||||||
pk, wasCompressed, err := btcec.RecoverCompact(btcec.S256(), sig,
|
pk, wasCompressed, err := btcec.RecoverCompact(btcec.S256(), sig,
|
||||||
btcwire.DoubleSha256([]byte("Bitcoin Signed Message:\n"+
|
wire.DoubleSha256([]byte("Bitcoin Signed Message:\n"+
|
||||||
cmd.Message)))
|
cmd.Message)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// copied from btcwire
|
// copied from wire
|
||||||
|
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
|
|
|
@ -27,9 +27,9 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/rename"
|
"github.com/btcsuite/btcwallet/rename"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// filename is the name of the file typically used to save a transaction
|
// filename is the name of the file typically used to save a transaction
|
||||||
|
@ -125,7 +125,7 @@ func (s *Store) ReadFrom(r io.Reader) (int64, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if cred.spentBy == nil {
|
if cred.spentBy == nil {
|
||||||
op := btcwire.OutPoint{
|
op := wire.OutPoint{
|
||||||
Hash: *tx.tx.Sha(),
|
Hash: *tx.tx.Sha(),
|
||||||
Index: uint32(outputIdx),
|
Index: uint32(outputIdx),
|
||||||
}
|
}
|
||||||
|
@ -419,7 +419,7 @@ func (t *txRecord) ReadFrom(r io.Reader) (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and save the btcutil.Tx of the read MsgTx and set its index.
|
// Create and save the btcutil.Tx of the read MsgTx and set its index.
|
||||||
tx := btcutil.NewTx((*btcwire.MsgTx)(msgTx))
|
tx := btcutil.NewTx((*wire.MsgTx)(msgTx))
|
||||||
tx.SetIndex(txIndex)
|
tx.SetIndex(txIndex)
|
||||||
t.tx = tx
|
t.tx = tx
|
||||||
|
|
||||||
|
@ -749,20 +749,20 @@ func (t *txRecord) WriteTo(w io.Writer) (int64, error) {
|
||||||
return n64, nil
|
return n64, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type msgTx btcwire.MsgTx
|
type msgTx wire.MsgTx
|
||||||
|
|
||||||
func (tx *msgTx) ReadFrom(r io.Reader) (int64, error) {
|
func (tx *msgTx) ReadFrom(r io.Reader) (int64, error) {
|
||||||
// Read from a TeeReader to return the number of read bytes.
|
// Read from a TeeReader to return the number of read bytes.
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
tr := io.TeeReader(r, &buf)
|
tr := io.TeeReader(r, &buf)
|
||||||
if err := (*btcwire.MsgTx)(tx).Deserialize(tr); err != nil {
|
if err := (*wire.MsgTx)(tx).Deserialize(tr); err != nil {
|
||||||
if buf.Len() != 0 && err == io.EOF {
|
if buf.Len() != 0 && err == io.EOF {
|
||||||
err = io.ErrUnexpectedEOF
|
err = io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
return int64(buf.Len()), err
|
return int64(buf.Len()), err
|
||||||
}
|
}
|
||||||
|
|
||||||
return int64((*btcwire.MsgTx)(tx).SerializeSize()), nil
|
return int64((*wire.MsgTx)(tx).SerializeSize()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *msgTx) WriteTo(w io.Writer) (int64, error) {
|
func (tx *msgTx) WriteTo(w io.Writer) (int64, error) {
|
||||||
|
@ -771,7 +771,7 @@ func (tx *msgTx) WriteTo(w io.Writer) (int64, error) {
|
||||||
// bytes.Buffer never fails except for OOM panics, so check and panic
|
// bytes.Buffer never fails except for OOM panics, so check and panic
|
||||||
// on any unexpected non-nil returned errors.
|
// on any unexpected non-nil returned errors.
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
if err := (*btcwire.MsgTx)(tx).Serialize(&buf); err != nil {
|
if err := (*wire.MsgTx)(tx).Serialize(&buf); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return io.Copy(w, &buf)
|
return io.Copy(w, &buf)
|
||||||
|
@ -920,7 +920,7 @@ func (u *unconfirmedStore) ReadFrom(r io.Reader) (int64, error) {
|
||||||
spentBlockOutPointCount := byteOrder.Uint32(uint32Bytes)
|
spentBlockOutPointCount := byteOrder.Uint32(uint32Bytes)
|
||||||
for i := uint32(0); i < spentBlockOutPointCount; i++ {
|
for i := uint32(0); i < spentBlockOutPointCount; i++ {
|
||||||
// Read outpoint hash and index (uint32).
|
// Read outpoint hash and index (uint32).
|
||||||
op := btcwire.OutPoint{}
|
op := wire.OutPoint{}
|
||||||
n, err := io.ReadFull(r, op.Hash[:])
|
n, err := io.ReadFull(r, op.Hash[:])
|
||||||
n64 += int64(n)
|
n64 += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -953,7 +953,7 @@ func (u *unconfirmedStore) ReadFrom(r io.Reader) (int64, error) {
|
||||||
|
|
||||||
// Read transaction record hash and check that it was previously
|
// Read transaction record hash and check that it was previously
|
||||||
// read into the txs map. Use full record as the map value.
|
// read into the txs map. Use full record as the map value.
|
||||||
var txHash btcwire.ShaHash
|
var txHash wire.ShaHash
|
||||||
n, err = io.ReadFull(r, txHash[:])
|
n, err = io.ReadFull(r, txHash[:])
|
||||||
n64 += int64(n)
|
n64 += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -987,7 +987,7 @@ func (u *unconfirmedStore) ReadFrom(r io.Reader) (int64, error) {
|
||||||
spentUnconfirmedCount := byteOrder.Uint32(uint32Bytes)
|
spentUnconfirmedCount := byteOrder.Uint32(uint32Bytes)
|
||||||
for i := uint32(0); i < spentUnconfirmedCount; i++ {
|
for i := uint32(0); i < spentUnconfirmedCount; i++ {
|
||||||
// Read outpoint hash and index (uint32).
|
// Read outpoint hash and index (uint32).
|
||||||
op := btcwire.OutPoint{}
|
op := wire.OutPoint{}
|
||||||
n, err := io.ReadFull(r, op.Hash[:])
|
n, err := io.ReadFull(r, op.Hash[:])
|
||||||
n64 += int64(n)
|
n64 += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1008,7 +1008,7 @@ func (u *unconfirmedStore) ReadFrom(r io.Reader) (int64, error) {
|
||||||
|
|
||||||
// Read transaction record hash and check that it was previously
|
// Read transaction record hash and check that it was previously
|
||||||
// read into the txs map. Use full record as the map value.
|
// read into the txs map. Use full record as the map value.
|
||||||
var txHash btcwire.ShaHash
|
var txHash wire.ShaHash
|
||||||
n, err = io.ReadFull(r, txHash[:])
|
n, err = io.ReadFull(r, txHash[:])
|
||||||
n64 += int64(n)
|
n64 += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -26,9 +26,9 @@ import (
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/blockchain"
|
"github.com/btcsuite/btcd/blockchain"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -128,7 +128,7 @@ type TxRecord struct {
|
||||||
|
|
||||||
// Block holds details about a block that contains wallet transactions.
|
// Block holds details about a block that contains wallet transactions.
|
||||||
type Block struct {
|
type Block struct {
|
||||||
Hash btcwire.ShaHash
|
Hash wire.ShaHash
|
||||||
Time time.Time
|
Time time.Time
|
||||||
Height int32
|
Height int32
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ type Store struct {
|
||||||
blocks []*blockTxCollection
|
blocks []*blockTxCollection
|
||||||
blockIndexes map[int32]uint32
|
blockIndexes map[int32]uint32
|
||||||
|
|
||||||
unspent map[btcwire.OutPoint]BlockTxKey
|
unspent map[wire.OutPoint]BlockTxKey
|
||||||
|
|
||||||
// unconfirmed holds a collection of wallet transactions that have not
|
// unconfirmed holds a collection of wallet transactions that have not
|
||||||
// been mined into a block yet.
|
// been mined into a block yet.
|
||||||
|
@ -211,23 +211,23 @@ type blockTxCollection struct {
|
||||||
type unconfirmedStore struct {
|
type unconfirmedStore struct {
|
||||||
// txs contains all unconfirmed transactions, mapping from their
|
// txs contains all unconfirmed transactions, mapping from their
|
||||||
// transaction hash to the records.
|
// transaction hash to the records.
|
||||||
txs map[btcwire.ShaHash]*txRecord
|
txs map[wire.ShaHash]*txRecord
|
||||||
|
|
||||||
// spentBlockOutPoints maps from spent outputs from mined transaction
|
// spentBlockOutPoints maps from spent outputs from mined transaction
|
||||||
// to the unconfirmed transaction which spends it. An additional
|
// to the unconfirmed transaction which spends it. An additional
|
||||||
// map is included to lookup the output key by its outpoint.
|
// map is included to lookup the output key by its outpoint.
|
||||||
spentBlockOutPoints map[BlockOutputKey]*txRecord
|
spentBlockOutPoints map[BlockOutputKey]*txRecord
|
||||||
spentBlockOutPointKeys map[btcwire.OutPoint]BlockOutputKey
|
spentBlockOutPointKeys map[wire.OutPoint]BlockOutputKey
|
||||||
|
|
||||||
// spentUnconfirmed maps from an unconfirmed outpoint to the unconfirmed
|
// spentUnconfirmed maps from an unconfirmed outpoint to the unconfirmed
|
||||||
// transaction which spends it.
|
// transaction which spends it.
|
||||||
spentUnconfirmed map[btcwire.OutPoint]*txRecord
|
spentUnconfirmed map[wire.OutPoint]*txRecord
|
||||||
|
|
||||||
// previousOutpoints maps all previous outputs to the transaction record
|
// previousOutpoints maps all previous outputs to the transaction record
|
||||||
// of the unconfirmed transaction which spends it. This is primarly
|
// of the unconfirmed transaction which spends it. This is primarly
|
||||||
// designed to assist with double spend detection without iterating
|
// designed to assist with double spend detection without iterating
|
||||||
// through each value of the txs map.
|
// through each value of the txs map.
|
||||||
previousOutpoints map[btcwire.OutPoint]*txRecord
|
previousOutpoints map[wire.OutPoint]*txRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockTxKey is a lookup key for a single mined transaction in the store.
|
// BlockTxKey is a lookup key for a single mined transaction in the store.
|
||||||
|
@ -280,13 +280,13 @@ func New(dir string) *Store {
|
||||||
dir: dir,
|
dir: dir,
|
||||||
file: filename,
|
file: filename,
|
||||||
blockIndexes: map[int32]uint32{},
|
blockIndexes: map[int32]uint32{},
|
||||||
unspent: map[btcwire.OutPoint]BlockTxKey{},
|
unspent: map[wire.OutPoint]BlockTxKey{},
|
||||||
unconfirmed: unconfirmedStore{
|
unconfirmed: unconfirmedStore{
|
||||||
txs: map[btcwire.ShaHash]*txRecord{},
|
txs: map[wire.ShaHash]*txRecord{},
|
||||||
spentBlockOutPoints: map[BlockOutputKey]*txRecord{},
|
spentBlockOutPoints: map[BlockOutputKey]*txRecord{},
|
||||||
spentBlockOutPointKeys: map[btcwire.OutPoint]BlockOutputKey{},
|
spentBlockOutPointKeys: map[wire.OutPoint]BlockOutputKey{},
|
||||||
spentUnconfirmed: map[btcwire.OutPoint]*txRecord{},
|
spentUnconfirmed: map[wire.OutPoint]*txRecord{},
|
||||||
previousOutpoints: map[btcwire.OutPoint]*txRecord{},
|
previousOutpoints: map[wire.OutPoint]*txRecord{},
|
||||||
},
|
},
|
||||||
notificationLock: new(sync.Mutex),
|
notificationLock: new(sync.Mutex),
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ func (s *Store) moveMinedTx(r *txRecord, block *Block) error {
|
||||||
// If the credit is not spent, modify the store's unspent bookkeeping
|
// If the credit is not spent, modify the store's unspent bookkeeping
|
||||||
// maps to include the credit and increment the amount deltas by the
|
// maps to include the credit and increment the amount deltas by the
|
||||||
// credit's value.
|
// credit's value.
|
||||||
op := btcwire.OutPoint{Hash: *r.Tx().Sha()}
|
op := wire.OutPoint{Hash: *r.Tx().Sha()}
|
||||||
for i, credit := range r.credits {
|
for i, credit := range r.credits {
|
||||||
if credit == nil {
|
if credit == nil {
|
||||||
continue
|
continue
|
||||||
|
@ -666,7 +666,7 @@ func (s *Store) findPreviousCredits(tx *btcutil.Tx) ([]Credit, error) {
|
||||||
creditChans := make([]chan createdCredit, len(inputs))
|
creditChans := make([]chan createdCredit, len(inputs))
|
||||||
for i, txIn := range inputs {
|
for i, txIn := range inputs {
|
||||||
creditChans[i] = make(chan createdCredit, 1)
|
creditChans[i] = make(chan createdCredit, 1)
|
||||||
go func(i int, op btcwire.OutPoint) {
|
go func(i int, op wire.OutPoint) {
|
||||||
key, ok := s.unspent[op]
|
key, ok := s.unspent[op]
|
||||||
if !ok {
|
if !ok {
|
||||||
// Does this input spend an unconfirmed output?
|
// Does this input spend an unconfirmed output?
|
||||||
|
@ -812,7 +812,7 @@ func (t *TxRecord) AddCredit(index uint32, change bool) (Credit, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New outputs are added unspent.
|
// New outputs are added unspent.
|
||||||
op := btcwire.OutPoint{Hash: *t.tx.Sha(), Index: index}
|
op := wire.OutPoint{Hash: *t.tx.Sha(), Index: index}
|
||||||
t.s.unspent[op] = t.BlockTxKey
|
t.s.unspent[op] = t.BlockTxKey
|
||||||
switch t.tx.Index() {
|
switch t.tx.Index() {
|
||||||
case 0: // Coinbase
|
case 0: // Coinbase
|
||||||
|
@ -875,7 +875,7 @@ func (s *Store) Rollback(height int32) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
op := btcwire.OutPoint{
|
op := wire.OutPoint{
|
||||||
Hash: *r.Tx().Sha(),
|
Hash: *r.Tx().Sha(),
|
||||||
Index: uint32(outIdx),
|
Index: uint32(outIdx),
|
||||||
}
|
}
|
||||||
|
@ -943,7 +943,7 @@ func (s *Store) Rollback(height int32) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
op := btcwire.OutPoint{
|
op := wire.OutPoint{
|
||||||
Hash: *rr.Tx().Sha(),
|
Hash: *rr.Tx().Sha(),
|
||||||
Index: prev.OutputIndex,
|
Index: prev.OutputIndex,
|
||||||
}
|
}
|
||||||
|
@ -1025,7 +1025,7 @@ func (s *Store) removeConflict(r *txRecord) error {
|
||||||
if credit == nil || credit.spentBy == nil {
|
if credit == nil || credit.spentBy == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
op := btcwire.NewOutPoint(r.Tx().Sha(), uint32(i))
|
op := wire.NewOutPoint(r.Tx().Sha(), uint32(i))
|
||||||
nextSpender, ok := u.spentUnconfirmed[*op]
|
nextSpender, ok := u.spentUnconfirmed[*op]
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrInconsistentStore
|
return ErrInconsistentStore
|
||||||
|
@ -1484,15 +1484,15 @@ func (c Credit) amount() btcutil.Amount {
|
||||||
|
|
||||||
// OutPoint returns the outpoint needed to include in a transaction input
|
// OutPoint returns the outpoint needed to include in a transaction input
|
||||||
// to spend this output.
|
// to spend this output.
|
||||||
func (c Credit) OutPoint() *btcwire.OutPoint {
|
func (c Credit) OutPoint() *wire.OutPoint {
|
||||||
c.s.mtx.RLock()
|
c.s.mtx.RLock()
|
||||||
defer c.s.mtx.RUnlock()
|
defer c.s.mtx.RUnlock()
|
||||||
|
|
||||||
return c.outPoint()
|
return c.outPoint()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Credit) outPoint() *btcwire.OutPoint {
|
func (c Credit) outPoint() *wire.OutPoint {
|
||||||
return btcwire.NewOutPoint(c.Tx().Sha(), c.OutputIndex)
|
return wire.NewOutPoint(c.Tx().Sha(), c.OutputIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// outputKey creates and returns the block lookup key for this credit.
|
// outputKey creates and returns the block lookup key for this credit.
|
||||||
|
@ -1512,7 +1512,7 @@ func (c Credit) Spent() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TxOut returns the transaction output which this credit references.
|
// TxOut returns the transaction output which this credit references.
|
||||||
func (c Credit) TxOut() *btcwire.TxOut {
|
func (c Credit) TxOut() *wire.TxOut {
|
||||||
c.s.mtx.RLock()
|
c.s.mtx.RLock()
|
||||||
defer c.s.mtx.RUnlock()
|
defer c.s.mtx.RUnlock()
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,10 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
. "github.com/btcsuite/btcwallet/txstore"
|
. "github.com/btcsuite/btcwallet/txstore"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Received transaction output for mainnet outpoint
|
// Received transaction output for mainnet outpoint
|
||||||
|
@ -31,7 +31,7 @@ import (
|
||||||
var (
|
var (
|
||||||
TstRecvSerializedTx, _ = hex.DecodeString("010000000114d9ff358894c486b4ae11c2a8cf7851b1df64c53d2e511278eff17c22fb7373000000008c493046022100995447baec31ee9f6d4ec0e05cb2a44f6b817a99d5f6de167d1c75354a946410022100c9ffc23b64d770b0e01e7ff4d25fbc2f1ca8091053078a247905c39fce3760b601410458b8e267add3c1e374cf40f1de02b59213a82e1d84c2b94096e22e2f09387009c96debe1d0bcb2356ffdcf65d2a83d4b34e72c62eccd8490dbf2110167783b2bffffffff0280969800000000001976a914479ed307831d0ac19ebc5f63de7d5f1a430ddb9d88ac38bfaa00000000001976a914dadf9e3484f28b385ddeaa6c575c0c0d18e9788a88ac00000000")
|
TstRecvSerializedTx, _ = hex.DecodeString("010000000114d9ff358894c486b4ae11c2a8cf7851b1df64c53d2e511278eff17c22fb7373000000008c493046022100995447baec31ee9f6d4ec0e05cb2a44f6b817a99d5f6de167d1c75354a946410022100c9ffc23b64d770b0e01e7ff4d25fbc2f1ca8091053078a247905c39fce3760b601410458b8e267add3c1e374cf40f1de02b59213a82e1d84c2b94096e22e2f09387009c96debe1d0bcb2356ffdcf65d2a83d4b34e72c62eccd8490dbf2110167783b2bffffffff0280969800000000001976a914479ed307831d0ac19ebc5f63de7d5f1a430ddb9d88ac38bfaa00000000001976a914dadf9e3484f28b385ddeaa6c575c0c0d18e9788a88ac00000000")
|
||||||
TstRecvTx, _ = btcutil.NewTxFromBytes(TstRecvSerializedTx)
|
TstRecvTx, _ = btcutil.NewTxFromBytes(TstRecvSerializedTx)
|
||||||
TstRecvTxSpendingTxBlockHash, _ = btcwire.NewShaHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4")
|
TstRecvTxSpendingTxBlockHash, _ = wire.NewShaHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4")
|
||||||
TstRecvAmt = int64(10000000)
|
TstRecvAmt = int64(10000000)
|
||||||
TstRecvIndex = 684
|
TstRecvIndex = 684
|
||||||
TstRecvTxBlockDetails = &Block{
|
TstRecvTxBlockDetails = &Block{
|
||||||
|
@ -46,7 +46,7 @@ var (
|
||||||
TstSpendingSerializedTx, _ = hex.DecodeString("0100000003ad3fba7ebd67c09baa9538898e10d6726dcb8eadb006be0c7388c8e46d69d361000000006b4830450220702c4fbde5532575fed44f8d6e8c3432a2a9bd8cff2f966c3a79b2245a7c88db02210095d6505a57e350720cb52b89a9b56243c15ddfcea0596aedc1ba55d9fb7d5aa0012103cccb5c48a699d3efcca6dae277fee6b82e0229ed754b742659c3acdfed2651f9ffffffffdbd36173f5610e34de5c00ed092174603761595d90190f790e79cda3e5b45bc2010000006b483045022000fa20735e5875e64d05bed43d81b867f3bd8745008d3ff4331ef1617eac7c44022100ad82261fc57faac67fc482a37b6bf18158da0971e300abf5fe2f9fd39e107f58012102d4e1caf3e022757512c204bf09ff56a9981df483aba3c74bb60d3612077c9206ffffffff65536c9d964b6f89b8ef17e83c6666641bc495cb27bab60052f76cd4556ccd0d040000006a473044022068e3886e0299ffa69a1c3ee40f8b6700f5f6d463a9cf9dbf22c055a131fc4abc02202b58957fe19ff1be7a84c458d08016c53fbddec7184ac5e633f2b282ae3420ae012103b4e411b81d32a69fb81178a8ea1abaa12f613336923ee920ffbb1b313af1f4d2ffffffff02ab233200000000001976a91418808b2fbd8d2c6d022aed5cd61f0ce6c0a4cbb688ac4741f011000000001976a914f081088a300c80ce36b717a9914ab5ec8a7d283988ac00000000")
|
TstSpendingSerializedTx, _ = hex.DecodeString("0100000003ad3fba7ebd67c09baa9538898e10d6726dcb8eadb006be0c7388c8e46d69d361000000006b4830450220702c4fbde5532575fed44f8d6e8c3432a2a9bd8cff2f966c3a79b2245a7c88db02210095d6505a57e350720cb52b89a9b56243c15ddfcea0596aedc1ba55d9fb7d5aa0012103cccb5c48a699d3efcca6dae277fee6b82e0229ed754b742659c3acdfed2651f9ffffffffdbd36173f5610e34de5c00ed092174603761595d90190f790e79cda3e5b45bc2010000006b483045022000fa20735e5875e64d05bed43d81b867f3bd8745008d3ff4331ef1617eac7c44022100ad82261fc57faac67fc482a37b6bf18158da0971e300abf5fe2f9fd39e107f58012102d4e1caf3e022757512c204bf09ff56a9981df483aba3c74bb60d3612077c9206ffffffff65536c9d964b6f89b8ef17e83c6666641bc495cb27bab60052f76cd4556ccd0d040000006a473044022068e3886e0299ffa69a1c3ee40f8b6700f5f6d463a9cf9dbf22c055a131fc4abc02202b58957fe19ff1be7a84c458d08016c53fbddec7184ac5e633f2b282ae3420ae012103b4e411b81d32a69fb81178a8ea1abaa12f613336923ee920ffbb1b313af1f4d2ffffffff02ab233200000000001976a91418808b2fbd8d2c6d022aed5cd61f0ce6c0a4cbb688ac4741f011000000001976a914f081088a300c80ce36b717a9914ab5ec8a7d283988ac00000000")
|
||||||
TstSpendingTx, _ = btcutil.NewTxFromBytes(TstSpendingSerializedTx)
|
TstSpendingTx, _ = btcutil.NewTxFromBytes(TstSpendingSerializedTx)
|
||||||
TstSpendingTxBlockHeight = int32(279143)
|
TstSpendingTxBlockHeight = int32(279143)
|
||||||
TstSignedTxBlockHash, _ = btcwire.NewShaHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4")
|
TstSignedTxBlockHash, _ = wire.NewShaHashFromStr("00000000000000017188b968a371bab95aa43522665353b646e41865abae02a4")
|
||||||
TstSignedTxIndex = 123
|
TstSignedTxIndex = 123
|
||||||
TstSignedTxBlockDetails = &Block{
|
TstSignedTxBlockDetails = &Block{
|
||||||
Height: TstSpendingTxBlockHeight,
|
Height: TstSpendingTxBlockHeight,
|
||||||
|
@ -68,11 +68,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
|
|
||||||
// Create a "signed" (with invalid sigs) tx that spends output 0 of
|
// Create a "signed" (with invalid sigs) tx that spends output 0 of
|
||||||
// the double spend.
|
// the double spend.
|
||||||
spendingTx := btcwire.NewMsgTx()
|
spendingTx := wire.NewMsgTx()
|
||||||
spendingTxIn := btcwire.NewTxIn(btcwire.NewOutPoint(TstDoubleSpendTx.Sha(), 0), []byte{0, 1, 2, 3, 4})
|
spendingTxIn := wire.NewTxIn(wire.NewOutPoint(TstDoubleSpendTx.Sha(), 0), []byte{0, 1, 2, 3, 4})
|
||||||
spendingTx.AddTxIn(spendingTxIn)
|
spendingTx.AddTxIn(spendingTxIn)
|
||||||
spendingTxOut1 := btcwire.NewTxOut(1e7, []byte{5, 6, 7, 8, 9})
|
spendingTxOut1 := wire.NewTxOut(1e7, []byte{5, 6, 7, 8, 9})
|
||||||
spendingTxOut2 := btcwire.NewTxOut(9e7, []byte{10, 11, 12, 13, 14})
|
spendingTxOut2 := wire.NewTxOut(9e7, []byte{10, 11, 12, 13, 14})
|
||||||
spendingTx.AddTxOut(spendingTxOut1)
|
spendingTx.AddTxOut(spendingTxOut1)
|
||||||
spendingTx.AddTxOut(spendingTxOut2)
|
spendingTx.AddTxOut(spendingTxOut2)
|
||||||
TstSpendingTx := btcutil.NewTx(spendingTx)
|
TstSpendingTx := btcutil.NewTx(spendingTx)
|
||||||
|
@ -82,8 +82,8 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
f func(*Store) (*Store, error)
|
f func(*Store) (*Store, error)
|
||||||
bal, unc btcutil.Amount
|
bal, unc btcutil.Amount
|
||||||
unspents map[btcwire.OutPoint]struct{}
|
unspents map[wire.OutPoint]struct{}
|
||||||
unmined map[btcwire.ShaHash]struct{}
|
unmined map[wire.ShaHash]struct{}
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "new store",
|
name: "new store",
|
||||||
|
@ -92,8 +92,8 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{},
|
unspents: map[wire.OutPoint]struct{}{},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "txout insert",
|
name: "txout insert",
|
||||||
|
@ -117,10 +117,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "insert duplicate unconfirmed",
|
name: "insert duplicate unconfirmed",
|
||||||
|
@ -143,10 +143,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "confirmed txout insert",
|
name: "confirmed txout insert",
|
||||||
|
@ -170,10 +170,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "insert duplicate confirmed",
|
name: "insert duplicate confirmed",
|
||||||
|
@ -197,10 +197,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "rollback confirmed credit",
|
name: "rollback confirmed credit",
|
||||||
|
@ -213,10 +213,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
unc: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "insert confirmed double spend",
|
name: "insert confirmed double spend",
|
||||||
|
@ -241,10 +241,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: btcutil.Amount(TstDoubleSpendTx.MsgTx().TxOut[0].Value),
|
bal: btcutil.Amount(TstDoubleSpendTx.MsgTx().TxOut[0].Value),
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstDoubleSpendTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstDoubleSpendTx.Sha(), 0): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "insert unconfirmed debit",
|
name: "insert unconfirmed debit",
|
||||||
|
@ -272,8 +272,8 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{},
|
unspents: map[wire.OutPoint]struct{}{},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{
|
unmined: map[wire.ShaHash]struct{}{
|
||||||
*TstSpendingTx.Sha(): {},
|
*TstSpendingTx.Sha(): {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -303,8 +303,8 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{},
|
unspents: map[wire.OutPoint]struct{}{},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{
|
unmined: map[wire.ShaHash]struct{}{
|
||||||
*TstSpendingTx.Sha(): {},
|
*TstSpendingTx.Sha(): {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -329,10 +329,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value),
|
unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value),
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{
|
unmined: map[wire.ShaHash]struct{}{
|
||||||
*TstSpendingTx.Sha(): {},
|
*TstSpendingTx.Sha(): {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -357,11 +357,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{
|
unmined: map[wire.ShaHash]struct{}{
|
||||||
*TstSpendingTx.Sha(): {},
|
*TstSpendingTx.Sha(): {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -382,11 +382,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
bal: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "rollback after spending tx",
|
name: "rollback after spending tx",
|
||||||
|
@ -399,11 +399,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
bal: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "rollback spending tx block",
|
name: "rollback spending tx block",
|
||||||
|
@ -416,11 +416,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{
|
unmined: map[wire.ShaHash]struct{}{
|
||||||
*TstSpendingTx.Sha(): {},
|
*TstSpendingTx.Sha(): {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -435,11 +435,11 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: 0,
|
bal: 0,
|
||||||
unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
unc: btcutil.Amount(TstSpendingTx.MsgTx().TxOut[0].Value + TstSpendingTx.MsgTx().TxOut[1].Value),
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 0): {},
|
||||||
*btcwire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
*wire.NewOutPoint(TstSpendingTx.Sha(), 1): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{
|
unmined: map[wire.ShaHash]struct{}{
|
||||||
*TstSpendingTx.Sha(): {},
|
*TstSpendingTx.Sha(): {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -465,10 +465,10 @@ func TestInsertsCreditsDebitsRollbacks(t *testing.T) {
|
||||||
},
|
},
|
||||||
bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
bal: btcutil.Amount(TstRecvTx.MsgTx().TxOut[0].Value),
|
||||||
unc: 0,
|
unc: 0,
|
||||||
unspents: map[btcwire.OutPoint]struct{}{
|
unspents: map[wire.OutPoint]struct{}{
|
||||||
*btcwire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
*wire.NewOutPoint(TstRecvTx.Sha(), 0): {},
|
||||||
},
|
},
|
||||||
unmined: map[btcwire.ShaHash]struct{}{},
|
unmined: map[wire.ShaHash]struct{}{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,7 +586,7 @@ func TestFindingSpentCredits(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
op := btcwire.NewOutPoint(TstSpendingTx.Sha(), 0)
|
op := wire.NewOutPoint(TstSpendingTx.Sha(), 0)
|
||||||
if *unspents[0].OutPoint() != *op {
|
if *unspents[0].OutPoint() != *op {
|
||||||
t.Fatal("unspent outpoint doesn't match expected")
|
t.Fatal("unspent outpoint doesn't match expected")
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
"github.com/btcsuite/fastsha256"
|
"github.com/btcsuite/fastsha256"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1116,7 +1116,7 @@ func putStartBlock(tx walletdb.Tx, bs *BlockStamp) error {
|
||||||
|
|
||||||
// fetchRecentBlocks returns the height of the most recent block height and
|
// fetchRecentBlocks returns the height of the most recent block height and
|
||||||
// hashes of the most recent blocks.
|
// hashes of the most recent blocks.
|
||||||
func fetchRecentBlocks(tx walletdb.Tx) (int32, []btcwire.ShaHash, error) {
|
func fetchRecentBlocks(tx walletdb.Tx) (int32, []wire.ShaHash, error) {
|
||||||
bucket := tx.RootBucket().Bucket(syncBucketName)
|
bucket := tx.RootBucket().Bucket(syncBucketName)
|
||||||
|
|
||||||
// The serialized recent blocks format is:
|
// The serialized recent blocks format is:
|
||||||
|
@ -1135,7 +1135,7 @@ func fetchRecentBlocks(tx walletdb.Tx) (int32, []btcwire.ShaHash, error) {
|
||||||
|
|
||||||
recentHeight := int32(binary.LittleEndian.Uint32(buf[0:4]))
|
recentHeight := int32(binary.LittleEndian.Uint32(buf[0:4]))
|
||||||
numHashes := binary.LittleEndian.Uint32(buf[4:8])
|
numHashes := binary.LittleEndian.Uint32(buf[4:8])
|
||||||
recentHashes := make([]btcwire.ShaHash, numHashes)
|
recentHashes := make([]wire.ShaHash, numHashes)
|
||||||
offset := 8
|
offset := 8
|
||||||
for i := uint32(0); i < numHashes; i++ {
|
for i := uint32(0); i < numHashes; i++ {
|
||||||
copy(recentHashes[i][:], buf[offset:offset+32])
|
copy(recentHashes[i][:], buf[offset:offset+32])
|
||||||
|
@ -1146,7 +1146,7 @@ func fetchRecentBlocks(tx walletdb.Tx) (int32, []btcwire.ShaHash, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// putRecentBlocks stores the provided start block stamp to the database.
|
// putRecentBlocks stores the provided start block stamp to the database.
|
||||||
func putRecentBlocks(tx walletdb.Tx, recentHeight int32, recentHashes []btcwire.ShaHash) error {
|
func putRecentBlocks(tx walletdb.Tx, recentHeight int32, recentHashes []wire.ShaHash) error {
|
||||||
bucket := tx.RootBucket().Bucket(syncBucketName)
|
bucket := tx.RootBucket().Bucket(syncBucketName)
|
||||||
|
|
||||||
// The serialized recent blocks format is:
|
// The serialized recent blocks format is:
|
||||||
|
|
|
@ -22,13 +22,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcec"
|
"github.com/btcsuite/btcec"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcutil/hdkeychain"
|
"github.com/btcsuite/btcutil/hdkeychain"
|
||||||
"github.com/btcsuite/btcwallet/snacl"
|
"github.com/btcsuite/btcwallet/snacl"
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -1724,7 +1724,7 @@ func loadManager(namespace walletdb.Namespace, pubPassphrase []byte, net *btcnet
|
||||||
var cryptoKeyPubEnc, cryptoKeyPrivEnc, cryptoKeyScriptEnc []byte
|
var cryptoKeyPubEnc, cryptoKeyPrivEnc, cryptoKeyScriptEnc []byte
|
||||||
var syncedTo, startBlock *BlockStamp
|
var syncedTo, startBlock *BlockStamp
|
||||||
var recentHeight int32
|
var recentHeight int32
|
||||||
var recentHashes []btcwire.ShaHash
|
var recentHashes []wire.ShaHash
|
||||||
err := namespace.View(func(tx walletdb.Tx) error {
|
err := namespace.View(func(tx walletdb.Tx) error {
|
||||||
// Load whether or not the manager is watching-only from the db.
|
// Load whether or not the manager is watching-only from the db.
|
||||||
var err error
|
var err error
|
||||||
|
@ -2012,7 +2012,7 @@ func Create(namespace walletdb.Namespace, seed, pubPassphrase, privPassphrase []
|
||||||
createdAt := &BlockStamp{Hash: *net.GenesisHash, Height: 0}
|
createdAt := &BlockStamp{Hash: *net.GenesisHash, Height: 0}
|
||||||
|
|
||||||
// Create the initial sync state.
|
// Create the initial sync state.
|
||||||
recentHashes := []btcwire.ShaHash{createdAt.Hash}
|
recentHashes := []wire.ShaHash{createdAt.Hash}
|
||||||
recentHeight := createdAt.Height
|
recentHeight := createdAt.Height
|
||||||
syncInfo := newSyncState(createdAt, createdAt, recentHeight, recentHashes)
|
syncInfo := newSyncState(createdAt, createdAt, recentHeight, recentHashes)
|
||||||
|
|
||||||
|
|
|
@ -23,19 +23,19 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// newShaHash converts the passed big-endian hex string into a btcwire.ShaHash.
|
// newShaHash converts the passed big-endian hex string into a wire.ShaHash.
|
||||||
// It only differs from the one available in btcwire in that it panics on an
|
// It only differs from the one available in wire in that it panics on an
|
||||||
// error since it will only (and must only) be called with hard-coded, and
|
// error since it will only (and must only) be called with hard-coded, and
|
||||||
// therefore known good, hashes.
|
// therefore known good, hashes.
|
||||||
func newShaHash(hexStr string) *btcwire.ShaHash {
|
func newShaHash(hexStr string) *wire.ShaHash {
|
||||||
sha, err := btcwire.NewShaHashFromStr(hexStr)
|
sha, err := wire.NewShaHashFromStr(hexStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -1207,7 +1207,7 @@ func testWatchingOnly(tc *testContext) bool {
|
||||||
func testSync(tc *testContext) bool {
|
func testSync(tc *testContext) bool {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
hash *btcwire.ShaHash
|
hash *wire.ShaHash
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Block 1",
|
name: "Block 1",
|
||||||
|
@ -1328,7 +1328,7 @@ func testSync(tc *testContext) bool {
|
||||||
iter := tc.manager.NewIterateRecentBlocks()
|
iter := tc.manager.NewIterateRecentBlocks()
|
||||||
for cont := iter != nil; cont; cont = iter.Prev() {
|
for cont := iter != nil; cont; cont = iter.Prev() {
|
||||||
wantHeight := int32(i) - int32(j) + 1
|
wantHeight := int32(i) - int32(j) + 1
|
||||||
var wantHash *btcwire.ShaHash
|
var wantHash *wire.ShaHash
|
||||||
if wantHeight == 0 {
|
if wantHeight == 0 {
|
||||||
wantHash = btcnet.MainNetParams.GenesisHash
|
wantHash = btcnet.MainNetParams.GenesisHash
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,8 +19,8 @@ package waddrmgr
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -34,7 +34,7 @@ const (
|
||||||
// synced to.
|
// synced to.
|
||||||
type BlockStamp struct {
|
type BlockStamp struct {
|
||||||
Height int32
|
Height int32
|
||||||
Hash btcwire.ShaHash
|
Hash wire.ShaHash
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncState houses the sync state of the manager. It consists of the recently
|
// syncState houses the sync state of the manager. It consists of the recently
|
||||||
|
@ -53,7 +53,7 @@ type syncState struct {
|
||||||
recentHeight int32
|
recentHeight int32
|
||||||
|
|
||||||
// recentHashes is a list of the last several seen block hashes.
|
// recentHashes is a list of the last several seen block hashes.
|
||||||
recentHashes []btcwire.ShaHash
|
recentHashes []wire.ShaHash
|
||||||
}
|
}
|
||||||
|
|
||||||
// iter returns a BlockIterator that can be used to iterate over the recently
|
// iter returns a BlockIterator that can be used to iterate over the recently
|
||||||
|
@ -72,7 +72,7 @@ func (s *syncState) iter(mtx *sync.RWMutex) *BlockIterator {
|
||||||
|
|
||||||
// newSyncState returns a new sync state with the provided parameters.
|
// newSyncState returns a new sync state with the provided parameters.
|
||||||
func newSyncState(startBlock, syncedTo *BlockStamp, recentHeight int32,
|
func newSyncState(startBlock, syncedTo *BlockStamp, recentHeight int32,
|
||||||
recentHashes []btcwire.ShaHash) *syncState {
|
recentHashes []wire.ShaHash) *syncState {
|
||||||
|
|
||||||
return &syncState{
|
return &syncState{
|
||||||
startBlock: *startBlock,
|
startBlock: *startBlock,
|
||||||
|
|
20
wallet.go
20
wallet.go
|
@ -27,13 +27,13 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/blockchain"
|
"github.com/btcsuite/btcd/blockchain"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcjson"
|
"github.com/btcsuite/btcjson"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/chain"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/btcsuite/btcwallet/keystore"
|
"github.com/btcsuite/btcwallet/keystore"
|
||||||
"github.com/btcsuite/btcwallet/txstore"
|
"github.com/btcsuite/btcwallet/txstore"
|
||||||
"github.com/btcsuite/btcwire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -54,7 +54,7 @@ func networkDir(net *btcnet.Params) string {
|
||||||
// paramaters will likely be switched to being named "testnet3" in the
|
// paramaters will likely be switched to being named "testnet3" in the
|
||||||
// future. This is done to future proof that change, and an upgrade
|
// future. This is done to future proof that change, and an upgrade
|
||||||
// plan to move the testnet3 data directory can be worked out later.
|
// plan to move the testnet3 data directory can be worked out later.
|
||||||
if net.Net == btcwire.TestNet3 {
|
if net.Net == wire.TestNet3 {
|
||||||
netname = "testnet"
|
netname = "testnet"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ type Wallet struct {
|
||||||
chainSvrLock sync.Locker
|
chainSvrLock sync.Locker
|
||||||
chainSynced chan struct{} // closed when synced
|
chainSynced chan struct{} // closed when synced
|
||||||
|
|
||||||
lockedOutpoints map[btcwire.OutPoint]struct{}
|
lockedOutpoints map[wire.OutPoint]struct{}
|
||||||
FeeIncrement btcutil.Amount
|
FeeIncrement btcutil.Amount
|
||||||
|
|
||||||
// Channels for rescan processing. Requests are added and merged with
|
// Channels for rescan processing. Requests are added and merged with
|
||||||
|
@ -117,7 +117,7 @@ func newWallet(keys *keystore.Store, txs *txstore.Store) *Wallet {
|
||||||
TxStore: txs,
|
TxStore: txs,
|
||||||
chainSvrLock: new(sync.Mutex),
|
chainSvrLock: new(sync.Mutex),
|
||||||
chainSynced: make(chan struct{}),
|
chainSynced: make(chan struct{}),
|
||||||
lockedOutpoints: map[btcwire.OutPoint]struct{}{},
|
lockedOutpoints: map[wire.OutPoint]struct{}{},
|
||||||
FeeIncrement: defaultFeeIncrement,
|
FeeIncrement: defaultFeeIncrement,
|
||||||
rescanAddJob: make(chan *RescanJob),
|
rescanAddJob: make(chan *RescanJob),
|
||||||
rescanBatch: make(chan *rescanBatch),
|
rescanBatch: make(chan *rescanBatch),
|
||||||
|
@ -1110,27 +1110,27 @@ func (w *Wallet) exportBase64() (map[string]string, error) {
|
||||||
|
|
||||||
// LockedOutpoint returns whether an outpoint has been marked as locked and
|
// LockedOutpoint returns whether an outpoint has been marked as locked and
|
||||||
// should not be used as an input for created transactions.
|
// should not be used as an input for created transactions.
|
||||||
func (w *Wallet) LockedOutpoint(op btcwire.OutPoint) bool {
|
func (w *Wallet) LockedOutpoint(op wire.OutPoint) bool {
|
||||||
_, locked := w.lockedOutpoints[op]
|
_, locked := w.lockedOutpoints[op]
|
||||||
return locked
|
return locked
|
||||||
}
|
}
|
||||||
|
|
||||||
// LockOutpoint marks an outpoint as locked, that is, it should not be used as
|
// LockOutpoint marks an outpoint as locked, that is, it should not be used as
|
||||||
// an input for newly created transactions.
|
// an input for newly created transactions.
|
||||||
func (w *Wallet) LockOutpoint(op btcwire.OutPoint) {
|
func (w *Wallet) LockOutpoint(op wire.OutPoint) {
|
||||||
w.lockedOutpoints[op] = struct{}{}
|
w.lockedOutpoints[op] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnlockOutpoint marks an outpoint as unlocked, that is, it may be used as an
|
// UnlockOutpoint marks an outpoint as unlocked, that is, it may be used as an
|
||||||
// input for newly created transactions.
|
// input for newly created transactions.
|
||||||
func (w *Wallet) UnlockOutpoint(op btcwire.OutPoint) {
|
func (w *Wallet) UnlockOutpoint(op wire.OutPoint) {
|
||||||
delete(w.lockedOutpoints, op)
|
delete(w.lockedOutpoints, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetLockedOutpoints resets the set of locked outpoints so all may be used
|
// ResetLockedOutpoints resets the set of locked outpoints so all may be used
|
||||||
// as inputs for new transactions.
|
// as inputs for new transactions.
|
||||||
func (w *Wallet) ResetLockedOutpoints() {
|
func (w *Wallet) ResetLockedOutpoints() {
|
||||||
w.lockedOutpoints = map[btcwire.OutPoint]struct{}{}
|
w.lockedOutpoints = map[wire.OutPoint]struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LockedOutpoints returns a slice of currently locked outpoints. This is
|
// LockedOutpoints returns a slice of currently locked outpoints. This is
|
||||||
|
@ -1310,7 +1310,7 @@ func (w *Wallet) RecoverAddresses(n int) error {
|
||||||
// ReqSpentUtxoNtfns sends a message to btcd to request updates for when
|
// ReqSpentUtxoNtfns sends a message to btcd to request updates for when
|
||||||
// a stored UTXO has been spent.
|
// a stored UTXO has been spent.
|
||||||
func (w *Wallet) ReqSpentUtxoNtfns(credits []txstore.Credit) {
|
func (w *Wallet) ReqSpentUtxoNtfns(credits []txstore.Credit) {
|
||||||
ops := make([]*btcwire.OutPoint, len(credits))
|
ops := make([]*wire.OutPoint, len(credits))
|
||||||
for i, c := range credits {
|
for i, c := range credits {
|
||||||
op := c.OutPoint()
|
op := c.OutPoint()
|
||||||
log.Debugf("Requesting spent UTXO notifications for Outpoint "+
|
log.Debugf("Requesting spent UTXO notifications for Outpoint "+
|
||||||
|
@ -1387,7 +1387,7 @@ func (w *Wallet) TotalReceivedForAddr(addr btcutil.Address, confirms int) (btcut
|
||||||
|
|
||||||
// TxRecord iterates through all transaction records saved in the store,
|
// TxRecord iterates through all transaction records saved in the store,
|
||||||
// returning the first with an equivalent transaction hash.
|
// returning the first with an equivalent transaction hash.
|
||||||
func (w *Wallet) TxRecord(txSha *btcwire.ShaHash) (r *txstore.TxRecord, ok bool) {
|
func (w *Wallet) TxRecord(txSha *wire.ShaHash) (r *txstore.TxRecord, ok bool) {
|
||||||
for _, r = range w.TxStore.Records() {
|
for _, r = range w.TxStore.Records() {
|
||||||
if *r.Tx().Sha() == *txSha {
|
if *r.Tx().Sha() == *txSha {
|
||||||
return r, true
|
return r, true
|
||||||
|
|
Loading…
Add table
Reference in a new issue