Merge pull request #1933 from yaslama/transactions-addresses
Add addresses to transactions returned by SubscribeTransactions
This commit is contained in:
commit
f819002b7a
@ -556,6 +556,7 @@ func minedTransactionsToDetails(
|
|||||||
// for an unconfirmed transaction to a transaction detail.
|
// for an unconfirmed transaction to a transaction detail.
|
||||||
func unminedTransactionsToDetail(
|
func unminedTransactionsToDetail(
|
||||||
summary base.TransactionSummary,
|
summary base.TransactionSummary,
|
||||||
|
chainParams *chaincfg.Params,
|
||||||
) (*lnwallet.TransactionDetail, error) {
|
) (*lnwallet.TransactionDetail, error) {
|
||||||
|
|
||||||
wireTx := &wire.MsgTx{}
|
wireTx := &wire.MsgTx{}
|
||||||
@ -565,10 +566,22 @@ func unminedTransactionsToDetail(
|
|||||||
return nil, err
|
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: *summary.Hash,
|
Hash: *summary.Hash,
|
||||||
TotalFees: int64(summary.Fee),
|
TotalFees: int64(summary.Fee),
|
||||||
Timestamp: summary.Timestamp,
|
Timestamp: summary.Timestamp,
|
||||||
|
DestAddresses: destAddresses,
|
||||||
RawTx: summary.Transaction,
|
RawTx: summary.Transaction,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,7 +631,7 @@ func (b *BtcWallet) ListTransactionDetails() ([]*lnwallet.TransactionDetail, err
|
|||||||
txDetails = append(txDetails, details...)
|
txDetails = append(txDetails, details...)
|
||||||
}
|
}
|
||||||
for _, tx := range txns.UnminedTransactions {
|
for _, tx := range txns.UnminedTransactions {
|
||||||
detail, err := unminedTransactionsToDetail(tx)
|
detail, err := unminedTransactionsToDetail(tx, b.netParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -705,7 +718,9 @@ out:
|
|||||||
// notifications for any newly unconfirmed transactions.
|
// notifications for any newly unconfirmed transactions.
|
||||||
go func() {
|
go func() {
|
||||||
for _, tx := range txNtfn.UnminedTransactions {
|
for _, tx := range txNtfn.UnminedTransactions {
|
||||||
detail, err := unminedTransactionsToDetail(tx)
|
detail, err := unminedTransactionsToDetail(
|
||||||
|
tx, t.w.ChainParams(),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1181,9 +1181,11 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
|||||||
|
|
||||||
// Next create a transaction paying to an output which isn't under the
|
// Next create a transaction paying to an output which isn't under the
|
||||||
// wallet's control.
|
// wallet's control.
|
||||||
b := txscript.NewScriptBuilder()
|
minerAddr, err := miner.NewAddress()
|
||||||
b.AddOp(txscript.OP_0)
|
if err != nil {
|
||||||
outputScript, err := b.Script()
|
t.Fatalf("unable to generate address: %v", err)
|
||||||
|
}
|
||||||
|
outputScript, err := txscript.PayToAddrScript(minerAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to make output script: %v", err)
|
t.Fatalf("unable to make output script: %v", err)
|
||||||
}
|
}
|
||||||
@ -1227,6 +1229,20 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
|||||||
t.Fatalf("num confs incorrect, got %v expected %v",
|
t.Fatalf("num confs incorrect, got %v expected %v",
|
||||||
txDetail.NumConfirmations, 0)
|
txDetail.NumConfirmations, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We test that each txDetail has destination addresses. This ensures
|
||||||
|
// that even when we have 0 confirmation transactions, the destination
|
||||||
|
// addresses are returned.
|
||||||
|
var match bool
|
||||||
|
for _, addr := range txDetail.DestAddresses {
|
||||||
|
if addr.String() == minerAddr.String() {
|
||||||
|
match = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !match {
|
||||||
|
t.Fatalf("minerAddr: %v should have been a dest addr", minerAddr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !mempoolTxFound {
|
if !mempoolTxFound {
|
||||||
t.Fatalf("unable to find mempool tx in tx details!")
|
t.Fatalf("unable to find mempool tx in tx details!")
|
||||||
|
10
rpcserver.go
10
rpcserver.go
@ -3576,6 +3576,10 @@ func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest,
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case tx := <-txClient.ConfirmedTransactions():
|
case tx := <-txClient.ConfirmedTransactions():
|
||||||
|
destAddresses := make([]string, 0, len(tx.DestAddresses))
|
||||||
|
for _, destAddress := range tx.DestAddresses {
|
||||||
|
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
||||||
|
}
|
||||||
detail := &lnrpc.Transaction{
|
detail := &lnrpc.Transaction{
|
||||||
TxHash: tx.Hash.String(),
|
TxHash: tx.Hash.String(),
|
||||||
Amount: int64(tx.Value),
|
Amount: int64(tx.Value),
|
||||||
@ -3583,6 +3587,7 @@ func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest,
|
|||||||
BlockHash: tx.BlockHash.String(),
|
BlockHash: tx.BlockHash.String(),
|
||||||
TimeStamp: tx.Timestamp,
|
TimeStamp: tx.Timestamp,
|
||||||
TotalFees: tx.TotalFees,
|
TotalFees: tx.TotalFees,
|
||||||
|
DestAddresses: destAddresses,
|
||||||
RawTxHex: hex.EncodeToString(tx.RawTx),
|
RawTxHex: hex.EncodeToString(tx.RawTx),
|
||||||
}
|
}
|
||||||
if err := updateStream.Send(detail); err != nil {
|
if err := updateStream.Send(detail); err != nil {
|
||||||
@ -3590,11 +3595,16 @@ func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case tx := <-txClient.UnconfirmedTransactions():
|
case tx := <-txClient.UnconfirmedTransactions():
|
||||||
|
var destAddresses []string
|
||||||
|
for _, destAddress := range tx.DestAddresses {
|
||||||
|
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
||||||
|
}
|
||||||
detail := &lnrpc.Transaction{
|
detail := &lnrpc.Transaction{
|
||||||
TxHash: tx.Hash.String(),
|
TxHash: tx.Hash.String(),
|
||||||
Amount: int64(tx.Value),
|
Amount: int64(tx.Value),
|
||||||
TimeStamp: tx.Timestamp,
|
TimeStamp: tx.Timestamp,
|
||||||
TotalFees: tx.TotalFees,
|
TotalFees: tx.TotalFees,
|
||||||
|
DestAddresses: destAddresses,
|
||||||
RawTxHex: hex.EncodeToString(tx.RawTx),
|
RawTxHex: hex.EncodeToString(tx.RawTx),
|
||||||
}
|
}
|
||||||
if err := updateStream.Send(detail); err != nil {
|
if err := updateStream.Send(detail); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user