Skip to content

Commit

Permalink
corrected linking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Dec 12, 2022
1 parent c3172db commit b88727e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.github.functionland:fula-build-aar:v0.7.3' // From jitpack.io
implementation 'com.github.functionland:wnfs-build-aar:v1.2.9' // From jitpack.io
implementation 'com.github.functionland:wnfs-build-aar:v1.2.7' // From jitpack.io
// implementation files('mobile.aar')
}
30 changes: 23 additions & 7 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +32,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
@Override
public void initialize() {
System.loadLibrary("wnfslib");
System.loadLibrary("gojni");
}


Expand All @@ -48,15 +51,15 @@ 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 {
Log.d("ReactNative", Arrays.toString(cid));
return internalClient.get(cid);
return this.internalClient.get(cid);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -69,7 +72,7 @@ public byte[] get(@NonNull byte[] cid) {
public byte[] put(@NonNull byte[] data, long codec) {
try {
//Log.d("ReactNative", "data="+ Arrays.toString(data) +" ;codec="+codec);
return client.put(data, codec);
return this.internalClient.put(data, codec);
} catch (Exception e) {
Log.d("ReactNative", "put Error="+e.getMessage());
e.printStackTrace();
Expand Down Expand Up @@ -146,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());
}
});
}
Expand Down Expand Up @@ -206,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);
Expand Down
13 changes: 6 additions & 7 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const App = () => {
const [value, setValue] = React.useState<string>('');
const [inprogress, setInprogress] = React.useState<boolean>(false);

const [initComplete, setInitComplete] = React.useState<[string] | []>([]);
const [initComplete, setInitComplete] = React.useState<{peerId: string, rootCid: string, private_ref:string} | {}>({});

React.useEffect(() => {
const initFula = async () => {
Expand All @@ -20,24 +20,23 @@ 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(),
'',
'',
'noop'
'noop',
Promise
);
console.log('initialization result', f);
return f;
} catch (e) {
console.log(e);
return Promise.reject(e);
}
};

initFula()
.then((res) => {
.then((res) => {
console.log("OK",res);
setInitComplete(res);
console.log('OK', res);
})
.catch((e) => {
console.log('error', e);
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
has: (key: Uint8Array) => Promise<boolean>;
push: () => Promise<string>;
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/fula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit b88727e

Please sign in to comment.