Skip to content

Commit

Permalink
cmd/chantools: remove use of deprecated ioutil pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Jul 12, 2024
1 parent 3c04692 commit d3ab662
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cmd/chantools/fakechanbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/chantools/forceclose.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"time"

"github.com/btcsuite/btcd/btcutil/hdkeychain"
Expand Down Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions cmd/chantools/rescueclosed.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"regexp"
"time"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions cmd/chantools/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"strings"
"time"
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 1 addition & 4 deletions cmd/chantools/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"io"
"io/ioutil"
"os"
"path"
"regexp"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/chantools/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"time"

"github.com/lightninglabs/chantools/btc"
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions cmd/chantools/zombierecovery_preparekeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"time"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d3ab662

Please sign in to comment.