diff --git a/.github/workflows/integration_tests.yaml b/.github/workflows/integration_tests.yaml index 1fc4ca0a..4720d206 100644 --- a/.github/workflows/integration_tests.yaml +++ b/.github/workflows/integration_tests.yaml @@ -137,7 +137,8 @@ jobs: max-parallel: 6 matrix: test: [ - testLsps0GetProtocolVersions + testLsps0GetProtocolVersions, + testLsps2GetVersions ] implementation: [ CLN diff --git a/itest/lspd_test.go b/itest/lspd_test.go index 39ad0657..3c25582c 100644 --- a/itest/lspd_test.go +++ b/itest/lspd_test.go @@ -167,4 +167,8 @@ var allTestCases = []*testCase{ name: "testLsps0GetProtocolVersions", test: testLsps0GetProtocolVersions, }, + { + name: "testLsps2GetVersions", + test: testLsps2GetVersions, + }, } diff --git a/itest/lsps2_get_versions_test.go b/itest/lsps2_get_versions_test.go new file mode 100644 index 00000000..b817ca6e --- /dev/null +++ b/itest/lsps2_get_versions_test.go @@ -0,0 +1,40 @@ +package itest + +import ( + "encoding/hex" + "encoding/json" + "log" + + "github.com/breez/lntest" + "github.com/breez/lspd/lsps0" + "github.com/stretchr/testify/assert" +) + +func testLsps2GetVersions(p *testParams) { + p.BreezClient().Node().ConnectPeer(p.Lsp().LightningNode()) + + rawMsg := `{ + "method": "lsps2.get_versions", + "jsonrpc": "2.0", + "id": "example#3cad6a54d302edba4c9ade2f7ffac098", + "params": {} + }` + p.BreezClient().Node().SendCustomMessage(&lntest.CustomMsgRequest{ + PeerId: hex.EncodeToString(p.Lsp().NodeId()), + Type: lsps0.Lsps0MessageType, + Data: []byte(rawMsg), + }) + + resp := p.BreezClient().ReceiveCustomMessage() + assert.Equal(p.t, uint32(37913), resp.Type) + + content := make(map[string]json.RawMessage) + err := json.Unmarshal(resp.Data[:], &content) + lntest.CheckError(p.t, err) + + log.Print(string(resp.Data)) + result := make(map[string][]int) + err = json.Unmarshal(content["result"], &result) + lntest.CheckError(p.t, err) + assert.Equal(p.t, []int{1}, result["versions"]) +} diff --git a/lsps2/server.go b/lsps2/server.go new file mode 100644 index 00000000..f2fbac85 --- /dev/null +++ b/lsps2/server.go @@ -0,0 +1,54 @@ +package lsps2 + +import ( + "context" + + "github.com/breez/lspd/lsps0" +) + +type GetVersionsRequest struct { +} + +type GetVersionsResponse struct { + Versions []int32 `json:"versions"` +} + +type Lsps2Server interface { + GetVersions(ctx context.Context, request *GetVersionsRequest) (*GetVersionsResponse, error) +} +type server struct{} + +func NewLsps2Server() Lsps2Server { + return &server{} +} + +func (s *server) GetVersions( + ctx context.Context, + request *GetVersionsRequest, +) (*GetVersionsResponse, error) { + return &GetVersionsResponse{ + Versions: []int32{1}, + }, nil +} + +func RegisterLsps2Server(s lsps0.ServiceRegistrar, l Lsps2Server) { + s.RegisterService( + &lsps0.ServiceDesc{ + ServiceName: "lsps2", + HandlerType: (*Lsps2Server)(nil), + Methods: []lsps0.MethodDesc{ + { + MethodName: "lsps2.get_versions", + Handler: func(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { + in := new(GetVersionsRequest) + if err := dec(in); err != nil { + return nil, err + } + return srv.(Lsps2Server).GetVersions(ctx, in) + }, + }, + }, + }, + l, + ) +} diff --git a/main.go b/main.go index 00e065c2..037bc92d 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "github.com/breez/lspd/interceptor" "github.com/breez/lspd/lnd" "github.com/breez/lspd/lsps0" + "github.com/breez/lspd/lsps2" "github.com/breez/lspd/mempool" "github.com/breez/lspd/notifications" "github.com/breez/lspd/postgresql" @@ -116,7 +117,9 @@ func main() { go msgClient.Start() msgServer := lsps0.NewServer() protocolServer := lsps0.NewProtocolServer([]uint32{2}) + lsps2Server := lsps2.NewLsps2Server() lsps0.RegisterProtocolServer(msgServer, protocolServer) + lsps2.RegisterLsps2Server(msgServer, lsps2Server) msgClient.WaitStarted() defer msgClient.Stop() go msgServer.Serve(msgClient)