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

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

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

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