Skip to content

Commit

Permalink
Merge pull request #460 from tari-project/ffi-lib-14.0-rc
Browse files Browse the repository at this point in the history
FFI v0.14.0-rc update.
  • Loading branch information
kukabi committed Jul 1, 2020
2 parents ff311dc + a9be956 commit 74646c8
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 45 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
// recycler view
implementation "androidx.recyclerview:recyclerview:1.1.0"
// swipe refresh
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
// the new view pager
implementation "androidx.viewpager2:viewpager2:1.0.0"
// for tab layout
Expand Down
29 changes: 26 additions & 3 deletions app/src/androidTest/java/com/tari/android/wallet/FFIWalletTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withTimeout
import org.junit.*
import org.junit.Assert.*
import java.io.File
import java.math.BigInteger
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
Expand Down Expand Up @@ -217,11 +218,10 @@ class FFIWalletTests {
assertTrue(completedTxFee > BigInteger("0"))
val completedTxTimestamp = completedTx.getTimestamp()
completedTxTimestamp.toString()
val completedTxIsOutbound = wallet.isCompletedTxOutbound(completedTx)
if (wallet.getPublicKey().toString() == completedTx.getSourcePublicKey().toString()) {
assertTrue(completedTxIsOutbound)
assertTrue(completedTx.isOutbound())
} else {
assertFalse(completedTxIsOutbound)
assertFalse(completedTx.isOutbound())
}
completedTx.destroy()
}
Expand Down Expand Up @@ -293,6 +293,29 @@ class FFIWalletTests {
// TODO test listeners
}

@Test
fun testPartialBackup() {
val transport = FFITransportType()
val commsConfig = FFICommsConfig(
transport.getAddress(),
transport,
FFITestUtil.WALLET_DB_NAME,
walletDir,
Constants.Wallet.discoveryTimeoutSec
)
val wallet = FFIWallet(commsConfig, "")
wallet.listenerAdapter = TestListener()

val backupDir = File(walletDir, "backup")
backupDir.mkdir()
val backupFile = File(backupDir, "backupfile.sqlite3")
wallet.doPartialBackup(backupFile.absolutePath)
assertTrue(backupFile.exists())
transport.destroy()
commsConfig.destroy()
wallet.destroy()
}

