rpc: add method to test for subscription support (#25942)

This adds two ways to check for subscription support. First, one can now check
whether the transport method (HTTP/WS/etc.) is capable of subscriptions using
the new Client.SupportsSubscriptions method.

Second, the error returned by Subscribe can now reliably be tested using this
pattern:
    
    sub, err := client.Subscribe(...)
    if errors.Is(err, rpc.ErrNotificationsUnsupported) {
        // no subscription support
    }

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
zhiqiangxu
2023-06-14 14:04:41 +02:00
committed by GitHub
co-authored by Felix Lange
parent 8bbaf882a6
commit 6f08c2f3f1
4 changed files with 54 additions and 12 deletions
+1 -4
View File
@@ -530,10 +530,7 @@ func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage
// handleSubscribe processes *_subscribe method calls.
func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage {
if !h.allowSubscribe {
return msg.errorResponse(&internalServerError{
code: errcodeNotificationsUnsupported,
message: ErrNotificationsUnsupported.Error(),
})
return msg.errorResponse(ErrNotificationsUnsupported)
}
// Subscription method name is first argument.