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

feat: added wrapper classes for TariTransactionKernel #638

Merged
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
1 change: 1 addition & 0 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ add_library(
jniContact.cpp
jniCommsConfig.cpp
jniCompletedTransaction.cpp
jniCompletedTransactionKernel.cpp
jniPendingInboundTransaction.cpp
jniPendingOutboundTransaction.cpp
jniCollections.cpp
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/cpp/jniCompletedTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ Java_com_tari_android_wallet_ffi_FFICompletedTx_jniGetSourcePublicKey(
return result;
}

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

extern "C"
JNIEXPORT jbyteArray JNICALL
Java_com_tari_android_wallet_ffi_FFICompletedTx_jniGetAmount(
Expand Down
102 changes: 102 additions & 0 deletions app/src/main/cpp/jniCompletedTransactionKernel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* Copyright 2020 The Tari Project
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <jni.h>
#include <android/log.h>
#include <wallet.h>
#include <string>
#include <cmath>
#include <android/log.h>
#include "jniCommon.cpp"

extern "C"
JNIEXPORT jstring JNICALL
Java_com_tari_android_wallet_ffi_FFICompletedTxKernel_jniGetExcess(
JNIEnv *jEnv,
jobject jThis,
jobject error) {
int i = 0;
int *r = &i;
jlong lKernel = GetPointerField(jEnv, jThis);
auto *pKernel = reinterpret_cast<TariTransactionKernel *>(lKernel);
const char *pStr = transaction_kernel_get_excess_hex(pKernel, r);
setErrorCode(jEnv, error, i);
jstring result = jEnv->NewStringUTF(pStr);
string_destroy(const_cast<char *>(pStr));
return result;
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_tari_android_wallet_ffi_FFICompletedTxKernel_jniGetExcessPublicNonce(
JNIEnv *jEnv,
jobject jThis,
jobject error) {
int i = 0;
int *r = &i;
jlong lKernel = GetPointerField(jEnv, jThis);
auto *pKernel = reinterpret_cast<TariTransactionKernel *>(lKernel);
const char *pStr = transaction_kernel_get_excess_public_nonce_hex(pKernel, r);
setErrorCode(jEnv, error, i);
jstring result = jEnv->NewStringUTF(pStr);
string_destroy(const_cast<char *>(pStr));
return result;
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_tari_android_wallet_ffi_FFICompletedTxKernel_jniGetExcessSignature(
JNIEnv *jEnv,
jobject jThis,
jobject error) {
int i = 0;
int *r = &i;
jlong lKernel = GetPointerField(jEnv, jThis);
auto *pKernel = reinterpret_cast<TariTransactionKernel *>(lKernel);
const char *pStr = transaction_kernel_get_excess_signature_hex(pKernel, r);
setErrorCode(jEnv, error, i);
jstring result = jEnv->NewStringUTF(pStr);
string_destroy(const_cast<char *>(pStr));
return result;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_tari_android_wallet_ffi_FFICompletedTxKernel_jniDestroy(
JNIEnv *jEnv,
jobject jThis) {
jlong lKernel = GetPointerField(jEnv, jThis);
auto *pKernel = reinterpret_cast<TariTransactionKernel *>(lKernel);
transaction_kernel_destroy(pKernel);
SetPointerField(jEnv, jThis, reinterpret_cast<jlong>(nullptr));
}
16 changes: 16 additions & 0 deletions app/src/main/cpp/jniWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniCreate(
pPassphrase = jEnv->GetStringUTFChars(jPassphrase, JNI_FALSE);
}

bool recoveryInProgress = false;
bool *recovery = &recoveryInProgress;

TariSeedWords *pSeedWords = nullptr;
if (jSeed_words != nullptr) {
jlong lSeedWords = GetPointerField(jEnv, jSeed_words);
Expand Down Expand Up @@ -512,6 +515,7 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniCreate(
invalidTxoValidationCompleteCallback,
transactionValidationCompleteCallback,
storeAndForwardMessagesReceivedCallback,
recovery,
r);

setErrorCode(jEnv, error, i);
Expand Down Expand Up @@ -1250,6 +1254,7 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniSetConfirmations(
}

//region Wallet Test Functions
/*
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniGenerateTestData(
Expand All @@ -1270,7 +1275,9 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniGenerateTestData(
jEnv->ReleaseStringUTFChars(jDatastorePath, pDatastorePath);
return result;
}
*/

/*
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniTestBroadcastTx(
Expand All @@ -1290,7 +1297,9 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniTestBroadcastTx(
setErrorCode(jEnv, error, i);
return result;
}
*/

/*
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniTestFinalizeReceivedTx(
Expand All @@ -1310,7 +1319,9 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniTestFinalizeReceivedTx(
setErrorCode(jEnv, error, i);
return result;
}
*/

/*
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniTestCompleteSentTx(
Expand All @@ -1329,7 +1340,9 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniTestCompleteSentTx(
setErrorCode(jEnv, error, i);
return result;
}
*/

/*
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniTestMineTx(
Expand All @@ -1349,7 +1362,9 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniTestMineTx(
setErrorCode(jEnv, error, i);
return result;
}
*/

/*
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_tari_android_wallet_ffi_FFIWallet_jniTestReceiveTx(
Expand All @@ -1364,6 +1379,7 @@ Java_com_tari_android_wallet_ffi_FFIWallet_jniTestReceiveTx(
setErrorCode(jEnv, error, i);
return result;
}
*/

extern "C"
JNIEXPORT jbyteArray JNICALL
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/com/tari/android/wallet/ffi/FFICompletedTx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class FFICompletedTx() : FFIBase() {
private external fun jniGetDestinationPublicKey(
libError: FFIError
): FFIPointer

private external fun jniGetTransactionKernel(
libError: FFIError
): FFIPointer
private external fun jniGetSourcePublicKey(
libError: FFIError
): FFIPointer
Expand Down Expand Up @@ -143,6 +145,13 @@ internal class FFICompletedTx() : FFIBase() {
return result
}

fun getTransactionKernel(): FFICompletedTxKernel {
val error = FFIError()
val result = FFICompletedTxKernel(jniGetTransactionKernel(error))
throwIf(error)
return result
}

override fun destroy() {
jniDestroy()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright 2020 The Tari Project
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of
* its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.tari.android.wallet.ffi

/**
* Wrapper for native TariTransactionKernel type.
*
* @author The Tari Development Team
*/
internal class FFICompletedTxKernel() : FFIBase() {

private external fun jniGetExcess(libError: FFIError): String
private external fun jniGetExcessPublicNonce(libError: FFIError): String
private external fun jniGetExcessSignature(libError: FFIError): String
private external fun jniDestroy()

// endregion
constructor(pointer: FFIPointer): this() {
this.pointer = pointer
}

fun getExcess(): String {
val error = FFIError()
val result = jniGetExcess(error)
throwIf(error)
return result
}

fun getExcessPublicNonce(): String {
val error = FFIError()
val result = jniGetExcessPublicNonce(error)
throwIf(error)
return result
}

fun getExcessSignature(): String {
val error = FFIError()
val result = jniGetExcessSignature(error)
throwIf(error)
return result
}

override fun destroy() {
jniDestroy()
}

}
Loading