Skip to content

Commit

Permalink
looprpc: expose server message to clients
Browse files Browse the repository at this point in the history
  • Loading branch information
joostjager committed Jun 30, 2020
1 parent 8b215ed commit 1869ad6
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 104 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
return &LoopOutSwapInfo{
SwapHash: swap.hash,
HtlcAddressP2WSH: swap.htlc.Address,
ServerMessage: initResult.serverMessage,
}, nil
}

Expand Down Expand Up @@ -500,6 +501,7 @@ func (s *Client) LoopIn(globalCtx context.Context,
SwapHash: swap.hash,
HtlcAddressP2WSH: swap.htlcP2WSH.Address,
HtlcAddressNP2WSH: swap.htlcNP2WSH.Address,
ServerMessage: initResult.serverMessage,
}
return swapInfo, nil
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/loop/loopin.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func loopIn(ctx *cli.Context) error {
fmt.Printf("HTLC address (NP2WSH): %v\n", resp.HtlcAddressNp2Wsh)
}
fmt.Printf("HTLC address (P2WSH): %v\n", resp.HtlcAddressP2Wsh)
if resp.ServerMessage != "" {
fmt.Printf("Server message: %v\n", resp.ServerMessage)
}
fmt.Println()
fmt.Printf("Run `loop monitor` to monitor progress.\n")

Expand Down
7 changes: 5 additions & 2 deletions cmd/loop/loopout.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,11 @@ func loopOut(ctx *cli.Context) error {
}

fmt.Printf("Swap initiated\n")
fmt.Printf("ID: %v\n", resp.Id)
fmt.Printf("HTLC address: %v\n", resp.HtlcAddress)
fmt.Printf("ID: %v\n", resp.Id)
fmt.Printf("HTLC address: %v\n", resp.HtlcAddress)
if resp.ServerMessage != "" {
fmt.Printf("Server message: %v\n", resp.ServerMessage)
}
fmt.Println()
fmt.Printf("Run `loop monitor` to monitor progress.\n")

Expand Down
8 changes: 8 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ type LoopInSwapInfo struct { // nolint
// HtlcAddressNP2WSH contains the nested segwit swap htlc address,
// where the loop-in funds may be paid.
HtlcAddressNP2WSH btcutil.Address

// ServerMessages is the human-readable message received from the loop
// server.
ServerMessage string
}

// LoopOutSwapInfo contains essential information of a loop-out swap after the
Expand All @@ -259,6 +263,10 @@ type LoopOutSwapInfo struct { // nolint:golint
// HtlcAddressP2WSH contains the native segwit swap htlc address that
// the server will publish to.
HtlcAddressP2WSH btcutil.Address

// ServerMessages is the human-readable message received from the loop
// server.
ServerMessage string
}

// SwapInfoKit contains common swap info fields.
Expand Down
2 changes: 2 additions & 0 deletions loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
IdBytes: info.SwapHash[:],
HtlcAddress: info.HtlcAddressP2WSH.String(),
HtlcAddressP2Wsh: info.HtlcAddressP2WSH.String(),
ServerMessage: info.ServerMessage,
}, nil
}

Expand Down Expand Up @@ -456,6 +457,7 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
Id: swapInfo.SwapHash.String(),
IdBytes: swapInfo.SwapHash[:],
HtlcAddressP2Wsh: swapInfo.HtlcAddressP2WSH.String(),
ServerMessage: swapInfo.ServerMessage,
}

if req.ExternalHtlc {
Expand Down
6 changes: 4 additions & 2 deletions loopin.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ type loopInSwap struct {

// loopInInitResult contains information about a just-initiated loop in swap.
type loopInInitResult struct {
swap *loopInSwap
swap *loopInSwap
serverMessage string
}

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

return &loopInInitResult{
swap: swap,
swap: swap,
serverMessage: swapResp.serverMessage,
}, nil
}

Expand Down
6 changes: 4 additions & 2 deletions loopout.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ type executeConfig struct {

// loopOutInitResult contains information about a just-initiated loop out swap.
type loopOutInitResult struct {
swap *loopOutSwap
swap *loopOutSwap
serverMessage string
}

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

return &loopOutInitResult{
swap: swap,
swap: swap,
serverMessage: swapResp.serverMessage,
}, nil
}

Expand Down
206 changes: 108 additions & 98 deletions looprpc/client.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions looprpc/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ message SwapResponse {
Used for both loop-in and loop-out.
*/
string htlc_address_p2wsh = 5;

// A human-readable message received from the loop server.
string server_message = 6;
}

message MonitorRequest {
Expand Down
4 changes: 4 additions & 0 deletions looprpc/client.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@
"htlc_address_p2wsh": {
"type": "string",
"description": "*\nThe native segwit address of the on-chain htlc.\nUsed for both loop-in and loop-out."
},
"server_message": {
"type": "string",
"description": "A human-readable message received from the loop server."
}
}
},
Expand Down

0 comments on commit 1869ad6

Please sign in to comment.