aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/utils.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-04-05 15:43:32 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-04-05 15:43:32 +0800
commited92f116f72646e73613afc2f2e7b83472a61434 (patch)
tree6c6d3cf414e21ee37d93e30e782ec028ff0144f8 /rpc/utils.go
parent6a185531d2cd2003bb4352c391f9dca023894d5a (diff)
parentf7328c5ecbd1076582a71ef7bf436485f3868b1f (diff)
downloaddexon-ed92f116f72646e73613afc2f2e7b83472a61434.tar
dexon-ed92f116f72646e73613afc2f2e7b83472a61434.tar.gz
dexon-ed92f116f72646e73613afc2f2e7b83472a61434.tar.bz2
dexon-ed92f116f72646e73613afc2f2e7b83472a61434.tar.lz
dexon-ed92f116f72646e73613afc2f2e7b83472a61434.tar.xz
dexon-ed92f116f72646e73613afc2f2e7b83472a61434.tar.zst
dexon-ed92f116f72646e73613afc2f2e7b83472a61434.zip
Merge pull request #2407 from bas-vk/rpc-notifications
RPC pub sub
Diffstat (limited to 'rpc/utils.go')
-rw-r--r--rpc/utils.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/rpc/utils.go b/rpc/utils.go
index fa114284d..d43c50495 100644
--- a/rpc/utils.go
+++ b/rpc/utils.go
@@ -45,6 +45,16 @@ func isExportedOrBuiltinType(t reflect.Type) bool {
return isExported(t.Name()) || t.PkgPath() == ""
}
+var contextType = reflect.TypeOf((*context.Context)(nil)).Elem()
+
+// isContextType returns an indication if the given t is of context.Context or *context.Context type
+func isContextType(t reflect.Type) bool {
+ for t.Kind() == reflect.Ptr {
+ t = t.Elem()
+ }
+ return t == contextType
+}
+
var errorType = reflect.TypeOf((*error)(nil)).Elem()
// Implements this type the error interface
@@ -57,6 +67,7 @@ func isErrorType(t reflect.Type) bool {
var subscriptionType = reflect.TypeOf((*Subscription)(nil)).Elem()
+// isSubscriptionType returns an indication if the given t is of Subscription or *Subscription type
func isSubscriptionType(t reflect.Type) bool {
for t.Kind() == reflect.Ptr {
t = t.Elem()
@@ -64,12 +75,17 @@ func isSubscriptionType(t reflect.Type) bool {
return t == subscriptionType
}
-// isPubSub tests whether the given method return the pair (v2.Subscription, error)
+// isPubSub tests whether the given method has as as first argument a context.Context
+// and returns the pair (Subscription, error)
func isPubSub(methodType reflect.Type) bool {
- if methodType.NumOut() != 2 {
+ // numIn(0) is the receiver type
+ if methodType.NumIn() < 2 || methodType.NumOut() != 2 {
return false
}
- return isSubscriptionType(methodType.Out(0)) && isErrorType(methodType.Out(1))
+
+ return isContextType(methodType.In(1)) &&
+ isSubscriptionType(methodType.Out(0)) &&
+ isErrorType(methodType.Out(1))
}
// formatName will convert to first character to lower case
@@ -110,8 +126,6 @@ func isBlockNumber(t reflect.Type) bool {
return t == blockNumberType
}
-var contextType = reflect.TypeOf(new(context.Context)).Elem()
-
// suitableCallbacks iterates over the methods of the given type. It will determine if a method satisfies the criteria
// for a RPC callback or a subscription callback and adds it to the collection of callbacks or subscriptions. See server
// documentation for a summary of these criteria.
@@ -205,7 +219,7 @@ METHODS:
return callbacks, subscriptions
}
-func newSubscriptionId() (string, error) {
+func newSubscriptionID() (string, error) {
var subid [16]byte
n, _ := rand.Read(subid[:])
if n != 16 {