Skip to content

Commit b88727e

Browse files
committed
corrected linking issue
1 parent c3172db commit b88727e

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ dependencies {
6464
//noinspection GradleDynamicVersion
6565
implementation "com.facebook.react:react-native:+" // From node_modules
6666
implementation 'com.github.functionland:fula-build-aar:v0.7.3' // From jitpack.io
67-
implementation 'com.github.functionland:wnfs-build-aar:v1.2.9' // From jitpack.io
67+
implementation 'com.github.functionland:wnfs-build-aar:v1.2.7' // From jitpack.io
6868
// implementation files('mobile.aar')
6969
}

android/src/main/java/land/fx/fula/FulaModule.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.facebook.react.bridge.ReactApplicationContext;
99
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1010
import com.facebook.react.bridge.ReactMethod;
11+
import com.facebook.react.bridge.WritableMap;
12+
import com.facebook.react.bridge.WritableNativeMap;
1113
import com.facebook.react.module.annotations.ReactModule;
1214

1315
import org.jetbrains.annotations.Contract;
@@ -30,6 +32,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
3032
@Override
3133
public void initialize() {
3234
System.loadLibrary("wnfslib");
35+
System.loadLibrary("gojni");
3336
}
3437

3538

@@ -48,15 +51,15 @@ public class Client implements land.fx.wnfslib.Datastore {
4851
private final fulamobile.Client internalClient;
4952

5053
Client(fulamobile.Client clientInput) {
51-
internalClient = clientInput;
54+
this.internalClient = clientInput;
5255
}
5356

5457
@NonNull
5558
@Override
5659
public byte[] get(@NonNull byte[] cid) {
5760
try {
5861
Log.d("ReactNative", Arrays.toString(cid));
59-
return internalClient.get(cid);
62+
return this.internalClient.get(cid);
6063
} catch (Exception e) {
6164
e.printStackTrace();
6265
}
@@ -69,7 +72,7 @@ public byte[] get(@NonNull byte[] cid) {
6972
public byte[] put(@NonNull byte[] data, long codec) {
7073
try {
7174
//Log.d("ReactNative", "data="+ Arrays.toString(data) +" ;codec="+codec);
72-
return client.put(data, codec);
75+
return this.internalClient.put(data, codec);
7376
} catch (Exception e) {
7477
Log.d("ReactNative", "put Error="+e.getMessage());
7578
e.printStackTrace();
@@ -146,15 +149,19 @@ public void init(String identityString, String storePath, String bloxAddr, Strin
146149
Log.d("ReactNative", "init started");
147150
ThreadUtils.runOnExecutor(() -> {
148151
try {
152+
WritableMap resultData = new WritableNativeMap();
149153
Log.d("ReactNative", "init storePath= " + storePath);
150154
byte[] identity = toByte(identityString);
151155
Log.d("ReactNative", "init identity= " + identityString);
152156
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);
155162
} 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());
158165
}
159166
});
160167
}
@@ -206,6 +213,15 @@ private String[] initInternal(byte[] identity, String storePath, String bloxAddr
206213
if (this.rootConfig == null) {
207214
Log.d("ReactNative", "creating rootConfig");
208215

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+
209225
this.privateForest = Fs.createPrivateForest(this.client);
210226
Log.d("ReactNative", "privateForest is created: " + this.privateForest);
211227
this.rootConfig = Fs.createRootDir(this.client, this.privateForest);

example/src/App.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const App = () => {
88
const [value, setValue] = React.useState<string>('');
99
const [inprogress, setInprogress] = React.useState<boolean>(false);
1010

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

1313
React.useEffect(() => {
1414
const initFula = async () => {
@@ -20,24 +20,23 @@ const App = () => {
2020
227, 170, 32, 54, 203, 243, 211, 78, 120, 114, 199, 1, 197, 134, 6,
2121
91, 87, 152,
2222
];
23-
let f = await fula.init(
23+
return fula.init(
2424
privateKey.toString(),
2525
'',
2626
'',
27-
'noop'
27+
'noop',
28+
Promise
2829
);
29-
console.log('initialization result', f);
30-
return f;
3130
} catch (e) {
3231
console.log(e);
3332
return Promise.reject(e);
3433
}
3534
};
3635

3736
initFula()
38-
.then((res) => {
37+
.then((res) => {
38+
console.log("OK",res);
3939
setInitComplete(res);
40-
console.log('OK', res);
4140
})
4241
.catch((e) => {
4342
console.log('error', e);

src/interfaces/fulaNativeModule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { NativeModules, Platform } from 'react-native';
22

33
interface FulaNativeModule {
44
init: (
5-
identity: string | null, //Private key of did identity
6-
storePath: string | null, //You can leave empty
5+
identity: string, //Private key of did identity
6+
storePath: string, //You can leave empty
77
bloxAddr: string, //Blox multiadddr needs to be manually entered now
88
exchange: string //set to 'noope' for testing
9-
) => Promise<[string, string, string]>;
9+
) => Promise<{peerId: string, rootCid: string, private_ref:string}>;
1010
get: (key: string) => Promise<string>;
1111
has: (key: Uint8Array) => Promise<boolean>;
1212
push: () => Promise<string>;

src/protocols/fula.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const init = (
1212
storePath: string,
1313
bloxAddr: string,
1414
exchange: string
15-
): Promise<[string, string, string]> => {
15+
): Promise<{peerId: string, rootCid: string, private_ref:string}> => {
1616
console.log('init in react-native started',identity, storePath, bloxAddr, exchange);
1717
return Fula.init(identity, storePath, bloxAddr, exchange);
1818
};

0 commit comments

Comments
 (0)