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
|
2020-07-09 10:14:38 +00:00
|
|
|
RCT_EXPORT_METHOD(initKeystore:(NSString *)keyUID
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2019-07-31 16:10:38 +00:00
|
|
|
#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];
|
|
|
|
|
2020-07-09 10:14:38 +00:00
|
|
|
NSURL *commonKeystoreDir = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
|
|
|
NSURL *keystoreDir = [commonKeystoreDir URLByAppendingPathComponent:keyUID];
|
|
|
|
|
2019-07-31 16:10:38 +00:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^(void)
|
|
|
|
{
|
|
|
|
NSString *res = StatusgoInitKeystore(keystoreDir.path);
|
2020-01-08 14:41:07 +00:00
|
|
|
NSLog(@"InitKeyStore result %@", res);
|
2020-07-09 10:14:38 +00:00
|
|
|
callback(@[]);
|
2019-07-31 16:10:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-14 13:33:59 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// multiAccountImportPrivateKey
|
|
|
|
RCT_EXPORT_METHOD(deleteMultiaccount:(NSString *)keyUID
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountImportPrivateKey() method called");
|
|
|
|
#endif
|
|
|
|
NSURL *multiaccountKeystoreDir = [self getKeyStoreDir:keyUID];
|
|
|
|
NSString *result = StatusgoDeleteMultiaccount(keyUID, multiaccountKeystoreDir.path);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2020-02-28 11:37:16 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// multiAccountImportPrivateKey
|
|
|
|
RCT_EXPORT_METHOD(multiAccountImportPrivateKey:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountImportPrivateKey() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountImportPrivateKey(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2020-05-07 10:57:10 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// hashTransaction
|
|
|
|
RCT_EXPORT_METHOD(hashTransaction:(NSString *)txArgsJSON
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"HashTransaction() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoHashTransaction(txArgsJSON);
|
|
|
|
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
|
|
|
|
2020-07-09 10:14:38 +00:00
|
|
|
-(NSString *) getKeyUID:(NSString *)jsonString {
|
|
|
|
NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSDictionary *json = [NSJSONSerialization
|
|
|
|
JSONObjectWithData:data
|
|
|
|
options:NSJSONReadingMutableContainers
|
|
|
|
error:nil];
|
|
|
|
|
|
|
|
return [json valueForKey:@"key-uid"];
|
|
|
|
}
|
|
|
|
|
2019-08-01 20:11:59 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// prepareDirAndUpdateConfig
|
2020-07-09 10:14:38 +00:00
|
|
|
-(NSString *) prepareDirAndUpdateConfig:(NSString *)config
|
|
|
|
withKeyUID:(NSString *)keyUID {
|
2019-08-01 20:11:59 +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-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");
|
|
|
|
|
2020-01-31 12:43:32 +00:00
|
|
|
NSString *keystore = @"keystore";
|
|
|
|
NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:keystore];
|
|
|
|
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:keystore];
|
2019-08-01 20:11:59 +00:00
|
|
|
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];
|
2020-01-31 12:43:32 +00:00
|
|
|
NSURL *dataDirUrl = [NSURL fileURLWithPath:relativeDataDir];
|
|
|
|
NSURL *logUrl = [dataDirUrl URLByAppendingPathComponent:@"geth.log"];
|
2020-07-09 10:14:38 +00:00
|
|
|
NSString *keystoreDir = [@"/keystore/" stringByAppendingString:keyUID];
|
|
|
|
[configJSON setValue:keystoreDir forKey:@"KeyStoreDir"];
|
2020-01-31 12:43:32 +00:00
|
|
|
[configJSON setValue:@"" forKey:@"LogDir"];
|
|
|
|
[configJSON setValue:logUrl.path forKey:@"LogFile"];
|
2019-08-01 20:11:59 +00:00
|
|
|
|
|
|
|
NSString *resultingConfig = [configJSON bv_jsonStringWithPrettyPrint:NO];
|
|
|
|
NSLog(@"node config %@", resultingConfig);
|
|
|
|
|
2020-01-31 12:43:32 +00:00
|
|
|
if(![fileManager fileExistsAtPath:absDataDir]) {
|
|
|
|
[fileManager createDirectoryAtPath:absDataDir
|
|
|
|
withIntermediateDirectories:YES attributes:nil error:nil];
|
2019-08-01 20:11:59 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 12:43:32 +00:00
|
|
|
NSLog(@"logUrlPath %@ rootDir %@", logUrl.path, rootUrl.path);
|
|
|
|
NSURL *absLogUrl = [absDataDirUrl URLByAppendingPathComponent:@"geth.log"];
|
2019-08-01 20:11:59 +00:00
|
|
|
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
|
2020-07-09 10:14:38 +00:00
|
|
|
RCT_EXPORT_METHOD(prepareDirAndUpdateConfig:(NSString *)keyUID
|
|
|
|
config:(NSString *)config
|
2019-08-01 20:11:59 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"PrepareDirAndUpdateConfig() method called");
|
|
|
|
#endif
|
2020-07-09 10:14:38 +00:00
|
|
|
NSString *updatedConfig = [self prepareDirAndUpdateConfig:config
|
|
|
|
withKeyUID:keyUID];
|
2019-08-01 20:11:59 +00:00
|
|
|
callback(@[updatedConfig]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// saveAccountAndLogin
|
2019-12-18 12:35:57 +00:00
|
|
|
RCT_EXPORT_METHOD(saveAccountAndLogin:(NSString *)multiaccountData
|
2019-08-01 20:11:59 +00:00
|
|
|
password:(NSString *)password
|
2019-12-10 11:31:22 +00:00
|
|
|
settings:(NSString *)settings
|
2019-08-01 20:11:59 +00:00
|
|
|
config:(NSString *)config
|
2019-12-18 12:35:57 +00:00
|
|
|
accountsData:(NSString *)accountsData) {
|
2019-08-01 20:11:59 +00:00
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SaveAccountAndLogin() method called");
|
|
|
|
#endif
|
2020-07-09 10:14:38 +00:00
|
|
|
NSString *keyUID = [self getKeyUID:multiaccountData];
|
|
|
|
NSString *finalConfig = [self prepareDirAndUpdateConfig:config
|
|
|
|
withKeyUID:keyUID];
|
2019-12-10 11:31:22 +00:00
|
|
|
NSString *result = StatusgoSaveAccountAndLogin(multiaccountData, password, settings, finalConfig, accountsData);
|
2019-08-01 20:11:59 +00:00
|
|
|
NSLog(@"%@", result);
|
|
|
|
}
|
|
|
|
|
2019-08-15 14:44:25 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// saveAccountAndLoginWithKeycard
|
2019-12-18 12:35:57 +00:00
|
|
|
RCT_EXPORT_METHOD(saveAccountAndLoginWithKeycard:(NSString *)multiaccountData
|
2019-08-15 14:44:25 +00:00
|
|
|
password:(NSString *)password
|
2019-12-10 11:31:22 +00:00
|
|
|
settings:(NSString *)settings
|
2019-08-15 14:44:25 +00:00
|
|
|
config:(NSString *)config
|
2019-12-18 12:35:57 +00:00
|
|
|
accountsData:(NSString *)accountsData
|
2019-08-15 14:44:25 +00:00
|
|
|
chatKey:(NSString *)chatKey) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SaveAccountAndLoginWithKeycard() method called");
|
|
|
|
#endif
|
2020-07-09 10:14:38 +00:00
|
|
|
NSString *keyUID = [self getKeyUID:multiaccountData];
|
|
|
|
NSString *finalConfig = [self prepareDirAndUpdateConfig:config
|
|
|
|
withKeyUID:keyUID];
|
2019-12-10 11:31:22 +00:00
|
|
|
NSString *result = StatusgoSaveAccountAndLoginWithKeycard(multiaccountData, password, settings, finalConfig, accountsData, chatKey);
|
2019-08-15 14:44:25 +00:00
|
|
|
NSLog(@"%@", result);
|
|
|
|
}
|
2019-08-01 20:11:59 +00:00
|
|
|
|
2020-07-14 13:33:59 +00:00
|
|
|
- (NSURL *) getKeyStoreDir:(NSString *)keyUID {
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSURL *rootUrl =[[fileManager
|
|
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
|
|
|
lastObject];
|
|
|
|
|
|
|
|
NSURL *oldKeystoreDir = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
|
|
|
NSURL *multiaccountKeystoreDir = [oldKeystoreDir URLByAppendingPathComponent:keyUID];
|
|
|
|
|
|
|
|
return multiaccountKeystoreDir;
|
|
|
|
}
|
|
|
|
|
2020-07-09 10:14:38 +00:00
|
|
|
- (void) migrateKeystore:(NSString *)accountData
|
|
|
|
password:(NSString *)password {
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSURL *rootUrl =[[fileManager
|
|
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
|
|
|
lastObject];
|
|
|
|
|
|
|
|
NSString *keyUID = [self getKeyUID:accountData];
|
|
|
|
NSURL *oldKeystoreDir = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
2020-07-14 13:33:59 +00:00
|
|
|
NSURL *multiaccountKeystoreDir = [self getKeyStoreDir:keyUID];
|
2020-07-09 10:14:38 +00:00
|
|
|
|
|
|
|
NSArray *keys = [fileManager contentsOfDirectoryAtPath:multiaccountKeystoreDir.path error:nil];
|
|
|
|
if (keys.count == 0) {
|
|
|
|
NSString *migrationResult = StatusgoMigrateKeyStoreDir(accountData, password, oldKeystoreDir.path, multiaccountKeystoreDir.path);
|
|
|
|
NSLog(@"keystore migration result %@", migrationResult);
|
|
|
|
|
|
|
|
NSString *initKeystoreResult = StatusgoInitKeystore(multiaccountKeystoreDir.path);
|
|
|
|
NSLog(@"InitKeyStore result %@", initKeystoreResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2020-07-09 10:14:38 +00:00
|
|
|
[self migrateKeystore:accountData password:password];
|
2019-08-01 20:11:59 +00:00
|
|
|
NSString *result = StatusgoLogin(accountData, password);
|
2019-09-18 09:38:43 +00:00
|
|
|
NSLog(@"%@", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// loginWithKeycard
|
|
|
|
RCT_EXPORT_METHOD(loginWithKeycard:(NSString *)accountData
|
|
|
|
password:(NSString *)password
|
|
|
|
chatKey:(NSString *)chatKey) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"LoginWithKeycard() method called");
|
|
|
|
#endif
|
2020-07-09 10:14:38 +00:00
|
|
|
[self migrateKeystore:accountData password:password];
|
|
|
|
|
2019-09-18 09:38:43 +00:00
|
|
|
NSString *result = StatusgoLoginWithKeycard(accountData, password, chatKey);
|
|
|
|
|
2019-08-01 20:11:59 +00:00
|
|
|
NSLog(@"%@", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// logout
|
|
|
|
RCT_EXPORT_METHOD(logout) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"Logout() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoLogout();
|
2020-01-08 14:41:07 +00:00
|
|
|
|
2019-08-01 20:11:59 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-09-12 09:41:25 +00:00
|
|
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(generateAlias:(NSString *)publicKey) {
|
|
|
|
return StatusgoGenerateAlias(publicKey);
|
|
|
|
}
|
|
|
|
|
2019-11-28 10:00:29 +00:00
|
|
|
RCT_EXPORT_METHOD(generateAliasAsync:(NSString *)publicKey
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"generateAliasAsync() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoGenerateAlias(publicKey);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-09-12 09:41:25 +00:00
|
|
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(identicon:(NSString *)publicKey) {
|
|
|
|
return StatusgoIdenticon(publicKey);
|
|
|
|
}
|
|
|
|
|
2019-12-31 10:50:45 +00:00
|
|
|
RCT_EXPORT_METHOD(validateMnemonic:(NSString *)seed
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"validateMnemonic() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoValidateMnemonic(seed);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-11-28 10:00:29 +00:00
|
|
|
RCT_EXPORT_METHOD(identiconAsync:(NSString *)publicKey
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"identiconAsync() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoIdenticon(publicKey);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(generateAliasAndIdenticonAsync:(NSString *)publicKey
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"generateAliasAndIdenticonAsync() method called");
|
|
|
|
#endif
|
|
|
|
NSString *identiconResult = StatusgoIdenticon(publicKey);
|
|
|
|
NSString *aliasResult = StatusgoGenerateAlias(publicKey);
|
|
|
|
callback(@[aliasResult, identiconResult]);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-28 11:10:42 +00:00
|
|
|
RCT_EXPORT_METHOD(stopWallet) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"StopWallet() method called");
|
|
|
|
#endif
|
|
|
|
StatusgoStopWallet();
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(startWallet) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"StartWallet() method called");
|
|
|
|
#endif
|
|
|
|
StatusgoStartWallet();
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2020-07-28 11:06:58 +00:00
|
|
|
RCT_EXPORT_METHOD(activateKeepAwake)
|
|
|
|
{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(deactivateKeepAwake)
|
|
|
|
{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|