From ca3cfc14310e906a8e28eebb6f45600b9aa91911 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 3 May 2019 10:17:26 +0200 Subject: [PATCH 1/2] loopd: use proper default swap server address This commit fixes the bug that caused running loopd on testnet to connect to the mainnet swap server. --- cmd/loopd/config.go | 1 - cmd/loopd/daemon.go | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/loopd/config.go b/cmd/loopd/config.go index 2d8855b..11d899c 100644 --- a/cmd/loopd/config.go +++ b/cmd/loopd/config.go @@ -28,7 +28,6 @@ const ( var defaultConfig = config{ Network: "mainnet", - SwapServer: mainnetServer, RPCListen: "localhost:11010", RESTListen: "localhost:8081", Insecure: false, diff --git a/cmd/loopd/daemon.go b/cmd/loopd/daemon.go index 371e548..224feb1 100644 --- a/cmd/loopd/daemon.go +++ b/cmd/loopd/daemon.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" "fmt" "net" "net/http" @@ -26,13 +27,21 @@ func daemon(config *config) error { } defer lnd.Close() - // If the user is targeting the testnet network, and they haven't - // specified new swap server, then we'll point towards the testnet swap - // server rather than the mainnet endpoint. - if config.Network == "testnet" && config.SwapServer == "" { - config.SwapServer = testnetServer + // If no swap server is specified, use the default addresses for mainnet + // and testnet. + if config.SwapServer == "" { + switch config.Network { + case "mainnet": + config.SwapServer = mainnetServer + case "testnet": + config.SwapServer = testnetServer + default: + return errors.New("no swap server address specified") + } } + logger.Infof("Swap server address: %v", config.SwapServer) + // Create an instance of the loop client library. swapClient, cleanup, err := getClient( config.Network, config.SwapServer, config.Insecure, From 753429547da17a305952034ef5bc5f546ae26419 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 3 May 2019 10:52:23 +0200 Subject: [PATCH 2/2] swap: fix htlc address generation This commit fixes the generation of the htlc address. This bug didn't affect the swap execution, because the htlc address is only used for display to the user/caller. --- swap/htlc.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/swap/htlc.go b/swap/htlc.go index 02a6510..539a187 100644 --- a/swap/htlc.go +++ b/swap/htlc.go @@ -67,15 +67,13 @@ func NewHtlc(cltvExpiry int32, senderKey, receiverKey [33]byte, return nil, err } - p2wshPkScriptHash := sha256.Sum256(p2wshPkScript) - var pkScript, sigScript []byte var address btcutil.Address switch outputType { case HtlcNP2WSH: // Generate p2sh script for p2wsh (nested). - + p2wshPkScriptHash := sha256.Sum256(p2wshPkScript) hash160 := input.Ripemd160H(p2wshPkScriptHash[:]) builder := txscript.NewScriptBuilder() @@ -111,7 +109,7 @@ func NewHtlc(cltvExpiry int32, senderKey, receiverKey [33]byte, pkScript = p2wshPkScript address, err = btcutil.NewAddressWitnessScriptHash( - p2wshPkScriptHash[:], + p2wshPkScript[2:], chainParams, ) if err != nil {