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:
Bjarne Magnussen committed 2022-03-23 11:28:18 +01:00
1 parent cbf6bd9aca
commit d43cdcf9a0
1 file changed
+58 -17
+58 -17
View File
@@ -1013,18 +1013,37 @@ func minedTransactionsToDetails(
return nil, err return nil, err
} }
var destAddresses []btcutil.Address // isOurAddress is a map containing the output indices
for _, txOut := range wireTx.TxOut { // controlled by the wallet.
_, outAddresses, _, err := txscript.ExtractPkScriptAddrs( // Note: We make use of the information in `MyOutputs` provided
txOut.PkScript, chainParams, // by the `wallet.TransactionSummary` structure that holds
) // information only if the output is controlled by the wallet.
if err != nil { isOurAddress := make(map[int]bool, len(tx.MyOutputs))
// Skip any unsupported addresses to prevent for _, o := range tx.MyOutputs {
// other transactions from not being returned. isOurAddress[int(o.Index)] = true
continue
} }
var destAddresses []btcutil.Address
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...) destAddresses = append(destAddresses, outAddresses...)
addresses = 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{ txDetail := &lnwallet.TransactionDetail{
@@ -1035,6 +1054,7 @@ func minedTransactionsToDetails(
Timestamp: block.Timestamp, Timestamp: block.Timestamp,
TotalFees: int64(tx.Fee), TotalFees: int64(tx.Fee),
DestAddresses: destAddresses, DestAddresses: destAddresses,
OutputDetails: outputDetails,
RawTx: tx.Transaction, RawTx: tx.Transaction,
Label: tx.Label, Label: tx.Label,
} }
@@ -1065,17 +1085,37 @@ func unminedTransactionsToDetail(
return nil, err return nil, err
} }
var destAddresses []btcutil.Address // isOurAddress is a map containing the output indices controlled by
for _, txOut := range wireTx.TxOut { // the wallet.
_, outAddresses, _, err := // Note: We make use of the information in `MyOutputs` provided
txscript.ExtractPkScriptAddrs(txOut.PkScript, chainParams) // by the `wallet.TransactionSummary` structure that holds information
if err != nil { // only if the output is controlled by the wallet.
// Skip any unsupported addresses to prevent other isOurAddress := make(map[int]bool, len(summary.MyOutputs))
// transactions from not being returned. for _, o := range summary.MyOutputs {
continue isOurAddress[int(o.Index)] = true
} }
var destAddresses []btcutil.Address
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...) destAddresses = append(destAddresses, outAddresses...)
addresses = 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{ txDetail := &lnwallet.TransactionDetail{
@@ -1083,6 +1123,7 @@ func unminedTransactionsToDetail(
TotalFees: int64(summary.Fee), TotalFees: int64(summary.Fee),
Timestamp: summary.Timestamp, Timestamp: summary.Timestamp,
DestAddresses: destAddresses, DestAddresses: destAddresses,
OutputDetails: outputDetails,
RawTx: summary.Transaction, RawTx: summary.Transaction,
Label: summary.Label, Label: summary.Label,
} }