diff --git a/btc/bip39.go b/btc/bip39.go index b368176..96f22cc 100644 --- a/btc/bip39.go +++ b/btc/bip39.go @@ -6,14 +6,15 @@ import ( "encoding/hex" "errors" "fmt" + "os" + "strings" + "syscall" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcutil/hdkeychain" "github.com/guggero/chantools/bip39" "golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/ssh/terminal" - "os" - "strings" - "syscall" ) const ( diff --git a/cmd/chantools/derivekey.go b/cmd/chantools/derivekey.go index 3c7a837..2cedd92 100644 --- a/cmd/chantools/derivekey.go +++ b/cmd/chantools/derivekey.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil/hdkeychain" "github.com/guggero/chantools/lnd" @@ -86,7 +87,7 @@ func deriveKey(extendedKey *hdkeychain.ExtendedKey, path string, return fmt.Errorf("could not create address: %v", err) } - privKey, xPriv := "n/a", "n/a" + privKey, xPriv := na, na if !neuter { privKey, xPriv = wif.String(), child.String() } @@ -96,7 +97,7 @@ func deriveKey(extendedKey *hdkeychain.ExtendedKey, path string, pubKey.SerializeCompressed(), neutered, addrP2WKH, addrP2PKH, privKey, xPriv, ) - fmt.Printf(result) + fmt.Println(result) // For the tests, also log as trace level which is disabled by default. log.Tracef(result) diff --git a/cmd/chantools/derivekey_test.go b/cmd/chantools/derivekey_test.go index 3512c33..1b55b70 100644 --- a/cmd/chantools/derivekey_test.go +++ b/cmd/chantools/derivekey_test.go @@ -1,11 +1,11 @@ package main import ( - "github.com/guggero/chantools/btc" - "github.com/guggero/chantools/lnd" "os" "testing" + "github.com/guggero/chantools/btc" + "github.com/guggero/chantools/lnd" "github.com/stretchr/testify/require" ) diff --git a/cmd/chantools/forceclose.go b/cmd/chantools/forceclose.go index 6a24f2a..42de5c2 100644 --- a/cmd/chantools/forceclose.go +++ b/cmd/chantools/forceclose.go @@ -20,7 +20,7 @@ import ( ) type forceCloseCommand struct { - ApiURL string + APIURL string ChannelDB string Publish bool @@ -54,7 +54,7 @@ blocks) transaction *or* they have a watch tower looking out for them. RunE: cc.Execute, } cc.cmd.Flags().StringVar( - &cc.ApiURL, "apiurl", defaultAPIURL, "API URL to use (must "+ + &cc.APIURL, "apiurl", defaultAPIURL, "API URL to use (must "+ "be esplora compatible)", ) cc.cmd.Flags().StringVar( @@ -92,7 +92,7 @@ func (c *forceCloseCommand) Execute(_ *cobra.Command, _ []string) error { if err != nil { return err } - return forceCloseChannels(c.ApiURL, extendedKey, entries, db, c.Publish) + return forceCloseChannels(c.APIURL, extendedKey, entries, db, c.Publish) } func forceCloseChannels(apiURL string, extendedKey *hdkeychain.ExtendedKey, diff --git a/cmd/chantools/rescuefunding.go b/cmd/chantools/rescuefunding.go index f9ea9cc..787f09b 100644 --- a/cmd/chantools/rescuefunding.go +++ b/cmd/chantools/rescuefunding.go @@ -147,10 +147,6 @@ func (c *rescueFundingCommand) Execute(_ *cobra.Command, _ []string) error { return fmt.Errorf("error parsing sweep addr: %v", err) } - if c.FeeRate < 0 { - return fmt.Errorf("satperbyte must be greater than 0") - } - return rescueFunding( db, signer, dbOp, chainOp, sweepScript, btcutil.Amount(c.FeeRate), diff --git a/cmd/chantools/root.go b/cmd/chantools/root.go index 7aced74..587a26d 100644 --- a/cmd/chantools/root.go +++ b/cmd/chantools/root.go @@ -5,7 +5,6 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/guggero/chantools/btc" "io/ioutil" "os" "strings" @@ -15,6 +14,7 @@ import ( "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btclog" "github.com/btcsuite/btcutil/hdkeychain" + "github.com/guggero/chantools/btc" "github.com/guggero/chantools/dataformat" "github.com/guggero/chantools/lnd" "github.com/lightningnetwork/lnd/build" @@ -27,6 +27,7 @@ import ( const ( defaultAPIURL = "https://blockstream.info/api" version = "0.8.0" + na = "n/a" Commit = "" ) @@ -67,7 +68,7 @@ Complete documentation is available at https://github.com/guggero/chantools/.`, DisableAutoGenTag: true, } -func init() { +func main() { rootCmd.PersistentFlags().BoolVarP( &Testnet, "testnet", "t", false, "Indicates if testnet "+ "parameters should be used", @@ -100,9 +101,7 @@ func init() { newVanityGenCommand(), newWalletInfoCommand(), ) -} -func main() { if err := rootCmd.Execute(); err != nil { _, _ = fmt.Fprintln(os.Stderr, err) os.Exit(1) diff --git a/cmd/chantools/root_test.go b/cmd/chantools/root_test.go index afb8ba6..5122aba 100644 --- a/cmd/chantools/root_test.go +++ b/cmd/chantools/root_test.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "fmt" "io/ioutil" "os" "path" @@ -36,9 +35,9 @@ const ( var ( datePattern = regexp.MustCompile( - "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3} ", + `\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} `, ) - addressPattern = regexp.MustCompile("\\(0x[0-9a-f]{10}\\)") + addressPattern = regexp.MustCompile(`\(0x[0-9a-f]{10}\)`) ) type harness struct { @@ -80,10 +79,10 @@ func (h *harness) clearLog() { h.logBuffer.Reset() } -func (h *harness) assertLogContains(format string, args ...interface{}) { +func (h *harness) assertLogContains(format string) { h.t.Helper() - require.Contains(h.t, h.logBuffer.String(), fmt.Sprintf(format, args...)) + require.Contains(h.t, h.logBuffer.String(), format) } func (h *harness) assertLogEqual(a, b string) { diff --git a/cmd/chantools/showrootkey.go b/cmd/chantools/showrootkey.go index d2894ec..8a418da 100644 --- a/cmd/chantools/showrootkey.go +++ b/cmd/chantools/showrootkey.go @@ -40,7 +40,7 @@ func (c *showRootKeyCommand) Execute(_ *cobra.Command, _ []string) error { } result := fmt.Sprintf(showRootKeyFormat, extendedKey) - fmt.Printf(result) + fmt.Println(result) // For the tests, also log as trace level which is disabled by default. log.Tracef(result) diff --git a/cmd/chantools/showrootkey_test.go b/cmd/chantools/showrootkey_test.go index fb7b892..c4704f2 100644 --- a/cmd/chantools/showrootkey_test.go +++ b/cmd/chantools/showrootkey_test.go @@ -1,10 +1,10 @@ package main import ( - "github.com/guggero/chantools/btc" "os" "testing" + "github.com/guggero/chantools/btc" "github.com/guggero/chantools/lnd" "github.com/stretchr/testify/require" ) @@ -64,4 +64,4 @@ func TestShowRootKeyBIP39WithPassphre(t *testing.T) { require.NoError(t, err) h.assertLogContains(rootKeyBip39Passphrase) -} \ No newline at end of file +} diff --git a/cmd/chantools/summary.go b/cmd/chantools/summary.go index 8415049..2e355ad 100644 --- a/cmd/chantools/summary.go +++ b/cmd/chantools/summary.go @@ -12,7 +12,7 @@ import ( ) type summaryCommand struct { - ApiURL string + APIURL string inputs *inputFlags cmd *cobra.Command @@ -32,7 +32,7 @@ chantools summary --fromchanneldb ~/.lnd/data/graph/mainnet/channel.db`, RunE: cc.Execute, } cc.cmd.Flags().StringVar( - &cc.ApiURL, "apiurl", defaultAPIURL, "API URL to use (must "+ + &cc.APIURL, "apiurl", defaultAPIURL, "API URL to use (must "+ "be esplora compatible)", ) @@ -47,7 +47,7 @@ func (c *summaryCommand) Execute(_ *cobra.Command, _ []string) error { if err != nil { return err } - return summarizeChannels(c.ApiURL, entries) + return summarizeChannels(c.APIURL, entries) } func summarizeChannels(apiURL string, diff --git a/cmd/chantools/sweeptimelock.go b/cmd/chantools/sweeptimelock.go index 4a28ec1..afddd2e 100644 --- a/cmd/chantools/sweeptimelock.go +++ b/cmd/chantools/sweeptimelock.go @@ -24,7 +24,7 @@ const ( ) type sweepTimeLockCommand struct { - ApiURL string + APIURL string Publish bool SweepAddr string MaxCsvLimit uint16 @@ -55,7 +55,7 @@ parameter to 144.`, RunE: cc.Execute, } cc.cmd.Flags().StringVar( - &cc.ApiURL, "apiurl", defaultAPIURL, "API URL to use (must "+ + &cc.APIURL, "apiurl", defaultAPIURL, "API URL to use (must "+ "be esplora compatible)", ) cc.cmd.Flags().BoolVar( @@ -105,7 +105,7 @@ func (c *sweepTimeLockCommand) Execute(_ *cobra.Command, _ []string) error { c.FeeRate = defaultFeeSatPerVByte } return sweepTimeLock( - extendedKey, c.ApiURL, entries, c.SweepAddr, c.MaxCsvLimit, + extendedKey, c.APIURL, entries, c.SweepAddr, c.MaxCsvLimit, c.Publish, c.FeeRate, ) } diff --git a/cmd/chantools/sweeptimelockmanual.go b/cmd/chantools/sweeptimelockmanual.go index 5d88690..a438ae8 100644 --- a/cmd/chantools/sweeptimelockmanual.go +++ b/cmd/chantools/sweeptimelockmanual.go @@ -26,7 +26,7 @@ const ( ) type sweepTimeLockManualCommand struct { - ApiURL string + APIURL string Publish bool SweepAddr string MaxCsvLimit uint16 @@ -65,7 +65,7 @@ address is always the one that's longer (because it's P2WSH and not P2PKH).`, RunE: cc.Execute, } cc.cmd.Flags().StringVar( - &cc.ApiURL, "apiurl", defaultAPIURL, "API URL to use (must "+ + &cc.APIURL, "apiurl", defaultAPIURL, "API URL to use (must "+ "be esplora compatible)", ) cc.cmd.Flags().BoolVar( @@ -122,7 +122,7 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error } return sweepTimeLockManual( - extendedKey, c.ApiURL, c.SweepAddr, c.TimeLockAddr, + extendedKey, c.APIURL, c.SweepAddr, c.TimeLockAddr, remoteRevPoint, c.MaxCsvLimit, c.Publish, c.FeeRate, ) } diff --git a/cmd/chantools/walletinfo.go b/cmd/chantools/walletinfo.go index dbcdd29..16fe078 100644 --- a/cmd/chantools/walletinfo.go +++ b/cmd/chantools/walletinfo.go @@ -163,7 +163,7 @@ func (c *walletInfoCommand) Execute(_ *cobra.Command, _ []string) error { if err != nil { return err } - rootKey := "n/a" + rootKey := na if c.WithRootKey { masterHDPrivKey, err := decryptRootKey(db, privateWalletPw) if err != nil { @@ -177,7 +177,7 @@ func (c *walletInfoCommand) Execute(_ *cobra.Command, _ []string) error { scopeInfo, ) - fmt.Printf(result) + fmt.Println(result) // For the tests, also log as trace level which is disabled by default. log.Tracef(result) diff --git a/go.mod b/go.mod index 6038461..15d0550 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/coreos/bbolt v1.3.3 github.com/davecgh/go-spew v1.1.1 github.com/gohugoio/hugo v0.79.1 // indirect - github.com/jessevdk/go-flags v1.4.0 + github.com/jessevdk/go-flags v1.4.0 // indirect github.com/lightningnetwork/lnd v0.11.1-beta github.com/ltcsuite/ltcd v0.0.0-20191228044241-92166e412499 // indirect github.com/miekg/dns v1.1.26 // indirect