Skip to content

Commit

Permalink
Integrate wtxmgr package.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Apr 8, 2015
1 parent 15856af commit a6c9c73
Show file tree
Hide file tree
Showing 10 changed files with 894 additions and 669 deletions.
83 changes: 34 additions & 49 deletions chain/chain.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014 Conformal Systems LLC <[email protected]>
* Copyright (c) 2013-2015 Conformal Systems LLC <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -26,8 +26,8 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcrpcclient"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwallet/legacy/txstore"
"github.com/btcsuite/btcwallet/waddrmgr"
"github.com/btcsuite/btcwallet/wtxmgr"
)

// Client represents a persistent client connection to a bitcoin RPC server
Expand Down Expand Up @@ -159,18 +159,11 @@ type (
// BlockStamp was reorganized out of the best chain.
BlockDisconnected waddrmgr.BlockStamp

// RecvTx is a notification for a transaction which pays to a wallet
// address.
RecvTx struct {
Tx *btcutil.Tx // Index is guaranteed to be set.
Block *txstore.Block // nil if unmined
}

// RedeemingTx is a notification for a transaction which spends an
// output controlled by the wallet.
RedeemingTx struct {
Tx *btcutil.Tx // Index is guaranteed to be set.
Block *txstore.Block // nil if unmined
// RelevantTx is a notification for a transaction which spends wallet
// inputs or pays to a watched address.
RelevantTx struct {
TxRecord *wtxmgr.TxRecord
Block *wtxmgr.BlockMeta // nil if unmined
}

// RescanProgress is a notification describing the current status
Expand Down Expand Up @@ -209,23 +202,25 @@ func (c *Client) BlockStamp() (*waddrmgr.BlockStamp, error) {
}
}

// parseBlock parses a btcjson definition of the block a tx is mined it to the
// Block structure of the txstore package, and the block index. This is done
// parseBlock parses a btcws definition of the block a tx is mined it to the
// Block structure of the wtxmgr package, and the block index. This is done
// here since btcrpcclient doesn't parse this nicely for us.
func parseBlock(block *btcjson.BlockDetails) (blk *txstore.Block, idx int, err error) {
func parseBlock(block *btcjson.BlockDetails) (*wtxmgr.BlockMeta, error) {
if block == nil {
return nil, btcutil.TxIndexUnknown, nil
return nil, nil
}
blksha, err := wire.NewShaHashFromStr(block.Hash)
if err != nil {
return nil, btcutil.TxIndexUnknown, err
return nil, err
}
blk = &txstore.Block{
Height: block.Height,
Hash: *blksha,
Time: time.Unix(block.Time, 0),
blk := &wtxmgr.BlockMeta{
Block: wtxmgr.Block{
Height: block.Height,
Hash: *blksha,
},
Time: time.Unix(block.Time, 0),
}
return blk, block.Index, nil
return blk, nil
}

func (c *Client) onClientConnect() {
Expand All @@ -242,35 +237,25 @@ func (c *Client) onBlockDisconnected(hash *wire.ShaHash, height int32) {
}

func (c *Client) onRecvTx(tx *btcutil.Tx, block *btcjson.BlockDetails) {
var blk *txstore.Block
index := btcutil.TxIndexUnknown
if block != nil {
var err error
blk, index, err = parseBlock(block)
if err != nil {
// Log and drop improper notification.
log.Errorf("recvtx notification bad block: %v", err)
return
}
blk, err := parseBlock(block)
if err != nil {
// Log and drop improper notification.
log.Errorf("recvtx notification bad block: %v", err)
return
}
tx.SetIndex(index)
c.enqueueNotification <- RecvTx{tx, blk}

rec, err := wtxmgr.NewTxRecordFromMsgTx(tx.MsgTx(), time.Now())
if err != nil {
log.Errorf("Cannot create transaction record for relevant "+
"tx: %v", err)
return
}
c.enqueueNotification <- RelevantTx{rec, blk}
}

func (c *Client) onRedeemingTx(tx *btcutil.Tx, block *btcjson.BlockDetails) {
var blk *txstore.Block
index := btcutil.TxIndexUnknown
if block != nil {
var err error
blk, index, err = parseBlock(block)
if err != nil {
// Log and drop improper notification.
log.Errorf("redeemingtx notification bad block: %v", err)
return
}
}
tx.SetIndex(index)
c.enqueueNotification <- RedeemingTx{tx, blk}
// Handled exactly like recvtx notifications.
c.onRecvTx(tx, block)
}

func (c *Client) onRescanProgress(hash *wire.ShaHash, height int32, blkTime time.Time) {
Expand Down
10 changes: 5 additions & 5 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/btcsuite/btclog"
"github.com/btcsuite/btcwallet/chain"
"github.com/btcsuite/btcwallet/legacy/txstore"
"github.com/btcsuite/btcwallet/wtxmgr"
"github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/seelog"
)
Expand All @@ -44,15 +44,15 @@ var (
backendLog = seelog.Disabled
log = btclog.Disabled
walletLog = btclog.Disabled
txstLog = btclog.Disabled
txmgrLog = btclog.Disabled
chainLog = btclog.Disabled
)

// subsystemLoggers maps each subsystem identifier to its associated logger.
var subsystemLoggers = map[string]btclog.Logger{
"BTCW": log,
"WLLT": walletLog,
"TXST": txstLog,
"TXST": txmgrLog,
"CHNS": chainLog,
}

Expand Down Expand Up @@ -87,8 +87,8 @@ func useLogger(subsystemID string, logger btclog.Logger) {
walletLog = logger
wallet.UseLogger(logger)
case "TXST":
txstLog = logger
txstore.UseLogger(logger)
txmgrLog = logger
wtxmgr.UseLogger(logger)
case "CHNS":
chainLog = logger
chain.UseLogger(logger)
Expand Down
Loading

0 comments on commit a6c9c73

Please sign in to comment.