mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
btcwallet: populate data to DestOutput field
Adds the output script and amount to the `DestOutput` field of `TransactionDetails`, as well as sets the flag `isOurAddress` if the output is controlled by the node's wallet.
This commit is contained in:
@@ -1013,18 +1013,37 @@ func minedTransactionsToDetails(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// isOurAddress is a map containing the output indices
|
||||
// controlled by the wallet.
|
||||
// Note: We make use of the information in `MyOutputs` provided
|
||||
// by the `wallet.TransactionSummary` structure that holds
|
||||
// information only if the output is controlled by the wallet.
|
||||
isOurAddress := make(map[int]bool, len(tx.MyOutputs))
|
||||
for _, o := range tx.MyOutputs {
|
||||
isOurAddress[int(o.Index)] = true
|
||||
}
|
||||
|
||||
var destAddresses []btcutil.Address
|
||||
for _, txOut := range wireTx.TxOut {
|
||||
_, outAddresses, _, err := txscript.ExtractPkScriptAddrs(
|
||||
var outputDetails []lnwallet.OutputDetail
|
||||
for i, txOut := range wireTx.TxOut {
|
||||
var addresses []btcutil.Address
|
||||
sc, outAddresses, _, err := txscript.ExtractPkScriptAddrs(
|
||||
txOut.PkScript, chainParams,
|
||||
)
|
||||
if err != nil {
|
||||
// Skip any unsupported addresses to prevent
|
||||
// other transactions from not being returned.
|
||||
continue
|
||||
if err == nil {
|
||||
// Add supported addresses.
|
||||
destAddresses = append(destAddresses, outAddresses...)
|
||||
addresses = outAddresses
|
||||
}
|
||||
|
||||
destAddresses = append(destAddresses, outAddresses...)
|
||||
outputDetails = append(outputDetails, lnwallet.OutputDetail{
|
||||
OutputType: sc,
|
||||
Addresses: addresses,
|
||||
PkScript: txOut.PkScript,
|
||||
OutputIndex: i,
|
||||
Value: btcutil.Amount(txOut.Value),
|
||||
IsOurAddress: isOurAddress[i],
|
||||
})
|
||||
}
|
||||
|
||||
txDetail := &lnwallet.TransactionDetail{
|
||||
@@ -1035,6 +1054,7 @@ func minedTransactionsToDetails(
|
||||
Timestamp: block.Timestamp,
|
||||
TotalFees: int64(tx.Fee),
|
||||
DestAddresses: destAddresses,
|
||||
OutputDetails: outputDetails,
|
||||
RawTx: tx.Transaction,
|
||||
Label: tx.Label,
|
||||
}
|
||||
@@ -1065,17 +1085,37 @@ func unminedTransactionsToDetail(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// isOurAddress is a map containing the output indices controlled by
|
||||
// the wallet.
|
||||
// Note: We make use of the information in `MyOutputs` provided
|
||||
// by the `wallet.TransactionSummary` structure that holds information
|
||||
// only if the output is controlled by the wallet.
|
||||
isOurAddress := make(map[int]bool, len(summary.MyOutputs))
|
||||
for _, o := range summary.MyOutputs {
|
||||
isOurAddress[int(o.Index)] = true
|
||||
}
|
||||
|
||||
var destAddresses []btcutil.Address
|
||||
for _, txOut := range wireTx.TxOut {
|
||||
_, outAddresses, _, err :=
|
||||
txscript.ExtractPkScriptAddrs(txOut.PkScript, chainParams)
|
||||
if err != nil {
|
||||
// Skip any unsupported addresses to prevent other
|
||||
// transactions from not being returned.
|
||||
continue
|
||||
var outputDetails []lnwallet.OutputDetail
|
||||
for i, txOut := range wireTx.TxOut {
|
||||
var addresses []btcutil.Address
|
||||
sc, outAddresses, _, err := txscript.ExtractPkScriptAddrs(
|
||||
txOut.PkScript, chainParams,
|
||||
)
|
||||
if err == nil {
|
||||
// Add supported addresses.
|
||||
destAddresses = append(destAddresses, outAddresses...)
|
||||
addresses = outAddresses
|
||||
}
|
||||
|
||||
destAddresses = append(destAddresses, outAddresses...)
|
||||
outputDetails = append(outputDetails, lnwallet.OutputDetail{
|
||||
OutputType: sc,
|
||||
Addresses: addresses,
|
||||
PkScript: txOut.PkScript,
|
||||
OutputIndex: i,
|
||||
Value: btcutil.Amount(txOut.Value),
|
||||
IsOurAddress: isOurAddress[i],
|
||||
})
|
||||
}
|
||||
|
||||
txDetail := &lnwallet.TransactionDetail{
|
||||
@@ -1083,6 +1123,7 @@ func unminedTransactionsToDetail(
|
||||
TotalFees: int64(summary.Fee),
|
||||
Timestamp: summary.Timestamp,
|
||||
DestAddresses: destAddresses,
|
||||
OutputDetails: outputDetails,
|
||||
RawTx: summary.Transaction,
|
||||
Label: summary.Label,
|
||||
}
|
||||
|
Reference in New Issue
Block a user