diff --git a/cmd/stellar-rpc/internal/config/flags.go b/cmd/stellar-rpc/internal/config/flags.go index d0af16d76..f64ad036b 100644 --- a/cmd/stellar-rpc/internal/config/flags.go +++ b/cmd/stellar-rpc/internal/config/flags.go @@ -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) diff --git a/cmd/stellar-rpc/internal/config/log_format.go b/cmd/stellar-rpc/internal/config/log_format.go index 1ab4c7fc6..db2e3f41e 100644 --- a/cmd/stellar-rpc/internal/config/log_format.go +++ b/cmd/stellar-rpc/internal/config/log_format.go @@ -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) diff --git a/cmd/stellar-rpc/internal/config/option.go b/cmd/stellar-rpc/internal/config/option.go index 91ce47858..e2efe0ef7 100644 --- a/cmd/stellar-rpc/internal/config/option.go +++ b/cmd/stellar-rpc/internal/config/option.go @@ -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 } @@ -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) } @@ -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) { @@ -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) } diff --git a/cmd/stellar-rpc/internal/config/option_test.go b/cmd/stellar-rpc/internal/config/option_test.go index 4fc083541..93855a262 100644 --- a/cmd/stellar-rpc/internal/config/option_test.go +++ b/cmd/stellar-rpc/internal/config/option_test.go @@ -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, ""}, @@ -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, ""}, @@ -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, ""}, @@ -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, ""}, @@ -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, ""}, @@ -201,7 +201,7 @@ func TestSetValueString(t *testing.T) { var s string testCases := []struct { name string - value interface{} + value any err string }{ {"valid-string", "foobar", ""}, @@ -209,9 +209,9 @@ func TestSetValueString(t *testing.T) { 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 }, ) { diff --git a/cmd/stellar-rpc/internal/config/options.go b/cmd/stellar-rpc/internal/config/options.go index cb6c0a92e..5fd905d74 100644 --- a/cmd/stellar-rpc/internal/config/options.go +++ b/cmd/stellar-rpc/internal/config/options.go @@ -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 @@ -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 }, }, @@ -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 @@ -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() }, }, @@ -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 == "." { @@ -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) @@ -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) @@ -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) diff --git a/cmd/stellar-rpc/internal/config/options_test.go b/cmd/stellar-rpc/internal/config/options_test.go index 0478b6288..df86bb04e 100644 --- a/cmd/stellar-rpc/internal/config/options_test.go +++ b/cmd/stellar-rpc/internal/config/options_test.go @@ -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] { diff --git a/cmd/stellar-rpc/internal/config/parse.go b/cmd/stellar-rpc/internal/config/parse.go index f07c1b5ef..78f12c63d 100644 --- a/cmd/stellar-rpc/internal/config/parse.go +++ b/cmd/stellar-rpc/internal/config/parse.go @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) diff --git a/cmd/stellar-rpc/internal/config/toml.go b/cmd/stellar-rpc/internal/config/toml.go index 038a6f749..f8cc2a0bb 100644 --- a/cmd/stellar-rpc/internal/config/toml.go +++ b/cmd/stellar-rpc/internal/config/toml.go @@ -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 } diff --git a/cmd/stellar-rpc/internal/config/toml_test.go b/cmd/stellar-rpc/internal/config/toml_test.go index f30f6a4ab..b80024d56 100644 --- a/cmd/stellar-rpc/internal/config/toml_test.go +++ b/cmd/stellar-rpc/internal/config/toml_test.go @@ -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 } diff --git a/cmd/stellar-rpc/internal/db/ledger.go b/cmd/stellar-rpc/internal/db/ledger.go index c28b1782f..37f3af45f 100644 --- a/cmd/stellar-rpc/internal/db/ledger.go +++ b/cmd/stellar-rpc/internal/db/ledger.go @@ -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 { diff --git a/cmd/stellar-rpc/internal/jsonrpc.go b/cmd/stellar-rpc/internal/jsonrpc.go index f7acbf8a5..a822855e9 100644 --- a/cmd/stellar-rpc/internal/jsonrpc.go +++ b/cmd/stellar-rpc/internal/jsonrpc.go @@ -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() diff --git a/cmd/stellar-rpc/internal/methods/get_events_test.go b/cmd/stellar-rpc/internal/methods/get_events_test.go index 110b8dbaa..87d54b343 100644 --- a/cmd/stellar-rpc/internal/methods/get_events_test.go +++ b/cmd/stellar-rpc/internal/methods/get_events_test.go @@ -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) diff --git a/cmd/stellar-rpc/internal/methods/get_ledgers_test.go b/cmd/stellar-rpc/internal/methods/get_ledgers_test.go index 9a47d7b5f..0b81d534c 100644 --- a/cmd/stellar-rpc/internal/methods/get_ledgers_test.go +++ b/cmd/stellar-rpc/internal/methods/get_ledgers_test.go @@ -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) diff --git a/cmd/stellar-rpc/internal/methods/get_transaction_test.go b/cmd/stellar-rpc/internal/methods/get_transaction_test.go index ef9d7c63e..f2ea8875a 100644 --- a/cmd/stellar-rpc/internal/methods/get_transaction_test.go +++ b/cmd/stellar-rpc/internal/methods/get_transaction_test.go @@ -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'") @@ -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"]) } diff --git a/cmd/stellar-rpc/internal/methods/get_transactions_test.go b/cmd/stellar-rpc/internal/methods/get_transactions_test.go index 55a7fa50e..0097c75f9 100644 --- a/cmd/stellar-rpc/internal/methods/get_transactions_test.go +++ b/cmd/stellar-rpc/internal/methods/get_transactions_test.go @@ -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'") diff --git a/cmd/stellar-rpc/internal/methods/json.go b/cmd/stellar-rpc/internal/methods/json.go index d4de18afe..71c8d0bbe 100644 --- a/cmd/stellar-rpc/internal/methods/json.go +++ b/cmd/stellar-rpc/internal/methods/json.go @@ -53,7 +53,7 @@ func ledgerToJSON(chunk *db.LedgerMetadataChunk) ([]byte, []byte, error) { return closeMetaJSON, headerJSON, nil } -func jsonifySlice(xdr interface{}, values [][]byte) ([]json.RawMessage, error) { +func jsonifySlice(xdr any, values [][]byte) ([]json.RawMessage, error) { result := make([]json.RawMessage, len(values)) var err error @@ -68,7 +68,7 @@ func jsonifySlice(xdr interface{}, values [][]byte) ([]json.RawMessage, error) { } // helper function to jsonify slices of slices like ContractEvents -func jsonifySliceOfSlices(xdr interface{}, values [][][]byte) ([][]json.RawMessage, error) { +func jsonifySliceOfSlices(xdr any, values [][][]byte) ([][]json.RawMessage, error) { jsonResult := make([][]json.RawMessage, 0, len(values)) for _, slice := range values { convertedSlice, err := jsonifySlice(xdr, slice) diff --git a/cmd/stellar-rpc/internal/network/backlogQ.go b/cmd/stellar-rpc/internal/network/backlogQ.go index 185604825..9cc42bb65 100644 --- a/cmd/stellar-rpc/internal/network/backlogQ.go +++ b/cmd/stellar-rpc/internal/network/backlogQ.go @@ -93,7 +93,7 @@ func (q *backlogHTTPQLimiter) ServeHTTP(res http.ResponseWriter, req *http.Reque q.httpDownstreamHandler.ServeHTTP(res, req) } -func (q *backlogJrpcQLimiter) Handle(ctx context.Context, req *jrpc2.Request) (interface{}, error) { +func (q *backlogJrpcQLimiter) Handle(ctx context.Context, req *jrpc2.Request) (any, error) { if q.limit == RequestBacklogQueueNoLimit { // if specified max duration, pass-through return q.jrpcDownstreamHandler(ctx, req) diff --git a/cmd/stellar-rpc/internal/network/backlogQ_test.go b/cmd/stellar-rpc/internal/network/backlogQ_test.go index ef35e4d91..b1c58c8d4 100644 --- a/cmd/stellar-rpc/internal/network/backlogQ_test.go +++ b/cmd/stellar-rpc/internal/network/backlogQ_test.go @@ -21,10 +21,10 @@ func (t *TestingHandlerWrapper) ServeHTTP(res http.ResponseWriter, req *http.Req } type TestingJrpcHandlerWrapper struct { - f func(context.Context, *jrpc2.Request) (interface{}, error) + f func(context.Context, *jrpc2.Request) (any, error) } -func (t *TestingJrpcHandlerWrapper) Handle(ctx context.Context, req *jrpc2.Request) (interface{}, error) { +func (t *TestingJrpcHandlerWrapper) Handle(ctx context.Context, req *jrpc2.Request) (any, error) { return t.f(ctx, req) } @@ -67,7 +67,7 @@ func TestBacklogQueueLimiter_JrpcNonBlocking(t *testing.T) { var sum uint64 var wg sync.WaitGroup requestsSizeLimit := uint64(1000) - adding := &TestingJrpcHandlerWrapper{f: func(context.Context, *jrpc2.Request) (interface{}, error) { + adding := &TestingJrpcHandlerWrapper{f: func(context.Context, *jrpc2.Request) (any, error) { atomic.AddUint64(&sum, 1) return nil, nil }} @@ -99,7 +99,7 @@ func TestBacklogQueueLimiter_JrpcNonBlocking(t *testing.T) { // and see that requests could go though. func TestBacklogQueueLimiter_HttpBlocking(t *testing.T) { for _, queueSize := range []uint64{7, 50, 80} { - blockedCh := make(chan interface{}) + blockedCh := make(chan any) var initialGroupBlocking sync.WaitGroup initialGroupBlocking.Add(int(queueSize) / 2) blockedHandlers := &TestingHandlerWrapper{f: func(res http.ResponseWriter, req *http.Request) { @@ -121,7 +121,7 @@ func TestBacklogQueueLimiter_HttpBlocking(t *testing.T) { var secondBlockingGroupWg sync.WaitGroup secondBlockingGroupWg.Add(int(queueSize) - int(queueSize)/2) - secondBlockingGroupWgCh := make(chan interface{}) + secondBlockingGroupWgCh := make(chan any) secondBlockingGroupWgHandlers := &TestingHandlerWrapper{f: func(res http.ResponseWriter, req *http.Request) { secondBlockingGroupWg.Done() <-secondBlockingGroupWgCh @@ -170,10 +170,10 @@ func TestBacklogQueueLimiter_HttpBlocking(t *testing.T) { // and see that requests could go though. func TestBacklogQueueLimiter_JrpcBlocking(t *testing.T) { for _, queueSize := range []uint64{7, 50, 80} { - blockedCh := make(chan interface{}) + blockedCh := make(chan any) var initialGroupBlocking sync.WaitGroup initialGroupBlocking.Add(int(queueSize) / 2) - blockedHandlers := &TestingJrpcHandlerWrapper{f: func(context.Context, *jrpc2.Request) (interface{}, error) { + blockedHandlers := &TestingJrpcHandlerWrapper{f: func(context.Context, *jrpc2.Request) (any, error) { initialGroupBlocking.Done() <-blockedCh return nil, nil @@ -193,8 +193,8 @@ func TestBacklogQueueLimiter_JrpcBlocking(t *testing.T) { var secondBlockingGroupWg sync.WaitGroup secondBlockingGroupWg.Add(int(queueSize) - int(queueSize)/2) - secondBlockingGroupWgCh := make(chan interface{}) - secondBlockingGroupWgHandlers := &TestingJrpcHandlerWrapper{f: func(context.Context, *jrpc2.Request) (interface{}, error) { + secondBlockingGroupWgCh := make(chan any) + secondBlockingGroupWgHandlers := &TestingJrpcHandlerWrapper{f: func(context.Context, *jrpc2.Request) (any, error) { secondBlockingGroupWg.Done() <-secondBlockingGroupWgCh return nil, nil diff --git a/cmd/stellar-rpc/internal/network/requestdurationlimiter.go b/cmd/stellar-rpc/internal/network/requestdurationlimiter.go index 6aaa6f243..131785c2a 100644 --- a/cmd/stellar-rpc/internal/network/requestdurationlimiter.go +++ b/cmd/stellar-rpc/internal/network/requestdurationlimiter.go @@ -229,7 +229,7 @@ func MakeJrpcRequestDurationLimiter( // TODO: this function is too complicated we should fix this and remove the nolint:gocognit // //nolint:gocognit,cyclop -func (q *RPCRequestDurationLimiter) Handle(ctx context.Context, req *jrpc2.Request) (interface{}, error) { +func (q *RPCRequestDurationLimiter) Handle(ctx context.Context, req *jrpc2.Request) (any, error) { if q.limitThreshold == RequestDurationLimiterNoLimit { // if specified max duration, pass-through return q.jrpcDownstreamHandler(ctx, req) @@ -243,7 +243,7 @@ func (q *RPCRequestDurationLimiter) Handle(ctx context.Context, req *jrpc2.Reque limitCh = time.NewTimer(q.limitThreshold).C } type requestResultOutput struct { - data interface{} + data any err error } requestCompleted := make(chan requestResultOutput, 1) diff --git a/cmd/stellar-rpc/internal/network/requestdurationlimiter_test.go b/cmd/stellar-rpc/internal/network/requestdurationlimiter_test.go index b76448808..53cd6478b 100644 --- a/cmd/stellar-rpc/internal/network/requestdurationlimiter_test.go +++ b/cmd/stellar-rpc/internal/network/requestdurationlimiter_test.go @@ -165,13 +165,13 @@ func TestHTTPRequestDurationLimiter_NoLimiting_Warn(t *testing.T) { shutdown() } -type JRPCHandlerFunc func(ctx context.Context, r *jrpc2.Request) (interface{}, error) +type JRPCHandlerFunc func(ctx context.Context, r *jrpc2.Request) (any, error) func bindRPCHoist(redirector *TestServerHandlerWrapper) *JRPCHandlerFunc { var hoistFunction JRPCHandlerFunc bridgeMap := handler.Map{ - "method": handler.New(func(ctx context.Context, r *jrpc2.Request) (interface{}, error) { + "method": handler.New(func(ctx context.Context, r *jrpc2.Request) (any, error) { return hoistFunction(ctx, r) }), } @@ -184,7 +184,7 @@ func TestJRPCRequestDurationLimiter_Limiting(t *testing.T) { addr, redirector, shutdown := createTestServer() hoistFunction := bindRPCHoist(redirector) - longExecutingHandler := handler.New(func(ctx context.Context, r *jrpc2.Request) (interface{}, error) { + longExecutingHandler := handler.New(func(ctx context.Context, r *jrpc2.Request) (any, error) { select { case <-ctx.Done(): return nil, ctx.Err() @@ -208,7 +208,7 @@ func TestJRPCRequestDurationLimiter_Limiting(t *testing.T) { client := jrpc2.NewClient(ch, nil) defer client.Close() - var res interface{} + var res any req := struct { i int }{1} @@ -229,7 +229,7 @@ func TestJRPCRequestDurationLimiter_NoLimiting(t *testing.T) { hoistFunction := bindRPCHoist(redirector) returnString := "ok" - longExecutingHandler := handler.New(func(ctx context.Context, r *jrpc2.Request) (interface{}, error) { + longExecutingHandler := handler.New(func(ctx context.Context, r *jrpc2.Request) (any, error) { select { case <-ctx.Done(): return nil, ctx.Err() @@ -253,7 +253,7 @@ func TestJRPCRequestDurationLimiter_NoLimiting(t *testing.T) { client := jrpc2.NewClient(ch, nil) defer client.Close() - var res interface{} + var res any req := struct { i int }{1} @@ -271,7 +271,7 @@ func TestJRPCRequestDurationLimiter_NoLimiting_Warn(t *testing.T) { hoistFunction := bindRPCHoist(redirector) returnString := "ok" - longExecutingHandler := handler.New(func(ctx context.Context, r *jrpc2.Request) (interface{}, error) { + longExecutingHandler := handler.New(func(ctx context.Context, r *jrpc2.Request) (any, error) { select { case <-ctx.Done(): return nil, ctx.Err() @@ -295,7 +295,7 @@ func TestJRPCRequestDurationLimiter_NoLimiting_Warn(t *testing.T) { client := jrpc2.NewClient(ch, nil) defer client.Close() - var res interface{} + var res any req := struct { i int }{1} diff --git a/cmd/stellar-rpc/internal/xdr2json/conversion_test.go b/cmd/stellar-rpc/internal/xdr2json/conversion_test.go index 006dbd8ea..62f91fc1e 100644 --- a/cmd/stellar-rpc/internal/xdr2json/conversion_test.go +++ b/cmd/stellar-rpc/internal/xdr2json/conversion_test.go @@ -27,14 +27,14 @@ func TestConversion(t *testing.T) { require.NoError(t, err) for _, rawJs := range []json.RawMessage{jsi, jsb} { - var dest map[string]interface{} + var dest map[string]any require.NoError(t, json.Unmarshal(rawJs, &dest)) require.Contains(t, dest, "credit_alphanum4") require.Contains(t, dest["credit_alphanum4"], "asset_code") require.Contains(t, dest["credit_alphanum4"], "issuer") - require.IsType(t, map[string]interface{}{}, dest["credit_alphanum4"]) - if converted, ok := dest["credit_alphanum4"].(map[string]interface{}); assert.True(t, ok) { + require.IsType(t, map[string]any{}, dest["credit_alphanum4"]) + if converted, ok := dest["credit_alphanum4"].(map[string]any); assert.True(t, ok) { require.Equal(t, pubkey.Address(), converted["issuer"]) } } diff --git a/protocol/get_events.go b/protocol/get_events.go index 21fc07459..33a8d3942 100644 --- a/protocol/get_events.go +++ b/protocol/get_events.go @@ -90,7 +90,7 @@ func (e *EventFilter) Valid() error { return nil } -type EventTypeSet map[string]interface{} //nolint:recvcheck +type EventTypeSet map[string]any //nolint:recvcheck func (e EventTypeSet) valid() error { for key := range e { @@ -106,14 +106,14 @@ func (e EventTypeSet) valid() error { func (e *EventTypeSet) UnmarshalJSON(data []byte) error { if len(data) == 0 { - *e = map[string]interface{}{} + *e = map[string]any{} return nil } var joined string if err := json.Unmarshal(data, &joined); err != nil { return err } - *e = map[string]interface{}{} + *e = map[string]any{} if len(joined) == 0 { return nil } diff --git a/protocol/get_events_test.go b/protocol/get_events_test.go index 480b65cd6..bcc23c642 100644 --- a/protocol/get_events_test.go +++ b/protocol/get_events_test.go @@ -661,7 +661,7 @@ func TestGetEventsRequestValid(t *testing.T) { err := (&GetEventsRequest{ StartLedger: 1, Filters: []EventFilter{ - {EventType: map[string]interface{}{"foo": nil}}, + {EventType: map[string]any{"foo": nil}}, }, Pagination: nil, }).Valid(1000)