From aca307f05f2af8a9f2ced178dd1ae7d04d2ef996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Sj=C3=B6berg?= Date: Fri, 4 Sep 2020 15:03:07 +0200 Subject: [PATCH] mobile: Add ServiceStatus for retrieving current runtime status of lnd Used for checking whether lnd is started or not. ServiceStatus can also be used to determine when lnd has shut down, since `stopDaemon` returns immediately and does not wait for the gRPC servers to be fully closed. --- mobile/bindings.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mobile/bindings.go b/mobile/bindings.go index e5fe5f71f..7766a7644 100644 --- a/mobile/bindings.go +++ b/mobile/bindings.go @@ -156,3 +156,18 @@ func Start(extraArgs string, rpcReady Callback) { rpcReady.OnResponse([]byte{}) }() } + +type LndStatusCallback interface { + OnResponse(lndStarted int32) +} + +// ServiceStatus returns 1 if lnd has started up successfully, allowing the +// caller to interact with the in-memory gRPC servers. If 0 is returned, the +// caller should invoke `Start` to initialize lnd. +// +// ServiceStatus can also be used to determine when lnd has shut down, since +// `stopDaemon` returns immediately and does not wait for the gRPC servers to be +// fully closed. +func ServiceStatus(callback LndStatusCallback) { + callback.OnResponse(atomic.LoadInt32(&lndStarted)) +}