Skip to content

Commit 3e4fc1f

Browse files
committed
Merge branch 'simulatorQT'
2 parents a0ab165 + 0be3526 commit 3e4fc1f

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ In order to do so:
103103

104104
If the simulator is listening on a custom port, `--simulatorPort=<port>` must also be provided.
105105

106+
Note: the simulator is currently only supported in the servewallet and in the Qt app and only when the app runs in testnet mode.
107+
106108
#### Watch and build the UI
107109

108110
Run `make webdev` to develop the UI inside a web browser (for quick development, automatic rebuilds

backend/bridgecommon/bridgecommon.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ func (env *BackendEnvironment) BluetoothConnect(identifier string) {
287287
// Serve serves the BitBox API for use in a native client.
288288
func Serve(
289289
testnet bool,
290+
simulator bool,
290291
gapLimits *btctypes.GapLimits,
291292
communication NativeCommunication,
292293
backendEnvironment backend.Environment) {
@@ -305,6 +306,11 @@ func Serve(
305306
WithField("version", versioninfo.Version).
306307
Info("environment")
307308

309+
if simulator {
310+
log.Info("Simulator mode enabled, ensuring testnet mode is enabled")
311+
testnet = true
312+
}
313+
308314
var err error
309315
globalBackend, err = backend.NewBackend(
310316
arguments.NewArguments(

backend/bridgecommon/bridgecommon_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (e environment) BluetoothConnect(string) {}
7878
// TestServeShutdownServe checks that you can call Serve twice in a row.
7979
func TestServeShutdownServe(t *testing.T) {
8080
bridgecommon.Serve(
81+
false,
8182
false,
8283
nil,
8384
communication{},
@@ -88,6 +89,7 @@ func TestServeShutdownServe(t *testing.T) {
8889
done := make(chan struct{})
8990
go func() {
9091
bridgecommon.Serve(
92+
false,
9193
false,
9294
nil,
9395
communication{},

backend/mobileserver/mobileserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func Serve(dataDir string, testnet bool, environment GoEnvironmentInterface, goA
185185

186186
bridgecommon.Serve(
187187
testnet,
188+
false,
188189
nil,
189190
goAPI,
190191
&bridgecommon.BackendEnvironment{

cmd/servewallet/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (webdevEnvironment) DeviceInfos() []usb.DeviceInfo {
7575
testDeviceInfo := simulator.TestDeviceInfo()
7676
if testDeviceInfo != nil {
7777
// We are in "test device" mode.
78-
return []usb.DeviceInfo{*testDeviceInfo}
78+
return []usb.DeviceInfo{testDeviceInfo}
7979
}
8080
return usb.DeviceInfos()
8181
}

frontends/qt/server/server.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import (
6868

6969
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/bridgecommon"
7070
btctypes "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/types"
71+
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/devices/bitbox02/simulator"
7172
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/devices/usb"
7273
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/mobileserver"
7374
"github.com/BitBoxSwiss/bitbox-wallet-app/util/logging"
@@ -109,6 +110,14 @@ func setOnline(isReachable bool) {
109110
bridgecommon.SetOnline(isReachable)
110111
}
111112

113+
func deviceInfos() []usb.DeviceInfo {
114+
testDeviceInfo := simulator.TestDeviceInfo()
115+
if testDeviceInfo != nil {
116+
return []usb.DeviceInfo{testDeviceInfo}
117+
}
118+
return usb.DeviceInfos()
119+
}
120+
112121
//export serve
113122
func serve(
114123
cppHeapFreeFn C.cppHeapFree,
@@ -121,6 +130,8 @@ func serve(
121130
log := logging.Get().WithGroup("server")
122131
log.WithField("args", os.Args).Info("Started Qt application")
123132
testnet := flag.Bool("testnet", false, "activate testnets")
133+
simulatorPort := flag.Int("simulatorPort", 15423, "port for the BitBox02 simulator")
134+
useSimulator := flag.Bool("simulator", false, "use the BitBox02 simulator. It implies --testnet.")
124135

125136
if runtime.GOOS == "darwin" {
126137
// eat "-psn_xxxx" on Mac, which is passed when starting an app from Finder for the first time.
@@ -146,12 +157,17 @@ func serve(
146157
}
147158
}
148159

160+
if *useSimulator {
161+
simulator.Init(*simulatorPort)
162+
}
163+
149164
// Capture C string early to avoid potential use when it's already popped
150165
// from the stack.
151166
nativeLocale := C.GoString(preferredLocale)
152167

153168
bridgecommon.Serve(
154169
*testnet,
170+
*useSimulator,
155171
gapLimits,
156172
&nativeCommunication{
157173
respond: func(queryID int, response string) {
@@ -171,7 +187,7 @@ func serve(
171187
defer C.free(unsafe.Pointer(cText))
172188
C.notifyUser(notifyUserFn, cText)
173189
},
174-
DeviceInfosFunc: usb.DeviceInfos,
190+
DeviceInfosFunc: deviceInfos,
175191
SystemOpenFunc: system.Open,
176192
UsingMobileDataFunc: func() bool { return false },
177193
NativeLocaleFunc: func() string { return nativeLocale },

0 commit comments

Comments
 (0)