Skip to content
Open
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
15 changes: 15 additions & 0 deletions mobile/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Comment on lines +160 to +173

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Your PR description mentions that the status should include walletUnlocked, which is a great idea for mobile clients. The current implementation only returns lndStarted. To make this function more useful and align with your description, I suggest returning a structured status object.

This makes the API more extensible for future status fields. You could then use the generated gRPC bindings for the StateService to query the wallet's state when lnd is running.

Here is a suggested structure that you can build upon. Note that you'll also need to import the encoding/json package.

// LndStatus represents the current status of the lnd daemon.
type LndStatus struct {
	LndStarted bool `json:"lnd_started"`

	// WalletState is the current state of the wallet, matching the states
	// from the `lnrpc.WalletState` enum. A value of 0 indicates that the
	// state is unknown, which is the case if lnd is not running.
	WalletState int `json:"wallet_state"`
}

// LndStatusCallback is an interface that must be implemented by the caller
// to retrieve the service status.
type LndStatusCallback interface {
	// OnResponse is called with the status of lnd, serialized as a JSON
	// byte slice. An error is returned as a string if one occurred.
	OnResponse(statusBytes []byte, errStr string)
}

// ServiceStatus retrieves the current status of the lnd daemon, including
// whether it has started and the wallet's current state. The status is passed
// to the provided callback as a JSON-encoded byte slice.
func ServiceStatus(callback LndStatusCallback) {
	// NOTE: This implementation only returns the lndStarted status.
	// A future commit should expand this to query the wallet state via the
	// State gRPC service when lnd is running.
	status := &LndStatus{
		LndStarted: atomic.LoadInt32(&lndStarted) == 1,
	}

	statusBytes, err := json.Marshal(status)
	if err != nil {
		callback.OnResponse(nil, "error marshalling status: "+err.Error())
		return
	}

	callback.OnResponse(statusBytes, "")
}

@hsjoberg hsjoberg Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR description now.

The old implementation had walletUnlocked bool.
But to keep the scope low and functionality targeted, I suggest checking wallet state in the gRPC server later on once lnd is running. This can be done with subscribeState. It's basically a necessity for wallet apps to subscribe to this stream anyway.
Figuring out wallet state is a solved problem. However figuring out whether lnd is started is not.

Loading