8
8
import com .facebook .react .bridge .ReactApplicationContext ;
9
9
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
10
10
import com .facebook .react .bridge .ReactMethod ;
11
+ import com .facebook .react .bridge .WritableMap ;
12
+ import com .facebook .react .bridge .WritableNativeMap ;
11
13
import com .facebook .react .module .annotations .ReactModule ;
12
14
13
15
import org .jetbrains .annotations .Contract ;
@@ -30,6 +32,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
30
32
@ Override
31
33
public void initialize () {
32
34
System .loadLibrary ("wnfslib" );
35
+ System .loadLibrary ("gojni" );
33
36
}
34
37
35
38
@@ -48,15 +51,15 @@ public class Client implements land.fx.wnfslib.Datastore {
48
51
private final fulamobile .Client internalClient ;
49
52
50
53
Client (fulamobile .Client clientInput ) {
51
- internalClient = clientInput ;
54
+ this . internalClient = clientInput ;
52
55
}
53
56
54
57
@ NonNull
55
58
@ Override
56
59
public byte [] get (@ NonNull byte [] cid ) {
57
60
try {
58
61
Log .d ("ReactNative" , Arrays .toString (cid ));
59
- return internalClient .get (cid );
62
+ return this . internalClient .get (cid );
60
63
} catch (Exception e ) {
61
64
e .printStackTrace ();
62
65
}
@@ -69,7 +72,7 @@ public byte[] get(@NonNull byte[] cid) {
69
72
public byte [] put (@ NonNull byte [] data , long codec ) {
70
73
try {
71
74
//Log.d("ReactNative", "data="+ Arrays.toString(data) +" ;codec="+codec);
72
- return client .put (data , codec );
75
+ return this . internalClient .put (data , codec );
73
76
} catch (Exception e ) {
74
77
Log .d ("ReactNative" , "put Error=" +e .getMessage ());
75
78
e .printStackTrace ();
@@ -146,15 +149,19 @@ public void init(String identityString, String storePath, String bloxAddr, Strin
146
149
Log .d ("ReactNative" , "init started" );
147
150
ThreadUtils .runOnExecutor (() -> {
148
151
try {
152
+ WritableMap resultData = new WritableNativeMap ();
149
153
Log .d ("ReactNative" , "init storePath= " + storePath );
150
154
byte [] identity = toByte (identityString );
151
155
Log .d ("ReactNative" , "init identity= " + identityString );
152
156
String [] obj = initInternal (identity , storePath , bloxAddr , exchange );
153
- Log .d ("ReactNative" , "init object created: [ " + obj [0 ] + ", " + obj [1 ] + ", " + obj [2 ] + " ]" );
154
- promise .resolve (obj );
157
+ Log .d ("ReactNative" , "init object created: [ " + obj [0 ].toString () + ", " + obj [1 ].toString () + ", " + obj [2 ].toString () + " ]" );
158
+ resultData .putString ("peerId" , obj [0 ]);
159
+ resultData .putString ("rootCid" , obj [1 ]);
160
+ resultData .putString ("private_ref" , obj [2 ]);
161
+ promise .resolve (resultData );
155
162
} catch (Exception e ) {
156
- Log .d ("ReactNative" , "init failed with Error: " + e .getMessage ());
157
- promise .reject (e );
163
+ Log .d ("ReactNative" , "init failed with Error: " + e .getMessage (). toString () );
164
+ promise .reject ("Error" , e . getMessage (). toString () );
158
165
}
159
166
});
160
167
}
@@ -206,6 +213,15 @@ private String[] initInternal(byte[] identity, String storePath, String bloxAddr
206
213
if (this .rootConfig == null ) {
207
214
Log .d ("ReactNative" , "creating rootConfig" );
208
215
216
+ /*byte[] testbyte = convertStringToByte("-104,40,24,-93,24,100,24,114,24,111,24,111,24,116,24,-126,24,-126,0,0,24,-128,24,103,24,118,24,101,24,114,24,115,24,105,24,111,24,110,24,101,24,48,24,46,24,49,24,46,24,48,24,105,24,115,24,116,24,114,24,117,24,99,24,116,24,117,24,114,24,101,24,100,24,104,24,97,24,109,24,116");
217
+ long testcodec = 85;
218
+ byte[] testputcid = this.client.put(testbyte, testcodec);
219
+ Log.d("ReactNative", "client.put test done"+ Arrays.toString(testputcid));
220
+ byte[] testfetchedcid = convertStringToByte("1,113,18,32,-6,-63,-128,79,-102,-89,57,77,-8,67,-98,8,-81,40,-87,123,122,29,-52,-124,-60,-53,100,105,125,123,-5,-99,41,106,-124,-64");
221
+ byte[] testfetchedbytes = this.client.get(testfetchedcid);
222
+ Log.d("ReactNative", "client.get test done"+ Arrays.toString(testfetchedbytes));
223
+ */
224
+
209
225
this .privateForest = Fs .createPrivateForest (this .client );
210
226
Log .d ("ReactNative" , "privateForest is created: " + this .privateForest );
211
227
this .rootConfig = Fs .createRootDir (this .client , this .privateForest );
0 commit comments