Skip to content

Commit

Permalink
multi: fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Jan 1, 2021
1 parent 729e71f commit 959dcf3
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 38 deletions.
7 changes: 4 additions & 3 deletions btc/bip39.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 3 additions & 2 deletions cmd/chantools/derivekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/hdkeychain"
"github.com/guggero/chantools/lnd"
Expand Down Expand Up @@ -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()
}
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/chantools/derivekey_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions cmd/chantools/forceclose.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

type forceCloseCommand struct {
ApiURL string
APIURL string
ChannelDB string
Publish bool

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions cmd/chantools/rescuefunding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 3 additions & 4 deletions cmd/chantools/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/guggero/chantools/btc"
"io/ioutil"
"os"
"strings"
Expand All @@ -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"
Expand All @@ -27,6 +27,7 @@ import (
const (
defaultAPIURL = "https://blockstream.info/api"
version = "0.8.0"
na = "n/a"

Commit = ""
)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -100,9 +101,7 @@ func init() {
newVanityGenCommand(),
newWalletInfoCommand(),
)
}

func main() {
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down
9 changes: 4 additions & 5 deletions cmd/chantools/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/chantools/showrootkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/chantools/showrootkey_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -64,4 +64,4 @@ func TestShowRootKeyBIP39WithPassphre(t *testing.T) {
require.NoError(t, err)

h.assertLogContains(rootKeyBip39Passphrase)
}
}
6 changes: 3 additions & 3 deletions cmd/chantools/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type summaryCommand struct {
ApiURL string
APIURL string

inputs *inputFlags
cmd *cobra.Command
Expand All @@ -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)",
)

Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions cmd/chantools/sweeptimelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
)

type sweepTimeLockCommand struct {
ApiURL string
APIURL string
Publish bool
SweepAddr string
MaxCsvLimit uint16
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/chantools/sweeptimelockmanual.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
)

type sweepTimeLockManualCommand struct {
ApiURL string
APIURL string
Publish bool
SweepAddr string
MaxCsvLimit uint16
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/chantools/walletinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 959dcf3

Please sign in to comment.