Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add go-fula Blockstore support #2

Merged
merged 6 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"rust-analyzer.cargo.target": "aarch64-linux-android",
// "rust-analyzer.cargo.target": "aarch64-linux-android",
}
9 changes: 7 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ A wnfslib wrapper for Android.
## Prerequisites

- Kotlin toolchain
- Android SDK + NDK r24 (latest)
- Android SDK + NDK (latest)
- python3 and Python command available
- Cargo and CMake
- java
- gradle
- rustup target add armv7-linux-androideabi aarch64-linux-android i686-linux-android x86_64-linux-android

## Debug

Expand Down Expand Up @@ -41,4 +46,4 @@ Ensure you have committed your changes.
./gradlew release
```

Then simply push to the repo.
Then simply push to the repo.
15 changes: 10 additions & 5 deletions appmock/src/androidTest/java/com/functionland/app/WNFSTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import land.fx.wnfslib.createRootDir
import land.fx.wnfslib.writeFile
import land.fx.wnfslib.readFile
import land.fx.wnfslib.ls
import land.fx.wnfslib.mkdir
import junit.framework.Assert.assertNotNull

@RunWith(AndroidJUnit4::class)
Expand All @@ -28,14 +29,18 @@ class WNFSTest {
var cid = createPrivateForest(path.toString())
println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
println(cid)
val config = createRootDir(path.toString(), cid)
var config = createRootDir(path.toString(), cid)
assertNotNull("cid should not be null", cid)
assertNotNull("private_ref should not be null", config.private_ref)
cid = writeFile(path.toString(), config.cid, config.private_ref, "root/test.txt", "Hello, World!".toByteArray())
config = writeFile(path.toString(), config.cid, config.private_ref, "root/test.txt", "Hello, World!".toByteArray())
assertNotNull("cid should not be null", cid)
val fileNames = ls(path.toString(), cid, config.private_ref, "root")
assertEquals(fileNames, "test.txt")
val content = readFile(path.toString(), cid, config.private_ref, "root/test.txt")
config = mkdir(path.toString(), config.cid, config.private_ref, "root/test1")
val fileNames = ls(path.toString(), config.cid, config.private_ref, "root")
assertEquals(fileNames, "test.txt\ntest1")
val content = readFile(path.toString(), config.cid, config.private_ref, "root/test.txt")
assert(content contentEquals "Hello, World!".toByteArray())
config = rm(path.toString(), config.cid, config.private_ref, "root/test.txt")
content = readFile(path.toString(), config.cid, config.private_ref, "root/test.txt")
assertNull(content)
}
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ allprojects {
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
gradlePluginPortal()
maven { url "https://jitpack.io" }
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.core:core-ktx:1.7.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.github.functionland:fula-build-aar:v0.6.6' // From jitpack.io
}

tasks.whenTaskAdded { task ->
Expand Down
45 changes: 30 additions & 15 deletions lib/src/main/java/land/fx/wnfslib/Lib.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package land.fx.wnfslib;

import fulamobile.Client;

data class Config(
val cid: String,
val private_ref: String){
Expand All @@ -9,34 +11,47 @@ data class Config(
}
}

private external fun createPrivateForestNative(dbPath: String): String
private external fun createPrivateForestNative(fulaClient: Client): String

private external fun createRootDirNative(fulaClient: Client, cid: String): Config

private external fun writeFileNative(fulaClient: Client, cid: String, privateRef: String, path: String, content: ByteArray): Config

private external fun lsNative(fulaClient: Client, cid: String, privateRef: String, path: String): String

private external fun createRootDirNative(dbPath: String, cid: String): Config
private external fun mkdirNative(fulaClient: Client, cid: String, privateRef: String, path: String): Config

private external fun writeFileNative(dbPath: String, cid: String, privateRef: String, path: String, content: ByteArray): String
private external fun rmNative(fulaClient: Client, cid: String, privateRef: String, path: String): Config

private external fun lsNative(dbPath: String, cid: String, privateRef: String, path: String): String
private external fun readFileNative(fulaClient: Client, cid: String, privateRef: String, path: String): ByteArray?

private external fun readFileNative(dbPath: String, cid: String, privateRef: String, path: String): ByteArray
fun createPrivateForest(fulaClient: Client): String {
return createPrivateForestNative(fulaClient)
}

fun createRootDir(fulaClient: Client, cid: String): Config {
return createRootDirNative(fulaClient, cid)
}

fun createPrivateForest(dbPath: String): String {
return createPrivateForestNative(dbPath)
fun writeFile(fulaClient: Client, cid: String, privateRef: String, path: String, content: ByteArray): Config {
return writeFileNative(fulaClient, cid, privateRef, path, content)
}

fun createRootDir(dbPath: String, cid: String): Config {
return createRootDirNative(dbPath, cid)
fun ls(fulaClient: Client, cid: String, privateRef: String, path: String): String {
return lsNative(fulaClient, cid, privateRef, path)
}

fun writeFile(dbPath: String, cid: String, privateRef: String, path: String, content: ByteArray): String {
return writeFileNative(dbPath, cid, privateRef, path, content)
fun mkdir(fulaClient: Client, cid: String, privateRef: String, path: String): Config {
return mkdirNative(fulaClient, cid, privateRef, path)
}

fun ls(dbPath: String, cid: String, privateRef: String, path: String): String {
return lsNative(dbPath, cid, privateRef, path)
fun rm(fulaClient: Client, cid: String, privateRef: String, path: String): Config {
return rmNative(fulaClient, cid, privateRef, path)
}

fun readFile(dbPath: String, cid: String, privateRef: String, path: String): ByteArray {
return readFileNative(dbPath, cid, privateRef, path)
fun readFile(fulaClient: Client, cid: String, privateRef: String, path: String): ByteArray? {
return readFileNative(fulaClient, cid, privateRef, path)
}

// Initialize Rust Library Logging
external fun initRustLogger()
Loading