Skip to content

Commit 6e5616a

Browse files
committed
wasm-client: add WASM client and example web page
1 parent 6406314 commit 6e5616a

14 files changed

+3072
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
wasm-client.wasm

Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ GOTEST := go test -v
1616

1717
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
1818

19+
LDFLAGS := -s -w -buildid=
20+
1921
RM := rm -f
2022
CP := cp
2123
MAKE := make
@@ -43,6 +45,12 @@ build:
4345
@$(call print, "Building terminal-connect.")
4446
$(GOBUILD) $(PKG)/...
4547

48+
wasm:
49+
# The appengine build tag is needed because of the jessevdk/go-flags library
50+
# that has some OS specific terminal code that doesn't compile to WASM.
51+
GOOS=js GOARCH=wasm go build -trimpath -ldflags="$(LDFLAGS)" -tags="appengine" -v -o wasm-client.wasm $(PKG)/cmd/wasm-client
52+
$(CP) wasm-client.wasm example/wasm-client.wasm
53+
4654
# =======
4755
# TESTING
4856
# =======
@@ -83,3 +91,5 @@ rpc-check: rpc
8391
@$(call print, "Verifying protos.")
8492
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with correct version!"; git status; git diff; exit 1; fi
8593

94+
rpc-stubs:
95+
cd cmd/wasm-client; ./gen_stubs.sh

cmd/wasm-client/config.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// +build js
2+
3+
package main
4+
5+
type config struct {
6+
MailboxServer string `long:"mailboxserver" description:"Use the mailbox server with the given address to connect to lnd"`
7+
MailboxPassword string `long:"mailboxpassword" description:"The password for connecting to the mailbox"`
8+
MailboxDevServer bool `long:"mailboxdevserver" description:"The mailbox server is a development server, turn off TLS validation"`
9+
DebugLevel string `long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems"`
10+
}

cmd/wasm-client/gen_stubs.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
function import_path() {
4+
local pkg=$1
5+
# Find out what version of pool to use for the imported auctioneer.proto by
6+
# parsing the go.mod file.
7+
LAST_LINE=$(grep "$pkg" ../../go.mod | tail -n 1)
8+
PKG_PATH=""
9+
if [[ $LAST_LINE =~ "replace" ]]
10+
then
11+
# There is a replace directive. Use awk to split by spaces then extract field
12+
# 4 and 5 and stitch them together with an @ which will resolve into
13+
# github.com/lightninglabs/[email protected].
14+
PKG_PATH=$(echo $LAST_LINE | awk -F " " '{ print $4"@"$5 }')
15+
else
16+
# This is a normal directive, just combine field 1 and 2 with an @.
17+
PKG_PATH=$(echo $LAST_LINE | awk -F " " '{ print $1"@"$2 }')
18+
fi
19+
echo "$GOPATH/pkg/mod/$PKG_PATH"
20+
}
21+
22+
falafel=$(which falafel)
23+
24+
# Name of the package for the generated APIs.
25+
pkg="main"
26+
27+
# The package where the protobuf definitions originally are found.
28+
target_pkg="github.com/lightningnetwork/lnd/lnrpc"
29+
30+
lnd_src=$(import_path "github.com/lightningnetwork/lnd ")
31+
opts="package_name=$pkg,target_package=$target_pkg,api_prefix=1,js_stubs=1,build_tags=// +build js"
32+
protoc -I/usr/local/include -I. -I"$lnd_src/lnrpc" \
33+
--plugin=protoc-gen-custom=$falafel\
34+
--custom_out=. \
35+
--custom_opt="$opts" \
36+
--proto_path="$1" \
37+
rpc.proto stateservice.proto
38+
39+
target_pkg="github.com/lightningnetwork/lnd/lnrpc/verrpc"
40+
opts="package_name=$pkg,target_package=$target_pkg,api_prefix=1,js_stubs=1,build_tags=// +build js"
41+
protoc -I/usr/local/include -I. -I"$lnd_src/lnrpc" \
42+
--plugin=protoc-gen-custom=$falafel\
43+
--custom_out=. \
44+
--custom_opt="$opts" \
45+
--proto_path="$1" \
46+
verrpc/verrpc.proto

0 commit comments

Comments
 (0)