Skip to content

Commit

Permalink
[R4R] replace ioutil with io/os (#852)
Browse files Browse the repository at this point in the history
* sidechain staking reward distribution

* update changelog and version

* use io and os to replace ioutil

* use io and os to replace ioutil

Co-authored-by: forcodedancing <[email protected]>
  • Loading branch information
forcodedancing and forcodedancing committed May 19, 2022
1 parent c321967 commit aea487c
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 42 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ $ export BNBCHAINPATH=~/go/src/github.com/bnb-chain/node
$ mkdir -p $BNBCHAINPATH
$ git clone [email protected]:bnb-chain/node.git $BNBCHAINPATH
$ cd $BNBCHAINPATH
$ make get_vendor_deps
$ make install
$ make build
```

> If you want run bnbchaind with cleveldb as backend, please ensure leveldb is installed: https://github.com/google/leveldb#building,
Expand All @@ -52,8 +51,7 @@ You may need add BNBCHAINPATH to the environment variables.
> md %BNBCHAINPATH%
> git clone [email protected]:bnb-chain/node.git %BNBCHAINPATH%
> cd %BNBCHAINPATH%
> make get_vendor_deps
> make install
> make build
```

> If you encounter some network issues when downloading the dependencies, make sure you have configured shadowsocks correctly and switch to global mode. Run `set(win)/export(linux/mac) https_proxy=127.0.0.1:1080` if you still have https issues.
Expand All @@ -76,7 +74,7 @@ $ cat ~/.bnbchaind/config/genesis.json
You may want to check the [Issuing assets](#issuing-assets) section below before you start, but this is how to start the node and begin generating blocks:

```bash
$ bnbchaind start
$ bnbchaind start --moniker ${YOURNAME}
```

If everything worked you will see blocks being generated around every 1s in your console.
Expand Down
10 changes: 5 additions & 5 deletions app/account_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app

import (
"io/ioutil"
"io"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -16,8 +16,8 @@ import (

func BenchmarkGetAccount(b *testing.B) {
memDB := db.NewMemDB()
logger := log.NewTMLogger(ioutil.Discard)
testApp := NewBinanceChain(logger, memDB, ioutil.Discard)
logger := log.NewTMLogger(io.Discard)
testApp := NewBinanceChain(logger, memDB, io.Discard)

pk := ed25519.GenPrivKey().PubKey()
addr := sdk.AccAddress(pk.Address())
Expand Down Expand Up @@ -48,8 +48,8 @@ func BenchmarkGetAccount(b *testing.B) {

func BenchmarkSetAccount(b *testing.B) {
memDB := db.NewMemDB()
logger := log.NewTMLogger(ioutil.Discard)
testApp := NewBinanceChain(logger, memDB, ioutil.Discard)
logger := log.NewTMLogger(io.Discard)
testApp := NewBinanceChain(logger, memDB, io.Discard)

pk := ed25519.GenPrivKey().PubKey()
addr := sdk.AccAddress(pk.Address())
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (app *BinanceChain) subscribeEvent(logger log.Logger) {
app.subscriber = sub
}

// setUpgradeConfig will overwrite default upgrade config
// SetUpgradeConfig will overwrite default upgrade config
func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
// register upgrade height
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP6, upgradeConfig.BEP6Height)
Expand Down
3 changes: 1 addition & 2 deletions app/pub/publisher_kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pub

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -278,7 +277,7 @@ func (publisher KafkaMarketDataPublisher) publishEssentialMsg(essMsg EssMsg, top
filePath := fmt.Sprintf("%s/%d_%s.log", publisher.essentialLogPath, height, tpe.String())
toWrite := []byte(essMsg.EssentialMsg())
if len(toWrite) != 0 {
if err := ioutil.WriteFile(filePath, toWrite, 0600); err != nil {
if err := os.WriteFile(filePath, toWrite, 0600); err != nil {
Logger.Error("failed to write essential log", "err", err)
}
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/bnbchaind/init/collect_gentxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package init
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -78,8 +77,8 @@ func genGenesisFile(cdc *codec.Codec, appInit server.AppInit, chainId, genTxDir,
}

func collectGenTxs(genTxsDir string, cdc *codec.Codec) (appGenTxs []auth.StdTx, err error) {
var fos []os.FileInfo
fos, err = ioutil.ReadDir(genTxsDir)
var fos []os.DirEntry
fos, err = os.ReadDir(genTxsDir)
if err != nil {
return
}
Expand All @@ -91,7 +90,7 @@ func collectGenTxs(genTxsDir string, cdc *codec.Codec) (appGenTxs []auth.StdTx,
}

var jsonRawTx []byte
if jsonRawTx, err = ioutil.ReadFile(filename); err != nil {
if jsonRawTx, err = os.ReadFile(filename); err != nil {
return
}
var genStdTx auth.StdTx
Expand Down
3 changes: 1 addition & 2 deletions cmd/bnbchaind/init/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package init

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -61,7 +60,7 @@ following delegation and commission default parameters:
prepareFlagsForTxCreateValidator(config, nodeID, ip, valPubKey)
createValidatorCmd := cli.GetCmdCreateValidator(cdc)

w, err := ioutil.TempFile("", "gentx")
w, err := os.CreateTemp("", "gentx")
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/bnbchaind/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package init
import (
"bytes"
"io"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestInitCmd(t *testing.T) {
}

func setupClientHome(t *testing.T) func() {
clientDir, err := ioutil.TempDir("", "mock-sdk-cmd")
clientDir, err := os.MkdirTemp("", "mock-sdk-cmd")
require.Nil(t, err)
viper.Set(flagClientHome, clientDir)
viper.Set(flagOverwriteKey, true)
Expand Down Expand Up @@ -95,7 +94,7 @@ func TestEmptyState(t *testing.T) {
}

func TestStartStandAlone(t *testing.T) {
home, err := ioutil.TempDir("", "mock-sdk-cmd")
home, err := os.MkdirTemp("", "mock-sdk-cmd")
require.Nil(t, err)
defer func() {
os.RemoveAll(home)
Expand Down Expand Up @@ -134,7 +133,7 @@ func TestStartStandAlone(t *testing.T) {
}

func TestInitNodeValidatorFiles(t *testing.T) {
home, err := ioutil.TempDir("", "mock-sdk-cmd")
home, err := os.MkdirTemp("", "mock-sdk-cmd")
require.Nil(t, err)
defer func() {
os.RemoveAll(home)
Expand Down
15 changes: 7 additions & 8 deletions cmd/dexperf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"math/rand"
"os"
"os/exec"
Expand Down Expand Up @@ -405,7 +404,7 @@ func createFolder(path string) {
}

func emptyFolder(path string) {
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -610,7 +609,7 @@ func create(wg *sync.WaitGroup, s *sequence) {
ts := fmt.Sprintf("%d", time.Now().UnixNano())
file := filepath.Join(*createPath, ts+"_"+name)
fmt.Println("Acc-", item.txBldr.AccountNumber, "signed tran saved,", file)
err = ioutil.WriteFile(file, txBytes, 0600)
err = os.WriteFile(file, txBytes, 0600)
if err != nil {
fmt.Println(err)
continue
Expand All @@ -633,7 +632,7 @@ func allocateSubmit() {
if err != nil {
panic(err)
}
files, err := ioutil.ReadDir(*submitPath)
files, err := os.ReadDir(*submitPath)
if err != nil {
panic(err)
}
Expand All @@ -642,7 +641,7 @@ func allocateSubmit() {
for i, file := range files {
matched := res.FindStringSubmatch(file.Name())
if matched != nil {
tran, err := ioutil.ReadFile(filepath.Join(*submitPath, file.Name()))
tran, err := os.ReadFile(filepath.Join(*submitPath, file.Name()))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -707,7 +706,7 @@ func doRecover() {
}

func moveFiles(srcPath string, dstPath string, count int) {
files, err := ioutil.ReadDir(srcPath)
files, err := os.ReadDir(srcPath)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -755,15 +754,15 @@ func save_hextx() {
if err != nil {
panic(err)
}
files, err := ioutil.ReadDir(*createPath)
files, err := os.ReadDir(*createPath)
if err != nil {
panic(err)
}
for _, file := range files {
matched := res.FindStringSubmatch(file.Name())
if matched != nil {
ip, _ := accToIp[matched[1]]
txBytes, err := ioutil.ReadFile(filepath.Join(*createPath, file.Name()))
txBytes, err := os.ReadFile(filepath.Join(*createPath, file.Name()))
if err != nil {
panic(err)
}
Expand Down
5 changes: 2 additions & 3 deletions common/log/async_file_writer_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package log

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -13,12 +12,12 @@ func TestWriter(t *testing.T) {
w.Write([]byte("hello\n"))
w.Write([]byte("world\n"))
w.Stop()
files, _ := ioutil.ReadDir("./")
files, _ := os.ReadDir("./")
for _, f := range files {
fn := f.Name()
if strings.HasPrefix(fn, "hello") {
t.Log(fn)
content, _ := ioutil.ReadFile(fn)
content, _ := os.ReadFile(fn)
t.Log(content)
os.Remove(fn)
}
Expand Down
7 changes: 3 additions & 4 deletions plugins/api/handlers/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package handlers
import (
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"

"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"io"
"net/http"

cctx "github.com/bnb-chain/node/common/client/context"
"github.com/bnb-chain/node/wire"
Expand All @@ -26,7 +25,7 @@ func SimulateReqHandler(cdc *wire.Codec, ctx context.CLIContext) http.HandlerFun
}

return func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)

if err != nil {
errMsg := fmt.Sprintf("Malformed request body. Error: %s", err.Error())
Expand Down
3 changes: 1 addition & 2 deletions plugins/dex/order/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package order

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -60,7 +59,7 @@ type orderbookWAL struct {
}

func locateLatestFile(dirPath string) (string, error) {
files, err := ioutil.ReadDir(dirPath)
files, err := os.ReadDir(dirPath)
if err != nil {
return "", errors.Wrap(err, fmt.Sprintf("failed to list directory[%s] for WAL", dirPath))
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/tokens/client/cli/multi_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package commands

import (
"encoding/json"
"io/ioutil"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -55,7 +55,7 @@ func MultiSendCmd(cdc *wire.Codec) *cobra.Command {
txPath := viper.GetString(flagTransfersFile)
txBytes := make([]byte, 0)
if txPath != "" {
txBytes, err = ioutil.ReadFile(txPath)
txBytes, err = os.ReadFile(txPath)
if err != nil {
return err
}
Expand Down

0 comments on commit aea487c

Please sign in to comment.