Skip to content

Commit 3dd1f11

Browse files
authored
Merge pull request #37 from functionland/puterror
Puterror
2 parents 37b1fb3 + b88727e commit 3dd1f11

File tree

9 files changed

+51
-38
lines changed

9 files changed

+51
-38
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
}
88

99
dependencies {
10-
classpath 'com.android.tools.build:gradle:7.0.4'
10+
classpath 'com.android.tools.build:gradle:7.3.0'
1111
}
1212
}
1313
}

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

Lines changed: 36 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;
@@ -25,6 +27,15 @@
2527

2628
@ReactModule(name = FulaModule.NAME)
2729
public 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);

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
66

7-
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
7+
<application android:usesCleartextTraffic="true" tools:targetApi="31" tools:ignore="GoogleAppIndexingWarning" />
88
</manifest>

example/android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
android:theme="@style/AppTheme">
1414
<activity
1515
android:name=".MainActivity"
16-
android:label="@string/app_name"
1716
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
1817
android:launchMode="singleTask"
1918
android:exported="true"

example/android/app/src/main/java/com/example/reactnativefula/MainApplication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public boolean getUseDeveloperSupport() {
2323

2424
@Override
2525
protected List<ReactPackage> getPackages() {
26-
@SuppressWarnings("UnnecessaryLocalVariable")
2726
List<ReactPackage> packages = new PackageList(this).getPackages();
2827
// Packages that cannot be autolinked yet can be added manually here, for FulaExample:
2928
// packages.add(new MyReactNativePackage());
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<resources>
2-
<string name="app_name">Fula Example</string>
2+
<string name="app_name">FulaExample</string>
33
</resources>

example/src/App.tsx

Lines changed: 8 additions & 22 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
'',
26-
'/ip4/59.23.13.76/tcp/46640/p2p/QmRS9H18XHFrbmGKxi2TEBFz5ZzurkU9cbAwMsRzXcjr5X',
27-
'noop'
26+
'',
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);
@@ -53,23 +52,10 @@ const App = () => {
5352
title={inprogress ? 'Putting & Getting...' : 'Test'}
5453
onPress={async () => {
5554
try {
56-
/*const jsonvalue = { hello: 'world' };
57-
const cid =
58-
'bagaaierasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea';*/
59-
const ciduint8 = [
60-
1, 112, 18, 32, 195, 196, 115, 62, 200, 175, 253, 6, 207, 158,
61-
159, 245, 15, 252, 107, 205, 46, 200, 90, 97, 112, 0, 75, 183,
62-
9, 102, 156, 49, 222, 148, 57, 26,
63-
];
6455

6556
if (initComplete) {
6657
console.log('initialization is completed. putting key/value');
67-
const res = await fula.put(ciduint8.toString(), '');
68-
console.log(res);
69-
console.log('Now fetching key...');
70-
const res2 = await fula.get(ciduint8.toString());
71-
console.log(JSON.parse(res2));
72-
//setBS64(_bs64)
58+
7359
} else {
7460
console.log('wait for init to complete');
7561
}

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)