mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 06:44:23 +01:00
lsps2: implement lsps2.get_versions
This commit is contained in:
3
.github/workflows/integration_tests.yaml
vendored
3
.github/workflows/integration_tests.yaml
vendored
@@ -142,7 +142,8 @@ jobs:
|
|||||||
max-parallel: 6
|
max-parallel: 6
|
||||||
matrix:
|
matrix:
|
||||||
test: [
|
test: [
|
||||||
testLsps0GetProtocolVersions
|
testLsps0GetProtocolVersions,
|
||||||
|
testLsps2GetVersions
|
||||||
]
|
]
|
||||||
implementation: [
|
implementation: [
|
||||||
CLN
|
CLN
|
||||||
|
|||||||
@@ -178,4 +178,8 @@ var allTestCases = []*testCase{
|
|||||||
name: "testLsps0GetProtocolVersions",
|
name: "testLsps0GetProtocolVersions",
|
||||||
test: testLsps0GetProtocolVersions,
|
test: testLsps0GetProtocolVersions,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "testLsps2GetVersions",
|
||||||
|
test: testLsps2GetVersions,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
40
itest/lsps2_get_versions_test.go
Normal file
40
itest/lsps2_get_versions_test.go
Normal file
@@ -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"])
|
||||||
|
}
|
||||||
54
lsps2/server.go
Normal file
54
lsps2/server.go
Normal file
@@ -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,
|
||||||
|
)
|
||||||
|
}
|
||||||
3
main.go
3
main.go
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/breez/lspd/interceptor"
|
"github.com/breez/lspd/interceptor"
|
||||||
"github.com/breez/lspd/lnd"
|
"github.com/breez/lspd/lnd"
|
||||||
"github.com/breez/lspd/lsps0"
|
"github.com/breez/lspd/lsps0"
|
||||||
|
"github.com/breez/lspd/lsps2"
|
||||||
"github.com/breez/lspd/mempool"
|
"github.com/breez/lspd/mempool"
|
||||||
"github.com/breez/lspd/notifications"
|
"github.com/breez/lspd/notifications"
|
||||||
"github.com/breez/lspd/postgresql"
|
"github.com/breez/lspd/postgresql"
|
||||||
@@ -116,7 +117,9 @@ func main() {
|
|||||||
go msgClient.Start()
|
go msgClient.Start()
|
||||||
msgServer := lsps0.NewServer()
|
msgServer := lsps0.NewServer()
|
||||||
protocolServer := lsps0.NewProtocolServer([]uint32{2})
|
protocolServer := lsps0.NewProtocolServer([]uint32{2})
|
||||||
|
lsps2Server := lsps2.NewLsps2Server()
|
||||||
lsps0.RegisterProtocolServer(msgServer, protocolServer)
|
lsps0.RegisterProtocolServer(msgServer, protocolServer)
|
||||||
|
lsps2.RegisterLsps2Server(msgServer, lsps2Server)
|
||||||
msgClient.WaitStarted()
|
msgClient.WaitStarted()
|
||||||
defer msgClient.Stop()
|
defer msgClient.Stop()
|
||||||
go msgServer.Serve(msgClient)
|
go msgServer.Serve(msgClient)
|
||||||
|
|||||||
Reference in New Issue
Block a user