Skip to content

Commit fac8387

Browse files
committed
Added Plugin support
1 parent 5c7920f commit fac8387

File tree

10 files changed

+1178
-424
lines changed

10 files changed

+1178
-424
lines changed

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ dependencies {
9898
// For < 0.71, this will be from the local maven repo
9999
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
100100
//noinspection GradleDynamicVersion
101-
implementation "com.facebook.react:react-native:+"
102-
implementation 'com.github.functionland:fula-build-aar:v1.54.10' // From jitpack.io
101+
implementation "com.facebook.react:react-android:+"
102+
implementation 'com.github.functionland:fula-build-aar:v1.54.13' // From jitpack.io
103103
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
104104
implementation 'commons-io:commons-io:20030203.000550'
105105
implementation 'commons-codec:commons-codec:1.15'

android/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ Fula_minSdkVersion=26
33
Fula_targetSdkVersion=33
44
Fula_compileSdkVersion=33
55
Fula_ndkversion=26.2.11394342
6+
android.useAndroidX=true
7+
android.enableJetifier=true
8+
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
44
org.gradle.java.home=JAVA_HOME
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

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

Lines changed: 93 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ public void setAuth(String peerIdString, boolean allow, Promise promise) {
11811181
}
11821182
promise.resolve(false);
11831183
} catch (Exception e) {
1184-
Log.d("ReactNative", e.getMessage());
1184+
Log.d("ReactNative", "ERROR:" + e.getMessage());
11851185
promise.reject(e);
11861186
}
11871187
});
@@ -1230,7 +1230,7 @@ public void getAccount(Promise promise) {
12301230
String resultString = toString(result);
12311231
promise.resolve(resultString);
12321232
} catch (Exception e) {
1233-
Log.d("ReactNative", e.getMessage());
1233+
Log.d("ReactNative", "ERROR:" + e.getMessage());
12341234
promise.reject(e);
12351235
}
12361236
});
@@ -1245,7 +1245,7 @@ public void accountFund(String accountString, Promise promise) {
12451245
String resultString = toString(result);
12461246
promise.resolve(resultString);
12471247
} catch (Exception e) {
1248-
Log.d("ReactNative", e.getMessage());
1248+
Log.d("ReactNative", "ERROR:" + e.getMessage());
12491249
promise.reject(e);
12501250
}
12511251
});
@@ -1262,7 +1262,7 @@ public void assetsBalance(String account, String assetId, String classId, Promis
12621262
String resultString = toString(result);
12631263
promise.resolve(resultString);
12641264
} catch (Exception e) {
1265-
Log.d("ReactNative", e.getMessage());
1265+
Log.d("ReactNative", "ERROR:" + e.getMessage());
12661266
promise.reject(e);
12671267
}
12681268
});
@@ -1277,7 +1277,7 @@ public void transferToFula(String amount, String wallet, String chain, Promise p
12771277
String resultString = toString(result);
12781278
promise.resolve(resultString);
12791279
} catch (Exception e) {
1280-
Log.d("ReactNative", e.getMessage());
1280+
Log.d("ReactNative", "ERROR:" + e.getMessage());
12811281
promise.reject(e);
12821282
}
12831283
});
@@ -1292,7 +1292,7 @@ public void checkAccountExists(String accountString, Promise promise) {
12921292
String resultString = toString(result);
12931293
promise.resolve(resultString);
12941294
} catch (Exception e) {
1295-
Log.d("ReactNative", e.getMessage());
1295+
Log.d("ReactNative", "ERROR:" + e.getMessage());
12961296
promise.reject(e);
12971297
}
12981298
});
@@ -1307,7 +1307,7 @@ public void listPools(Promise promise) {
13071307
String resultString = toString(result);
13081308
promise.resolve(resultString);
13091309
} catch (Exception e) {
1310-
Log.d("ReactNative", e.getMessage());
1310+
Log.d("ReactNative", "ERROR:" + e.getMessage());
13111311
promise.reject(e);
13121312
}
13131313
});
@@ -1323,7 +1323,7 @@ public void joinPool(String poolID, Promise promise) {
13231323
String resultString = toString(result);
13241324
promise.resolve(resultString);
13251325
} catch (Exception e) {
1326-
Log.d("ReactNative", e.getMessage());
1326+
Log.d("ReactNative", "ERROR:" + e.getMessage());
13271327
promise.reject(e);
13281328
}
13291329
});
@@ -1339,7 +1339,7 @@ public void cancelPoolJoin(String poolID, Promise promise) {
13391339
String resultString = toString(result);
13401340
promise.resolve(resultString);
13411341
} catch (Exception e) {
1342-
Log.d("ReactNative", e.getMessage());
1342+
Log.d("ReactNative", "ERROR:" + e.getMessage());
13431343
promise.reject(e);
13441344
}
13451345
});
@@ -1355,7 +1355,7 @@ public void listPoolJoinRequests(String poolIDStr, Promise promise) {
13551355
String resultString = toString(result);
13561356
promise.resolve(resultString);
13571357
} catch (Exception e) {
1358-
Log.d("ReactNative", e.getMessage());
1358+
Log.d("ReactNative", "ERROR:" + e.getMessage());
13591359
promise.reject(e);
13601360
}
13611361
});
@@ -1371,7 +1371,7 @@ public void leavePool(String poolID, Promise promise) {
13711371
String resultString = toString(result);
13721372
promise.resolve(resultString);
13731373
} catch (Exception e) {
1374-
Log.d("ReactNative", e.getMessage());
1374+
Log.d("ReactNative", "ERROR:" + e.getMessage());
13751375
promise.reject(e);
13761376
}
13771377
});
@@ -1387,7 +1387,7 @@ public void listAvailableReplicationRequests(String poolIDStr, Promise promise)
13871387
String resultString = toString(result);
13881388
promise.resolve(resultString);
13891389
} catch (Exception e) {
1390-
Log.d("ReactNative", e.getMessage());
1390+
Log.d("ReactNative", "ERROR:" + e.getMessage());
13911391
promise.reject(e);
13921392
}
13931393
});
@@ -1561,7 +1561,7 @@ public void bloxFreeSpace(Promise promise) {
15611561
Log.d("ReactNative", "result string="+resultString);
15621562
promise.resolve(resultString);
15631563
} catch (Exception e) {
1564-
Log.d("ReactNative", e.getMessage());
1564+
Log.d("ReactNative", "ERROR:" + e.getMessage());
15651565
promise.reject(e);
15661566
}
15671567
});
@@ -1577,7 +1577,7 @@ public void wifiRemoveall(Promise promise) {
15771577
Log.d("ReactNative", "result string="+resultString);
15781578
promise.resolve(resultString);
15791579
} catch (Exception e) {
1580-
Log.d("ReactNative", e.getMessage());
1580+
Log.d("ReactNative", "ERROR:" + e.getMessage());
15811581
promise.reject(e);
15821582
}
15831583
});
@@ -1657,7 +1657,7 @@ public void reboot(Promise promise) {
16571657
Log.d("ReactNative", "result string="+resultString);
16581658
promise.resolve(resultString);
16591659
} catch (Exception e) {
1660-
Log.d("ReactNative", e.getMessage());
1660+
Log.d("ReactNative", "ERROR:" + e.getMessage());
16611661
promise.reject(e);
16621662
}
16631663
});
@@ -1673,7 +1673,7 @@ public void partition(Promise promise) {
16731673
Log.d("ReactNative", "result string="+resultString);
16741674
promise.resolve(resultString);
16751675
} catch (Exception e) {
1676-
Log.d("ReactNative", e.getMessage());
1676+
Log.d("ReactNative", "ERROR:" + e.getMessage());
16771677
promise.reject(e);
16781678
}
16791679
});
@@ -1689,7 +1689,7 @@ public void eraseBlData(Promise promise) {
16891689
Log.d("ReactNative", "result string="+resultString);
16901690
promise.resolve(resultString);
16911691
} catch (Exception e) {
1692-
Log.d("ReactNative", e.getMessage());
1692+
Log.d("ReactNative", "ERROR:" + e.getMessage());
16931693
promise.reject(e);
16941694
}
16951695
});
@@ -1726,4 +1726,80 @@ public void testData(String identityString, String bloxAddr, Promise promise) {
17261726
}
17271727
}
17281728

