diff --git a/android/build.gradle b/android/build.gradle
index 2e4681d..233fbf7 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:7.0.4'
+ classpath 'com.android.tools.build:gradle:7.3.0'
}
}
}
diff --git a/android/src/main/java/land/fx/fula/FulaModule.java b/android/src/main/java/land/fx/fula/FulaModule.java
index 36a8e81..0330422 100644
--- a/android/src/main/java/land/fx/fula/FulaModule.java
+++ b/android/src/main/java/land/fx/fula/FulaModule.java
@@ -8,6 +8,8 @@
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
+import com.facebook.react.bridge.WritableMap;
+import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.module.annotations.ReactModule;
import org.jetbrains.annotations.Contract;
@@ -25,6 +27,15 @@
@ReactModule(name = FulaModule.NAME)
public class FulaModule extends ReactContextBaseJavaModule {
+
+
+ @Override
+ public void initialize() {
+ System.loadLibrary("wnfslib");
+ System.loadLibrary("gojni");
+ }
+
+
public static final String NAME = "FulaModule";
fulamobile.Client fula;
Client client;
@@ -40,17 +51,19 @@ public class Client implements land.fx.wnfslib.Datastore {
private final fulamobile.Client internalClient;
Client(fulamobile.Client clientInput) {
- internalClient = clientInput;
+ this.internalClient = clientInput;
}
@NonNull
@Override
public byte[] get(@NonNull byte[] cid) {
try {
- internalClient.get(cid);
+ Log.d("ReactNative", Arrays.toString(cid));
+ return this.internalClient.get(cid);
} catch (Exception e) {
e.printStackTrace();
}
+ Log.d("ReactNative","Error get");
return cid;
}
@@ -58,10 +71,13 @@ public byte[] get(@NonNull byte[] cid) {
@Override
public byte[] put(@NonNull byte[] data, long codec) {
try {
- return client.put(data, codec);
+ //Log.d("ReactNative", "data="+ Arrays.toString(data) +" ;codec="+codec);
+ return this.internalClient.put(data, codec);
} catch (Exception e) {
+ Log.d("ReactNative", "put Error="+e.getMessage());
e.printStackTrace();
}
+ Log.d("ReactNative","Error put");
return data;
}
}
@@ -133,15 +149,19 @@ public void init(String identityString, String storePath, String bloxAddr, Strin
Log.d("ReactNative", "init started");
ThreadUtils.runOnExecutor(() -> {
try {
+ WritableMap resultData = new WritableNativeMap();
Log.d("ReactNative", "init storePath= " + storePath);
byte[] identity = toByte(identityString);
Log.d("ReactNative", "init identity= " + identityString);
String[] obj = initInternal(identity, storePath, bloxAddr, exchange);
- Log.d("ReactNative", "init object created: [ " + obj[0] + ", " + obj[1] + ", " + obj[2] + " ]");
- promise.resolve(obj);
+ Log.d("ReactNative", "init object created: [ " + obj[0].toString() + ", " + obj[1].toString() + ", " + obj[2].toString() + " ]");
+ resultData.putString("peerId", obj[0]);
+ resultData.putString("rootCid", obj[1]);
+ resultData.putString("private_ref", obj[2]);
+ promise.resolve(resultData);
} catch (Exception e) {
- Log.d("ReactNative", "init failed with Error: " + e.getMessage());
- promise.reject(e);
+ Log.d("ReactNative", "init failed with Error: " + e.getMessage().toString());
+ promise.reject("Error", e.getMessage().toString());
}
});
}
@@ -193,6 +213,15 @@ private String[] initInternal(byte[] identity, String storePath, String bloxAddr
if (this.rootConfig == null) {
Log.d("ReactNative", "creating rootConfig");
+ /*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");
+ long testcodec = 85;
+ byte[] testputcid = this.client.put(testbyte, testcodec);
+ Log.d("ReactNative", "client.put test done"+ Arrays.toString(testputcid));
+ 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");
+ byte[] testfetchedbytes = this.client.get(testfetchedcid);
+ Log.d("ReactNative", "client.get test done"+ Arrays.toString(testfetchedbytes));
+*/
+
this.privateForest = Fs.createPrivateForest(this.client);
Log.d("ReactNative", "privateForest is created: " + this.privateForest);
this.rootConfig = Fs.createRootDir(this.client, this.privateForest);
diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml
index fa26aa5..eaaca68 100644
--- a/example/android/app/src/debug/AndroidManifest.xml
+++ b/example/android/app/src/debug/AndroidManifest.xml
@@ -4,5 +4,5 @@
-
+
diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml
index 9d496da..af9bd55 100644
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -13,7 +13,6 @@
android:theme="@style/AppTheme">
getPackages() {
- @SuppressWarnings("UnnecessaryLocalVariable")
List packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for FulaExample:
// packages.add(new MyReactNativePackage());
diff --git a/example/android/app/src/main/res/values/strings.xml b/example/android/app/src/main/res/values/strings.xml
index 9448024..6816788 100644
--- a/example/android/app/src/main/res/values/strings.xml
+++ b/example/android/app/src/main/res/values/strings.xml
@@ -1,3 +1,3 @@
- Fula Example
+ FulaExample
diff --git a/example/src/App.tsx b/example/src/App.tsx
index aef9f3f..141a737 100644
--- a/example/src/App.tsx
+++ b/example/src/App.tsx
@@ -8,7 +8,7 @@ const App = () => {
const [value, setValue] = React.useState('');
const [inprogress, setInprogress] = React.useState(false);
- const [initComplete, setInitComplete] = React.useState<[string] | []>([]);
+ const [initComplete, setInitComplete] = React.useState<{peerId: string, rootCid: string, private_ref:string} | {}>({});
React.useEffect(() => {
const initFula = async () => {
@@ -20,14 +20,13 @@ const App = () => {
227, 170, 32, 54, 203, 243, 211, 78, 120, 114, 199, 1, 197, 134, 6,
91, 87, 152,
];
- let f = await fula.init(
+ return fula.init(
privateKey.toString(),
'',
- '/ip4/59.23.13.76/tcp/46640/p2p/QmRS9H18XHFrbmGKxi2TEBFz5ZzurkU9cbAwMsRzXcjr5X',
- 'noop'
+ '',
+ 'noop',
+ Promise
);
- console.log('initialization result', f);
- return f;
} catch (e) {
console.log(e);
return Promise.reject(e);
@@ -35,9 +34,9 @@ const App = () => {
};
initFula()
- .then((res) => {
+ .then((res) => {
+ console.log("OK",res);
setInitComplete(res);
- console.log('OK', res);
})
.catch((e) => {
console.log('error', e);
@@ -53,23 +52,10 @@ const App = () => {
title={inprogress ? 'Putting & Getting...' : 'Test'}
onPress={async () => {
try {
- /*const jsonvalue = { hello: 'world' };
- const cid =
- 'bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea';*/
- const ciduint8 = [
- 1, 112, 18, 32, 195, 196, 115, 62, 200, 175, 253, 6, 207, 158,
- 159, 245, 15, 252, 107, 205, 46, 200, 90, 97, 112, 0, 75, 183,
- 9, 102, 156, 49, 222, 148, 57, 26,
- ];
if (initComplete) {
console.log('initialization is completed. putting key/value');
- const res = await fula.put(ciduint8.toString(), '');
- console.log(res);
- console.log('Now fetching key...');
- const res2 = await fula.get(ciduint8.toString());
- console.log(JSON.parse(res2));
- //setBS64(_bs64)
+
} else {
console.log('wait for init to complete');
}
diff --git a/src/interfaces/fulaNativeModule.ts b/src/interfaces/fulaNativeModule.ts
index 18be50c..b054955 100644
--- a/src/interfaces/fulaNativeModule.ts
+++ b/src/interfaces/fulaNativeModule.ts
@@ -2,11 +2,11 @@ import { NativeModules, Platform } from 'react-native';
interface FulaNativeModule {
init: (
- identity: string | null, //Private key of did identity
- storePath: string | null, //You can leave empty
+ identity: string, //Private key of did identity
+ storePath: string, //You can leave empty
bloxAddr: string, //Blox multiadddr needs to be manually entered now
exchange: string //set to 'noope' for testing
- ) => Promise<[string, string, string]>;
+ ) => Promise<{peerId: string, rootCid: string, private_ref:string}>;
get: (key: string) => Promise;
has: (key: Uint8Array) => Promise;
push: () => Promise;
diff --git a/src/protocols/fula.ts b/src/protocols/fula.ts
index 3ef2b44..3bfb73d 100644
--- a/src/protocols/fula.ts
+++ b/src/protocols/fula.ts
@@ -12,7 +12,7 @@ export const init = (
storePath: string,
bloxAddr: string,
exchange: string
-): Promise<[string, string, string]> => {
+): Promise<{peerId: string, rootCid: string, private_ref:string}> => {
console.log('init in react-native started',identity, storePath, bloxAddr, exchange);
return Fula.init(identity, storePath, bloxAddr, exchange);
};