Skip to content

Commit

Permalink
Merge pull request #613 from tari-project/wallet_confirmations
Browse files Browse the repository at this point in the history
Added confirmation settings
  • Loading branch information
kukabi authored Feb 19, 2021
2 parents 6af3ded + da7f336 commit 74e76a9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/src/main/cpp/jniWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,4 +1231,41 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniRemoveKeyValue(
return result;
}

extern "C"
JNIEXPORT jbyteArray JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniGetConfirmations(
JNIEnv *jEnv,
jobject jThis,
jobject error) {
int i = 0;
int *r = &i;
jlong lWallet = GetPointerField(jEnv, jThis);
auto *pWallet = reinterpret_cast<TariWallet *>(lWallet);
jbyteArray result = getBytesFromUnsignedLongLong(
jEnv,
wallet_get_num_confirmations_required(pWallet, r)
);
setErrorCode(jEnv, error, i);
return result;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniSetConfirmations(
JNIEnv *jEnv,
jobject jThis,
jstring jNumber,
jobject error) {
int i = 0;
int *r = &i;
jlong lWallet = GetPointerField(jEnv, jThis);
auto *pWallet = reinterpret_cast<TariWallet *>(lWallet);
const char *nativeString = jEnv->GetStringUTFChars(jNumber, JNI_FALSE);
char *pEnd;
unsigned long long number = strtoull(nativeString, &pEnd, 10);
wallet_set_num_confirmations_required(pWallet, number, r);
jEnv->ReleaseStringUTFChars(jNumber, nativeString);
setErrorCode(jEnv, error, i);
}

//endregion
27 changes: 27 additions & 0 deletions app/src/main/java/com/tari/android/wallet/ffi/FFIWallet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ internal class FFIWallet(
libError: FFIError
): Boolean

private external fun jniGetConfirmations(
libError: FFIError
): ByteArray

private external fun jniSetConfirmations(
number: String,
libError: FFIError
)

private external fun jniDestroy()

// endregion
Expand Down Expand Up @@ -790,6 +799,24 @@ internal class FFIWallet(
jniLogMessage(message)
}

fun getConfirmations(): BigInteger {
val error = FFIError()
val bytes = jniGetConfirmations(
error
)
throwIf(error)
return BigInteger(1, bytes)
}

fun setConfirmations(number: BigInteger) {
val error = FFIError()
val bytes = jniSetConfirmations(
number.toString(),
error
)
throwIf(error)
}

override fun destroy() {
listener = null
jniDestroy()
Expand Down

0 comments on commit 74e76a9

Please sign in to comment.