From d3ab66241880d0873a3fa2668e52dba3c4d5a976 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 12 Jul 2024 09:19:03 +0200 Subject: [PATCH] cmd/chantools: remove use of deprecated ioutil pkg --- cmd/chantools/fakechanbackup.go | 4 ++-- cmd/chantools/forceclose.go | 4 ++-- cmd/chantools/rescueclosed.go | 6 +++--- cmd/chantools/root.go | 6 +++--- cmd/chantools/root_test.go | 5 +---- cmd/chantools/summary.go | 4 ++-- cmd/chantools/zombierecovery_preparekeys.go | 3 +-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/cmd/chantools/fakechanbackup.go b/cmd/chantools/fakechanbackup.go index 74acaae..06eccc3 100644 --- a/cmd/chantools/fakechanbackup.go +++ b/cmd/chantools/fakechanbackup.go @@ -5,8 +5,8 @@ import ( "encoding/hex" "errors" "fmt" - "io/ioutil" "net" + "os" "strconv" "strings" "time" @@ -133,7 +133,7 @@ func (c *fakeChanBackupCommand) Execute(_ *cobra.Command, _ []string) error { } if c.FromChannelGraph != "" { - graphBytes, err := ioutil.ReadFile(c.FromChannelGraph) + graphBytes, err := os.ReadFile(c.FromChannelGraph) if err != nil { return fmt.Errorf("error reading graph JSON file %s: "+ "%v", c.FromChannelGraph, err) diff --git a/cmd/chantools/forceclose.go b/cmd/chantools/forceclose.go index 13c9867..9e4cc57 100644 --- a/cmd/chantools/forceclose.go +++ b/cmd/chantools/forceclose.go @@ -7,7 +7,7 @@ import ( "errors" "fmt" "io" - "io/ioutil" + "os" "time" "github.com/btcsuite/btcd/btcutil/hdkeychain" @@ -230,5 +230,5 @@ func forceCloseChannels(apiURL string, extendedKey *hdkeychain.ExtendedKey, fileName := fmt.Sprintf("results/forceclose-%s.json", time.Now().Format("2006-01-02-15-04-05")) log.Infof("Writing result to %s", fileName) - return ioutil.WriteFile(fileName, summaryBytes, 0644) + return os.WriteFile(fileName, summaryBytes, 0644) } diff --git a/cmd/chantools/rescueclosed.go b/cmd/chantools/rescueclosed.go index b10dffd..cf502d6 100644 --- a/cmd/chantools/rescueclosed.go +++ b/cmd/chantools/rescueclosed.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "os" "regexp" "time" @@ -204,7 +204,7 @@ func commitPointsFromDB(chanDb *channeldb.ChannelStateDB) ([]*btcec.PublicKey, } func commitPointsFromLogFile(lndLog string) ([]*btcec.PublicKey, error) { - logFileBytes, err := ioutil.ReadFile(lndLog) + logFileBytes, err := os.ReadFile(lndLog) if err != nil { return nil, fmt.Errorf("error reading log file %s: %w", lndLog, err) @@ -313,7 +313,7 @@ outer: fileName := fmt.Sprintf("results/rescueclosed-%s.json", time.Now().Format("2006-01-02-15-04-05")) log.Infof("Writing result to %s", fileName) - return ioutil.WriteFile(fileName, summaryBytes, 0644) + return os.WriteFile(fileName, summaryBytes, 0644) } func rescueClosedChannel(extendedKey *hdkeychain.ExtendedKey, diff --git a/cmd/chantools/root.go b/cmd/chantools/root.go index e3775af..be52da8 100644 --- a/cmd/chantools/root.go +++ b/cmd/chantools/root.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "os" "strings" "time" @@ -299,9 +299,9 @@ func (f *inputFlags) parseInputType() ([]*dataformat.SummaryEntry, error) { func readInput(input string) ([]byte, error) { if strings.TrimSpace(input) == "-" { - return ioutil.ReadAll(os.Stdin) + return io.ReadAll(os.Stdin) } - return ioutil.ReadFile(input) + return os.ReadFile(input) } func setupLogging() { diff --git a/cmd/chantools/root_test.go b/cmd/chantools/root_test.go index 7427e63..c94b665 100644 --- a/cmd/chantools/root_test.go +++ b/cmd/chantools/root_test.go @@ -3,7 +3,6 @@ package main import ( "bytes" "io" - "io/ioutil" "os" "path" "regexp" @@ -53,14 +52,12 @@ func newHarness(t *testing.T) *harness { buf := &bytes.Buffer{} logBackend := btclog.NewBackend(buf) - tempDir, err := ioutil.TempDir("", "chantools") - require.NoError(t, err) h := &harness{ t: t, logBuffer: buf, logger: logBackend.Logger("CHAN"), - tempDir: tempDir, + tempDir: t.TempDir(), } h.logger.SetLevel(btclog.LevelTrace) diff --git a/cmd/chantools/summary.go b/cmd/chantools/summary.go index 2544975..aa824d8 100644 --- a/cmd/chantools/summary.go +++ b/cmd/chantools/summary.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "os" "time" "github.com/lightninglabs/chantools/btc" @@ -88,5 +88,5 @@ func summarizeChannels(apiURL string, fileName := fmt.Sprintf("results/summary-%s.json", time.Now().Format("2006-01-02-15-04-05")) log.Infof("Writing result to %s", fileName) - return ioutil.WriteFile(fileName, summaryBytes, 0644) + return os.WriteFile(fileName, summaryBytes, 0644) } diff --git a/cmd/chantools/zombierecovery_preparekeys.go b/cmd/chantools/zombierecovery_preparekeys.go index 269776d..3871987 100644 --- a/cmd/chantools/zombierecovery_preparekeys.go +++ b/cmd/chantools/zombierecovery_preparekeys.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "time" @@ -76,7 +75,7 @@ func (c *zombieRecoveryPrepareKeysCommand) Execute(_ *cobra.Command, return errors.New("invalid payout address, must be P2WPKH") } - matchFileBytes, err := ioutil.ReadFile(c.MatchFile) + matchFileBytes, err := os.ReadFile(c.MatchFile) if err != nil { return fmt.Errorf("error reading match file %s: %w", c.MatchFile, err)