2016-09-07 17:35:04 +00:00
|
|
|
#import "RCTStatus.h"
|
2017-10-17 10:56:14 +00:00
|
|
|
#import "ReactNativeConfig.h"
|
2017-04-24 14:50:16 +00:00
|
|
|
#import "React/RCTBridge.h"
|
|
|
|
#import "React/RCTEventDispatcher.h"
|
2019-02-12 11:35:26 +00:00
|
|
|
#import "Statusgo/Statusgo.h"
|
2019-05-03 14:22:43 +00:00
|
|
|
#import <SSZipArchive.h>
|
2017-05-22 08:43:13 +00:00
|
|
|
|
|
|
|
@interface NSDictionary (BVJSONString)
|
|
|
|
-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSDictionary (BVJSONString)
|
|
|
|
|
|
|
|
-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint {
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
|
|
|
|
options:(NSJSONWritingOptions) (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
|
|
|
|
error:&error];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-05-22 08:43:13 +00:00
|
|
|
if (! jsonData) {
|
|
|
|
NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
|
|
|
|
return @"{}";
|
|
|
|
} else {
|
|
|
|
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSArray (BVJSONString)
|
|
|
|
- (NSString *)bv_jsonStringWithPrettyPrint:(BOOL)prettyPrint;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSArray (BVJSONString)
|
|
|
|
-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint {
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
|
|
|
|
options:(NSJSONWritingOptions) (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
|
|
|
|
error:&error];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-05-22 08:43:13 +00:00
|
|
|
if (! jsonData) {
|
|
|
|
NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
|
|
|
|
return @"[]";
|
|
|
|
} else {
|
|
|
|
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
2016-09-07 17:35:04 +00:00
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
static RCTBridge *bridge;
|
2019-02-12 11:35:26 +00:00
|
|
|
|
|
|
|
@implementation Status
|
|
|
|
|
|
|
|
- (instancetype)init {
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
// Subscribing to the signals from Status-Go
|
|
|
|
StatusgoSetMobileSignalHandler(self);
|
|
|
|
return self;
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
-(RCTBridge *)bridge
|
|
|
|
{
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)setBridge:(RCTBridge *)newBridge
|
|
|
|
{
|
|
|
|
bridge = newBridge;
|
|
|
|
}
|
2016-09-07 17:35:04 +00:00
|
|
|
|
2019-02-12 11:35:26 +00:00
|
|
|
- (void)handleSignal:(NSString *)signal
|
|
|
|
{
|
|
|
|
if(!signal){
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SignalEvent nil");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"[handleSignal] Received an event from Status-Go: %@", signal);
|
|
|
|
#endif
|
|
|
|
[bridge.eventDispatcher sendAppEventWithName:@"gethEvent"
|
|
|
|
body:@{@"jsonEvent": signal}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-07 17:35:04 +00:00
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - startNode
|
|
|
|
//////////////////////////////////////////////////////////////////// startNode
|
2018-09-07 09:53:43 +00:00
|
|
|
RCT_EXPORT_METHOD(startNode:(NSString *)configString) {
|
2016-09-12 08:16:07 +00:00
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"StartNode() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *rootUrl =[[fileManager
|
|
|
|
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
|
|
|
|
lastObject];
|
2018-09-07 09:53:43 +00:00
|
|
|
NSURL *absTestnetFolderName = [rootUrl URLByAppendingPathComponent:@"ethereum/testnet"];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-09-07 09:53:43 +00:00
|
|
|
if (![fileManager fileExistsAtPath:absTestnetFolderName.path])
|
|
|
|
[fileManager createDirectoryAtPath:absTestnetFolderName.path withIntermediateDirectories:YES attributes:nil error:&error];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSURL *flagFolderUrl = [rootUrl URLByAppendingPathComponent:@"ropsten_flag"];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
if(![fileManager fileExistsAtPath:flagFolderUrl.path]){
|
|
|
|
NSLog(@"remove lightchaindata");
|
2018-09-07 09:53:43 +00:00
|
|
|
NSURL *absLightChainDataUrl = [absTestnetFolderName URLByAppendingPathComponent:@"StatusIM/lightchaindata"];
|
|
|
|
if([fileManager fileExistsAtPath:absLightChainDataUrl.path]) {
|
|
|
|
[fileManager removeItemAtPath:absLightChainDataUrl.path
|
2017-08-21 14:49:31 +00:00
|
|
|
error:nil];
|
2017-04-04 07:15:57 +00:00
|
|
|
}
|
2017-08-21 14:49:31 +00:00
|
|
|
[fileManager createDirectoryAtPath:flagFolderUrl.path
|
|
|
|
withIntermediateDirectories:NO
|
|
|
|
attributes:nil
|
|
|
|
error:&error];
|
|
|
|
}
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"after remove lightchaindata");
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-09-07 09:53:43 +00:00
|
|
|
NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:@"keystore"];
|
|
|
|
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
|
|
|
if([fileManager fileExistsAtPath:absTestnetKeystoreUrl.path]){
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"copy keystore");
|
2018-09-07 09:53:43 +00:00
|
|
|
[fileManager copyItemAtPath:absTestnetKeystoreUrl.path toPath:absKeystoreUrl.path error:nil];
|
|
|
|
[fileManager removeItemAtPath:absTestnetKeystoreUrl.path error:nil];
|
2017-08-21 14:49:31 +00:00
|
|
|
}
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"after lightChainData");
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"preconfig: %@", configString);
|
|
|
|
NSData *configData = [configString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSDictionary *configJSON = [NSJSONSerialization JSONObjectWithData:configData options:NSJSONReadingMutableContainers error:nil];
|
2018-09-07 09:53:43 +00:00
|
|
|
NSString *relativeDataDir = [configJSON objectForKey:@"DataDir"];
|
|
|
|
NSString *absDataDir = [rootUrl.path stringByAppendingString:relativeDataDir];
|
|
|
|
NSURL *absDataDirUrl = [NSURL fileURLWithPath:absDataDir];
|
|
|
|
NSURL *absLogUrl = [absDataDirUrl URLByAppendingPathComponent:@"geth.log"];
|
|
|
|
[configJSON setValue:absDataDirUrl.path forKey:@"DataDir"];
|
|
|
|
[configJSON setValue:absKeystoreUrl.path forKey:@"KeyStoreDir"];
|
|
|
|
[configJSON setValue:absLogUrl.path forKey:@"LogFile"];
|
|
|
|
|
|
|
|
NSString *resultingConfig = [configJSON bv_jsonStringWithPrettyPrint:NO];
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"node config %@", resultingConfig);
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-09-07 09:53:43 +00:00
|
|
|
if(![fileManager fileExistsAtPath:absDataDirUrl.path]) {
|
|
|
|
[fileManager createDirectoryAtPath:absDataDirUrl.path withIntermediateDirectories:YES attributes:nil error:nil];
|
2017-08-21 14:49:31 +00:00
|
|
|
}
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-09-07 09:53:43 +00:00
|
|
|
NSLog(@"logUrlPath %@", absLogUrl.path);
|
|
|
|
if(![fileManager fileExistsAtPath:absLogUrl.path]) {
|
2017-05-22 08:43:13 +00:00
|
|
|
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
|
|
[dict setObject:[NSNumber numberWithInt:511] forKey:NSFilePosixPermissions];
|
2018-09-07 09:53:43 +00:00
|
|
|
[fileManager createFileAtPath:absLogUrl.path contents:nil attributes:dict];
|
2017-08-21 14:49:31 +00:00
|
|
|
}
|
2018-03-29 09:50:55 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^(void)
|
|
|
|
{
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *res = StatusgoStartNode(resultingConfig);
|
|
|
|
NSLog(@"StartNode result %@", res);
|
2018-09-07 09:53:43 +00:00
|
|
|
});
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 17:29:59 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - shouldMoveToInternalStorage
|
|
|
|
//////////////////////////////////////////////////////////////////// shouldMoveToInternalStorage
|
|
|
|
RCT_EXPORT_METHOD(shouldMoveToInternalStorage:(RCTResponseSenderBlock)onResultCallback) {
|
|
|
|
// Android only
|
|
|
|
onResultCallback(@[[NSNull null]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - moveToInternalStorage
|
|
|
|
//////////////////////////////////////////////////////////////////// moveToInternalStorage
|
|
|
|
RCT_EXPORT_METHOD(moveToInternalStorage:(RCTResponseSenderBlock)onResultCallback) {
|
|
|
|
// Android only
|
|
|
|
onResultCallback(@[[NSNull null]]);
|
|
|
|
}
|
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - StopNode method
|
|
|
|
//////////////////////////////////////////////////////////////////// StopNode
|
|
|
|
RCT_EXPORT_METHOD(stopNode) {
|
2016-09-12 08:16:07 +00:00
|
|
|
#if DEBUG
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"StopNode() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2017-08-21 14:49:31 +00:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^(void)
|
|
|
|
{
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *res = StatusgoStopNode();
|
|
|
|
NSLog(@"StopNode result %@", res);
|
2017-08-21 14:49:31 +00:00
|
|
|
});
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - Accounts method
|
|
|
|
//////////////////////////////////////////////////////////////////// createAccount
|
|
|
|
RCT_EXPORT_METHOD(createAccount:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"CreateAccount() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoCreateAccount(password);
|
|
|
|
callback(@[result]);
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 07:08:47 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
2019-01-17 22:46:48 +00:00
|
|
|
#pragma mark - SendDataNotification method
|
|
|
|
//////////////////////////////////////////////////////////////////// sendDataNotification
|
|
|
|
RCT_EXPORT_METHOD(sendDataNotification:(NSString *)dataPayloadJSON
|
2018-01-04 10:50:14 +00:00
|
|
|
tokensJSON:(NSString *)tokensJSON
|
2017-10-09 09:34:29 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString* result = StatusgoSendDataNotification(dataPayloadJSON, tokensJSON);
|
|
|
|
callback(@[result]);
|
2017-09-16 07:08:47 +00:00
|
|
|
#if DEBUG
|
2019-01-17 22:46:48 +00:00
|
|
|
NSLog(@"SendDataNotification() method called");
|
2017-09-16 07:08:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-12-15 18:57:00 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - SendLogs method
|
|
|
|
//////////////////////////////////////////////////////////////////// sendLogs
|
2019-05-03 14:22:43 +00:00
|
|
|
RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson
|
2019-04-30 11:49:45 +00:00
|
|
|
jsLogs:(NSString *)jsLogs
|
2019-05-03 14:22:43 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2018-12-15 18:57:00 +00:00
|
|
|
// TODO: Implement SendLogs for iOS
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SendLogs() method called, not implemented");
|
|
|
|
#endif
|
2019-05-03 14:22:43 +00:00
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *rootUrl =[[fileManager
|
|
|
|
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
|
|
|
|
lastObject];
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
NSURL *zipFile = [rootUrl URLByAppendingPathComponent:@"logs.zip"];
|
|
|
|
[fileManager removeItemAtPath:zipFile.path error:nil];
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
NSURL *logsFolderName = [rootUrl URLByAppendingPathComponent:@"logs"];
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
if (![fileManager fileExistsAtPath:logsFolderName.path])
|
|
|
|
[fileManager createDirectoryAtPath:logsFolderName.path withIntermediateDirectories:YES attributes:nil error:&error];
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
NSURL *dbFile = [logsFolderName URLByAppendingPathComponent:@"db.json"];
|
2019-04-30 11:49:45 +00:00
|
|
|
NSURL *jsLogsFile = [logsFolderName URLByAppendingPathComponent:@"Status.log"];
|
2019-05-03 14:22:43 +00:00
|
|
|
#if DEBUG
|
|
|
|
NSString *networkDirPath = @"ethereum/mainnet_rpc_dev";
|
|
|
|
#else
|
|
|
|
NSString *networkDirPath = @"ethereum/mainnet_rpc";
|
|
|
|
#endif
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
NSURL *networkDir = [rootUrl URLByAppendingPathComponent:networkDirPath];
|
|
|
|
NSURL *originalGethLogsFile = [networkDir URLByAppendingPathComponent:@"geth.log"];
|
|
|
|
NSURL *gethLogsFile = [logsFolderName URLByAppendingPathComponent:@"geth.log"];
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
[dbJson writeToFile:dbFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
2019-04-30 11:49:45 +00:00
|
|
|
[jsLogs writeToFile:jsLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
//NSString* gethLogs = StatusgoExportNodeLogs();
|
|
|
|
//[gethLogs writeToFile:gethLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
|
|
|
[fileManager copyItemAtPath:originalGethLogsFile.path toPath:gethLogsFile.path error:nil];
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
[SSZipArchive createZipFileAtPath:zipFile.path withContentsOfDirectory:logsFolderName.path];
|
|
|
|
[fileManager removeItemAtPath:logsFolderName.path error:nil];
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
callback(@[zipFile.path]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// addPeer
|
|
|
|
RCT_EXPORT_METHOD(exportLogs:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"exportLogs() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoExportNodeLogs();
|
|
|
|
callback(@[result]);
|
2018-12-15 18:57:00 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 10:18:30 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// addPeer
|
|
|
|
RCT_EXPORT_METHOD(addPeer:(NSString *)enode
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoAddPeer(enode);
|
|
|
|
callback(@[result]);
|
2017-12-05 10:18:30 +00:00
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"AddPeer() method called");
|
|
|
|
#endif
|
|
|
|
}
|
2017-09-16 07:08:47 +00:00
|
|
|
|
Add mailservers confirmations & use peer count for online status
We now check that we are only connected to some `peers` instead of using `NetInfo` from `react-native`.
This is because it has been reported to be quite flaky at times, not reporting online status after sleeping, and for privacy concerns (on ios it pings `apple.com`, on desktop `google.com`).
Adds a new banner `Wallet Offline` and change `Connecting to peers` to `Chat offline`.
A message will be marked as `Sent` only if it made it to the mailserver you are connected to, which will increase the guarantees that we can make about a message (if you see it as sent, it has reached at least a mailserver), this has the consequence that:
- If you are not connected to any mailserver or the mailserver is non responsive/down, and you send a message, it will be marked as `Not sent`, although it might have been actually made it in the network.
Probably this is something that we would like to communicate to the user through UX (i.e. tick if made it to at least a peer, double tick if it made to a mailserver )
Currently I have only enabled this feature in nightlies & devs, I would give it a run and see how we feel about it.
2018-12-06 10:53:45 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// updateMailservers
|
|
|
|
RCT_EXPORT_METHOD(updateMailservers:(NSString *)enodes
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString* result = StatusgoUpdateMailservers(enodes);
|
|
|
|
callback(@[result]);
|
Add mailservers confirmations & use peer count for online status
We now check that we are only connected to some `peers` instead of using `NetInfo` from `react-native`.
This is because it has been reported to be quite flaky at times, not reporting online status after sleeping, and for privacy concerns (on ios it pings `apple.com`, on desktop `google.com`).
Adds a new banner `Wallet Offline` and change `Connecting to peers` to `Chat offline`.
A message will be marked as `Sent` only if it made it to the mailserver you are connected to, which will increase the guarantees that we can make about a message (if you see it as sent, it has reached at least a mailserver), this has the consequence that:
- If you are not connected to any mailserver or the mailserver is non responsive/down, and you send a message, it will be marked as `Not sent`, although it might have been actually made it in the network.
Probably this is something that we would like to communicate to the user through UX (i.e. tick if made it to at least a peer, double tick if it made to a mailserver )
Currently I have only enabled this feature in nightlies & devs, I would give it a run and see how we feel about it.
2018-12-06 10:53:45 +00:00
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"UpdateMailservers() method called");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-03-29 18:00:12 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// getNodesFromContract
|
|
|
|
RCT_EXPORT_METHOD(getNodesFromContract:(NSString *)url
|
|
|
|
address:(NSString *) address
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
NSString* result = StatusgoGetNodesFromContract(url, address);
|
|
|
|
callback(@[result]);
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"GetNodesFromContract() method called");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-03-22 13:57:27 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// chaosModeUpdate
|
|
|
|
RCT_EXPORT_METHOD(chaosModeUpdate:(BOOL)on
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
NSString* result = StatusgoChaosModeUpdate(on);
|
|
|
|
callback(@[result]);
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"ChaosModeUpdate() method called");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// recoverAccount
|
|
|
|
RCT_EXPORT_METHOD(recoverAccount:(NSString *)passphrase
|
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"RecoverAccount() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoRecoverAccount(password, passphrase);
|
|
|
|
callback(@[result]);
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// login
|
|
|
|
RCT_EXPORT_METHOD(login:(NSString *)address
|
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"Login() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoLogin(address, password);
|
|
|
|
callback(@[result]);
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 15:52:29 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// login
|
|
|
|
RCT_EXPORT_METHOD(verify:(NSString *)address
|
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"VerifyAccountPassword() method called");
|
|
|
|
#endif
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSURL *rootUrl =[[fileManager
|
|
|
|
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
|
|
|
|
lastObject];
|
|
|
|
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
2019-04-30 11:49:45 +00:00
|
|
|
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoVerifyAccountPassword(absKeystoreUrl.path, address, password);
|
|
|
|
callback(@[result]);
|
2018-11-26 15:52:29 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
2018-08-10 17:15:16 +00:00
|
|
|
#pragma mark - SendTransaction
|
|
|
|
//////////////////////////////////////////////////////////////////// sendTransaction
|
|
|
|
RCT_EXPORT_METHOD(sendTransaction:(NSString *)txArgsJSON
|
2016-09-12 08:16:07 +00:00
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2018-08-10 17:15:16 +00:00
|
|
|
NSLog(@"SendTransaction() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoSendTransaction(txArgsJSON, password);
|
|
|
|
callback(@[result]);
|
2018-06-03 10:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2018-08-10 17:15:16 +00:00
|
|
|
#pragma mark - SignMessage
|
|
|
|
//////////////////////////////////////////////////////////////////// signMessage
|
|
|
|
RCT_EXPORT_METHOD(signMessage:(NSString *)message
|
2018-06-03 10:25:14 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2018-08-10 17:15:16 +00:00
|
|
|
NSLog(@"SignMessage() method called");
|
2018-06-03 10:25:14 +00:00
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoSignMessage(message);
|
|
|
|
callback(@[result]);
|
2019-03-05 14:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - SignTypedData
|
|
|
|
//////////////////////////////////////////////////////////////////// signTypedData
|
|
|
|
RCT_EXPORT_METHOD(signTypedData:(NSString *)data
|
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SignTypedData() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoSignTypedData(data, password);
|
|
|
|
callback(@[result]);
|
2016-09-07 17:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-07-19 15:51:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - SignGroupMembership
|
|
|
|
//////////////////////////////////////////////////////////////////// signGroupMembership
|
|
|
|
RCT_EXPORT_METHOD(signGroupMembership:(NSString *)content
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SignGroupMembership() method called");
|
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoSignGroupMembership(content);
|
|
|
|
callback(@[result]);
|
2018-07-19 15:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2018-10-01 08:47:20 +00:00
|
|
|
#pragma mark - ExtractGroupMembershipSignatures
|
|
|
|
//////////////////////////////////////////////////////////////////// extractGroupMembershipSignatures
|
|
|
|
RCT_EXPORT_METHOD(extractGroupMembershipSignatures:(NSString *)content
|
2018-07-19 15:51:06 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2018-10-01 08:47:20 +00:00
|
|
|
NSLog(@"ExtractGroupMembershipSignatures() method called");
|
2018-07-19 15:51:06 +00:00
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoExtractGroupMembershipSignatures(content);
|
|
|
|
callback(@[result]);
|
2018-07-19 15:51:06 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 13:48:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - EnableInstallation
|
|
|
|
//////////////////////////////////////////////////////////////////// enableInstallation
|
|
|
|
RCT_EXPORT_METHOD(enableInstallation:(NSString *)content
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"EnableInstallation() method called");
|
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoEnableInstallation(content);
|
|
|
|
callback(@[result]);
|
2018-11-02 13:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - DisableInstallation
|
|
|
|
//////////////////////////////////////////////////////////////////// disableInstallation
|
|
|
|
RCT_EXPORT_METHOD(disableInstallation:(NSString *)content
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"DisableInstallation() method called");
|
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoDisableInstallation(content);
|
|
|
|
callback(@[result]);
|
2018-11-02 13:48:45 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - only android methods
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2016-09-07 17:35:04 +00:00
|
|
|
RCT_EXPORT_METHOD(setAdjustResize) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"setAdjustResize() works only on Android");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(setAdjustPan) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"setAdjustPan() works only on Android");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(setSoftInputMode: (NSInteger) i) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"setSoftInputMode() works only on Android");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-01-16 21:16:55 +00:00
|
|
|
RCT_EXPORT_METHOD(clearCookies) {
|
|
|
|
NSHTTPCookie *cookie;
|
|
|
|
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
|
|
|
|
for (cookie in [storage cookies]) {
|
|
|
|
[storage deleteCookie:cookie];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(clearStorageAPIs) {
|
|
|
|
[[NSURLCache sharedURLCache] removeAllCachedResponses];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-01-16 21:16:55 +00:00
|
|
|
NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
|
|
|
|
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
|
|
|
|
for (NSString *string in array) {
|
|
|
|
NSLog(@"Removing %@", [path stringByAppendingPathComponent:string]);
|
2017-10-09 09:34:29 +00:00
|
|
|
if ([[string pathExtension] isEqualToString:@"localstorage"])
|
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:[path stringByAppendingPathComponent:string] error:nil];
|
2017-01-16 21:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:15:16 +00:00
|
|
|
RCT_EXPORT_METHOD(callRPC:(NSString *)payload
|
2017-04-18 14:22:05 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2017-08-01 18:42:16 +00:00
|
|
|
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoCallRPC(payload);
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
callback(@[result]);
|
2017-08-01 18:42:16 +00:00
|
|
|
});
|
|
|
|
});
|
2017-04-18 14:22:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:15:16 +00:00
|
|
|
RCT_EXPORT_METHOD(callPrivateRPC:(NSString *)payload
|
2018-04-18 08:49:15 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
2019-02-12 11:35:26 +00:00
|
|
|
NSString *result = StatusgoCallPrivateRPC(payload);
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
callback(@[result]);
|
2018-04-18 08:49:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-05 11:23:25 +00:00
|
|
|
RCT_EXPORT_METHOD(closeApplication) {
|
|
|
|
exit(0);
|
|
|
|
}
|
2017-04-18 14:22:05 +00:00
|
|
|
|
2018-02-26 02:27:29 +00:00
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(connectionChange:(NSString *)type
|
|
|
|
isExpensive:(BOOL)isExpensive) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"ConnectionChange() method called");
|
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
StatusgoConnectionChange(type, isExpensive ? 1 : 0);
|
2018-02-26 02:27:29 +00:00
|
|
|
}
|
|
|
|
|
2018-03-16 12:01:10 +00:00
|
|
|
RCT_EXPORT_METHOD(appStateChange:(NSString *)type) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"AppStateChange() method called");
|
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
StatusgoAppStateChange(type);
|
2018-03-16 12:01:10 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 10:27:04 +00:00
|
|
|
RCT_EXPORT_METHOD(getDeviceUUID:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"getDeviceUUID() method called");
|
|
|
|
#endif
|
|
|
|
NSString* Identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-05-01 10:27:04 +00:00
|
|
|
callback(@[Identifier]);
|
|
|
|
}
|
|
|
|
|
2018-08-03 16:43:37 +00:00
|
|
|
- (bool) is24Hour
|
|
|
|
{
|
|
|
|
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
|
|
|
|
return ([format rangeOfString:@"a"].location == NSNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)constantsToExport
|
|
|
|
{
|
|
|
|
return @{
|
|
|
|
@"is24Hour": @(self.is24Hour),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:54:29 +00:00
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2016-09-07 17:35:04 +00:00
|
|
|
@end
|