lnwallet: remove DestAddresses from lnwallet

With `OutputDetail` now containing the destination addresses, the `DestAddresses` field can be removed from the `lnwallet.TransactionDetail`. It is already populated when needed for backwards compatibility to `lnrpc.TransactionDetail` via `OutputDetail.Addresses`.
This commit is contained in:
Bjarne Magnussen
2021-07-12 12:57:14 +02:00
parent 48c773ec87
commit 052bb9d711
3 changed files with 22 additions and 20 deletions

View File

@@ -1023,7 +1023,6 @@ func minedTransactionsToDetails(
isOurAddress[int(o.Index)] = true
}
var destAddresses []btcutil.Address
var outputDetails []lnwallet.OutputDetail
for i, txOut := range wireTx.TxOut {
var addresses []btcutil.Address
@@ -1032,7 +1031,6 @@ func minedTransactionsToDetails(
)
if err == nil {
// Add supported addresses.
destAddresses = append(destAddresses, outAddresses...)
addresses = outAddresses
}
@@ -1053,7 +1051,6 @@ func minedTransactionsToDetails(
BlockHeight: block.Height,
Timestamp: block.Timestamp,
TotalFees: int64(tx.Fee),
DestAddresses: destAddresses,
OutputDetails: outputDetails,
RawTx: tx.Transaction,
Label: tx.Label,
@@ -1095,7 +1092,6 @@ func unminedTransactionsToDetail(
isOurAddress[int(o.Index)] = true
}
var destAddresses []btcutil.Address
var outputDetails []lnwallet.OutputDetail
for i, txOut := range wireTx.TxOut {
var addresses []btcutil.Address
@@ -1104,7 +1100,6 @@ func unminedTransactionsToDetail(
)
if err == nil {
// Add supported addresses.
destAddresses = append(destAddresses, outAddresses...)
addresses = outAddresses
}
@@ -1122,7 +1117,6 @@ func unminedTransactionsToDetail(
Hash: *summary.Hash,
TotalFees: int64(summary.Fee),
Timestamp: summary.Timestamp,
DestAddresses: destAddresses,
OutputDetails: outputDetails,
RawTx: summary.Transaction,
Label: summary.Label,

View File

@@ -128,9 +128,6 @@ type TransactionDetail struct {
// TotalFees is the total fee in satoshis paid by this transaction.
TotalFees int64
// DestAddresses are the destinations for a transaction
DestAddresses []btcutil.Address
// OutputDetails contains output data for each destination address, such
// as the output script and amount.
OutputDetails []OutputDetail

View File

@@ -1140,6 +1140,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
// Create 5 new outputs spendable by the wallet.
const numTxns = 5
const outputAmt = btcutil.SatoshiPerBitcoin
isOurAddress := make(map[string]bool)
txids := make(map[chainhash.Hash]struct{})
for i := 0; i < numTxns; i++ {
addr, err := alice.NewAddress(
@@ -1149,6 +1150,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
if err != nil {
t.Fatalf("unable to create new address: %v", err)
}
isOurAddress[addr.EncodeAddress()] = true
script, err := txscript.PayToAddrScript(addr)
if err != nil {
t.Fatalf("unable to create output script: %v", err)
@@ -1245,20 +1247,27 @@ func testListTransactionDetails(miner *rpctest.Harness,
t.Fatalf("tx (%v) not found in block (%v)",
txDetail.Hash, txDetail.BlockHash)
} else {
var destinationAddresses []btcutil.Address
var destinationOutputs []lnwallet.OutputDetail
for _, txOut := range txOuts {
_, addrs, _, err :=
for i, txOut := range txOuts {
sc, addrs, _, err :=
txscript.ExtractPkScriptAddrs(txOut.PkScript, &alice.Cfg.NetParams)
if err != nil {
t.Fatalf("err extract script addresses: %s", err)
}
destinationAddresses = append(destinationAddresses, addrs...)
destinationOutputs = append(destinationOutputs, lnwallet.OutputDetail{
OutputType: sc,
Addresses: addrs,
PkScript: txOut.PkScript,
OutputIndex: i,
Value: btcutil.Amount(txOut.Value),
IsOurAddress: isOurAddress[addrs[0].EncodeAddress()],
})
}
if !reflect.DeepEqual(txDetail.DestAddresses, destinationAddresses) {
t.Fatalf("destination addresses mismatch, got %v expected %v",
txDetail.DestAddresses, destinationAddresses)
if !reflect.DeepEqual(txDetail.OutputDetails, destinationOutputs) {
t.Fatalf("destination outputs mismatch, got %v expected %v",
txDetail.OutputDetails, destinationOutputs)
}
}
@@ -1330,10 +1339,12 @@ func testListTransactionDetails(miner *rpctest.Harness,
// 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
for _, o := range txDetail.OutputDetails {
for _, addr := range o.Addresses {
if addr.String() == minerAddr.String() {
match = true
break
}
}
}
if !match {