multi: use default API URLs for testnet and regtest

pull/107/head
Oliver Gugger 4 months ago
parent 858995a317
commit d830ebe57a
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -7,13 +7,12 @@ import (
"github.com/lightninglabs/chantools/dataformat"
)
func SummarizeChannels(apiURL string, channels []*dataformat.SummaryEntry,
func SummarizeChannels(api *ExplorerAPI, channels []*dataformat.SummaryEntry,
log btclog.Logger) (*dataformat.SummaryEntryFile, error) {
summaryFile := &dataformat.SummaryEntryFile{
Channels: channels,
}
api := &ExplorerAPI{BaseURL: apiURL}
for idx, channel := range channels {
tx, err := api.Transaction(channel.FundingTXID)

@ -10,7 +10,6 @@ import (
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/chantools/btc"
"github.com/lightninglabs/chantools/lnd"
"github.com/lightninglabs/pool/account"
"github.com/lightninglabs/pool/poolscript"
@ -165,7 +164,7 @@ func closePoolAccount(extendedKey *hdkeychain.ExtendedKey, apiURL string,
ExtendedKey: extendedKey,
ChainParams: chainParams,
}
api := &btc.ExplorerAPI{BaseURL: apiURL}
api := newExplorerAPI(apiURL)
tx, err := api.Transaction(outpoint.Hash.String())
if err != nil {

@ -13,7 +13,6 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/lightninglabs/chantools/btc"
"github.com/lightninglabs/chantools/lnd"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
@ -93,7 +92,7 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error {
return fmt.Errorf("inputoutpoints are required")
}
api := &btc.ExplorerAPI{BaseURL: c.APIURL}
api := newExplorerAPI(c.APIURL)
addresses := make([]btcutil.Address, 0, len(c.InputOutpoints))
outpoints := make([]*wire.OutPoint, 0, len(c.InputOutpoints))

@ -11,7 +11,6 @@ import (
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/btcsuite/btcd/txscript"
"github.com/lightninglabs/chantools/btc"
"github.com/lightninglabs/chantools/dataformat"
"github.com/lightninglabs/chantools/lnd"
"github.com/lightningnetwork/lnd/channeldb"
@ -105,7 +104,7 @@ func forceCloseChannels(apiURL string, extendedKey *hdkeychain.ExtendedKey,
if err != nil {
return err
}
api := &btc.ExplorerAPI{BaseURL: apiURL}
api := newExplorerAPI(apiURL)
signer := &lnd.Signer{
ExtendedKey: extendedKey,
ChainParams: chainParams,

@ -132,7 +132,7 @@ func createPullTransactionTemplate(rootKey *hdkeychain.ExtendedKey,
ExtendedKey: rootKey,
ChainParams: chainParams,
}
api := &btc.ExplorerAPI{BaseURL: apiURL}
api := newExplorerAPI(apiURL)
estimator := input.TxWeightEstimator{}
// Make sure the sponsor input is a P2WPKH or P2TR input and is known

@ -9,7 +9,6 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/chantools/btc"
"github.com/lightninglabs/chantools/lnd"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/loopdb"
@ -121,7 +120,7 @@ func (c *recoverLoopInCommand) Execute(_ *cobra.Command, _ []string) error {
return fmt.Errorf("sweep_addr is required")
}
api := &btc.ExplorerAPI{BaseURL: c.APIURL}
api := newExplorerAPI(c.APIURL)
signer := &lnd.Signer{
ExtendedKey: extendedKey,

@ -9,7 +9,6 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/psbt"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/chantools/btc"
"github.com/lightninglabs/chantools/lnd"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
@ -255,7 +254,7 @@ func rescueFunding(localKeyDesc *keychain.KeyDescriptor,
}
// Locate the output in the funding TX.
api := &btc.ExplorerAPI{BaseURL: apiURL}
api := newExplorerAPI(apiURL)
tx, err := api.Transaction(chainPoint.Hash.String())
if err != nil {
return fmt.Errorf("error fetching UTXO info for outpoint %s: "+

@ -26,7 +26,9 @@ import (
)
const (
defaultAPIURL = "https://blockstream.info/api"
defaultAPIURL = "https://blockstream.info/api"
defaultTestnetAPIURL = "https://blockstream.info/testnet/api"
defaultRegtestAPIURL = "http://localhost:3004"
// version is the current version of the tool. It is set during build.
// NOTE: When changing this, please also update the version in the
@ -56,7 +58,8 @@ var rootCmd = &cobra.Command{
Short: "Chantools helps recover funds from lightning channels",
Long: `This tool provides helper functions that can be used rescue
funds locked in lnd channels in case lnd itself cannot run properly anymore.
Complete documentation is available at https://github.com/lightninglabs/chantools/.`,
Complete documentation is available at
https://github.com/lightninglabs/chantools/.`,
Version: fmt.Sprintf("v%s, commit %s", version, Commit),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
switch {
@ -326,3 +329,22 @@ func setSubLogger(subsystem string, logger btclog.Logger,
func noConsole() ([]byte, error) {
return nil, fmt.Errorf("wallet db requires console access")
}
func newExplorerAPI(apiURL string) *btc.ExplorerAPI {
// Override for testnet if default is used.
if apiURL == defaultAPIURL &&
chainParams.Name == chaincfg.TestNet3Params.Name {
return &btc.ExplorerAPI{BaseURL: defaultTestnetAPIURL}
}
// Also override for regtest if default is used.
if apiURL == defaultAPIURL &&
chainParams.Name == chaincfg.RegressionNetParams.Name {
return &btc.ExplorerAPI{BaseURL: defaultRegtestAPIURL}
}
// Otherwise use the provided URL.
return &btc.ExplorerAPI{BaseURL: apiURL}
}

@ -53,7 +53,8 @@ func (c *summaryCommand) Execute(_ *cobra.Command, _ []string) error {
func summarizeChannels(apiURL string,
channels []*dataformat.SummaryEntry) error {
summaryFile, err := btc.SummarizeChannels(apiURL, channels, log)
api := newExplorerAPI(apiURL)
summaryFile, err := btc.SummarizeChannels(api, channels, log)
if err != nil {
return fmt.Errorf("error running summary: %w", err)
}

@ -129,7 +129,7 @@ func sweepRemoteClosed(extendedKey *hdkeychain.ExtendedKey, apiURL,
var (
targets []*targetAddr
api = &btc.ExplorerAPI{BaseURL: apiURL}
api = newExplorerAPI(apiURL)
)
for index := uint32(0); index < recoveryWindow; index++ {
path := fmt.Sprintf("m/1017'/%d'/%d'/0/%d",

@ -10,7 +10,6 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/chantools/btc"
"github.com/lightninglabs/chantools/dataformat"
"github.com/lightninglabs/chantools/lnd"
"github.com/lightningnetwork/lnd/input"
@ -220,7 +219,7 @@ func sweepTimeLock(extendedKey *hdkeychain.ExtendedKey, apiURL string,
ExtendedKey: extendedKey,
ChainParams: chainParams,
}
api := &btc.ExplorerAPI{BaseURL: apiURL}
api := newExplorerAPI(apiURL)
var (
sweepTx = wire.NewMsgTx(2)

@ -10,7 +10,6 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/chantools/btc"
"github.com/lightninglabs/chantools/lnd"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
@ -298,7 +297,7 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
ExtendedKey: extendedKey,
ChainParams: chainParams,
}
api := &btc.ExplorerAPI{BaseURL: apiURL}
api := newExplorerAPI(apiURL)
// We now know everything we need to construct the sweep transaction,
// except for what outpoint to sweep. We'll ask the chain API to give

@ -10,7 +10,6 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/connmgr"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/chantools/btc"
"github.com/lightninglabs/chantools/lnd"
"github.com/lightningnetwork/lnd/brontide"
"github.com/lightningnetwork/lnd/keychain"
@ -152,7 +151,7 @@ func (c *triggerForceCloseCommand) Execute(_ *cobra.Command, _ []string) error {
log.Infof("Message sent, waiting for force close transaction to " +
"appear in mempool")
api := &btc.ExplorerAPI{BaseURL: c.APIURL}
api := newExplorerAPI(c.APIURL)
channelAddress, err := api.Address(c.ChannelPoint)
if err != nil {
return fmt.Errorf("error getting channel address: %w", err)

@ -14,7 +14,6 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/hasura/go-graphql-client"
"github.com/lightninglabs/chantools/btc"
"github.com/spf13/cobra"
"golang.org/x/oauth2"
)
@ -188,7 +187,7 @@ func (c *zombieRecoveryFindMatchesCommand) Execute(_ *cobra.Command,
log.Infof("%s: %s", groups[1], groups[2])
}
api := &btc.ExplorerAPI{BaseURL: c.APIURL}
api := newExplorerAPI(c.APIURL)
src := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: c.AmbossKey})
httpClient := oauth2.NewClient(context.Background(), src)
client := graphql.NewClient(

Loading…
Cancel
Save