Skip to content

Commit 1869ad6

Browse files
committed
looprpc: expose server message to clients
1 parent 8b215ed commit 1869ad6

10 files changed

+143
-104
lines changed

client.go

+2
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
382382
return &LoopOutSwapInfo{
383383
SwapHash: swap.hash,
384384
HtlcAddressP2WSH: swap.htlc.Address,
385+
ServerMessage: initResult.serverMessage,
385386
}, nil
386387
}
387388

@@ -500,6 +501,7 @@ func (s *Client) LoopIn(globalCtx context.Context,
500501
SwapHash: swap.hash,
501502
HtlcAddressP2WSH: swap.htlcP2WSH.Address,
502503
HtlcAddressNP2WSH: swap.htlcNP2WSH.Address,
504+
ServerMessage: initResult.serverMessage,
503505
}
504506
return swapInfo, nil
505507
}

cmd/loop/loopin.go

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ func loopIn(ctx *cli.Context) error {
157157
fmt.Printf("HTLC address (NP2WSH): %v\n", resp.HtlcAddressNp2Wsh)
158158
}
159159
fmt.Printf("HTLC address (P2WSH): %v\n", resp.HtlcAddressP2Wsh)
160+
if resp.ServerMessage != "" {
161+
fmt.Printf("Server message: %v\n", resp.ServerMessage)
162+
}
160163
fmt.Println()
161164
fmt.Printf("Run `loop monitor` to monitor progress.\n")
162165

cmd/loop/loopout.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@ func loopOut(ctx *cli.Context) error {
180180
}
181181

182182
fmt.Printf("Swap initiated\n")
183-
fmt.Printf("ID: %v\n", resp.Id)
184-
fmt.Printf("HTLC address: %v\n", resp.HtlcAddress)
183+
fmt.Printf("ID: %v\n", resp.Id)
184+
fmt.Printf("HTLC address: %v\n", resp.HtlcAddress)
185+
if resp.ServerMessage != "" {
186+
fmt.Printf("Server message: %v\n", resp.ServerMessage)
187+
}
185188
fmt.Println()
186189
fmt.Printf("Run `loop monitor` to monitor progress.\n")
187190

interface.go

+8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ type LoopInSwapInfo struct { // nolint
248248
// HtlcAddressNP2WSH contains the nested segwit swap htlc address,
249249
// where the loop-in funds may be paid.
250250
HtlcAddressNP2WSH btcutil.Address
251+
252+
// ServerMessages is the human-readable message received from the loop
253+
// server.
254+
ServerMessage string
251255
}
252256

253257
// LoopOutSwapInfo contains essential information of a loop-out swap after the
@@ -259,6 +263,10 @@ type LoopOutSwapInfo struct { // nolint:golint
259263
// HtlcAddressP2WSH contains the native segwit swap htlc address that
260264
// the server will publish to.
261265
HtlcAddressP2WSH btcutil.Address
266+
267+
// ServerMessages is the human-readable message received from the loop
268+
// server.
269+
ServerMessage string
262270
}
263271

264272
// SwapInfoKit contains common swap info fields.

loopd/swapclient_server.go

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
114114
IdBytes: info.SwapHash[:],
115115
HtlcAddress: info.HtlcAddressP2WSH.String(),
116116
HtlcAddressP2Wsh: info.HtlcAddressP2WSH.String(),
117+
ServerMessage: info.ServerMessage,
117118
}, nil
118119
}
119120

@@ -456,6 +457,7 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
456457
Id: swapInfo.SwapHash.String(),
457458
IdBytes: swapInfo.SwapHash[:],
458459
HtlcAddressP2Wsh: swapInfo.HtlcAddressP2WSH.String(),
460+
ServerMessage: swapInfo.ServerMessage,
459461
}
460462

461463
if req.ExternalHtlc {

loopin.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ type loopInSwap struct {
6565

6666
// loopInInitResult contains information about a just-initiated loop in swap.
6767
type loopInInitResult struct {
68-
swap *loopInSwap
68+
swap *loopInSwap
69+
serverMessage string
6970
}
7071

7172
// newLoopInSwap initiates a new loop in swap.
@@ -191,7 +192,8 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
191192
}
192193

193194
return &loopInInitResult{
194-
swap: swap,
195+
swap: swap,
196+
serverMessage: swapResp.serverMessage,
195197
}, nil
196198
}
197199

loopout.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ type executeConfig struct {
7575

7676
// loopOutInitResult contains information about a just-initiated loop out swap.
7777
type loopOutInitResult struct {
78-
swap *loopOutSwap
78+
swap *loopOutSwap
79+
serverMessage string
7980
}
8081

8182
// newLoopOutSwap initiates a new swap with the server and returns a
@@ -186,7 +187,8 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
186187
}
187188

188189
return &loopOutInitResult{
189-
swap: swap,
190+
swap: swap,
191+
serverMessage: swapResp.serverMessage,
190192
}, nil
191193
}
192194

looprpc/client.pb.go

+108-98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.proto

+3
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ message SwapResponse {
272272
Used for both loop-in and loop-out.
273273
*/
274274
string htlc_address_p2wsh = 5;
275+
276+
// A human-readable message received from the loop server.
277+
string server_message = 6;
275278
}
276279

277280
message MonitorRequest {

looprpc/client.swagger.json

+4
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@
524524
"htlc_address_p2wsh": {
525525
"type": "string",
526526
"description": "*\nThe native segwit address of the on-chain htlc.\nUsed for both loop-in and loop-out."
527+
},
528+
"server_message": {
529+
"type": "string",
530+
"description": "A human-readable message received from the loop server."
527531
}
528532
}
529533
},

0 commit comments

Comments
 (0)