Skip to content

Commit 67c8120

Browse files
committed
looprpc: extract REST annotations into yaml
1 parent df5924f commit 67c8120

File tree

6 files changed

+313
-348
lines changed

6 files changed

+313
-348
lines changed

looprpc/client.pb.go

Lines changed: 157 additions & 168 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.proto

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
syntax = "proto3";
22

3-
import "google/api/annotations.proto";
4-
53
package looprpc;
64

75
/*
@@ -15,25 +13,15 @@ service SwapClient {
1513
point onwards, progress can be tracked via the SwapStatus stream that is
1614
returned from Monitor().
1715
*/
18-
rpc LoopOut (LoopOutRequest) returns (SwapResponse) {
19-
option (google.api.http) = {
20-
post: "/v1/loop/out"
21-
body: "*"
22-
};
23-
}
16+
rpc LoopOut (LoopOutRequest) returns (SwapResponse);
2417

2518
/* loop: `in`
2619
LoopIn initiates a loop in swap with the given parameters. The call
2720
returns after the swap has been set up with the swap server. From that
2821
point onwards, progress can be tracked via the SwapStatus stream
2922
that is returned from Monitor().
3023
*/
31-
rpc LoopIn (LoopInRequest) returns (SwapResponse) {
32-
option (google.api.http) = {
33-
post: "/v1/loop/in"
34-
body: "*"
35-
};
36-
}
24+
rpc LoopIn (LoopInRequest) returns (SwapResponse);
3725

3826
/* loop: `monitor`
3927
Monitor will return a stream of swap updates for currently active swaps.
@@ -44,102 +32,63 @@ service SwapClient {
4432
ListSwaps returns a list of all currently known swaps and their current
4533
status.
4634
*/
47-
rpc ListSwaps (ListSwapsRequest) returns (ListSwapsResponse) {
48-
option (google.api.http) = {
49-
get: "/v1/loop/swaps"
50-
};
51-
}
35+
rpc ListSwaps (ListSwapsRequest) returns (ListSwapsResponse);
5236

5337
/* loop: `swapinfo`
5438
SwapInfo returns all known details about a single swap.
5539
*/
56-
rpc SwapInfo (SwapInfoRequest) returns (SwapStatus) {
57-
option (google.api.http) = {
58-
get: "/v1/loop/swap/{id}"
59-
};
60-
}
40+
rpc SwapInfo (SwapInfoRequest) returns (SwapStatus);
6141

6242
/* loop: `terms`
6343
LoopOutTerms returns the terms that the server enforces for a loop out swap.
6444
*/
65-
rpc LoopOutTerms (TermsRequest) returns (OutTermsResponse) {
66-
option (google.api.http) = {
67-
get: "/v1/loop/out/terms"
68-
};
69-
}
45+
rpc LoopOutTerms (TermsRequest) returns (OutTermsResponse);
7046

7147
/* loop: `quote`
7248
LoopOutQuote returns a quote for a loop out swap with the provided
7349
parameters.
7450
*/
75-
rpc LoopOutQuote (QuoteRequest) returns (OutQuoteResponse) {
76-
option (google.api.http) = {
77-
get: "/v1/loop/out/quote/{amt}"
78-
};
79-
}
51+
rpc LoopOutQuote (QuoteRequest) returns (OutQuoteResponse);
8052

8153
/* loop: `terms`
8254
GetTerms returns the terms that the server enforces for swaps.
8355
*/
84-
rpc GetLoopInTerms (TermsRequest) returns (InTermsResponse) {
85-
option (google.api.http) = {
86-
get: "/v1/loop/in/terms"
87-
};
88-
}
56+
rpc GetLoopInTerms (TermsRequest) returns (InTermsResponse);
8957

9058
/* loop: `quote`
9159
GetQuote returns a quote for a swap with the provided parameters.
9260
*/
93-
rpc GetLoopInQuote (QuoteRequest) returns (InQuoteResponse) {
94-
option (google.api.http) = {
95-
get: "/v1/loop/in/quote/{amt}"
96-
};
97-
}
61+
rpc GetLoopInQuote (QuoteRequest) returns (InQuoteResponse);
9862

9963
/* loop: `listauth`
10064
GetLsatTokens returns all LSAT tokens the daemon ever paid for.
10165
*/
102-
rpc GetLsatTokens (TokensRequest) returns (TokensResponse) {
103-
option (google.api.http) = {
104-
get: "/v1/lsat/tokens"
105-
};
106-
}
66+
rpc GetLsatTokens (TokensRequest) returns (TokensResponse);
10767