1729+
// Plugin Methods
1730+
@ReactMethod
1731+
public void listPlugins(Promise promise) {
1732+
ThreadUtils.runOnExecutor(() -> {
1733+
Log.d("ReactNative", "listPlugins");
1734+
try {
1735+
byte[] result = this.fula.listPlugins();
1736+
String resultString = toString(result);
1737+
promise.resolve(resultString);
1738+
} catch (Exception e) {
1739+
Log.d("ReactNative", "ERROR:" + e.getMessage());
1740+
promise.reject(e);
1741+
}
1742+
});
1743+
}
1744+
1745+
@ReactMethod
1746+
public void listActivePlugins(Promise promise) {
1747+
ThreadUtils.runOnExecutor(() -> {
1748+
Log.d("ReactNative", "listActivePlugins");
1749+
try {
1750+
byte[] result = this.fula.listActivePlugins();
1751+
String resultString = toString(result);
1752+
promise.resolve(resultString);
1753+
} catch (Exception e) {
1754+
Log.d("ReactNative", "ERROR:" + e.getMessage());
1755+
promise.reject(e);
1756+
}
1757+
});
1758+
}
1759+
1760+
@ReactMethod
1761+
public void installPlugin(String pluginName, String params, Promise promise) {
1762+
ThreadUtils.runOnExecutor(() -> {
1763+
Log.d("ReactNative", "installPlugin: pluginName = " + pluginName + ", params = " + params);
1764+
try {
1765+
byte[] result = this.fula.installPlugin(pluginName, params);
1766+
String resultString = toString(result);
1767+
promise.resolve(resultString);
1768+
} catch (Exception e) {
1769+
Log.d("ReactNative", "ERROR:" + e.getMessage());
1770+
promise.reject(e);
1771+
}
1772+
});
1773+
}
1774+
1775+
@ReactMethod
1776+
public void uninstallPlugin(String pluginName, Promise promise) {
1777+
ThreadUtils.runOnExecutor(() -> {
1778+
Log.d("ReactNative", "uninstallPlugin: pluginName = " + pluginName);
1779+
try {
1780+
byte[] result = this.fula.uninstallPlugin(pluginName);
1781+
String resultString = toString(result);
1782+
promise.resolve(resultString);
1783+
} catch (Exception e) {
1784+
Log.d("ReactNative", "ERROR:" + e.getMessage());
1785+
promise.reject(e);
1786+
}
1787+
});
1788+
}
1789+
1790+
@ReactMethod
1791+
public void showPluginStatus(String pluginName, int lines, Promise promise) {
1792+
ThreadUtils.runOnExecutor(() -> {
1793+
Log.d("ReactNative", "showPluginStatus: pluginName = " + pluginName + ", lines = " + lines);
1794+
try {
1795+
byte[] result = this.fula.showPluginStatus(pluginName, lines);
1796+
String resultString = toString(result);
1797+
promise.resolve(resultString);
1798+
} catch (Exception e) {
1799+
Log.d("ReactNative", "ERROR:" + e.getMessage());
1800+
promise.reject(e);
1801+
}
1802+
});
1803+
}
1804+
17291805
}

