Skip to content
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
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.PHONY: ast-lint ast-grep-fix
.PHONY: unit unit-cover unit-race unit-swapruntime check-go-version build install clean release
.PHONY: build build-swapruntime build-swapclient build-walletdkrpc rpc install install-swapruntime install-walletdkrpc help clean-networks
.PHONY: mobile mobile-android mobile-ios
.PHONY: mobile mobile-android mobile-ios wasm-wallet
.PHONY: systest systest-verbose
.PHONY: commitmsg-lint commitmsg-fmt commitmsg-reword

Expand Down Expand Up @@ -449,6 +449,29 @@ mobile-ios: #? Build the iOS .xcframework for sdk/walletdk
@$(call print, "Building iOS .xcframework for walletdk.")
./sdk/walletdk/mobile/gen_bindings.sh ios

WASM_WALLET_OUT := bin/wasm
WASMSQLITE_DIR := $(shell $(GOCC) list -m -f '{{.Dir}}' github.com/lightninglabs/go-wasmsqlite 2>/dev/null)

wasm-wallet: #? Build the walletdk browser wasm blob + runtime assets into bin/wasm
@$(call print, "Building walletdk browser wasm blob.")
$(RM) -r $(WASM_WALLET_OUT)
mkdir -p $(WASM_WALLET_OUT)
GOOS=js GOARCH=wasm $(GOBUILD) -trimpath -ldflags="-s -w" \
-tags="mobile walletdkrpc swapruntime" \
-o $(WASM_WALLET_OUT)/walletdk.wasm ./cmd/walletdk-wasm
gzip -9 -c $(WASM_WALLET_OUT)/walletdk.wasm \
> $(WASM_WALLET_OUT)/walletdk.wasm.gz
cp "$$($(GOCC) env GOROOT)/lib/wasm/wasm_exec.js" $(WASM_WALLET_OUT)/
cp $(WASMSQLITE_DIR)/assets/sqlite3.js $(WASM_WALLET_OUT)/
cp $(WASMSQLITE_DIR)/assets/sqlite3.wasm $(WASM_WALLET_OUT)/
cp $(WASMSQLITE_DIR)/assets/sqlite3-opfs-async-proxy.js $(WASM_WALLET_OUT)/
cp $(WASMSQLITE_DIR)/bridge/sqlite-bridge.js $(WASM_WALLET_OUT)/
cp $(WASMSQLITE_DIR)/bridge/sqlite-worker.js $(WASM_WALLET_OUT)/
# The go-wasmsqlite assets are read-only in the module cache; make the
# copies writable so re-runs (and callers staging the bundle) aren't
# blocked by a read-only destination.
chmod -R u+w $(WASM_WALLET_OUT)

install: #? Build and install binaries to GOPATH/bin
@$(call print, "Installing binaries.")
$(GOINSTALL) -trimpath -tags="$(DEV_TAGS)" $(DEV_LDFLAGS) ./cmd/merge-sql-schemas
Expand Down
2 changes: 2 additions & 0 deletions btcwbackend/boarding_backend.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js || !wasm

package btcwbackend

