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:
3 files changed
+22
-20
No files matched your search
@@ -1023,7 +1023,6 @@ func minedTransactionsToDetails(
|
|||||||
isOurAddress[int(o.Index)] = true
|
isOurAddress[int(o.Index)] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var destAddresses []btcutil.Address
|
|
||||||
var outputDetails []lnwallet.OutputDetail
|
var outputDetails []lnwallet.OutputDetail
|
||||||
for i, txOut := range wireTx.TxOut {
|
for i, txOut := range wireTx.TxOut {
|
||||||
var addresses []btcutil.Address
|
var addresses []btcutil.Address
|
||||||
@@ -1032,7 +1031,6 @@ func minedTransactionsToDetails(
|
|||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Add supported addresses.
|
// Add supported addresses.
|
||||||
destAddresses = append(destAddresses, outAddresses...)
|
|
||||||
addresses = outAddresses
|
addresses = outAddresses
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1053,7 +1051,6 @@ func minedTransactionsToDetails(
|
|||||||
BlockHeight: block.Height,
|
BlockHeight: block.Height,
|
||||||
Timestamp: block.Timestamp,
|
Timestamp: block.Timestamp,
|
||||||
TotalFees: int64(tx.Fee),
|
TotalFees: int64(tx.Fee),
|
||||||
DestAddresses: destAddresses,
|
|
||||||
OutputDetails: outputDetails,
|
OutputDetails: outputDetails,
|
||||||
RawTx: tx.Transaction,
|
RawTx: tx.Transaction,
|
||||||
Label: tx.Label,
|
Label: tx.Label,
|
||||||
@@ -1095,7 +1092,6 @@ func unminedTransactionsToDetail(
|
|||||||
isOurAddress[int(o.Index)] = true
|
isOurAddress[int(o.Index)] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var destAddresses []btcutil.Address
|
|
||||||
var outputDetails []lnwallet.OutputDetail
|
var outputDetails []lnwallet.OutputDetail
|
||||||
for i, txOut := range wireTx.TxOut {
|
for i, txOut := range wireTx.TxOut {
|
||||||
var addresses []btcutil.Address
|
var addresses []btcutil.Address
|
||||||
@@ -1104,7 +1100,6 @@ func unminedTransactionsToDetail(
|
|||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Add supported addresses.
|
// Add supported addresses.
|
||||||
destAddresses = append(destAddresses, outAddresses...)
|
|
||||||
addresses = outAddresses
|
addresses = outAddresses
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1122,7 +1117,6 @@ func unminedTransactionsToDetail(
|
|||||||
Hash: *summary.Hash,
|
Hash: *summary.Hash,
|
||||||
TotalFees: int64(summary.Fee),
|
TotalFees: int64(summary.Fee),
|
||||||
Timestamp: summary.Timestamp,
|
Timestamp: summary.Timestamp,
|
||||||
DestAddresses: destAddresses,
|
|
||||||
OutputDetails: outputDetails,
|
OutputDetails: outputDetails,
|
||||||
RawTx: summary.Transaction,
|
RawTx: summary.Transaction,
|
||||||
Label: summary.Label,
|
Label: summary.Label,
|
||||||
|
|||||||
@@ -128,9 +128,6 @@ type TransactionDetail struct {
|
|||||||
// TotalFees is the total fee in satoshis paid by this transaction.
|
// TotalFees is the total fee in satoshis paid by this transaction.
|
||||||
TotalFees int64
|
TotalFees int64
|
||||||
|
|
||||||
// DestAddresses are the destinations for a transaction
|
|
||||||
DestAddresses []btcutil.Address
|
|
||||||
|
|
||||||
// OutputDetails contains output data for each destination address, such
|
// OutputDetails contains output data for each destination address, such
|
||||||
// as the output script and amount.
|
// as the output script and amount.
|
||||||
OutputDetails []OutputDetail
|
OutputDetails []OutputDetail
|
||||||
|
|||||||
@@ -1140,6 +1140,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
|||||||
// Create 5 new outputs spendable by the wallet.
|
// Create 5 new outputs spendable by the wallet.
|
||||||
const numTxns = 5
|
const numTxns = 5
|
||||||
const outputAmt = btcutil.SatoshiPerBitcoin
|
const outputAmt = btcutil.SatoshiPerBitcoin
|
||||||
|
isOurAddress := make(map[string]bool)
|
||||||
txids := make(map[chainhash.Hash]struct{})
|
txids := make(map[chainhash.Hash]struct{})
|
||||||
for i := 0; i < numTxns; i++ {
|
for i := 0; i < numTxns; i++ {
|
||||||
addr, err := alice.NewAddress(
|
addr, err := alice.NewAddress(
|
||||||
@@ -1149,6 +1150,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create new address: %v", err)
|
t.Fatalf("unable to create new address: %v", err)
|
||||||
}
|
}
|
||||||
|
isOurAddress[addr.EncodeAddress()] = true
|
||||||
script, err := txscript.PayToAddrScript(addr)
|
script, err := txscript.PayToAddrScript(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create output script: %v", err)
|
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)",
|
t.Fatalf("tx (%v) not found in block (%v)",
|
||||||
txDetail.Hash, txDetail.BlockHash)
|
txDetail.Hash, txDetail.BlockHash)
|
||||||
} else {
|
} else {
|
||||||
var destinationAddresses []btcutil.Address
|
var destinationOutputs []lnwallet.OutputDetail
|
||||||
|
|
||||||
for _, txOut := range txOuts {
|
for i, txOut := range txOuts {
|
||||||
_, addrs, _, err :=
|
sc, addrs, _, err :=
|
||||||
txscript.ExtractPkScriptAddrs(txOut.PkScript, &alice.Cfg.NetParams)
|
txscript.ExtractPkScriptAddrs(txOut.PkScript, &alice.Cfg.NetParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err extract script addresses: %s", err)
|
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) {
|
if !reflect.DeepEqual(txDetail.OutputDetails, destinationOutputs) {
|
||||||
t.Fatalf("destination addresses mismatch, got %v expected %v",
|
t.Fatalf("destination outputs mismatch, got %v expected %v",
|
||||||
txDetail.DestAddresses, destinationAddresses)
|
txDetail.OutputDetails, destinationOutputs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1330,10 +1339,12 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
|||||||
// that even when we have 0 confirmation transactions, the destination
|
// that even when we have 0 confirmation transactions, the destination
|
||||||
// addresses are returned.
|
// addresses are returned.
|
||||||
var match bool
|
var match bool
|
||||||
for _, addr := range txDetail.DestAddresses {
|
for _, o := range txDetail.OutputDetails {
|
||||||
if addr.String() == minerAddr.String() {
|
for _, addr := range o.Addresses {
|
||||||
match = true
|
if addr.String() == minerAddr.String() {
|
||||||
break
|
match = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !match {
|
if !match {
|
||||||
|
|||||||
Reference in new issue
Block a user