mobile/bindings: update API for falafel v0.8.1

This commit is contained in:
Johan T. Halseth 2021-02-03 15:39:36 +01:00
parent cf5b0b7943
commit 321141600e
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
3 changed files with 39 additions and 49 deletions

4
lnd.go
View File

@ -153,10 +153,6 @@ type ListenerWithSignal struct {
// ListenerCfg is a wrapper around custom listeners that can be passed to lnd
// when calling its main method.
type ListenerCfg struct {
// WalletUnlocker can be set to the listener to use for the wallet
// unlocker. If nil a regular network listener will be created.
WalletUnlocker *ListenerWithSignal
// RPCListener can be set to the listener to use for the RPC server. If
// nil a regular network listener will be created.
RPCListener *ListenerWithSignal

View File

@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y \
ARG PROTOC_GEN_VERSION
ARG GRPC_GATEWAY_VERSION
ENV FALAFEL_VERSION="v0.7.1"
ENV FALAFEL_VERSION="v0.8.1"
ENV GOCACHE=/tmp/build/.cache
ENV GOMODCACHE=/tmp/build/.modcache

View File

@ -10,6 +10,7 @@ import (
flags "github.com/jessevdk/go-flags"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/signal"
"google.golang.org/grpc"
)
// Start starts lnd in a new goroutine.
@ -18,14 +19,12 @@ import (
// override what is found in the config file. Example:
// extraArgs = "--bitcoin.testnet --lnddir=\"/tmp/folder name/\" --profile=5050"
//
// 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.
// The rpcReady is called lnd is ready to accept RPC calls.
//
// NOTE: On mobile platforms the '--lnddir` argument should be set to the
// current app directory in order to ensure lnd has the permissions needed to
// write to it.
func Start(extraArgs string, unlockerReady, rpcReady Callback) {
func Start(extraArgs string, rpcReady Callback) {
// Split the argument string on "--" to get separated command line
// arguments.
var splitArgs []string
@ -62,20 +61,16 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) {
return
}
// Set up channels that will be notified when the RPC servers are ready
// to accept calls.
// Set a channel that will be notified when the RPC server is ready to
// accept calls.
var (
unlockerListening = make(chan struct{})
rpcListening = make(chan struct{})
rpcListening = make(chan struct{})
quit = make(chan struct{})
)
// We call the main method with the custom in-memory listeners called
// by the mobile APIs, such that the grpc server will use these.
// We call the main method with the custom in-memory listener called by
// the mobile APIs, such that the grpc server will use it.
cfg := lnd.ListenerCfg{
WalletUnlocker: &lnd.ListenerWithSignal{
Listener: walletUnlockerLis,
Ready: unlockerListening,
},
RPCListener: &lnd.ListenerWithSignal{
Listener: lightningLis,
Ready: rpcListening,
@ -85,6 +80,8 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) {
// Call the "real" main in a nested manner so the defers will properly
// be executed in the case of a graceful shutdown.
go func() {
defer close(quit)
if err := lnd.Main(
loadedConfig, cfg, shutdownInterceptor,
); err != nil {
@ -98,40 +95,37 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) {
}
}()
// Finally we start two go routines that will call the provided
// callbacks when the RPC servers are ready to accept calls.
go func() {
<-unlockerListening
// By default we'll apply the admin auth options, which will include
// macaroons.
setDefaultDialOption(
func() ([]grpc.DialOption, error) {
return lnd.AdminAuthOptions(loadedConfig, false)
},
)
// We must set the TLS certificates in order to properly
// authenticate with the wallet unlocker service.
auth, err := lnd.AdminAuthOptions(loadedConfig, true)
if err != nil {
unlockerReady.OnError(err)
// For the WalletUnlocker and StateService, the macaroons might not be
// available yet when called, so we use a more restricted set of
// options that don't include them.
setWalletUnlockerDialOption(
func() ([]grpc.DialOption, error) {
return lnd.AdminAuthOptions(loadedConfig, true)
},
)
setStateDialOption(
func() ([]grpc.DialOption, error) {
return lnd.AdminAuthOptions(loadedConfig, true)
},
)
// Finally we start a go routine that will call the provided callback
// when the RPC server is ready to accept calls.
go func() {
select {
case <-rpcListening:
case <-quit:
return
}
// Add the auth options to the listener's dial options.
addWalletUnlockerLisDialOption(auth...)
unlockerReady.OnResponse([]byte{})
}()
go func() {
<-rpcListening
// Now that the RPC server is ready, we can get the needed
// authentication options, and add them to the global dial
// options.
auth, err := lnd.AdminAuthOptions(loadedConfig, false)
if err != nil {
rpcReady.OnError(err)
return
}
// Add the auth options to the listener's dial options.
addLightningLisDialOption(auth...)
rpcReady.OnResponse([]byte{})
}()
}