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();
|
|
|
|
|
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]]);
|
|
|
|
}
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
|
2019-07-31 16:10:38 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - InitKeystore method
|
|
|
|
//////////////////////////////////////////////////////////////////// StopNode
|
|
|
|
RCT_EXPORT_METHOD(initKeystore) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"initKeystore() method called");
|
|
|
|
#endif
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSURL *rootUrl =[[fileManager
|
2019-08-26 07:39:13 +00:00
|
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
2019-07-31 16:10:38 +00:00
|
|
|
lastObject];
|
|
|
|
|
|
|
|
NSURL *keystoreDir = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^(void)
|
|
|
|
{
|
|
|
|
NSString *res = StatusgoInitKeystore(keystoreDir.path);
|
|
|
|
NSLog(@"StopNode result %@", res);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
2019-08-26 07:39:13 +00:00
|
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
2019-05-03 14:22:43 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-07-19 14:11:10 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// multiAccountGenerateAndDeriveAddresses
|
|
|
|
RCT_EXPORT_METHOD(multiAccountGenerateAndDeriveAddresses:(NSString *)json
|
2019-05-13 07:58:41 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2019-07-19 14:11:10 +00:00
|
|
|
NSLog(@"MultiAccountGenerateAndDeriveAddresses() method called");
|
2019-05-13 07:58:41 +00:00
|
|
|
#endif
|
2019-07-19 14:11:10 +00:00
|
|
|
NSString *result = StatusgoMultiAccountGenerateAndDeriveAddresses(json);
|
2019-05-13 07:58:41 +00:00
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-08-12 08:53:31 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// MultiAccountStoreAccount
|
|
|
|
RCT_EXPORT_METHOD(multiAccountStoreAccount:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountStoreAccount() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountStoreAccount(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// MultiAccountLoadAccount
|
|
|
|
RCT_EXPORT_METHOD(multiAccountLoadAccount:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountLoadAccount() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountLoadAccount(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// MultiAccountReset
|
|
|
|
RCT_EXPORT_METHOD(multiAccountReset:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountReset() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountReset();
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-07-19 14:11:10 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// multiAccountStoreDerived
|
|
|
|
RCT_EXPORT_METHOD(multiAccountStoreDerived:(NSString *)json
|
2019-05-13 07:58:41 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2019-07-19 14:11:10 +00:00
|
|
|
NSLog(@"MultiAccountStoreDerived() method called");
|
2019-05-13 07:58:41 +00:00
|
|
|
#endif
|
2019-07-19 14:11:10 +00:00
|
|
|
NSString *result = StatusgoMultiAccountStoreDerivedAccounts(json);
|
2019-05-13 07:58:41 +00:00
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-08-01 15:49:33 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// multiAccountImportMnemonic
|
|
|
|
RCT_EXPORT_METHOD(multiAccountImportMnemonic:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountImportMnemonic() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountImportMnemonic(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// multiAccountDeriveAddresses
|
2019-08-12 08:53:31 +00:00
|
|
|
RCT_EXPORT_METHOD(multiAccountDeriveAddresses:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountDeriveAddresses() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountDeriveAddresses(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
2019-05-13 07:58:41 +00:00
|
|
|
|
2019-08-01 20:11:59 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// prepareDirAndUpdateConfig
|
|
|
|
-(NSString *) prepareDirAndUpdateConfig:(NSString *)config {
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *rootUrl =[[fileManager
|
2019-08-26 07:39:13 +00:00
|
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
2019-08-01 20:11:59 +00:00
|
|
|
lastObject];
|
|
|
|
NSURL *absTestnetFolderName = [rootUrl URLByAppendingPathComponent:@"ethereum/testnet"];
|
|
|
|
|
|
|
|
if (![fileManager fileExistsAtPath:absTestnetFolderName.path])
|
|
|
|
[fileManager createDirectoryAtPath:absTestnetFolderName.path withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
|
|
|
|
|
NSURL *flagFolderUrl = [rootUrl URLByAppendingPathComponent:@"ropsten_flag"];
|
|
|
|
|
|
|
|
if(![fileManager fileExistsAtPath:flagFolderUrl.path]){
|
|
|
|
NSLog(@"remove lightchaindata");
|
|
|
|
NSURL *absLightChainDataUrl = [absTestnetFolderName URLByAppendingPathComponent:@"StatusIM/lightchaindata"];
|
|
|
|
if([fileManager fileExistsAtPath:absLightChainDataUrl.path]) {
|
|
|
|
[fileManager removeItemAtPath:absLightChainDataUrl.path
|
|
|
|
error:nil];
|
|
|
|
}
|
|
|
|
[fileManager createDirectoryAtPath:flagFolderUrl.path
|
|
|
|
withIntermediateDirectories:NO
|
|
|
|
attributes:nil
|
|
|
|
error:&error];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSLog(@"after remove lightchaindata");
|
|
|
|
|
|
|
|
NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:@"keystore"];
|
|
|
|
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
|
|
|
if([fileManager fileExistsAtPath:absTestnetKeystoreUrl.path]){
|
|
|
|
NSLog(@"copy keystore");
|
|
|
|
[fileManager copyItemAtPath:absTestnetKeystoreUrl.path toPath:absKeystoreUrl.path error:nil];
|
|
|
|
[fileManager removeItemAtPath:absTestnetKeystoreUrl.path error:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSLog(@"after lightChainData");
|
|
|
|
|
|
|
|
NSLog(@"preconfig: %@", config);
|
|
|
|
NSData *configData = [config dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSDictionary *configJSON = [NSJSONSerialization JSONObjectWithData:configData options:NSJSONReadingMutableContainers error:nil];
|
|
|
|
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];
|
|
|
|
NSLog(@"node config %@", resultingConfig);
|
|
|
|
|
|
|
|
if(![fileManager fileExistsAtPath:absDataDirUrl.path]) {
|
|
|
|
[fileManager createDirectoryAtPath:absDataDirUrl.path withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSLog(@"logUrlPath %@", absLogUrl.path);
|
|
|
|
if(![fileManager fileExistsAtPath:absLogUrl.path]) {
|
|
|
|
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
|
|
[dict setObject:[NSNumber numberWithInt:511] forKey:NSFilePosixPermissions];
|
|
|
|
[fileManager createFileAtPath:absLogUrl.path contents:nil attributes:dict];
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultingConfig;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// prepareDirAndUpdateConfig
|
|
|
|
RCT_EXPORT_METHOD(prepareDirAndUpdateConfig:(NSString *)config
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"PrepareDirAndUpdateConfig() method called");
|
|
|
|
#endif
|
|
|
|
NSString *updatedConfig = [self prepareDirAndUpdateConfig:config];
|
|
|
|
callback(@[updatedConfig]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// saveAccountAndLogin
|
|
|
|
RCT_EXPORT_METHOD(saveAccountAndLogin:(NSString *)accountData
|
|
|
|
password:(NSString *)password
|
|
|
|
config:(NSString *)config
|
|
|
|
subAccountsData:(NSString *)subAccountsData) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SaveAccountAndLogin() method called");
|
|
|
|
#endif
|
|
|
|
NSString *finalConfig = [self prepareDirAndUpdateConfig:config];
|
|
|
|
NSString *result = StatusgoSaveAccountAndLogin(accountData, password, finalConfig, subAccountsData);
|
|
|
|
NSLog(@"%@", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// login
|
2019-08-01 20:11:59 +00:00
|
|
|
RCT_EXPORT_METHOD(login:(NSString *)accountData
|
|
|
|
password:(NSString *)password) {
|
2016-09-12 08:16:07 +00:00
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"Login() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2019-08-01 20:11:59 +00:00
|
|
|
NSString *result = StatusgoLogin(accountData, password);
|
|
|
|
|
|
|
|
NSLog(@"%@", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// logout
|
|
|
|
RCT_EXPORT_METHOD(logout) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"Logout() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoLogout();
|
|
|
|
|
|
|
|
NSLog(@"%@", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// openAccounts
|
|
|
|
RCT_EXPORT_METHOD(openAccounts:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"OpenAccounts() method called");
|
|
|
|
#endif
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSURL *rootUrl =[[fileManager
|
2019-08-26 07:39:13 +00:00
|
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
2019-08-01 20:11:59 +00:00
|
|
|
lastObject];
|
|
|
|
|
|
|
|
NSString *result = StatusgoOpenAccounts(rootUrl.path);
|
2019-02-12 11:35:26 +00:00
|
|
|
callback(@[result]);
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-01 20:11:59 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// verityAccountPassword
|
2018-11-26 15:52:29 +00:00
|
|
|
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
|
2019-08-26 07:39:13 +00:00
|
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
2018-11-26 15:52:29 +00:00
|
|
|
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
|
2019-07-19 14:11:10 +00:00
|
|
|
account:(NSString *)account
|
2019-03-05 14:44:50 +00:00
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SignTypedData() method called");
|
|
|
|
#endif
|
2019-07-19 14:11:10 +00:00
|
|
|
NSString *result = StatusgoSignTypedData(data, account, password);
|
2019-03-05 14:44:50 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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];
|
2019-05-13 07:58:41 +00:00
|
|
|
|
2017-01-16 21:16:55 +00:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2019-05-08 12:26:39 +00:00
|
|
|
RCT_EXPORT_METHOD(setBlankPreviewFlag:(BOOL *)newValue)
|
|
|
|
{
|
|
|
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
[userDefaults setBool:newValue forKey:@"BLANK_PREVIEW"];
|
|
|
|
|
|
|
|
[userDefaults synchronize];
|
|
|
|
}
|
|
|
|
|
2019-05-30 14:01:20 +00:00
|
|
|
//// deviceinfo
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-05-30 14:01:20 +00:00
|
|
|
- (NSString *)getBuildId {
|
|
|
|
return @"not available";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) deviceId
|
|
|
|
{
|
|
|
|
struct utsname systemInfo;
|
|
|
|
|
|
|
|
uname(&systemInfo);
|
|
|
|
|
|
|
|
NSString* deviceId = [NSString stringWithCString:systemInfo.machine
|
|
|
|
encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
if ([deviceId isEqualToString:@"i386"] || [deviceId isEqualToString:@"x86_64"] ) {
|
|
|
|
deviceId = [NSString stringWithFormat:@"%s", getenv("SIMULATOR_MODEL_IDENTIFIER")];
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) deviceName
|
|
|
|
{
|
|
|
|
|
|
|
|
NSString* deviceName = nil;
|
|
|
|
|
|
|
|
if ([self.deviceId rangeOfString:@"iPod"].location != NSNotFound) {
|
|
|
|
deviceName = @"iPod Touch";
|
|
|
|
}
|
|
|
|
else if([self.deviceId rangeOfString:@"iPad"].location != NSNotFound) {
|
|
|
|
deviceName = @"iPad";
|
|
|
|
}
|
|
|
|
else if([self.deviceId rangeOfString:@"iPhone"].location != NSNotFound){
|
|
|
|
deviceName = @"iPhone";
|
|
|
|
}
|
|
|
|
else if([self.deviceId rangeOfString:@"AppleTV"].location != NSNotFound){
|
|
|
|
deviceName = @"Apple TV";
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceName;
|
|
|
|
}
|
|
|
|
|
2018-08-03 16:43:37 +00:00
|
|
|
- (NSDictionary *)constantsToExport
|
|
|
|
{
|
|
|
|
return @{
|
|
|
|
@"is24Hour": @(self.is24Hour),
|
2019-05-30 14:01:20 +00:00
|
|
|
@"model": self.deviceName ?: [NSNull null],
|
|
|
|
@"brand": @"Apple",
|
|
|
|
@"buildId": [self getBuildId],
|
|
|
|
@"deviceId": self.deviceId ?: [NSNull null],
|
2018-08-03 16:43:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:54:29 +00:00
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2016-09-07 17:35:04 +00:00
|
|
|
@end
|