Skip to content

Commit

Permalink
Merge pull request #288 from YusukeShimizu/lwk-swap
Browse files Browse the repository at this point in the history
make lwk available
  • Loading branch information
YusukeShimizu authored Jul 5, 2024
2 parents 2f9f779 + 66fead0 commit 95b9983
Show file tree
Hide file tree
Showing 67 changed files with 6,922 additions and 759 deletions.
33 changes: 8 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
test-vector: [bitcoin-cln, bitcoin-lnd, liquid-cln, liquid-lnd, misc-integration]

test-vector: [bitcoin-cln, bitcoin-lnd, liquid-cln, liquid-lnd, misc-integration, lwk-cln, lwk-lnd]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: "Cache Nix store"
uses: actions/[email protected]
id: nix-cache
with:
path: /tmp/nixcache
key: nix-${{ hashFiles('packages.nix') }}

- name: Install Nix
uses: cachix/install-nix-action@v20
uses: actions/checkout@v4
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: "Import Nix store cache"
if: "steps.nix-cache.outputs.cache-hit == 'true'"
run: "nix-store --import < /tmp/nixcache"

- name: Run tests
run: nix-shell --run "make test-${{matrix.test-vector}}"

- name: "Export Nix store cache"
if: "steps.nix-cache.outputs.cache-hit != 'true'"
run: "nix-store --export $(find /nix/store -maxdepth 1 -name '*-*') > /tmp/nixcache"
fetch-depth: 0
- name: Install Nix and run tests
uses: determinateSystems/nix-installer-action@v12
- uses: DeterminateSystems/magic-nix-cache-action@v7
- uses: DeterminateSystems/flake-checker-action@v8
- run: nix-shell --run "make test-${{matrix.test-vector}}"
26 changes: 24 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ${TEST_BIN_DIR}/peerswap:

# Test section. Has commads for local and ci testing.
test:
PAYMENT_RETRY_TIME=5 go test -tags dev -tags fast_test -timeout=10m -v ./...
PAYMENT_RETRY_TIME=5 go test -tags dev -tags fast_test -race -timeout=10m -v ./...
.PHONY: test

test-integration: test-bins
Expand Down Expand Up @@ -127,6 +127,20 @@ test-liquid-lnd: test-bins
./test
.PHONY: test-liquid-lnd

test-lwk-cln: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_ClnCln_LWK_SwapIn)'\
./test
.PHONY: test-lwk-cln

test-lwk-lnd: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_LndLnd_LWK_SwapIn)'\
./test
.PHONY: test-lwk-lnd

test-misc-integration: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
Expand Down Expand Up @@ -185,12 +199,12 @@ TOOLS_DIR := ${CURDIR}/tools
tool:
## Install an individual dependent tool.
@cd $(TOOLS_DIR) && env GOBIN=$(TOOLS_DIR)/bin go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint
@cd $(TOOLS_DIR) && env GOBIN=$(TOOLS_DIR)/bin go install -trimpath go.uber.org/mock/mockgen@latest

.PHONY: clean
clean: ## clean project directory.
env GOBIN=${TOOLS_DIR}/bin && @rm -rf ${GOBIN} $(TOOLS_DIR)/bin


.PHONY: lint
lint: lint/golangci-lint
lint: ## Lint source.
Expand All @@ -203,3 +217,11 @@ lint/golangci-lint: ## Lint source with golangci-lint.
.PHONY: lint/fix
lint/fix: ## Lint and fix source.
@${MAKE} lint/golangci-lint args='--fix'


.PHONY: mockgen
mockgen: mockgen/lwk

