2016-09-07 17:35:04 +00:00
|
|
|
#import "RCTStatus.h"
|
2016-10-11 14:24:52 +00:00
|
|
|
#import "RCTBridge.h"
|
|
|
|
#import "RCTEventDispatcher.h"
|
2016-09-07 17:35:04 +00:00
|
|
|
#import <Statusgo/Statusgo.h>
|
|
|
|
|
2016-09-16 15:30:19 +00:00
|
|
|
static bool isStatusInitialized;
|
2016-10-11 14:24:52 +00:00
|
|
|
static RCTBridge *bridge;
|
2016-09-12 08:16:07 +00:00
|
|
|
@implementation Status{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - Jails functions
|
|
|
|
//////////////////////////////////////////////////////////////////// initJail
|
2016-09-07 17:35:04 +00:00
|
|
|
RCT_EXPORT_METHOD(initJail: (NSString *) js
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2016-09-12 08:16:07 +00:00
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"InitJail() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2016-09-23 14:14:43 +00:00
|
|
|
InitJail((char *) [js UTF8String]);
|
2016-09-07 17:35:04 +00:00
|
|
|
callback(@[[NSNull null]]);
|
|
|
|
}
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// parseJail
|
2016-09-07 17:35:04 +00:00
|
|
|
RCT_EXPORT_METHOD(parseJail:(NSString *)chatId
|
|
|
|
js:(NSString *)js
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"ParseJail() method called");
|
2016-09-07 17:35:04 +00:00
|
|
|
#endif
|
2016-09-23 14:14:43 +00:00
|
|
|
char * result = Parse((char *) [chatId UTF8String], (char *) [js UTF8String]);
|
2016-09-12 08:16:07 +00:00
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
2016-09-07 17:35:04 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// callJail
|
2016-09-07 17:35:04 +00:00
|
|
|
RCT_EXPORT_METHOD(callJail:(NSString *)chatId
|
|
|
|
path:(NSString *)path
|
|
|
|
params:(NSString *)params
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"CallJail() method called");
|
2016-09-07 17:35:04 +00:00
|
|
|
#endif
|
2016-10-11 14:24:52 +00:00
|
|
|
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
char * result = Call((char *) [chatId UTF8String], (char *) [path UTF8String], (char *) [params UTF8String]);
|
|
|
|
dispatch_async( dispatch_get_main_queue(), ^{
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
});
|
|
|
|
});
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - startNode
|
|
|
|
//////////////////////////////////////////////////////////////////// startNode
|
2016-09-16 15:30:19 +00:00
|
|
|
RCT_EXPORT_METHOD(startNode:(RCTResponseSenderBlock)onResultCallback) {
|
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
|
|
|
|
if (!isStatusInitialized){
|
|
|
|
isStatusInitialized = true;
|
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *folderName =[[[[NSFileManager defaultManager]
|
|
|
|
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
|
|
|
|
lastObject]
|
|
|
|
URLByAppendingPathComponent:@"ethereum"];
|
|
|
|
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath:folderName.path])
|
|
|
|
[[NSFileManager defaultManager] createDirectoryAtPath:folderName.path withIntermediateDirectories:NO attributes:nil error:&error];
|
|
|
|
|
|
|
|
if (error){
|
|
|
|
NSLog(@"error %@", error);
|
|
|
|
}else
|
|
|
|
NSLog(@"folderName: %@", folderName);
|
2016-10-11 14:24:52 +00:00
|
|
|
|
2016-11-28 08:54:42 +00:00
|
|
|
NSString *peer1 = @"enode://5f23bf4913dd005ce945648cb12d3ef970069818d8563a3fe054e5e1dc3898b9cb83e0af1f51b2dce75eaffc76e93f996caf538e21c5b64db5fa324958d59630@95.85.40.211:30303";
|
|
|
|
NSString *peer2 = @"enode://b9de2532421f15ac55da9d9a7cddc0dc08b0d646d631fd7ab2a170bd2163fb86b095dd8bde66b857592812f7cd9539f2919b6c64bc1a784a1d1c6ec8137681ed@188.166.229.119:30303";
|
2016-09-12 08:16:07 +00:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^(void) {
|
|
|
|
StartNode((char *) [folderName.path UTF8String]);
|
|
|
|
});
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)),
|
|
|
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^(void) {
|
2016-10-11 14:24:52 +00:00
|
|
|
AddPeer((char *) [peer1 UTF8String]);
|
|
|
|
AddPeer((char *) [peer2 UTF8String]);
|
2016-09-12 08:16:07 +00:00
|
|
|
});
|
|
|
|
onResultCallback(@[[NSNull null]]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(stopNode:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"stopNode() method called");
|
|
|
|
#endif
|
|
|
|
// TODO: stop node
|
|
|
|
|
|
|
|
callback(@[[NSNull null]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#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
|
|
|
|
char * result = CreateAccount((char *) [password UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// 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
|
|
|
|
char * result = RecoverAccount((char *) [password UTF8String], (char *) [passphrase UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// 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
|
|
|
|
char * result = Login((char *) [address UTF8String], (char *) [password UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2016-11-01 16:08:16 +00:00
|
|
|
#pragma mark - Complete Transaction
|
2016-09-12 08:16:07 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// completeTransaction
|
|
|
|
RCT_EXPORT_METHOD(completeTransaction:(NSString *)hash
|
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"CompleteTransaction() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
|
|
|
char * result = CompleteTransaction((char *) [hash UTF8String], (char *) [password UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
2016-09-07 17:35:04 +00:00
|
|
|
}
|
|
|
|
|
2016-11-01 16:08:16 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - Discard Transaction
|
|
|
|
//////////////////////////////////////////////////////////////////// completeTransaction
|
|
|
|
RCT_EXPORT_METHOD(discardTransaction:(NSString *)id) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"DiscardTransaction() method called");
|
|
|
|
#endif
|
|
|
|
DiscardTransaction((char *) [id UTF8String]);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
+ (void)signalEvent:(char *) signal
|
|
|
|
{
|
2016-11-09 10:40:17 +00:00
|
|
|
if(!signal){
|
|
|
|
return;
|
|
|
|
}
|
2016-10-11 14:24:52 +00:00
|
|
|
NSString *sig = [NSString stringWithUTF8String:signal];
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SignalEvent");
|
|
|
|
NSLog(sig);
|
|
|
|
#endif
|
|
|
|
[bridge.eventDispatcher sendAppEventWithName:@"gethEvent"
|
|
|
|
body:@{@"jsonEvent": sig}];
|
|
|
|
}
|
|
|
|
|
2016-09-07 17:35:04 +00:00
|
|
|
@end
|