mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
rpc: use interface instead of json.RawMessage
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
6502413f26
commit
229e19055d
1 changed files with 8 additions and 10 deletions
|
|
@ -105,7 +105,7 @@ type Notifier struct {
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
sub *Subscription
|
sub *Subscription
|
||||||
buffer []json.RawMessage
|
buffer []interface{}
|
||||||
callReturned bool
|
callReturned bool
|
||||||
activated bool
|
activated bool
|
||||||
}
|
}
|
||||||
|
|
@ -130,11 +130,6 @@ func (n *Notifier) CreateSubscription() *Subscription {
|
||||||
// Notify sends a notification to the client with the given data as payload.
|
// Notify sends a notification to the client with the given data as payload.
|
||||||
// If an error occurs the RPC connection is closed and the error is returned.
|
// If an error occurs the RPC connection is closed and the error is returned.
|
||||||
func (n *Notifier) Notify(id ID, data interface{}) error {
|
func (n *Notifier) Notify(id ID, data interface{}) error {
|
||||||
enc, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
n.mu.Lock()
|
n.mu.Lock()
|
||||||
defer n.mu.Unlock()
|
defer n.mu.Unlock()
|
||||||
|
|
||||||
|
|
@ -144,9 +139,9 @@ func (n *Notifier) Notify(id ID, data interface{}) error {
|
||||||
panic("Notify with wrong ID")
|
panic("Notify with wrong ID")
|
||||||
}
|
}
|
||||||
if n.activated {
|
if n.activated {
|
||||||
return n.send(n.sub, enc)
|
return n.send(n.sub, data)
|
||||||
}
|
}
|
||||||
n.buffer = append(n.buffer, enc)
|
n.buffer = append(n.buffer, data)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,8 +176,11 @@ func (n *Notifier) activate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) send(sub *Subscription, data json.RawMessage) error {
|
func (n *Notifier) send(sub *Subscription, data interface{}) error {
|
||||||
params, _ := json.Marshal(&subscriptionResult{ID: string(sub.ID), Result: data})
|
params, _ := json.Marshal(struct {
|
||||||
|
ID string `json:"subscription"`
|
||||||
|
Result interface{} `json:"result,omitempty"`
|
||||||
|
}{ID: string(sub.ID), Result: data})
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
msg := &jsonrpcMessage{
|
msg := &jsonrpcMessage{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue