Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeShimizu committed Jun 15, 2024
1 parent 1d98fe2 commit 35df61c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion clightning/clightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
log2 "log"
Expand Down Expand Up @@ -426,12 +427,32 @@ func (cl *ClightningClient) OnRPCCommand(event *glightning.RpcCommandEvent) (*gl
ok, err := cl.liquidWallet.Ping()
if err != nil || !ok {
log.Infof("trying to send command %s, but failed to connect: %v", event.Cmd.MethodName, err)
return event.ReturnError("liquid_unavailable", -1)
return cl.ReturnError("liquid_unavailable", -1)
}
}
return event.Continue(), nil
}

func (cl *ClightningClient) ReturnError(errMsg string, errCode int) (*glightning.RpcCommandResponse, error) {
type ErrResp struct {
Message string `json:"message"`
Code int `json:"code"`
}
result := &struct {
Result ErrResp `json:"error"`
}{
Result: ErrResp{errMsg, errCode},
}
marshaled, err := json.Marshal(result)
if err != nil {
return nil, err
}
marshaled = append(marshaled, []byte("\n\n")...)
return &glightning.RpcCommandResponse{
ReturnObj: marshaled,
}, nil
}

// AddMessageHandler adds a listener for incoming peermessages
func (cl *ClightningClient) AddMessageHandler(f func(peerId string, msgType string, payload []byte) error) {
cl.msgHandlers = append(cl.msgHandlers, f)
Expand Down

0 comments on commit 35df61c

Please sign in to comment.