Skip to content

Commit 7318698

Browse files
authored
Merge pull request #51 from joostjager/swapserver-address
loopd: use proper default swap server address
2 parents 56ab811 + 7534295 commit 7318698

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

cmd/loopd/config.go

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const (
2828

2929
var defaultConfig = config{
3030
Network: "mainnet",
31-
SwapServer: mainnetServer,
3231
RPCListen: "localhost:11010",
3332
RESTListen: "localhost:8081",
3433
Insecure: false,

cmd/loopd/daemon.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net"
78
"net/http"
@@ -26,13 +27,21 @@ func daemon(config *config) error {
2627
}
2728
defer lnd.Close()
2829

29-
// If the user is targeting the testnet network, and they haven't
30-
// specified new swap server, then we'll point towards the testnet swap
31-
// server rather than the mainnet endpoint.
32-
if config.Network == "testnet" && config.SwapServer == "" {
33-
config.SwapServer = testnetServer
30+
// If no swap server is specified, use the default addresses for mainnet
31+
// and testnet.
32+
if config.SwapServer == "" {
33+
switch config.Network {
34+
case "mainnet":
35+
config.SwapServer = mainnetServer
36+
case "testnet":
37+
config.SwapServer = testnetServer
38+
default:
39+
return errors.New("no swap server address specified")
40+
}
3441
}
3542

43+
logger.Infof("Swap server address: %v", config.SwapServer)
44+
3645
// Create an instance of the loop client library.
3746
swapClient, cleanup, err := getClient(
3847
config.Network, config.SwapServer, config.Insecure,

swap/htlc.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,13 @@ func NewHtlc(cltvExpiry int32, senderKey, receiverKey [33]byte,
6767
return nil, err
6868
}
6969

70-
p2wshPkScriptHash := sha256.Sum256(p2wshPkScript)
71-
7270
var pkScript, sigScript []byte
7371
var address btcutil.Address
7472

7573
switch outputType {
7674
case HtlcNP2WSH:
7775
// Generate p2sh script for p2wsh (nested).
78-
76+
p2wshPkScriptHash := sha256.Sum256(p2wshPkScript)
7977
hash160 := input.Ripemd160H(p2wshPkScriptHash[:])
8078

8179
builder := txscript.NewScriptBuilder()
@@ -111,7 +109,7 @@ func NewHtlc(cltvExpiry int32, senderKey, receiverKey [33]byte,
111109
pkScript = p2wshPkScript
112110

113111
address, err = btcutil.NewAddressWitnessScriptHash(
114-
p2wshPkScriptHash[:],
112+
p2wshPkScript[2:],
115113
chainParams,
116114
)
117115
if err != nil {

0 commit comments

Comments
 (0)