import (
Expand Down
2 changes: 2 additions & 0 deletions btcwbackend/chain_backend.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js || !wasm

package btcwbackend

import (
Expand Down
2 changes: 2 additions & 0 deletions btcwbackend/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js || !wasm

package btcwbackend

import (
Expand Down
2 changes: 2 additions & 0 deletions btcwbackend/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js || !wasm

// Package btcwbackend provides a lightweight in-process Bitcoin wallet backed
// by LND's btcwallet and a neutrino (BIP 157/158) chain backend. It wraps
// lnwallet/btcwallet.BtcWallet with a neutrino-based chain.Interface,
Expand Down
2 changes: 2 additions & 0 deletions btcwbackend/log.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js || !wasm

package btcwbackend

// Subsystem defines the logging code for this subsystem.
Expand Down
2 changes: 2 additions & 0 deletions btcwbackend/neutrino.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js || !wasm

package btcwbackend

import (
Expand Down
2 changes: 2 additions & 0 deletions btcwbackend/wallet.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js || !wasm

package btcwbackend

import (
Expand Down
129 changes: 129 additions & 0 deletions btcwbackend/wasm_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//go:build js && wasm

// Package btcwbackend is unavailable in browser WASM builds.
package btcwbackend

import (
"context"
"fmt"
"time"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btclog/v2"
"github.com/lightninglabs/darepo-client/chainbackends"
"github.com/lightninglabs/darepo-client/chainsource"
"github.com/lightninglabs/darepo-client/wallet"
"github.com/lightninglabs/darepo-client/walletcore"
fn "github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/keychain"
)

const (
// Subsystem defines the logging code for this subsystem.
Subsystem = "BTCW"

// DefaultFeeMinUpdateTimeout is the default minimum interval between
// fee estimation API queries.
DefaultFeeMinUpdateTimeout = 5 * time.Minute

// DefaultFeeMaxUpdateTimeout is the default maximum interval between
// fee estimation API queries.
DefaultFeeMaxUpdateTimeout = 20 * time.Minute
)

// Config holds the configuration for the native neutrino-backed wallet.
type Config struct {
walletcore.Config

NeutrinoDataDir string
ConnectPeers []string
AddPeers []string
BlockHeadersSource string
FilterHeadersSource string
FeeURL string
FeeMinUpdateTimeout time.Duration
FeeMaxUpdateTimeout time.Duration
PackageSubmitter chainbackends.PackageSubmitter
PersistFilters bool
DisableGlobalLoggers bool
}

// WithLogger returns a new config with the given logger set.
func (c Config) WithLogger(log btclog.Logger) Config {
c.Log = fn.Some(log)

return c
}

// NeutrinoServiceOption configures a NeutrinoService.
type NeutrinoServiceOption func(*NeutrinoService)

// NeutrinoService is a browser stub for the native neutrino service.
type NeutrinoService struct{}

// WithoutGlobalDependencyLoggers disables native package-global loggers.
func WithoutGlobalDependencyLoggers() NeutrinoServiceOption {
return func(*NeutrinoService) {}
}

// NewNeutrinoService reports that neutrino is unavailable in browser builds.
func NewNeutrinoService(string, *chaincfg.Params, []string, []string, bool,
string, string, btclog.Logger,
...NeutrinoServiceOption) (*NeutrinoService, error) {

return nil, fmt.Errorf("btcwallet backend is not available in wasm")
}

// Start reports that neutrino is unavailable in browser builds.
func (n *NeutrinoService) Start(context.Context) error {
return fmt.Errorf("btcwallet backend is not available in wasm")
}

// Stop is a no-op for the browser stub.
func (n *NeutrinoService) Stop() error {
return nil
}

// Wallet is a browser stub for the native neutrino-backed wallet.
type Wallet struct {
walletcore.Wallet
}

// New reports that btcwallet is unavailable in browser builds.
func New(Config) (*Wallet, error) {
return nil, fmt.Errorf("btcwallet backend is not available in wasm")
}

// NewWithNeutrino reports that btcwallet is unavailable in browser builds.
func NewWithNeutrino(Config, *NeutrinoService) (*Wallet, error) {
return nil, fmt.Errorf("btcwallet backend is not available in wasm")
}

// Start reports that btcwallet is unavailable in browser builds.
func (w *Wallet) Start() error {
return fmt.Errorf("btcwallet backend is not available in wasm")
}

// Stop is a no-op for the browser stub.
func (w *Wallet) Stop() {}

// BoardingBackend reports that no btcwallet boarding backend exists in WASM.
func (w *Wallet) BoardingBackend() wallet.BoardingBackend {
return nil
}

// ChainBackend reports that no btcwallet chain backend exists in WASM.
func (w *Wallet) ChainBackend() chainsource.ChainBackend {
return nil
}

// KeyRing returns the embedded walletcore key ring, if one was set by tests.
func (w *Wallet) KeyRing() keychain.SecretKeyRing {
return w.Wallet.KeyRing
}

// IsSynced reports that the unavailable browser stub is not synced.
func (w *Wallet) IsSynced() (bool, int64, error) {
return false, 0, fmt.Errorf("btcwallet backend is not available in " +
"wasm")
}
Loading
Loading