Skip to content

Commit

Permalink
use any instead of interface{}
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Sep 12, 2023
1 parent 088b9dd commit 7db15ed
Show file tree
Hide file tree
Showing 85 changed files with 247 additions and 247 deletions.
4 changes: 2 additions & 2 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ var DefaultConfig = Config{
// ParseCLIConfig parses the command-line arguments into the provided struct
// with go-flags tags. If the --help flag has been passed, the struct is
// described back to the terminal and the program exits using os.Exit.
func ParseCLIConfig(cfg interface{}) error {
func ParseCLIConfig(cfg any) error {
preParser := flags.NewParser(cfg, flags.HelpFlag|flags.PassDoubleDash)
_, flagerr := preParser.Parse()

Expand Down Expand Up @@ -251,7 +251,7 @@ func ResolveCLIConfigPaths(cfg *Config) (appData, configPath string) {

// ParseFileConfig parses the INI file into the provided struct with go-flags
// tags. The CLI args are then parsed, and take precedence over the file values.
func ParseFileConfig(path string, cfg interface{}) error {
func ParseFileConfig(path string, cfg any) error {
parser := flags.NewParser(cfg, flags.Default)
err := flags.NewIniParser(parser).ParseFile(path)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions client/asset/bch/spv.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,32 +992,32 @@ type fileLoggerPlus struct {
log dex.Logger
}

func (f *fileLoggerPlus) Warnf(format string, params ...interface{}) {
func (f *fileLoggerPlus) Warnf(format string, params ...any) {
f.log.Warnf(format, params...)
f.Logger.Warnf(format, params...)
}

func (f *fileLoggerPlus) Errorf(format string, params ...interface{}) {
func (f *fileLoggerPlus) Errorf(format string, params ...any) {
f.log.Errorf(format, params...)
f.Logger.Errorf(format, params...)
}

func (f *fileLoggerPlus) Criticalf(format string, params ...interface{}) {
func (f *fileLoggerPlus) Criticalf(format string, params ...any) {
f.log.Criticalf(format, params...)
f.Logger.Criticalf(format, params...)
}

func (f *fileLoggerPlus) Warn(v ...interface{}) {
func (f *fileLoggerPlus) Warn(v ...any) {
f.log.Warn(v...)
f.Logger.Warn(v...)
}

func (f *fileLoggerPlus) Error(v ...interface{}) {
func (f *fileLoggerPlus) Error(v ...any) {
f.log.Error(v...)
f.Logger.Error(v...)
}

func (f *fileLoggerPlus) Critical(v ...interface{}) {
func (f *fileLoggerPlus) Critical(v ...any) {
f.log.Critical(v...)
f.Logger.Critical(v...)
}
Expand Down
10 changes: 5 additions & 5 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ type findRedemptionReq struct {
contractHash []byte
}

func (req *findRedemptionReq) fail(s string, a ...interface{}) {
func (req *findRedemptionReq) fail(s string, a ...any) {
req.success(&findRedemptionResult{err: fmt.Errorf(s, a...)})

}
Expand Down Expand Up @@ -4517,7 +4517,7 @@ func (btc *intermediaryWallet) tryRedemptionRequests(ctx context.Context, startB
undiscovered[req.outPt] = req
}

epicFail := func(s string, a ...interface{}) {
epicFail := func(s string, a ...any) {
errMsg := fmt.Sprintf(s, a...)
for _, req := range reqs {
req.fail(errMsg)
Expand Down Expand Up @@ -5180,7 +5180,7 @@ func (btc *intermediaryWallet) reportNewTip(ctx context.Context, newTip *block)
// be determined, as searching just the new tip might result in blocks
// being omitted from the search operation. If that happens, cancel all
// find redemption requests in queue.
notifyFatalFindRedemptionError := func(s string, a ...interface{}) {
notifyFatalFindRedemptionError := func(s string, a ...any) {
for _, req := range reqs {
req.fail("tipChange handler - "+s, a...)
}
Expand Down Expand Up @@ -5355,7 +5355,7 @@ func (btc *baseWallet) sendWithReturn(baseTx *wire.MsgTx, addr btcutil.Address,
func (btc *baseWallet) signTxAndAddChange(baseTx *wire.MsgTx, addr btcutil.Address,
totalIn, totalOut, feeRate uint64) (*wire.MsgTx, *output, uint64, error) {

makeErr := func(s string, a ...interface{}) (*wire.MsgTx, *output, uint64, error) {
makeErr := func(s string, a ...any) (*wire.MsgTx, *output, uint64, error) {
return nil, nil, 0, fmt.Errorf(s, a...)
}

Expand Down Expand Up @@ -6351,7 +6351,7 @@ func (btc *baseWallet) scriptHashScript(contract []byte) ([]byte, error) {
// CallRPC is a method for making RPC calls directly on an underlying RPC
// client. CallRPC is not part of the wallet interface. Its intended use is for
// clone wallets to implement custom functionality.
func (btc *baseWallet) CallRPC(method string, args []interface{}, thing interface{}) error {
func (btc *baseWallet) CallRPC(method string, args []any, thing any) error {
rpcCl, is := btc.node.(*rpcClient)
if !is {
return errors.New("wallet is not RPC")
Expand Down
6 changes: 3 additions & 3 deletions client/asset/btc/btc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (c *testData) bestBlock() (*chainhash.Hash, int64) {
return bestHash, bestBlkHeight
}

func encodeOrError(thing interface{}, err error) (json.RawMessage, error) {
func encodeOrError(thing any, err error) (json.RawMessage, error) {
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -718,7 +718,7 @@ func tNewWallet(segwit bool, walletType string) (*intermediaryWallet, *testData,
return wallet, data, shutdownAndWait
}

func mustMarshal(thing interface{}) []byte {
func mustMarshal(thing any) []byte {
b, err := json.Marshal(thing)
if err != nil {
panic("mustMarshal error: " + err.Error())
Expand Down Expand Up @@ -1980,7 +1980,7 @@ func testFundMultiOrder(t *testing.T, segwit bool, walletType string) {
if totalNumCoins != len(node.lockedCoins) {
t.Fatalf("%s: expected %d locked coins, got %d", test.name, totalNumCoins, len(node.lockedCoins))
}
lockedCoins := make(map[RPCOutpoint]interface{})
lockedCoins := make(map[RPCOutpoint]any)
for _, coin := range node.lockedCoins {
lockedCoins[*coin] = true
}
Expand Down
4 changes: 2 additions & 2 deletions client/asset/btc/electrum/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
)

type positional []interface{}
type positional []any

type request struct {
Jsonrpc string `json:"jsonrpc"`
Expand Down Expand Up @@ -43,7 +43,7 @@ type ntfnData struct {
Params json.RawMessage `json:"params"`
}

func prepareRequest(id uint64, method string, args interface{}) ([]byte, error) {
func prepareRequest(id uint64, method string, args any) ([]byte, error) {
// nil args should marshal as [] instead of null.
if args == nil {
args = []json.RawMessage{}
Expand Down
18 changes: 9 additions & 9 deletions client/asset/btc/electrum/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ import (
)

// Printer is a function with the signature of a logger method.
type Printer func(format string, params ...interface{})
type Printer func(format string, params ...any)

var (
// StdoutPrinter is a DebugLogger that uses fmt.Printf.
StdoutPrinter = Printer(func(format string, params ...interface{}) {
StdoutPrinter = Printer(func(format string, params ...any) {
fmt.Printf(format+"\n", params...) // discard the returns
})
// StderrPrinter is a DebugLogger that uses fmt.Fprintf(os.Stderr, ...).
StderrPrinter = Printer(func(format string, params ...interface{}) {
StderrPrinter = Printer(func(format string, params ...any) {
fmt.Fprintf(os.Stderr, format+"\n", params...)
})

disabledPrinter = Printer(func(string, ...interface{}) {})
disabledPrinter = Printer(func(string, ...any) {})
)

const pingInterval = 10 * time.Second
Expand Down Expand Up @@ -356,7 +356,7 @@ func (sc *ServerConn) deleteSubscriptions() {
// arguments. args may not be any other basic type. The the response does not
// include an error, the result will be unmarshalled into result, unless the
// provided result is nil in which case the response payload will be ignored.
func (sc *ServerConn) Request(ctx context.Context, method string, args interface{}, result interface{}) error {
func (sc *ServerConn) Request(ctx context.Context, method string, args any, result any) error {
id := sc.nextID()
reqMsg, err := prepareRequest(id, method, args)
if err != nil {
Expand Down Expand Up @@ -417,7 +417,7 @@ type ServerFeatures struct {
Hosts map[string]map[string]uint32 `json:"hosts"` // e.g. {"host.com": {"tcp_port": 51001, "ssl_port": 51002}}, may be unset!
ProtoMax string `json:"protocol_max"`
ProtoMin string `json:"protocol_min"`
Pruning interface{} `json:"pruning,omitempty"` // supposedly an integer, but maybe a string or even JSON null
Pruning any `json:"pruning,omitempty"` // supposedly an integer, but maybe a string or even JSON null
Version string `json:"server_version"` // server software version, not proto
HashFunc string `json:"hash_function"` // e.g. sha256
// Services []string `json:"services,omitempty"` // e.g. ["tcp://host.com:51001", "ssl://host.com:51002"]
Expand Down Expand Up @@ -450,8 +450,8 @@ func (sc *ServerConn) Peers(ctx context.Context) ([]*PeersResult, error) {
// (*WalletClient).GetServers. We might wish to in the future though.

// [["ip", "host", ["featA", "featB", ...]], ...]
// [][]interface{}{string, string, []interface{}{string, ...}}
var resp [][]interface{}
// [][]any{string, string, []any{string, ...}}
var resp [][]any
err := sc.Request(ctx, "server.peers.subscribe", nil, &resp) // not really a subscription!
if err != nil {
return nil, err
Expand All @@ -472,7 +472,7 @@ func (sc *ServerConn) Peers(ctx context.Context) ([]*PeersResult, error) {
sc.debug("bad peer hostname: %v (%T)", peer[1], peer[1])
continue
}
featsI, ok := peer[2].([]interface{})
featsI, ok := peer[2].([]any)
if !ok {
sc.debug("bad peer feature data: %v (%T)", peer[2], peer[2])
continue
Expand Down
2 changes: 1 addition & 1 deletion client/asset/btc/electrum/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (ec *WalletClient) nextID() uint64 {
// should have their fields appropriately tagged for JSON marshalling. The
// result is marshaled into result if it is non-nil, otherwise the result is
// discarded.
func (ec *WalletClient) Call(ctx context.Context, method string, args interface{}, result interface{}) error {
func (ec *WalletClient) Call(ctx context.Context, method string, args any, result any) error {
reqMsg, err := prepareRequest(ec.nextID(), method, args)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions client/asset/btc/rpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type RawRequester interface {

// anylist is a list of RPC parameters to be converted to []json.RawMessage and
// sent via RawRequest.
type anylist []interface{}
type anylist []any

type rpcCore struct {
rpcConfig *RPCConfig
Expand Down Expand Up @@ -1132,11 +1132,11 @@ func (wc *rpcClient) searchBlockForRedemptions(ctx context.Context, reqs map[out
// call is used internally to marshal parameters and send requests to the RPC
// server via (*rpcclient.Client).RawRequest. If thing is non-nil, the result
// will be marshaled into thing.
func (wc *rpcClient) call(method string, args anylist, thing interface{}) error {
func (wc *rpcClient) call(method string, args anylist, thing any) error {
return call(wc.ctx, wc.requester(), method, args, thing)
}

func call(ctx context.Context, r RawRequester, method string, args anylist, thing interface{}) error {
func call(ctx context.Context, r RawRequester, method string, args anylist, thing any) error {
params := make([]json.RawMessage, 0, len(args))
for i := range args {
p, err := json.Marshal(args[i])
Expand Down
2 changes: 1 addition & 1 deletion client/asset/dcr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func loadRPCConfig(settings map[string]string, network dex.Network) (*rpcConfig,
// RPCListen or RPCCert in the specified file, default values will be used. If
// there is no error, the module-level chainParams variable will be set
// appropriately for the network.
func loadConfig(settings map[string]string, network dex.Network, cfg interface{}) (*chaincfg.Params, error) {
func loadConfig(settings map[string]string, network dex.Network, cfg any) (*chaincfg.Params, error) {
if err := config.Unmapify(settings, cfg); err != nil {
return nil, fmt.Errorf("error parsing config: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -5521,7 +5521,7 @@ func (dcr *ExchangeWallet) monitorPeers(ctx context.Context) {
}

func (dcr *ExchangeWallet) emitTipChange(height int64) {
var data interface{}
var data any
// stakeInfo, err := dcr.wallet.StakeInfo(dcr.ctx)
// if err != nil {
// dcr.log.Errorf("Error getting stake info for tip change notification data: %v", err)
Expand Down Expand Up @@ -5671,7 +5671,7 @@ func (dcr *ExchangeWallet) handleTipChange(ctx context.Context, newTipHash *chai
// be determined, as searching just the new tip might result in blocks
// being omitted from the search operation. If that happens, cancel all
// find redemption requests in queue.
notifyFatalFindRedemptionError := func(s string, a ...interface{}) {
notifyFatalFindRedemptionError := func(s string, a ...any) {
dcr.fatalFindRedemptionsError(fmt.Errorf("tipChange handler - "+s, a...), contractOutpoints)
}

Expand Down
2 changes: 1 addition & 1 deletion client/asset/dcr/dcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2479,7 +2479,7 @@ func TestFundMultiOrder(t *testing.T) {
if totalNumCoins != len(node.lockedCoins) {
t.Fatalf("%s: expected %d locked coins, got %d", test.name, totalNumCoins, len(node.lockedCoins))
}
lockedCoins := make(map[wire.OutPoint]interface{})
lockedCoins := make(map[wire.OutPoint]any)
for _, coin := range node.lockedCoins {
lockedCoins[*coin] = true
}
Expand Down
4 changes: 2 additions & 2 deletions client/asset/dcr/rpcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,12 @@ func (w *rpcWallet) SetTxFee(ctx context.Context, feePerKB dcrutil.Amount) error

// anylist is a list of RPC parameters to be converted to []json.RawMessage and
// sent via nodeRawRequest.
type anylist []interface{}
type anylist []any

// rpcClientRawRequest is used to marshal parameters and send requests to the
// RPC server via rpcClient.RawRequest. If `thing` is non-nil, the result will
// be marshaled into `thing`.
func (w *rpcWallet) rpcClientRawRequest(ctx context.Context, method string, args anylist, thing interface{}) error {
func (w *rpcWallet) rpcClientRawRequest(ctx context.Context, method string, args anylist, thing any) error {
params := make([]json.RawMessage, 0, len(args))
for i := range args {
p, err := json.Marshal(args[i])
Expand Down
4 changes: 2 additions & 2 deletions client/asset/eth/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (c *contractorV0) estimateInitGas(ctx context.Context, n int) (uint64, erro
}

// estimateGas estimates the gas used to interact with the swap contract.
func (c *contractorV0) estimateGas(ctx context.Context, value *big.Int, method string, args ...interface{}) (uint64, error) {
func (c *contractorV0) estimateGas(ctx context.Context, value *big.Int, method string, args ...any) (uint64, error) {
data, err := c.abi.Pack(method, args...)
if err != nil {
return 0, fmt.Errorf("Pack error: %v", err)
Expand Down Expand Up @@ -422,7 +422,7 @@ func (c *tokenContractorV0) estimateTransferGas(ctx context.Context, amount *big

// estimateGas estimates the gas needed for methods on the ERC20 token contract.
// For estimating methods on the swap contract, use (contractorV0).estimateGas.
func (c *tokenContractorV0) estimateGas(ctx context.Context, method string, args ...interface{}) (uint64, error) {
func (c *tokenContractorV0) estimateGas(ctx context.Context, method string, args ...any) (uint64, error) {
data, err := erc20.ERC20ABI.Pack(method, args...)
if err != nil {
return 0, fmt.Errorf("token estimateGas Pack error: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,7 @@ func (w *ETHWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uint6
return nil, nil, 0, fmt.Errorf("cannot send swap with with zero fee rate")
}

fail := func(s string, a ...interface{}) ([]asset.Receipt, asset.Coin, uint64, error) {
fail := func(s string, a ...any) ([]asset.Receipt, asset.Coin, uint64, error) {
return nil, nil, 0, fmt.Errorf(s, a...)
}

Expand Down Expand Up @@ -2057,7 +2057,7 @@ func (w *TokenWallet) Swap(swaps *asset.Swaps) ([]asset.Receipt, asset.Coin, uin
return nil, nil, 0, fmt.Errorf("cannot send swap with with zero fee rate")
}

fail := func(s string, a ...interface{}) ([]asset.Receipt, asset.Coin, uint64, error) {
fail := func(s string, a ...any) ([]asset.Receipt, asset.Coin, uint64, error) {
return nil, nil, 0, fmt.Errorf(s, a...)
}

Expand Down
2 changes: 1 addition & 1 deletion client/asset/eth/multirpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ func allRPCErrorsAreFails(err error) (discard, propagate, fail bool) {
return false, false, true
}

func errorFilter(err error, matches ...interface{}) bool {
func errorFilter(err error, matches ...any) bool {
errStr := err.Error()
for _, mi := range matches {
var s string
Expand Down
18 changes: 9 additions & 9 deletions client/asset/eth/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ethLogger struct {

// New returns a new Logger that has this logger's context plus the given
// context.
func (el *ethLogger) New(ctx ...interface{}) log.Logger {
func (el *ethLogger) New(ctx ...any) log.Logger {
s := ""
for _, v := range ctx {
if s == "" {
Expand Down Expand Up @@ -74,8 +74,8 @@ func (el *ethLogger) GetHandler() log.Handler {
// Used during setup in geth when a logger is not supplied. Does nothing here.
func (el *ethLogger) SetHandler(h log.Handler) {}

func formatEthLog(msg string, ctx ...interface{}) []interface{} {
msgs := []interface{}{msg, " "}
func formatEthLog(msg string, ctx ...any) []any {
msgs := []any{msg, " "}
alternator := 0
for _, v := range ctx {
deliminator := "="
Expand All @@ -89,32 +89,32 @@ func formatEthLog(msg string, ctx ...interface{}) []interface{} {
}

// Trace logs at Trace level.
func (el *ethLogger) Trace(msg string, ctx ...interface{}) {
func (el *ethLogger) Trace(msg string, ctx ...any) {
el.dl.Trace(formatEthLog(msg, ctx...)...)
}

// Debug logs at debug level.
func (el *ethLogger) Debug(msg string, ctx ...interface{}) {
func (el *ethLogger) Debug(msg string, ctx ...any) {
el.dl.Debug(formatEthLog(msg, ctx...)...)
}

// Info logs at info level.
func (el *ethLogger) Info(msg string, ctx ...interface{}) {
func (el *ethLogger) Info(msg string, ctx ...any) {
el.dl.Info(formatEthLog(msg, ctx...)...)
}

// Warn logs at warn level.
func (el *ethLogger) Warn(msg string, ctx ...interface{}) {
func (el *ethLogger) Warn(msg string, ctx ...any) {
el.dl.Warn(formatEthLog(msg, ctx...)...)
}

// Error logs at error level.
func (el *ethLogger) Error(msg string, ctx ...interface{}) {
func (el *ethLogger) Error(msg string, ctx ...any) {
el.dl.Error(formatEthLog(msg, ctx...)...)
}

// Crit logs at critical level.
func (el *ethLogger) Crit(msg string, ctx ...interface{}) {
func (el *ethLogger) Crit(msg string, ctx ...any) {
el.dl.Critical(formatEthLog(msg, ctx...)...)
}

Expand Down
Loading

0 comments on commit 7db15ed

Please sign in to comment.