lnwallet: Add destination addresses to listchaintxns

This commit is contained in:
Micah Lerner authored and Olaoluwa Osuntokun committed 2017-12-08 15:11:23 -08:00
1 parent 9e4da6566a
commit 6ae7d275ab
3 files changed
+52 -15

No files matched your search

+43 -15
View File
@@ -395,13 +395,10 @@ func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx) error {
// extractBalanceDelta extracts the net balance delta from the PoV of the // extractBalanceDelta extracts the net balance delta from the PoV of the
// wallet given a TransactionSummary. // wallet given a TransactionSummary.
func extractBalanceDelta(txSummary base.TransactionSummary) (btcutil.Amount, error) { func extractBalanceDelta(
tx := wire.NewMsgTx(1) txSummary base.TransactionSummary,
txReader := bytes.NewReader(txSummary.Transaction) tx *wire.MsgTx,
if err := tx.Deserialize(txReader); err != nil { ) (btcutil.Amount, error) {
return -1, nil
}
// For each input we debit the wallet's outflow for this transaction, // For each input we debit the wallet's outflow for this transaction,
// and for each output we credit the wallet's inflow for this // and for each output we credit the wallet's inflow for this
// transaction. // transaction.
@@ -418,11 +415,32 @@ func extractBalanceDelta(txSummary base.TransactionSummary) (btcutil.Amount, err
// minedTransactionsToDetails is a helper function which converts a summary // minedTransactionsToDetails is a helper function which converts a summary
// information about mined transactions to a TransactionDetail. // information about mined transactions to a TransactionDetail.
func minedTransactionsToDetails(currentHeight int32, func minedTransactionsToDetails(
block base.Block) ([]*lnwallet.TransactionDetail, error) { currentHeight int32,
block base.Block,
chainParams *chaincfg.Params,
) ([]*lnwallet.TransactionDetail, error) {
details := make([]*lnwallet.TransactionDetail, 0, len(block.Transactions)) details := make([]*lnwallet.TransactionDetail, 0, len(block.Transactions))
for _, tx := range block.Transactions { for _, tx := range block.Transactions {
wireTx := &wire.MsgTx{}
txReader := bytes.NewReader(tx.Transaction)
if err := wireTx.Deserialize(txReader); err != nil {
return nil, err
}
var destAddresses []btcutil.Address
for _, txOut := range wireTx.TxOut {
_, outAddresses, _, err :=
txscript.ExtractPkScriptAddrs(txOut.PkScript, chainParams)
if err != nil {
return nil, err
}
destAddresses = append(destAddresses, outAddresses...)
}
txDetail := &lnwallet.TransactionDetail{ txDetail := &lnwallet.TransactionDetail{
Hash: *tx.Hash, Hash: *tx.Hash,
NumConfirmations: currentHeight - block.Height + 1, NumConfirmations: currentHeight - block.Height + 1,
@@ -430,9 +448,10 @@ func minedTransactionsToDetails(currentHeight int32,
BlockHeight: block.Height, BlockHeight: block.Height,
Timestamp: block.Timestamp, Timestamp: block.Timestamp,
TotalFees: int64(tx.Fee), TotalFees: int64(tx.Fee),
DestAddresses: destAddresses,
} }
balanceDelta, err := extractBalanceDelta(tx) balanceDelta, err := extractBalanceDelta(tx, wireTx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -444,16 +463,25 @@ func minedTransactionsToDetails(currentHeight int32,
return details, nil return details, nil
} }
// unminedTransactionsToDetail is a helper funciton which converts a summary // unminedTransactionsToDetail is a helper function which converts a summary
// for a unconfirmed transaction to a transaction detail. // for a unconfirmed transaction to a transaction detail.
func unminedTransactionsToDetail(summary base.TransactionSummary) (*lnwallet.TransactionDetail, error) { func unminedTransactionsToDetail(
summary base.TransactionSummary,
) (*lnwallet.TransactionDetail, error) {
wireTx := &wire.MsgTx{}
txReader := bytes.NewReader(summary.Transaction)
if err := wireTx.Deserialize(txReader); err != nil {
return nil, err
}
txDetail := &lnwallet.TransactionDetail{ txDetail := &lnwallet.TransactionDetail{
Hash: *summary.Hash, Hash: *summary.Hash,
TotalFees: int64(summary.Fee), TotalFees: int64(summary.Fee),
Timestamp: summary.Timestamp, Timestamp: summary.Timestamp,
} }
balanceDelta, err := extractBalanceDelta(summary) balanceDelta, err := extractBalanceDelta(summary, wireTx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -487,7 +515,7 @@ func (b *BtcWallet) ListTransactionDetails() ([]*lnwallet.TransactionDetail, err
// TransactionDetail which re-packages the data returned by the base // TransactionDetail which re-packages the data returned by the base
// wallet. // wallet.
for _, blockPackage := range txns.MinedTransactions { for _, blockPackage := range txns.MinedTransactions {
details, err := minedTransactionsToDetails(currentHeight, blockPackage) details, err := minedTransactionsToDetails(currentHeight, blockPackage, b.netParams)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -562,7 +590,7 @@ out:
// notifications for any newly confirmed transactions. // notifications for any newly confirmed transactions.
go func() { go func() {
for _, block := range txNtfn.AttachedBlocks { for _, block := range txNtfn.AttachedBlocks {
details, err := minedTransactionsToDetails(currentHeight, block) details, err := minedTransactionsToDetails(currentHeight, block, t.w.ChainParams())
if err != nil { if err != nil {
continue continue
} }
+3
View File
@@ -79,6 +79,9 @@ type TransactionDetail struct {
// TotalFees is the total fee in satoshis paid by this transaction. // TotalFees is the total fee in satoshis paid by this transaction.
TotalFees int64 TotalFees int64
// DestAddresses are the destinations for a transaction
DestAddresses []btcutil.Address
} }
// TransactionSubscription is an interface which describes an object capable of // TransactionSubscription is an interface which describes an object capable of
+6
View File
@@ -2349,6 +2349,11 @@ func (r *rpcServer) GetTransactions(ctx context.Context,
Transactions: make([]*lnrpc.Transaction, len(transactions)), Transactions: make([]*lnrpc.Transaction, len(transactions)),
} }
for i, tx := range transactions { for i, tx := range transactions {
var destAddresses []string
for _, destAddress := range tx.DestAddresses {
destAddresses = append(destAddresses, destAddress.EncodeAddress())
}
txDetails.Transactions[i] = &lnrpc.Transaction{ txDetails.Transactions[i] = &lnrpc.Transaction{
TxHash: tx.Hash.String(), TxHash: tx.Hash.String(),
Amount: int64(tx.Value), Amount: int64(tx.Value),
@@ -2357,6 +2362,7 @@ func (r *rpcServer) GetTransactions(ctx context.Context,
BlockHeight: tx.BlockHeight, BlockHeight: tx.BlockHeight,
TimeStamp: tx.Timestamp, TimeStamp: tx.Timestamp,
TotalFees: tx.TotalFees, TotalFees: tx.TotalFees,
DestAddresses: destAddresses,
} }
} }