10868
/*
10969
GetLiquidityParams gets the parameters that the daemon's liquidity manager
11070
is currently configured with. This may be nil if nothing is configured.
11171
[EXPERIMENTAL]: endpoint is subject to change.
11272
*/
113-
rpc GetLiquidityParams (GetLiquidityParamsRequest) returns (LiquidityParameters) {
114-
option (google.api.http) = {
115-
get: "/v1/liquidity/params"
116-
};
117-
}
73+
rpc GetLiquidityParams (GetLiquidityParamsRequest)
74+
returns (LiquidityParameters);
11875

11976
/*
12077
SetLiquidityParams sets a new set of parameters for the daemon's liquidity
12178
manager. Note that the full set of parameters must be provided, because
12279
this call fully overwrites our existing parameters.
12380
[EXPERIMENTAL]: endpoint is subject to change.
12481
*/
125-
rpc SetLiquidityParams (SetLiquidityParamsRequest) returns (SetLiquidityParamsResponse) {
126-
option (google.api.http) = {
127-
post: "/v1/liquidity/params"
128-
body: "*"
129-
};
130-
}
82+
rpc SetLiquidityParams (SetLiquidityParamsRequest)
83+
returns (SetLiquidityParamsResponse);
13184

13285
/*
13386
SuggestSwaps returns a list of recommended swaps based on the current
13487
state of your node's channels and it's liquidity manager parameters.
13588
Note that only loop out suggestions are currently supported.
13689
[EXPERIMENTAL]: endpoint is subject to change.
13790
*/
138-
rpc SuggestSwaps (SuggestSwapsRequest) returns (SuggestSwapsResponse) {
139-
option (google.api.http) = {
140-
get: "/v1/auto/suggest"
141-
};
142-
}
91+
rpc SuggestSwaps (SuggestSwapsRequest) returns (SuggestSwapsResponse);
14392
}
14493

14594
message LoopOutRequest {

looprpc/gen_protos.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ set -e
66
for file in ./*.proto
77
do
88
protoc -I/usr/local/include -I. \
9-
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
109
--go_out=plugins=grpc,paths=source_relative:. \
1110
${file}
1211

1312
done
1413

1514
# Only generate the REST proxy and definitions for the client component.
1615
protoc -I/usr/local/include -I. \
17-
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
18-
--grpc-gateway_out=logtostderr=true:. \
16+
--grpc-gateway_out=logtostderr=true,paths=source_relative,grpc_api_configuration=rest-annotations.yaml:. \
1917
client.proto
2018

2119
protoc -I/usr/local/include -I. \
2220
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
23-
--swagger_out=logtostderr=true:. \
21+
--swagger_out=logtostderr=true,grpc_api_configuration=rest-annotations.yaml:. \
2422
client.proto

looprpc/rest-annotations.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
type: google.api.Service
2+
config_version: 3
3+
4+
http:
5+
rules:
6+
# client.proto
7+
- selector: looprpc.SwapClient.LoopOut
8+
post: "/v1/loop/out"
9+
body: "*"
10+
- selector: looprpc.SwapClient.LoopIn
11+
post: "/v1/loop/in"
12+
body: "*"
13+
- selector: looprpc.SwapClient.ListSwaps
14+
get: "/v1/loop/swaps"
15+
- selector: looprpc.SwapClient.SwapInfo
16+
get: "/v1/loop/swap/{id}"
17+
- selector: looprpc.SwapClient.LoopOutTerms
18+
get: "/v1/loop/out/terms"
19+
- selector: looprpc.SwapClient.LoopOutQuote
20+
get: "/v1/loop/out/quote/{amt}"
21+
- selector: looprpc.SwapClient.GetLoopInTerms
22+
get: "/v1/loop/in/terms"
23+
- selector: looprpc.SwapClient.GetLoopInQuote
24+
get: "/v1/loop/in/quote/{amt}"
25+
- selector: looprpc.SwapClient.GetLsatTokens
26+
get: "/v1/lsat/tokens"
27+
- selector: looprpc.SwapClient.GetLiquidityParams
28+
get: "/v1/liquidity/params"
29+
- selector: looprpc.SwapClient.SetLiquidityParams
30+
post: "/v1/liquidity/params"
31+
body: "*"
32+
- selector: looprpc.SwapClient.SuggestSwaps
33+
get: "/v1/auto/suggest"

0 commit comments

Comments
 (0)