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:
1 file changed
+56
-15
@@ -1013,18 +1013,37 @@ func minedTransactionsToDetails(
|
|||||||
return nil, err
|
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
|
var destAddresses []btcutil.Address
|
||||||
for _, txOut := range wireTx.TxOut {
|
var outputDetails []lnwallet.OutputDetail
|
||||||
_, outAddresses, _, err := txscript.ExtractPkScriptAddrs(
|
for i, txOut := range wireTx.TxOut {
|
||||||
|
var addresses []btcutil.Address
|
||||||
|
sc, outAddresses, _, err := txscript.ExtractPkScriptAddrs(
|
||||||
txOut.PkScript, chainParams,
|
txOut.PkScript, chainParams,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
// Skip any unsupported addresses to prevent
|
// Add supported addresses.
|
||||||
// other transactions from not being returned.
|
destAddresses = append(destAddresses, outAddresses...)
|
||||||
continue
|
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{
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
var destAddresses []btcutil.Address
|
||||||
for _, txOut := range wireTx.TxOut {
|
var outputDetails []lnwallet.OutputDetail
|
||||||
_, outAddresses, _, err :=
|
for i, txOut := range wireTx.TxOut {
|
||||||
txscript.ExtractPkScriptAddrs(txOut.PkScript, chainParams)
|
var addresses []btcutil.Address
|
||||||
if err != nil {
|
sc, outAddresses, _, err := txscript.ExtractPkScriptAddrs(
|
||||||
// Skip any unsupported addresses to prevent other
|
txOut.PkScript, chainParams,
|
||||||
// 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{
|
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,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user