mobile: call Start callback when lnd ready, add unlock callback
Use the custom listeners' Ready channels to provide callbacks to the mobile application when the gRPC services are ready. NOTE: this changes the Start() API by adding one extra callback.
This commit is contained in:
parent
dc6c040803
commit
260704f3cd
@ -16,7 +16,11 @@ import (
|
|||||||
// extraArgs can be used to pass command line arguments to lnd that will
|
// extraArgs can be used to pass command line arguments to lnd that will
|
||||||
// override what is found in the config file. Example:
|
// override what is found in the config file. Example:
|
||||||
// extraArgs = "--bitcoin.testnet --lnddir=\"/tmp/folder name/\" --profile=5050"
|
// extraArgs = "--bitcoin.testnet --lnddir=\"/tmp/folder name/\" --profile=5050"
|
||||||
func Start(extraArgs string, callback Callback) {
|
//
|
||||||
|
// The unlockerReady callback is called when the WalletUnlocker service is
|
||||||
|
// ready, and rpcReady is called after the wallet has been unlocked and lnd is
|
||||||
|
// ready to accept RPC calls.
|
||||||
|
func Start(extraArgs string, unlockerReady, rpcReady Callback) {
|
||||||
// Split the argument string on "--" to get separated command line
|
// Split the argument string on "--" to get separated command line
|
||||||
// arguments.
|
// arguments.
|
||||||
var splitArgs []string
|
var splitArgs []string
|
||||||
@ -33,11 +37,24 @@ func Start(extraArgs string, callback Callback) {
|
|||||||
// startup.
|
// startup.
|
||||||
os.Args = append(os.Args, splitArgs...)
|
os.Args = append(os.Args, splitArgs...)
|
||||||
|
|
||||||
|
// Set up channels that will be notified when the RPC servers are ready
|
||||||
|
// to accept calls.
|
||||||
|
var (
|
||||||
|
unlockerListening = make(chan struct{})
|
||||||
|
rpcListening = make(chan struct{})
|
||||||
|
)
|
||||||
|
|
||||||
// We call the main method with the custom in-memory listeners called
|
// We call the main method with the custom in-memory listeners called
|
||||||
// by the mobile APIs, such that the grpc server will use these.
|
// by the mobile APIs, such that the grpc server will use these.
|
||||||
cfg := lnd.ListenerCfg{
|
cfg := lnd.ListenerCfg{
|
||||||
WalletUnlocker: walletUnlockerLis,
|
WalletUnlocker: &lnd.ListenerWithSignal{
|
||||||
RPCListener: lightningLis,
|
Listener: walletUnlockerLis,
|
||||||
|
Ready: unlockerListening,
|
||||||
|
},
|
||||||
|
RPCListener: &lnd.ListenerWithSignal{
|
||||||
|
Listener: lightningLis,
|
||||||
|
Ready: rpcListening,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the "real" main in a nested manner so the defers will properly
|
// Call the "real" main in a nested manner so the defers will properly
|
||||||
@ -53,9 +70,15 @@ func Start(extraArgs string, callback Callback) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// TODO(halseth): callback when RPC server is actually running. Since
|
// Finally we start two go routines that will call the provided
|
||||||
// the RPC server might take a while to start up, the client might
|
// callbacks when the RPC servers are ready to accept calls.
|
||||||
// assume it is ready to accept calls when this callback is sent, while
|
go func() {
|
||||||
// it's not.
|
<-unlockerListening
|
||||||
callback.OnResponse([]byte("started"))
|
unlockerReady.OnResponse([]byte{})
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-rpcListening
|
||||||
|
rpcReady.OnResponse([]byte{})
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user