class TestListener : FFIWalletListenerAdapter {
override fun onTxBroadcast(completedTx: CompletedTx) {
Logger.i("Tx Broadcast :: completed tx id %s", completedTx.id.toString())
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/cpp/jniCompletedTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ Java_com_tari_android_wallet_ffi_FFICompletedTx_jniGetStatus(
return result;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_tari_android_wallet_ffi_FFICompletedTx_jniIsOutbound(
JNIEnv *jEnv,
jobject jThis,
jobject error) {
int i = 0;
int *r = &i;
jlong lCompletedTx = GetPointerField(jEnv,jThis);
TariCompletedTransaction *pCompletedTx = reinterpret_cast<TariCompletedTransaction *>(lCompletedTx);
jboolean result = static_cast<jboolean>(completed_transaction_is_outbound(pCompletedTx, r) != 0);
setErrorCode(jEnv, error, i);
return result;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_tari_android_wallet_ffi_FFICompletedTx_jniDestroy(
Expand Down
36 changes: 17 additions & 19 deletions app/src/main/cpp/jniWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,25 +562,6 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniRemoveContact(
return result;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniIsCompletedTxOutbound(
JNIEnv *jEnv,
jobject jThis,
jobject jpCompletedTx,
jobject error) {
int i = 0;
int *r = &i;
jlong lWallet = GetPointerField(jEnv, jThis);
TariWallet *pWallet = reinterpret_cast<TariWallet *>(lWallet);
jlong lCompletedTx = GetPointerField(jEnv, jpCompletedTx);
TariCompletedTransaction *pTransaction = reinterpret_cast<TariCompletedTransaction *>(lCompletedTx);
jboolean result = static_cast<jboolean>(
wallet_is_completed_transaction_outbound(pWallet, pTransaction, r) != 0);
setErrorCode(jEnv, error, i);
return result;
}

extern "C"
JNIEXPORT jlong JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniGetCompletedTxs(
Expand Down Expand Up @@ -1131,4 +1112,21 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniGetSeedWords(
return reinterpret_cast<jlong>(pSeedwords);
}

extern "C"
JNIEXPORT void JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniDoPartialBackup(
JNIEnv *jEnv,
jobject jThis,
jstring jBackupFileTargetPath,
jobject error) {
int i = 0;
int *r = &i;
jlong lWallet = GetPointerField(jEnv, jThis);
TariWallet *pWallet = reinterpret_cast<TariWallet *>(lWallet);
const char *pTargetPath = jEnv->GetStringUTFChars(jBackupFileTargetPath, JNI_FALSE);
wallet_partial_backup(pWallet, pTargetPath, r);
setErrorCode(jEnv, error, i);
jEnv->ReleaseStringUTFChars(jBackupFileTargetPath, pTargetPath);
}

//endregion
11 changes: 11 additions & 0 deletions app/src/main/java/com/tari/android/wallet/ffi/FFICompletedTx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ internal class FFICompletedTx constructor(pointer: FFICompletedTxPtr) : FFIBase(

private external fun jniGetMessage(libError: FFIError): String
private external fun jniGetStatus(libError: FFIError): Int
private external fun jniIsOutbound(
libError: FFIError
): Boolean

private external fun jniDestroy()

// endregion
Expand Down Expand Up @@ -141,6 +145,13 @@ internal class FFICompletedTx constructor(pointer: FFICompletedTxPtr) : FFIBase(
}
}

fun isOutbound(): Boolean {
val error = FFIError()
val result = jniIsOutbound(error)
throwIf(error)
return result
}

override fun destroy() {
jniDestroy()
}
Expand Down
23 changes: 11 additions & 12 deletions app/src/main/java/com/tari/android/wallet/ffi/FFIWallet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ internal class FFIWallet(
libError: FFIError
): Boolean

private external fun jniIsCompletedTxOutbound(
completedTx: FFICompletedTx,
libError: FFIError
): Boolean

private external fun jniSendTx(
publicKeyPtr: FFIPublicKey,
amount: String,
Expand Down Expand Up @@ -225,6 +220,11 @@ internal class FFIWallet(
libError: FFIError
): FFISeedWordsPtr

private external fun jniDoPartialBackup(
backupFileTargetPath: String,
libError: FFIError
)

private external fun jniDestroy()

// endregion
Expand Down Expand Up @@ -309,13 +309,6 @@ internal class FFIWallet(
return result
}

fun isCompletedTxOutbound(completedTx: FFICompletedTx): Boolean {
val error = FFIError()
val result = jniIsCompletedTxOutbound(completedTx, error)
throwIf(error)
return result
}

fun getCompletedTxs(): FFICompletedTxs {
val error = FFIError()
val result = FFICompletedTxs(jniGetCompletedTxs(error))
Expand Down Expand Up @@ -721,6 +714,12 @@ internal class FFIWallet(
return result
}

fun doPartialBackup(backupFileTargetPath: String) {
val error = FFIError()
jniDoPartialBackup(backupFileTargetPath, error)
throwIf(error)
}

override fun destroy() {
jniDestroy()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ internal class WalletService : Service(), FFIWalletListenerAdapter, LifecycleObs
throw FFIException(message = error.message)
}

if (wallet.isCompletedTxOutbound(completedTxFFI)) {
if (completedTxFFI.isOutbound()) {
direction = OUTBOUND
val userPublicKey = PublicKey(
destinationPublicKeyFFI.toString(),
Expand Down Expand Up @@ -985,7 +985,7 @@ internal class WalletService : Service(), FFIWalletListenerAdapter, LifecycleObs
throw FFIException(message = error.message)
}

if (wallet.isCompletedTxOutbound(completedTxFFI)) {
if (completedTxFFI.isOutbound()) {
direction = OUTBOUND
val userPublicKey = PublicKey(
destinationPublicKeyFFI.toString(),
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ buildscript {
ext.buildNumber = 121
ext.versionNumber = "0.2.1"

// JNI libs
ext.jniLibsVersion = "0.14.0-rc"
ext.jniLibsHostURL = "https://tari-binaries.s3.amazonaws.com/libwallet/"
ext.supportedABIs = ["arm64-v8a", "armeabi-v7a", "x86_64"]

repositories {
google()
jcenter()
Expand Down
6 changes: 0 additions & 6 deletions download-jni-binaries.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
ext {
jniLibsVersion = "0.13.1"
jniLibsHostURL = "https://tari-binaries.s3.amazonaws.com/libwallet/"
supportedABIs = ["arm64-v8a", "armeabi-v7a", "x86_64"]
}

/**
* Downloads JNI binaries as version specified in the project-level gradle file.
*/
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip

0 comments on commit 74646c8

Please sign in to comment.