.PHONY: mockgen/lwk
mockgen/lwk:
$(TOOLS_DIR)/bin/mockgen -source=electrum/electrum.go -destination=electrum/mock/electrum.go
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ To run PeerSwap as a standalone daemon with LND, see the [LND setup guide](./doc

To run Elements for L-BTC swaps, see the [Elements setup guide](./docs/setup_elementsd.md).

To run LWK for L-BTC swaps, see the [LWK setup guide](./docs/setup_lwk.md).

> **Note**
> Most of the benefits of PeerSwap come from using L-BTC. Swaps using L-BTC are more private, faster, and avoid the mainchain blockchain during high fee environments that can make swaps uneconomical.
Expand Down
5 changes: 0 additions & 5 deletions ci.nix

This file was deleted.

22 changes: 15 additions & 7 deletions clightning/clightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/elementsproject/glightning/gbitcoin"
"github.com/elementsproject/peerswap/onchain"

"github.com/elementsproject/glightning/gelements"
"github.com/elementsproject/glightning/glightning"
"github.com/elementsproject/glightning/jrpc2"
"github.com/elementsproject/peerswap/lightning"
Expand Down Expand Up @@ -64,14 +63,12 @@ type ClightningClient struct {
glightning *glightning.Lightning
Plugin *glightning.Plugin

liquidWallet *wallet.ElementsRpcWallet
liquidWallet wallet.Wallet
swaps *swap.SwapService
requestedSwaps *swap.RequestedSwapsPrinter
policy PolicyReloader
pollService *poll.Service

Gelements *gelements.Elements

gbitcoin *gbitcoin.Bitcoin
bitcoinChain *onchain.BitcoinOnChain
bitcoinNetwork *chaincfg.Params
Expand Down Expand Up @@ -323,14 +320,13 @@ func (cl *ClightningClient) GetPreimage() (lightning.Preimage, error) {
}

// SetupClients injects the required services
func (cl *ClightningClient) SetupClients(liquidWallet *wallet.ElementsRpcWallet,
func (cl *ClightningClient) SetupClients(liquidWallet wallet.Wallet,
swaps *swap.SwapService,
policy PolicyReloader, requestedSwaps *swap.RequestedSwapsPrinter, elements *gelements.Elements,
policy PolicyReloader, requestedSwaps *swap.RequestedSwapsPrinter,
bitcoin *gbitcoin.Bitcoin, bitcoinChain *onchain.BitcoinOnChain, pollService *poll.Service) {
cl.liquidWallet = liquidWallet
cl.requestedSwaps = requestedSwaps
cl.swaps = swaps
cl.Gelements = elements
cl.policy = policy
cl.gbitcoin = bitcoin
cl.pollService = pollService
Expand Down Expand Up @@ -359,6 +355,14 @@ func (cl *ClightningClient) SetPeerswapConfig(config *Config) {
LiquidSwaps: *config.Liquid.LiquidSwaps,
PeerswapDir: config.PeerswapDir,
}
if config.LWK != nil {
cl.peerswapConfig.LWKSignerName = config.LWK.GetSignerName()
cl.peerswapConfig.LWKWalletName = config.LWK.GetWalletName()
cl.peerswapConfig.LWKEndpoint = config.LWK.GetLWKEndpoint()
cl.peerswapConfig.ElectrumEndpoint = config.LWK.GetElectrumEndpoint()
cl.peerswapConfig.LWKNetwork = config.LWK.GetNetwork()
cl.peerswapConfig.LWKLiquidSwaps = config.LWK.GetLiquidSwaps()
}
}

func (cl *ClightningClient) GetLightningRpc() *glightning.Lightning {
Expand Down Expand Up @@ -404,6 +408,10 @@ func (cl *ClightningClient) OnCustomMsg(event *glightning.CustomMsgReceivedEvent
return event.Continue(), nil
}

type Message struct {
Message string `json:"message"`
}

// AddMessageHandler adds a listener for incoming peermessages
func (cl *ClightningClient) AddMessageHandler(f func(peerId string, msgType string, payload []byte) error) {
cl.msgHandlers = append(cl.msgHandlers, f)
Expand Down
7 changes: 2 additions & 5 deletions clightning/clightning_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ func (l *SwapOut) Call() (jrpc2.Result, error) {
if !l.cl.swaps.LiquidEnabled {
return nil, errors.New("liquid swaps are not enabled")
}
if l.cl.Gelements == nil {
return nil, errors.New("peerswap was not started with liquid node config")
if ok, perr := l.cl.liquidWallet.Ping(); perr != nil || !ok {
return nil, fmt.Errorf("liquid wallet not reachable: %v", perr)
}

} else if strings.Compare(l.Asset, "btc") == 0 {
Expand Down Expand Up @@ -366,9 +366,6 @@ func (l *SwapIn) Call() (jrpc2.Result, error) {
if !l.cl.swaps.LiquidEnabled {
return nil, errors.New("liquid swaps are not enabled")
}
if l.cl.Gelements == nil {
return nil, errors.New("peerswap was not started with liquid node config")
}
liquidBalance, err := l.cl.liquidWallet.GetBalance()
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 95b9983

Please sign in to comment.