Skip to content

Commit

Permalink
Merge pull request #74 from functionland/chain-api
Browse files Browse the repository at this point in the history
Chain api
  • Loading branch information
ehsan6sha authored Nov 21, 2023
2 parents c0f0d89 + 3ca633b commit 95facd8
Show file tree
Hide file tree
Showing 28 changed files with 10,275 additions and 2,606 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ await fula.logout(

```
## Polkadot type creation
You can follow the documentation here: https://polkadot.js.org/docs/api/examples/promise/typegen
Alternatively you do the below on a Linux or WSL inside the react-native-fula folder:
```bash
curl -H "Content-Type: application/json" -d "{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}" https://node3.functionyard.fula.network > edgeware.json

yarn build:polkadot
```
## Roadmap
Please note the following might not be done in order:
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ dependencies {
// 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.14.3' // From jitpack.io
implementation 'com.github.functionland:fula-build-aar:v1.15.1' // 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
85 changes: 76 additions & 9 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ private byte[] newClientInternal(byte[] identity, String storePath, String bloxA
Log.d("ReactNative", "Creating a new Fula instance");
try {
shutdownInternal();
Log.d("ReactNative", "Creating a new Fula instance with config");
this.fula = Fulamobile.newClient(fulaConfig);
if (this.fula != null) {
this.fula.flush();
Expand Down Expand Up @@ -1121,6 +1122,8 @@ private void shutdownInternal() throws Exception {
this.fula.shutdown();
this.fula = null;
this.client = null;
Log.d("ReactNative", "shutdownInternal done");

}
} catch (Exception e) {
Log.d("ReactNative", "shutdownInternal"+ e.getMessage());
Expand Down Expand Up @@ -1216,11 +1219,12 @@ public void listPools(Promise promise) {
}

@ReactMethod
public void joinPool(String seedString, long poolID, Promise promise) {
public void joinPool(String poolID, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "joinPool: seedString = " + seedString + "; poolID = " + poolID);
long poolIdLong = Long.parseLong(poolID);
Log.d("ReactNative", "joinPool: poolID = " + poolIdLong);
try {
byte[] result = this.fula.poolJoin(seedString, poolID);
byte[] result = this.fula.poolJoin(poolIdLong);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Expand All @@ -1231,11 +1235,11 @@ public void joinPool(String seedString, long poolID, Promise promise) {
}

@ReactMethod
public void cancelPoolJoin(String seedString, long poolID, Promise promise) {
public void cancelPoolJoin(long poolID, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "cancelPoolJoin: seedString = " + seedString + "; poolID = " + poolID);
Log.d("ReactNative", "cancelPoolJoin: poolID = " + poolID);
try {
byte[] result = this.fula.poolCancelJoin(seedString, poolID);
byte[] result = this.fula.poolCancelJoin(poolID);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Expand Down Expand Up @@ -1276,11 +1280,11 @@ public void votePoolJoinRequest(String seedString, long poolID, String accountSt
}

@ReactMethod
public void leavePool(String seedString, long poolID, Promise promise) {
public void leavePool(long poolID, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "leavePool: seedString = " + seedString + "; poolID = " + poolID);
Log.d("ReactNative", "leavePool: poolID = " + poolID);
try {
byte[] result = this.fula.poolLeave(seedString, poolID);
byte[] result = this.fula.poolLeave(poolID);
String resultString = toString(result);
promise.resolve(resultString);
} catch (Exception e) {
Expand Down Expand Up @@ -1380,6 +1384,69 @@ public void removeStoredReplication(String seedString, String uploader, long poo
});
}

@ReactMethod
private void listRecentCidsAsString(Promise promise) throws Exception {
ThreadUtils.runOnExecutor(() -> {
try {
if (this.fula != null) {
Log.d("ReactNative", "ListRecentCidsAsString");
fulamobile.StringIterator recentLinks = this.fula.listRecentCidsAsString();
ArrayList<String> recentLinksList = new ArrayList<>();
while (recentLinks.hasNext()) {
recentLinksList.add(recentLinks.next());
}
if (!recentLinksList.isEmpty()) {
// return the whole list
Log.d("ReactNative", "ListRecentCidsAsString found: "+ recentLinksList);
WritableArray recentLinksArray = Arguments.createArray();
for (String link : recentLinksList) {
recentLinksArray.pushString(link);
}
promise.resolve(recentLinksArray);
} else {
promise.resolve(false);
}
} else {
throw new Exception("ListRecentCidsAsString: Fula is not initialized");
}
} catch (Exception e) {
Log.d("ReactNative", "ListRecentCidsAsString failed with Error: " + e.getMessage());
try {
throw (e);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
}

@ReactMethod
public void clearCidsFromRecent(ReadableArray cidArray, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
try {
if (this.fula != null) {
StringBuilder cidStrBuilder = new StringBuilder();
for (int i = 0; i < cidArray.size(); i++) {
if (i > 0) {
cidStrBuilder.append("|");
}
cidStrBuilder.append(cidArray.getString(i));
}

byte[] cidsBytes = cidStrBuilder.toString().getBytes(StandardCharsets.UTF_8);
this.fula.clearCidsFromRecent(cidsBytes);
promise.resolve(true); // Indicate success
} else {
throw new Exception("clearCidsFromRecent: Fula is not initialized");
}
} catch (Exception e) {
Log.d("ReactNative", "clearCidsFromRecent failed with Error: " + e.getMessage());
promise.reject("Error", e.getMessage());
}
});
}


////////////////////////////////////////////////////////////////
///////////////// Blox Hardware Methods ////////////////////////
////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions edgeware.json

Large diffs are not rendered by default.

Loading

0 comments on commit 95facd8

Please sign in to comment.