example/src/App.tsx

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect } from 'react';
22
import { StyleSheet, ScrollView, View, Button } from 'react-native';
3+
import { installPlugin, listPlugins } from '../../src/protocols/fxblox';
34

45
import {
56
fula,
@@ -69,8 +70,8 @@ const App = () => {
6970
// const bloxPeerId = '12D3KooWQZBdE5zNUVTE2Aayajyy9cJDmK4bJwMZG52ieHt2f6nb'; //laptop2
7071
//const bloxPeerId = '12D3KooWAN5FaAnC4d1GhAvoYxyUXdrkCGqux1NB6Pr4cZXn813E'; //test aws server
7172

72-
const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/' + bloxPeerId;
73-
//const bloxAddr = '/ip4/192.168.2.14/tcp/40001/p2p/' + bloxPeerId; // /ip4/192.168.2.14/tcp/40001/p2p/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q
73+
// const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/' + bloxPeerId;
74+
const bloxAddr = '/ip4/192.168.2.14/tcp/40001/p2p/' + bloxPeerId; // /ip4/192.168.2.14/tcp/40001/p2p/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q
7475
//const bloxAddr = '/dns4/1.pools.test.fula.network/tcp/40001/p2p/12D3KooWHb38UxY8akVGWZBuFtS3NJ7rJUwd36t3cfkoY7EbgNt9';
7576
const initFula = async () => {
7677
try {
@@ -1063,6 +1064,106 @@ const App = () => {
10631064
color={inprogress ? 'green' : 'blue'}
10641065
/>
10651066
</View>
1067+
1068+
<View style={styles.section}>
1069+
<Button
1070+
title={inprogress ? 'Getting...' : 'Test List Active Plugins'}
1071+
onPress={async () => {
1072+
try {
1073+
if (initComplete) {
1074+
fula.checkConnection().then((r: any) => {
1075+
console.log('connection check');
1076+
console.log(r);
1077+
if (r) {
1078+
console.log(
1079+
'initialization is completed. send list plugin'
1080+
);
1081+
fxblox
1082+
.listActivePlugins()
1083+
.then((res: any) => {
1084+
console.log('list active plugins received');
1085+
console.log(res);
1086+
})
1087+
.catch((e: any) => {
1088+
console.log('list plugins failed');
1089+
console.log(e);
1090+
});
1091+
}
1092+
});
1093+
} else {
1094+
console.log('wait for init to complete');
1095+
}
1096+
} catch (e) {}
1097+
}}
1098+
color={inprogress ? 'green' : 'blue'}
1099+
/>
1100+
</View>
1101+
<View style={styles.section}>
1102+
<Button
1103+
title={inprogress ? 'Getting...' : 'Test Install Plugins'}
1104+
onPress={async () => {
1105+
try {
1106+
if (initComplete) {
1107+
fula.checkConnection().then((r: any) => {
1108+
console.log('connection check');
1109+
console.log(r);
1110+
if (r) {
1111+
console.log(
1112+
'initialization is completed. send install plugin'
1113+
);
1114+
fxblox
1115+
.installPlugin('streamr-node', 'contractAddress====test')
1116+
.then((res: any) => {
1117+
console.log('install plugins received');
1118+
console.log(res);
1119+
})
1120+
.catch((e: any) => {
1121+
console.log('install plugins failed');
1122+
console.log(e);
1123+
});
1124+
}
1125+
});
1126+
} else {
1127+
console.log('wait for init to complete');
1128+
}
1129+
} catch (e) {}
1130+
}}
1131+
color={inprogress ? 'green' : 'blue'}
1132+
/>
1133+
</View>
1134+
<View style={styles.section}>
1135+
<Button
1136+
title={inprogress ? 'Getting...' : 'Test Uninstall Plugins'}
1137+
onPress={async () => {
1138+
try {
1139+
if (initComplete) {
1140+
fula.checkConnection().then((r: any) => {
1141+
console.log('connection check');
1142+
console.log(r);
1143+
if (r) {
1144+
console.log(
1145+
'initialization is completed. send uninstall plugin'
1146+
);
1147+
fxblox
1148+
.uninstallPlugin('streamr-node')
1149+
.then((res: any) => {
1150+
console.log('uninstall plugins received');
1151+
console.log(res);
1152+
})
1153+
.catch((e: any) => {
1154+
console.log('uninstall plugins failed');
1155+
console.log(e);
1156+
});
1157+
}
1158+
});
1159+
} else {
1160+
console.log('wait for init to complete');
1161+
}
1162+
} catch (e) {}
1163+
}}
1164+
color={inprogress ? 'green' : 'blue'}
1165+
/>
1166+
</View>
10661167
</ScrollView>
10671168
);
10681169
};

0 commit comments

Comments
 (0)