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 2 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
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 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
35 changes: 25 additions & 10 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 createRootDirNative(dbPath: String, cid: String): Config
private external fun writeFileNative(fulaClient: Client, cid: String, privateRef: String, path: String, content: ByteArray): Config

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

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

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

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

fun createPrivateForest(fulaClient: Client): String {
return createPrivateForestNative(dbPath)
}

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

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

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

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

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

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

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