discovery+lnwallet: add fetchPKScript helper to gossiper

This commit makes an lnwallet.BlockChainIO available to the gossiper and
uses it to construct a helper that can be used to fetch the pk script
for a given SCID. This will be used for channel announcement
verification in an upcoming commit.
This commit is contained in:
Elle Mouton committed 2024-09-18 16:13:17 +02:00
1 parent 9be84c1bdc
commit a6bf76a0b7
3 files changed
+36

No files matched your search

+24
View File
@@ -21,6 +21,7 @@ import (
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanvalidate"
"github.com/lightningnetwork/lnd/lnwire"
)
@@ -737,3 +738,26 @@ func FetchFundingTx(chain BlockChainIO,
return fundingBlock.Transactions[chanID.TxIndex].Copy(), nil
}
// FetchPKScriptWithQuit fetches the output script for the given SCID and exits
// early with an error if the provided quit channel is closed before
// completion.
func FetchPKScriptWithQuit(chain BlockChainIO, chanID *lnwire.ShortChannelID,
quit chan struct{}) ([]byte, error) {
tx, err := FetchFundingTxWrapper(chain, chanID, quit)
if err != nil {
return nil, err
}
outputLocator := chanvalidate.ShortChanIDChanLocator{
ID: *chanID,
}
output, _, err := outputLocator.Locate(tx)
if err != nil {
return nil, err
}
return output.PkScript, nil
}