Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (o *Option) AddFlag(flagset *pflag.FlagSet) error {
}

//nolint:cyclop
func (o *Option) GetFlag(flagset *pflag.FlagSet) (interface{}, error) {
func (o *Option) GetFlag(flagset *pflag.FlagSet) (any, error) {
// Treat any option with a custom parser as a string option.
if o.CustomSetValue != nil {
return flagset.GetString(o.Name)
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/config/log_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (f LogFormat) MarshalTOML() ([]byte, error) {
return f.MarshalText()
}

func (f *LogFormat) UnmarshalTOML(i interface{}) error {
func (f *LogFormat) UnmarshalTOML(i any) error {
switch v := i.(type) {
case []byte:
return f.UnmarshalText(v)
Expand Down
14 changes: 7 additions & 7 deletions cmd/stellar-rpc/internal/config/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ type Option struct {
// Help text
Usage string
// A default if no option is provided. Omit or set to `nil` if no default
DefaultValue interface{}
DefaultValue any
// Pointer to the final key in the linked Config struct
ConfigKey interface{}
ConfigKey any
// Optional function for custom validation/transformation
CustomSetValue func(*Option, interface{}) error
CustomSetValue func(*Option, any) error
// Function called after loading all options, to validate the configuration
Validate func(*Option) error
MarshalTOML func(*Option) (interface{}, error)
MarshalTOML func(*Option) (any, error)

flag *pflag.Flag // The persistent flag that the config option is attached to
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func (o Option) getEnvKey() (string, bool) {
}

// TODO: See if we can remove CustomSetValue into just SetValue/ParseValue
func (o *Option) setValue(i interface{}) (err error) {
func (o *Option) setValue(i any) (err error) {
if o.CustomSetValue != nil {
return o.CustomSetValue(o, i)
}
Expand All @@ -108,7 +108,7 @@ func (o *Option) setValue(i interface{}) (err error) {
err = fmt.Errorf("config option setting error ('%s') %v", o.Name, recoverRes)
}
}()
parser := func(_ *Option, _ interface{}) error {
parser := func(_ *Option, _ any) error {
return fmt.Errorf("no parser for flag %s", o.Name)
}
switch o.ConfigKey.(type) {
Expand All @@ -133,7 +133,7 @@ func (o *Option) setValue(i interface{}) (err error) {
return parser(o, i)
}

func (o *Option) marshalTOML() (interface{}, error) {
func (o *Option) marshalTOML() (any, error) {
if o.MarshalTOML != nil {
return o.MarshalTOML(o)
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/stellar-rpc/internal/config/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestSetValueBool(t *testing.T) {
var b bool
testCases := []struct {
name string
value interface{}
value any
err string
}{
{"valid-bool", true, ""},
Expand All @@ -145,7 +145,7 @@ func TestSetValueInt(t *testing.T) {
var i int
testCases := []struct {
name string
value interface{}
value any
err string
}{
{"valid-int", 1, ""},
Expand All @@ -159,7 +159,7 @@ func TestSetValueUint32(t *testing.T) {
var u32 uint32
testCases := []struct {
name string
value interface{}
value any
err string
}{
{"valid-uint32", 1, ""},
Expand All @@ -173,7 +173,7 @@ func TestSetValueUint64(t *testing.T) {
var u64 uint64
testCases := []struct {
name string
value interface{}
value any
err string
}{
{"valid-uint", 1, ""},
Expand All @@ -186,7 +186,7 @@ func TestSetValueFloat64(t *testing.T) {
var f64 float64
testCases := []struct {
name string
value interface{}
value any
err string
}{
{"valid-float", 1.05, ""},
Expand All @@ -201,17 +201,17 @@ func TestSetValueString(t *testing.T) {
var s string
testCases := []struct {
name string
value interface{}
value any
err string
}{
{"valid-string", "foobar", ""},
}
runTestCases(t, &s, testCases)
}

func runTestCases(t *testing.T, key interface{}, testCases []struct {
func runTestCases(t *testing.T, key any, testCases []struct {
name string
value interface{}
value any
err string
},
) {
Expand Down
20 changes: 10 additions & 10 deletions cmd/stellar-rpc/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (cfg *Config) options() Options {
Usage: "minimum log severity (debug, info, warn, error) to log",
ConfigKey: &cfg.LogLevel,
DefaultValue: logrus.InfoLevel,
CustomSetValue: func(option *Option, i interface{}) error {
CustomSetValue: func(option *Option, i any) error {
switch v := i.(type) {
case nil:
return nil
Expand All @@ -137,7 +137,7 @@ func (cfg *Config) options() Options {
}
return nil
},
MarshalTOML: func(_ *Option) (interface{}, error) {
MarshalTOML: func(_ *Option) (any, error) {
return cfg.LogLevel.String(), nil
},
},
Expand All @@ -146,7 +146,7 @@ func (cfg *Config) options() Options {
Usage: "format used for output logs (json or text)",
ConfigKey: &cfg.LogFormat,
DefaultValue: LogFormatText,
CustomSetValue: func(option *Option, i interface{}) error {
CustomSetValue: func(option *Option, i any) error {
switch v := i.(type) {
case nil:
return nil
Expand All @@ -163,7 +163,7 @@ func (cfg *Config) options() Options {
}
return nil
},
MarshalTOML: func(_ *Option) (interface{}, error) {
MarshalTOML: func(_ *Option) (any, error) {
return cfg.LogFormat.String()
},
},
Expand All @@ -184,7 +184,7 @@ func (cfg *Config) options() Options {
Name: "captive-core-storage-path",
Usage: "Storage location for Captive Core bucket data",
ConfigKey: &cfg.CaptiveCoreStoragePath,
CustomSetValue: func(option *Option, i interface{}) error {
CustomSetValue: func(option *Option, i any) error {
switch v := i.(type) {
case string:
if v == "" || v == "." {
Expand Down Expand Up @@ -590,10 +590,10 @@ func (cfg *Config) options() Options {
TomlKey: "buffered_storage_backend_config",
ConfigKey: &cfg.BufferedStorageBackendConfig,
Usage: "Buffered storage backend configuration for reading ledgers from the datastore.",
CustomSetValue: func(option *Option, i interface{}) error {
CustomSetValue: func(option *Option, i any) error {
return unmarshalTOMLTree(i, option.ConfigKey, "buffered_storage_backend_config")
},
MarshalTOML: func(_ *Option) (interface{}, error) {
MarshalTOML: func(_ *Option) (any, error) {
tomlBytes, err := toml.Marshal(defaultBufferedStorageBackendConfig())
if err != nil {
return nil, fmt.Errorf("failed to marshal buffered_storage_backend_config: %w", err)
Expand All @@ -605,10 +605,10 @@ func (cfg *Config) options() Options {
TomlKey: "datastore_config",
ConfigKey: &cfg.DataStoreConfig,
Usage: "External datastore configuration including type, bucket name and schema.",
CustomSetValue: func(option *Option, i interface{}) error {
CustomSetValue: func(option *Option, i any) error {
return unmarshalTOMLTree(i, option.ConfigKey, "datastore_config")
},
MarshalTOML: func(_ *Option) (interface{}, error) {
MarshalTOML: func(_ *Option) (any, error) {
tomlBytes, err := toml.Marshal(defaultDataStoreConfig())
if err != nil {
return nil, fmt.Errorf("failed to marshal datastore_config: %w", err)
Expand Down Expand Up @@ -641,7 +641,7 @@ func defaultDataStoreConfig() datastore.DataStoreConfig {
}
}

func unmarshalTOMLTree(tree interface{}, out interface{}, configName string) error {
func unmarshalTOMLTree(tree any, out any, configName string) error {
t, ok := tree.(*toml.Tree)
if !ok {
return fmt.Errorf("expected TOML table for %s, got %T", configName, tree)
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/config/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestAllOptionsMustHaveAUniqueValidTomlKey(t *testing.T) {

cfg := Config{}
options := cfg.options()
optionsByTomlKey := map[string]interface{}{}
optionsByTomlKey := map[string]any{}
for _, option := range options {
key, ok := option.getTomlKey()
if excluded[option.Name] {
Expand Down
18 changes: 9 additions & 9 deletions cmd/stellar-rpc/internal/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"
)

func parseBool(option *Option, i interface{}) error {
func parseBool(option *Option, i any) error {
switch v := i.(type) {
case nil:
return nil
Expand All @@ -30,7 +30,7 @@ func parseBool(option *Option, i interface{}) error {
return nil
}

func parseInt(option *Option, i interface{}) error {
func parseInt(option *Option, i any) error {
switch v := i.(type) {
case nil:
return nil
Expand All @@ -48,7 +48,7 @@ func parseInt(option *Option, i interface{}) error {
return nil
}

func parseUint(option *Option, i interface{}) error {
func parseUint(option *Option, i any) error {
switch v := i.(type) {
case nil:
return nil
Expand All @@ -71,7 +71,7 @@ func parseUint(option *Option, i interface{}) error {
return nil
}

func parseFloat(option *Option, i interface{}) error {
func parseFloat(option *Option, i any) error {
switch v := i.(type) {
case nil:
return nil
Expand All @@ -89,7 +89,7 @@ func parseFloat(option *Option, i interface{}) error {
return nil
}

func parseString(option *Option, i interface{}) error {
func parseString(option *Option, i any) error {
switch v := i.(type) {
case nil:
return nil
Expand All @@ -105,7 +105,7 @@ func parseString(option *Option, i interface{}) error {
return nil
}

func parseUint32(option *Option, i interface{}) error {
func parseUint32(option *Option, i any) error {
switch v := i.(type) {
case nil:
return nil
Expand All @@ -131,7 +131,7 @@ func parseUint32(option *Option, i interface{}) error {
return nil
}

func parseDuration(option *Option, i interface{}) error {
func parseDuration(option *Option, i any) error {
durationPtr, ok := option.ConfigKey.(*time.Duration)
if !ok {
return fmt.Errorf("invalid type for %s: expected *time.Duration", option.Name)
Expand All @@ -156,7 +156,7 @@ func parseDuration(option *Option, i interface{}) error {
return nil
}

func parseStringSlice(option *Option, i interface{}) error {
func parseStringSlice(option *Option, i any) error {
stringSlicePtr, ok := option.ConfigKey.(*[]string)
if !ok {
return fmt.Errorf("invalid type for %s: expected *[]string", option.Name)
Expand All @@ -173,7 +173,7 @@ func parseStringSlice(option *Option, i interface{}) error {
}
case []string:
*stringSlicePtr = v
case []interface{}:
case []any:
result := make([]string, len(v))
for i, s := range v {
str, ok := s.(string)
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func parseToml(r io.Reader, strict bool, cfg *Config) error {
}

func (cfg *Config) MarshalTOML() ([]byte, error) {
tree, err := toml.TreeFromMap(map[string]interface{}{})
tree, err := toml.TreeFromMap(map[string]any{})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/config/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestRoundTripDataStoreConfig(t *testing.T) {
}

func marshalTOML(cfg *Config) ([]byte, error) {
tree, err := toml.TreeFromMap(map[string]interface{}{})
tree, err := toml.TreeFromMap(map[string]any{})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/db/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type LedgerWriter interface {
}

type readDB interface {
Select(ctx context.Context, dest interface{}, query sq.Sqlizer) error
Select(ctx context.Context, dest any, query sq.Sqlizer) error
}

type ledgerReader struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func decorateHandlers(daemon interfaces.Daemon, logger *log.Entry, m handler.Map
for endpoint, h := range m {
// create copy of h, so it can be used in closure below
h := h
decorated[endpoint] = handler.New(func(ctx context.Context, r *jrpc2.Request) (interface{}, error) {
decorated[endpoint] = handler.New(func(ctx context.Context, r *jrpc2.Request) (any, error) {
reqID := strconv.FormatUint(middleware.NextRequestID(), 10)
logRequest(logger, reqID, r)
startTime := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/methods/get_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func TestGetEvents(t *testing.T) {
results, err := handler.getEvents(context.TODO(), protocol.GetEventsRequest{
StartLedger: 1,
Filters: []protocol.EventFilter{
{EventType: map[string]interface{}{protocol.EventTypeSystem: nil}},
{EventType: map[string]any{protocol.EventTypeSystem: nil}},
},
})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/stellar-rpc/internal/methods/get_ledgers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ func TestGetLedgers_JSONFormat(t *testing.T) {
assert.NotEmpty(t, ledger.LedgerMetadataJSON)
assert.Empty(t, ledger.LedgerMetadata)

var headerJSON map[string]interface{}
var headerJSON map[string]any
err = json.Unmarshal(ledger.LedgerHeaderJSON, &headerJSON)
require.NoError(t, err)
assert.NotEmpty(t, headerJSON)

var metaJSON map[string]interface{}
var metaJSON map[string]any
err = json.Unmarshal(ledger.LedgerMetadataJSON, &metaJSON)
require.NoError(t, err)
assert.NotEmpty(t, metaJSON)
Expand Down
4 changes: 2 additions & 2 deletions cmd/stellar-rpc/internal/methods/get_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func TestGetTransaction_JSONFormat(t *testing.T) {
jsBytes, err := json.Marshal(txResp)
require.NoError(t, err)

var tx map[string]interface{}
var tx map[string]any
require.NoError(t, json.Unmarshal(jsBytes, &tx))

require.Nilf(t, tx["envelopeXdr"], "field: 'envelopeXdr'")
Expand All @@ -449,7 +449,7 @@ func TestGetTransaction_JSONFormat(t *testing.T) {
envJs, err := xdr2json.ConvertInterface(lookupEnv)
require.NoError(t, err)

var envelope map[string]interface{}
var envelope map[string]any
require.NoError(t, json.Unmarshal(envJs, &envelope))
require.Equal(t, envelope, tx["envelopeJson"])
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/stellar-rpc/internal/methods/get_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestGetTransactions_JSONFormat(t *testing.T) {
jsBytes, err := json.Marshal(txResp)
require.NoError(t, err)

var tx map[string]interface{}
var tx map[string]any
require.NoError(t, json.Unmarshal(jsBytes, &tx))

require.Nilf(t, tx["envelopeXdr"], "field: 'envelopeXdr'")
Expand Down
Loading