Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion cmd/wasm-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,15 @@ func (w *wasmClient) Status(_ js.Value, _ []js.Value) interface{} {

func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
if len(args) != 3 {
log.Errorf("Invalid use of wasmClientInvokeRPC, need 3 "+
"parameters: rpcName, request, callback")
return js.ValueOf("invalid use of wasmClientInvokeRPC, " +
Comment on lines +330 to 331
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line above return

"need 3 parameters: rpcName, request, callback")
}

if w.lndConn == nil {
log.Errorf("Attempted to invoke RPC but connection is not "+
"ready")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

return js.ValueOf("RPC connection not ready")
}

Expand All @@ -340,16 +344,29 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {

method, ok := w.registry[rpcName]
if !ok {
log.Errorf("RPC method '%s' not found in registry", rpcName)
return js.ValueOf("rpc with name " + rpcName + " not found")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

}

go func() {
defer func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we seen such panics happen?

if r := recover(); r != nil {
errMsg := fmt.Sprintf("Panic in RPC call: "+
"%v", r)
log.Errorf("%s\n%s", errMsg, debug.Stack())
jsCallback.Invoke(js.ValueOf(errMsg))
}
}()

log.Infof("Calling '%s' on RPC with request %s",
rpcName, requestJSON)
cb := func(resultJSON string, err error) {
if err != nil {
log.Errorf("RPC '%s' failed: %v", rpcName, err)
jsCallback.Invoke(js.ValueOf(err.Error()))
} else {
log.Debugf("RPC '%s' succeeded with result: %s",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would Trace make more sense?

rpcName, resultJSON)
jsCallback.Invoke(js.ValueOf(resultJSON))
}
}
Expand All @@ -358,7 +375,6 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
<-ctx.Done()
}()
return nil

}

func (w *wasmClient) GetExpiry(_ js.Value, _ []js.Value) interface{} {
Expand Down