-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Open
Labels
Description
Rationale
The ws/wss client needs to add rate limiting calls. Most third-party nodes have frequency limitations.
Or a global data convert.
(I can use "http.Client.RoundTripper.RoundTrip()" implement custom handling support for http/https in the current client code. But ws/wss/other cannot do it because the now ethclient code directly writes raw data, which is not suitable for RPC responses. )
Implementation
//case 1:
type NextRpcHandler func(context.Context, any) error
client1 := rpc.DialOptions(ctx, target, rpc.WithRpcHandler(function(ctx context.Context, msg any, next rpc.NextRpcHandler) error{
// todo: some rate limit code // before
return next(ctx, msg)
// after
}))
//case 2:
ctx = rpc.WithContextRpcHandler(ctx, function(ctx context.Context, msg any, next rpc.NextRpcHandler) error{
// todo: some rate limit code // before
return next(ctx, msg)
// after
}))
client2.xxxxMethod(ctx, ...)
client2.xxxxMethod(ctx, ...)
//////////////