Skip to content

Commit

Permalink
Added Plugin support
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Oct 8, 2024
1 parent 5c7920f commit fac8387
Show file tree
Hide file tree
Showing 10 changed files with 1,178 additions and 424 deletions.
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ dependencies {
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation 'com.github.functionland:fula-build-aar:v1.54.10' // From jitpack.io
implementation "com.facebook.react:react-android:+"
implementation 'com.github.functionland:fula-build-aar:v1.54.13' // From jitpack.io
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
implementation 'commons-io:commons-io:20030203.000550'
implementation 'commons-codec:commons-codec:1.15'
Expand Down
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ Fula_minSdkVersion=26
Fula_targetSdkVersion=33
Fula_compileSdkVersion=33
Fula_ndkversion=26.2.11394342
android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
org.gradle.java.home=JAVA_HOME
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
110 changes: 93 additions & 17 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ public void setAuth(String peerIdString, boolean allow, Promise promise) {
}
promise.resolve(false);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand Down Expand Up @@ -1230,7 +1230,7 @@ public void getAccount(Promise promise) {
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1245,7 +1245,7 @@ public void accountFund(String accountString, Promise promise) {
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1262,7 +1262,7 @@ public void assetsBalance(String account, String assetId, String classId, Promis
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1277,7 +1277,7 @@ public void transferToFula(String amount, String wallet, String chain, Promise p
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1292,7 +1292,7 @@ public void checkAccountExists(String accountString, Promise promise) {
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1307,7 +1307,7 @@ public void listPools(Promise promise) {
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1323,7 +1323,7 @@ public void joinPool(String poolID, Promise promise) {
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1339,7 +1339,7 @@ public void cancelPoolJoin(String poolID, Promise promise) {
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1355,7 +1355,7 @@ public void listPoolJoinRequests(String poolIDStr, Promise promise) {
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1371,7 +1371,7 @@ public void leavePool(String poolID, Promise promise) {
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1387,7 +1387,7 @@ public void listAvailableReplicationRequests(String poolIDStr, Promise promise)
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand Down Expand Up @@ -1561,7 +1561,7 @@ public void bloxFreeSpace(Promise promise) {
Log.d("ReactNative", "result string="+resultString);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1577,7 +1577,7 @@ public void wifiRemoveall(Promise promise) {
Log.d("ReactNative", "result string="+resultString);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand Down Expand Up @@ -1657,7 +1657,7 @@ public void reboot(Promise promise) {
Log.d("ReactNative", "result string="+resultString);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1673,7 +1673,7 @@ public void partition(Promise promise) {
Log.d("ReactNative", "result string="+resultString);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand All @@ -1689,7 +1689,7 @@ public void eraseBlData(Promise promise) {
Log.d("ReactNative", "result string="+resultString);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", e.getMessage());
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
Expand Down Expand Up @@ -1726,4 +1726,80 @@ public void testData(String identityString, String bloxAddr, Promise promise) {
}
}

// Plugin Methods
@ReactMethod
public void listPlugins(Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "listPlugins");
try {
byte[] result = this.fula.listPlugins();
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
}

@ReactMethod
public void listActivePlugins(Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "listActivePlugins");
try {
byte[] result = this.fula.listActivePlugins();
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
}

@ReactMethod
public void installPlugin(String pluginName, String params, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "installPlugin: pluginName = " + pluginName + ", params = " + params);
try {
byte[] result = this.fula.installPlugin(pluginName, params);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
}

@ReactMethod
public void uninstallPlugin(String pluginName, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "uninstallPlugin: pluginName = " + pluginName);
try {
byte[] result = this.fula.uninstallPlugin(pluginName);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
}

@ReactMethod
public void showPluginStatus(String pluginName, int lines, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "showPluginStatus: pluginName = " + pluginName + ", lines = " + lines);
try {
byte[] result = this.fula.showPluginStatus(pluginName, lines);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", "ERROR:" + e.getMessage());
promise.reject(e);
}
});
}

}
105 changes: 103 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect } from 'react';
import { StyleSheet, ScrollView, View, Button } from 'react-native';
import { installPlugin, listPlugins } from '../../src/protocols/fxblox';

import {
fula,
Expand Down Expand Up @@ -69,8 +70,8 @@ const App = () => {
// const bloxPeerId = '12D3KooWQZBdE5zNUVTE2Aayajyy9cJDmK4bJwMZG52ieHt2f6nb'; //laptop2
//const bloxPeerId = '12D3KooWAN5FaAnC4d1GhAvoYxyUXdrkCGqux1NB6Pr4cZXn813E'; //test aws server

const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/' + bloxPeerId;
//const bloxAddr = '/ip4/192.168.2.14/tcp/40001/p2p/' + bloxPeerId; // /ip4/192.168.2.14/tcp/40001/p2p/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q
// const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/' + bloxPeerId;
const bloxAddr = '/ip4/192.168.2.14/tcp/40001/p2p/' + bloxPeerId; // /ip4/192.168.2.14/tcp/40001/p2p/12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q
//const bloxAddr = '/dns4/1.pools.test.fula.network/tcp/40001/p2p/12D3KooWHb38UxY8akVGWZBuFtS3NJ7rJUwd36t3cfkoY7EbgNt9';
const initFula = async () => {
try {
Expand Down Expand Up @@ -1063,6 +1064,106 @@ const App = () => {
color={inprogress ? 'green' : 'blue'}
/>
</View>

<View style={styles.section}>
<Button
title={inprogress ? 'Getting...' : 'Test List Active Plugins'}
onPress={async () => {
try {
if (initComplete) {
fula.checkConnection().then((r: any) => {
console.log('connection check');
console.log(r);
if (r) {
console.log(
'initialization is completed. send list plugin'
);
fxblox
.listActivePlugins()
.then((res: any) => {
console.log('list active plugins received');
console.log(res);
})
.catch((e: any) => {
console.log('list plugins failed');
console.log(e);
});
}
});
} else {
console.log('wait for init to complete');
}
} catch (e) {}
}}
color={inprogress ? 'green' : 'blue'}
/>
</View>
<View style={styles.section}>
<Button
title={inprogress ? 'Getting...' : 'Test Install Plugins'}
onPress={async () => {
try {
if (initComplete) {
fula.checkConnection().then((r: any) => {
console.log('connection check');
console.log(r);
if (r) {
console.log(
'initialization is completed. send install plugin'
);
fxblox
.installPlugin('streamr-node', 'contractAddress====test')
.then((res: any) => {
console.log('install plugins received');
console.log(res);
})
.catch((e: any) => {
console.log('install plugins failed');
console.log(e);
});
}
});
} else {
console.log('wait for init to complete');
}
} catch (e) {}
}}
color={inprogress ? 'green' : 'blue'}
/>
</View>
<View style={styles.section}>
<Button
title={inprogress ? 'Getting...' : 'Test Uninstall Plugins'}
onPress={async () => {
try {
if (initComplete) {
fula.checkConnection().then((r: any) => {
console.log('connection check');
console.log(r);
if (r) {
console.log(
'initialization is completed. send uninstall plugin'
);
fxblox
.uninstallPlugin('streamr-node')
.then((res: any) => {
console.log('uninstall plugins received');
console.log(res);
})
.catch((e: any) => {
console.log('uninstall plugins failed');
console.log(e);
});
}
});
} else {
console.log('wait for init to complete');
}
} catch (e) {}
}}
color={inprogress ? 'green' : 'blue'}
/>
</View>
</ScrollView>
);
};
Expand Down
Loading

0 comments on commit fac8387

Please sign in to comment.