Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swapserverrpc: add module for server protos #445

Merged
merged 2 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ install:

rpc:
@$(call print, "Compiling protos.")
cd ./swapserverrpc; ./gen_protos_docker.sh
cd ./looprpc; ./gen_protos_docker.sh

rpc-check: rpc
Expand All @@ -85,6 +86,9 @@ rpc-js-compile:
@$(call print, "Compiling JSON/WASM stubs.")
GOOS=js GOARCH=wasm $(GOBUILD) $(PKG)/looprpc

rpc-format:
cd ./looprpc; find . -name "*.proto" | xargs clang-format --style=file -i
cd ./swapserverrpc; find . -name "*.proto" | xargs clang-format --style=file -i

clean:
@$(call print, "Cleaning up.")
Expand Down
6 changes: 3 additions & 3 deletions cmd/loop/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"encoding/json"
"fmt"

"github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swapserverrpc"
"github.com/urfave/cli"
)

// validateRouteHints ensures that the Private flag isn't set along with
// the RouteHints flag. We don't allow both options to be set as these options
// are alternatives to each other. Private autogenerates hopHints while
// RouteHints are manually passed.
func validateRouteHints(ctx *cli.Context) ([]*looprpc.RouteHint, error) {
var hints []*looprpc.RouteHint
func validateRouteHints(ctx *cli.Context) ([]*swapserverrpc.RouteHint, error) {
var hints []*swapserverrpc.RouteHint

if ctx.IsSet(routeHintsFlag.Name) {
if ctx.IsSet(privateFlag.Name) {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/jessevdk/go-flags v1.4.0
github.com/lightninglabs/aperture v0.1.6-beta
github.com/lightninglabs/lndclient v0.14.0-5
github.com/lightninglabs/loop/swapserverrpc v1.0.0
github.com/lightninglabs/protobuf-hex-display v1.4.3-hex-display
github.com/lightningnetwork/lnd v0.14.1-beta
github.com/lightningnetwork/lnd/cert v1.1.0
Expand All @@ -28,3 +29,5 @@ require (
)

go 1.15

replace github.com/lightninglabs/loop/swapserverrpc => ./swapserverrpc
5 changes: 3 additions & 2 deletions loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swap"
"github.com/lightninglabs/loop/swapserverrpc"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire"
Expand Down Expand Up @@ -525,7 +526,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
}

// unmarshallRouteHints unmarshalls a list of route hints.
func unmarshallRouteHints(rpcRouteHints []*looprpc.RouteHint) (
func unmarshallRouteHints(rpcRouteHints []*swapserverrpc.RouteHint) (
[][]zpay32.HopHint, error) {

routeHints := make([][]zpay32.HopHint, 0, len(rpcRouteHints))
Expand All @@ -548,7 +549,7 @@ func unmarshallRouteHints(rpcRouteHints []*looprpc.RouteHint) (
}

// unmarshallHopHint unmarshalls a single hop hint.
func unmarshallHopHint(rpcHint *looprpc.HopHint) (zpay32.HopHint, error) {
func unmarshallHopHint(rpcHint *swapserverrpc.HopHint) (zpay32.HopHint, error) {
pubBytes, err := hex.DecodeString(rpcHint.NodeId)
if err != nil {
return zpay32.HopHint{}, err
Expand Down
4 changes: 2 additions & 2 deletions loopdb/protocol_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package loopdb
import (
"math"

"github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swapserverrpc"
)

// ProtocolVersion represents the protocol version (declared on rpc level) that
Expand Down Expand Up @@ -53,7 +53,7 @@ const (

// CurrentRPCProtocolVersion defines the version of the RPC protocol
// that is currently supported by the loop client.
CurrentRPCProtocolVersion = looprpc.ProtocolVersion_PROBE
CurrentRPCProtocolVersion = swapserverrpc.ProtocolVersion_PROBE

// CurrentInternalProtocolVersion defines the RPC current protocol in
// the internal representation.
Expand Down
22 changes: 11 additions & 11 deletions loopdb/protocol_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package loopdb
import (
"testing"

"github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swapserverrpc"
"github.com/stretchr/testify/require"
)

Expand All @@ -25,16 +25,16 @@ func TestProtocolVersionSanity(t *testing.T) {
ProtocolVersionProbe,
}

rpcVersions := [...]looprpc.ProtocolVersion{
looprpc.ProtocolVersion_LEGACY,
looprpc.ProtocolVersion_MULTI_LOOP_OUT,
looprpc.ProtocolVersion_NATIVE_SEGWIT_LOOP_IN,
looprpc.ProtocolVersion_PREIMAGE_PUSH_LOOP_OUT,
looprpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT,
looprpc.ProtocolVersion_HTLC_V2,
looprpc.ProtocolVersion_MULTI_LOOP_IN,
looprpc.ProtocolVersion_LOOP_OUT_CANCEL,
looprpc.ProtocolVersion_PROBE,
rpcVersions := [...]swapserverrpc.ProtocolVersion{
swapserverrpc.ProtocolVersion_LEGACY,
swapserverrpc.ProtocolVersion_MULTI_LOOP_OUT,
swapserverrpc.ProtocolVersion_NATIVE_SEGWIT_LOOP_IN,
swapserverrpc.ProtocolVersion_PREIMAGE_PUSH_LOOP_OUT,
swapserverrpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT,
swapserverrpc.ProtocolVersion_HTLC_V2,
swapserverrpc.ProtocolVersion_MULTI_LOOP_IN,
swapserverrpc.ProtocolVersion_LOOP_OUT_CANCEL,
swapserverrpc.ProtocolVersion_PROBE,
}

require.Equal(t, len(versions), len(rpcVersions))
Expand Down
2 changes: 1 addition & 1 deletion looprpc/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ BasedOnStyle: Google
IndentWidth: 4
AllowShortFunctionsOnASingleLine: None
SpaceBeforeParens: Always
CompactNamespaces: false
CompactNamespaces: false
Loading