88import com .facebook .react .bridge .ReactApplicationContext ;
99import com .facebook .react .bridge .ReactContextBaseJavaModule ;
1010import com .facebook .react .bridge .ReactMethod ;
11+ import com .facebook .react .bridge .WritableMap ;
12+ import com .facebook .react .bridge .WritableNativeMap ;
1113import com .facebook .react .module .annotations .ReactModule ;
1214
1315import org .jetbrains .annotations .Contract ;
2527
2628@ ReactModule (name = FulaModule .NAME )
2729public class FulaModule extends ReactContextBaseJavaModule {
30+
31+
32+ @ Override
33+ public void initialize () {
34+ System .loadLibrary ("wnfslib" );
35+ System .loadLibrary ("gojni" );
36+ }
37+
38+
2839 public static final String NAME = "FulaModule" ;
2940 fulamobile .Client fula ;
3041 Client client ;
@@ -40,28 +51,33 @@ public class Client implements land.fx.wnfslib.Datastore {
4051 private final fulamobile .Client internalClient ;
4152
4253 Client (fulamobile .Client clientInput ) {
43- internalClient = clientInput ;
54+ this . internalClient = clientInput ;
4455 }
4556
4657 @ NonNull
4758 @ Override
4859 public byte [] get (@ NonNull byte [] cid ) {
4960 try {
50- internalClient .get (cid );
61+ Log .d ("ReactNative" , Arrays .toString (cid ));
62+ return this .internalClient .get (cid );
5163 } catch (Exception e ) {
5264 e .printStackTrace ();
5365 }
66+ Log .d ("ReactNative" ,"Error get" );
5467 return cid ;
5568 }
5669
5770 @ NonNull
5871 @ Override
5972 public byte [] put (@ NonNull byte [] data , long codec ) {
6073 try {
61- return client .put (data , codec );
74+ //Log.d("ReactNative", "data="+ Arrays.toString(data) +" ;codec="+codec);
75+ return this .internalClient .put (data , codec );
6276 } catch (Exception e ) {
77+ Log .d ("ReactNative" , "put Error=" +e .getMessage ());
6378 e .printStackTrace ();
6479 }
80+ Log .d ("ReactNative" ,"Error put" );
6581 return data ;
6682 }
6783 }
@@ -133,15 +149,19 @@ public void init(String identityString, String storePath, String bloxAddr, Strin
133149 Log .d ("ReactNative" , "init started" );
134150 ThreadUtils .runOnExecutor (() -> {
135151 try {
152+ WritableMap resultData = new WritableNativeMap ();
136153 Log .d ("ReactNative" , "init storePath= " + storePath );
137154 byte [] identity = toByte (identityString );
138155 Log .d ("ReactNative" , "init identity= " + identityString );
139156 String [] obj = initInternal (identity , storePath , bloxAddr , exchange );
140- Log .d ("ReactNative" , "init object created: [ " + obj [0 ] + ", " + obj [1 ] + ", " + obj [2 ] + " ]" );
141- 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 );
142162 } catch (Exception e ) {
143- Log .d ("ReactNative" , "init failed with Error: " + e .getMessage ());
144- promise .reject (e );
163+ Log .d ("ReactNative" , "init failed with Error: " + e .getMessage (). toString () );
164+ promise .reject ("Error" , e . getMessage (). toString () );
145165 }
146166 });
147167 }
@@ -193,6 +213,15 @@ private String[] initInternal(byte[] identity, String storePath, String bloxAddr
193213 if (this .rootConfig == null ) {
194214 Log .d ("ReactNative" , "creating rootConfig" );
195215
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+
196225 this .privateForest = Fs .createPrivateForest (this .client );
197226 Log .d ("ReactNative" , "privateForest is created: " + this .privateForest );
198227 this .rootConfig = Fs .createRootDir (this .client , this .privateForest );
0 commit comments