Skip to content

Commit

Permalink
chantools: replace deprecated ioutil functions
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Jun 1, 2024
1 parent 85f207c commit a348c7f
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cmd/chantools/fakechanbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"encoding/hex"
"fmt"
"io/ioutil"
"net"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -132,7 +132,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 @@ -6,7 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"time"

"github.com/btcsuite/btcd/btcutil/hdkeychain"
Expand Down Expand Up @@ -229,5 +229,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 @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"strings"
"time"
Expand Down Expand Up @@ -298,9 +298,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
4 changes: 1 addition & 3 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"
"io/ioutil"
"os"
"path"
"regexp"
Expand Down Expand Up @@ -52,8 +51,7 @@ func newHarness(t *testing.T) *harness {

buf := &bytes.Buffer{}
logBackend := btclog.NewBackend(buf)
tempDir, err := ioutil.TempDir("", "chantools")
require.NoError(t, err)
tempDir := t.TempDir()

h := &harness{
t: t,
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)
}
Binary file modified cmd/chantools/testdata/wallet.db
Binary file not shown.
3 changes: 1 addition & 2 deletions cmd/chantools/zombierecovery_preparekeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"time"

Expand Down Expand Up @@ -75,7 +74,7 @@ func (c *zombieRecoveryPrepareKeysCommand) Execute(_ *cobra.Command,
return fmt.Errorf("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 a348c7f

Please sign in to comment.