-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
903 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Callback.h | ||
// LncRn | ||
// | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTEventEmitter.h> | ||
|
||
@interface Callback : NSObject | ||
@property (nonatomic, copy) RCTResponseSenderBlock rnCallback; | ||
-(void)setCallback:(RCTResponseSenderBlock)callback; | ||
-(void)sendResult:(NSString *)data; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Callback.m | ||
#import "Callback.h" | ||
#import <React/RCTEventEmitter.h> | ||
|
||
@implementation Callback | ||
|
||
-(void)setCallback:(RCTResponseSenderBlock)callback { | ||
NSLog(@"setCallback"); | ||
self.rnCallback = callback; | ||
} | ||
|
||
-(void)sendResult:(NSString *)data { | ||
NSLog(@"sendResult"); | ||
NSLog(data); | ||
self.rnCallback(@[data]); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <React/RCTEventEmitter.h> | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface LncModule : RCTEventEmitter <RCTBridgeModule> | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
#import "LncModule.h" | ||
#import "Callback.h" | ||
#import "StreamingCallback.h" | ||
#import "Lndmobile.xcframework/ios-arm64/Lndmobile.framework/Headers/Lndmobile.h" | ||
|
||
|
||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import "RNLncRnSpec.h" | ||
#endif | ||
|
||
@implementation LncModule | ||
RCT_EXPORT_MODULE() | ||
|
||
RCT_EXPORT_METHOD(initLNC:(NSString *)nameSpace) | ||
{ | ||
NSError *error; | ||
MobileInitLNC(nameSpace, @"info", &error); | ||
if (error) { | ||
NSLog(@"Init error %@", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(registerLocalPrivCreateCallback:(NSString *)nameSpace | ||
resolver:(RCTResponseSenderBlock)onLocalPrivCreate) | ||
{ | ||
Callback *lpccb = [[Callback alloc] init]; | ||
[lpccb setCallback:onLocalPrivCreate]; | ||
NSError *error; | ||
MobileRegisterLocalPrivCreateCallback(nameSpace, lpccb, &error); | ||
if (error) { | ||
NSLog(@"registerLocalPrivCreateCallback error %@", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(registerRemoteKeyReceiveCallback:(NSString *)nameSpace | ||
resolver:(RCTResponseSenderBlock)onRemoteKeyReceive) | ||
{ | ||
Callback * rkrcb = [[Callback alloc] init]; | ||
[rkrcb setCallback:onRemoteKeyReceive]; | ||
NSError *error; | ||
MobileRegisterRemoteKeyReceiveCallback(nameSpace, rkrcb, &error); | ||
if (error) { | ||
NSLog(@"registerRemoteKeyReceiveCallback error %@", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(registerAuthDataCallback:(NSString *)nameSpace | ||
resolver:(RCTResponseSenderBlock)onAuthData) | ||
{ | ||
Callback * oacb = [[Callback alloc] init]; | ||
[oacb setCallback:onAuthData]; | ||
NSError *error; | ||
MobileRegisterAuthDataCallback(nameSpace, oacb, &error); | ||
if (error) { | ||
NSLog(@"registerAuthDataCallback error %@", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(isConnected:(NSString *)nameSpace | ||
resolver:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)reject) | ||
{ | ||
BOOL isConnected; | ||
NSError *error; | ||
MobileIsConnected(nameSpace, &isConnected, &error); | ||
if (error) { | ||
reject(@"isConnected_failure", @"error thrown", error); | ||
} else { | ||
resolve(@(isConnected)); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(status:(NSString *)nameSpace | ||
resolver:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)reject) | ||
{ | ||
NSError *error; | ||
NSString *status = MobileStatus(nameSpace, &error); | ||
if (status) { | ||
resolve(status); | ||
} else if (error) { | ||
reject(@"status_failure", @"error thrown", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(expiry:(NSString *)nameSpace | ||
resolver:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)reject) | ||
{ | ||
NSError *error; | ||
NSString *expiry = MobileGetExpiry(nameSpace, &error); | ||
if (expiry) { | ||
resolve(expiry); | ||
} else if (error) { | ||
reject(@"expiry_error", @"error thrown", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(isReadOnly:(NSString *)nameSpace | ||
resolver:(RCTPromiseResolveBlock)resolve) | ||
{ | ||
BOOL readOnly = MobileIsReadOnly(nameSpace, nil, nil); | ||
resolve(@(readOnly)); | ||
} | ||
|
||
RCT_EXPORT_METHOD(hasPerms:(NSString *)nameSpace | ||
permission:(NSString *)permission | ||
resolver:(RCTPromiseResolveBlock)resolve) | ||
{ | ||
BOOL hasPermissions; | ||
NSError *error; | ||
MobileHasPermissions(nameSpace, permission, &hasPermissions, &error); | ||
resolve(@(hasPermissions)); | ||
if (error) { | ||
NSLog(@"disconnect error %@", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(connectServer:(NSString *)nameSpace | ||
mailboxServerAddr:(NSString *)mailboxServerAddr | ||
isDevServer:(BOOL)isDevServer | ||
connectPhrase:(NSString *)connectPhrase | ||
localStatic:(NSString *)localStatic | ||
remoteStatic:(NSString *)remoteStatic) | ||
{ | ||
NSError *error; | ||
MobileConnectServer(nameSpace, mailboxServerAddr, isDevServer, connectPhrase, localStatic, remoteStatic, nil); | ||
if (error) { | ||
NSLog(@"connectServer error %@", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(disconnect:(NSString *)nameSpace) | ||
{ | ||
NSError *error; | ||
MobileDisconnect(nameSpace, &error); | ||
if (error) { | ||
NSLog(@"disconnect error %@", error); | ||
} | ||
} | ||
|
||
RCT_EXPORT_METHOD(invokeRPC:(NSString *)nameSpace | ||
route:(NSString *)route | ||
requestData:(NSString *)requestData | ||
resolver:(RCTResponseSenderBlock)resolve) | ||
{ | ||
Callback * gocb = [[Callback alloc] init]; | ||
[gocb setCallback:resolve]; | ||
NSError *error; | ||
MobileInvokeRPC(nameSpace, route, requestData, gocb, &error); | ||
if (error) { | ||
NSLog(@"connectServer error %@", error); | ||
} | ||
} | ||
|
||
// placeholders to prevent NativeEventEmitter from erroring | ||
// on initialization | ||
-(void)startObserving {} | ||
-(void)stopObserving {} | ||
|
||
RCT_EXPORT_METHOD(initListener:(NSString *)nameSpace | ||
eventName:(NSString *)eventName | ||
request:(NSString *)request) | ||
{ | ||
StreamingCallback * gocb = [[StreamingCallback alloc] init]; | ||
gocb.delegate = self; | ||
[gocb setEventName:eventName]; | ||
NSError *error; | ||
MobileInvokeRPC(nameSpace, eventName, request, gocb, &error); | ||
if (error) { | ||
NSLog(@"%@ error %@", eventName, error); | ||
} | ||
} | ||
|
||
- (NSArray<NSString *> *)supportedEvents { | ||
// TODO add all streaming events names to list | ||
return @[ | ||
@"lnrpc.Lightning.SubscribePeerEvents", | ||
@"lnrpc.Lightning.SubscribePeerEvents", | ||
@"chainrpc.ChainNotifier.RegisterConfirmationsNtfn", | ||
@"chainrpc.ChainNotifier.RegisterSpendNtfn", | ||
@"chainrpc.ChainNotifier.RegisterBlockEpochNtfn", | ||
@"invoicesrpc.Invoices.SubscribeSingleInvoice", | ||
@"lnrpc.Lightning.SubscribeTransactions", | ||
@"lnrpc.Lightning.SubscribePeerEvents", | ||
@"lnrpc.Lightning.SubscribeChannelEvents", | ||
@"lnrpc.Lightning.OpenChannel", | ||
@"lnrpc.Lightning.ChannelAcceptor", | ||
@"lnrpc.Lightning.CloseChannel", | ||
@"lnrpc.Lightning.SendPayment", | ||
@"lnrpc.Lightning.SendToRoute", | ||
@"lnrpc.Lightning.SubscribeInvoices", | ||
@"lnrpc.Lightning.SubscribeChannelGraph", | ||
@"lnrpc.Lightning.SubscribeChannelBackups", | ||
@"lnrpc.Lightning.RegisterRPCMiddleware", | ||
@"lnrpc.Lightning.SubscribeCustomMessages", | ||
@"routerrpc.Router.SendPaymentV2", | ||
@"routerrpc.Router.TrackPaymentV2", | ||
@"routerrpc.Router.SubscribeHtlcEvents", | ||
@"routerrpc.Router.SendPayment", | ||
@"routerrpc.Router.TrackPayment", | ||
@"routerrpc.Router.HtlcInterceptor", | ||
@"looprpc.SwapClient.Monitor", | ||
@"poolrpc.ChannelAuctioneer.SubscribeBatchAuction", | ||
@"poolrpc.ChannelAuctioneer.SubscribeSidecar", | ||
@"poolrpc.HashMail.RecvStream" | ||
]; | ||
} | ||
|
||
// Don't compile this code when we build for the old architecture. | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||
(const facebook::react::ObjCTurboModule::InitParams &)params | ||
{ | ||
return std::make_shared<facebook::react::NativeLncRnSpecJSI>(params); | ||
} | ||
#endif | ||
|
||
@end |
Oops, something went wrong.