|
|
|
@ -37,7 +37,7 @@ static JavaVM *cachedJVM;
|
|
|
|
|
static jclass class_ArrayList;
|
|
|
|
|
static jclass class_WalletListener;
|
|
|
|
|
static jclass class_TransactionInfo;
|
|
|
|
|
static jclass class_TransactionInfo$Transfer;
|
|
|
|
|
static jclass class_Transfer;
|
|
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
|
|
|
|
|
cachedJVM = jvm;
|
|
|
|
@ -52,8 +52,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
|
|
|
|
|
jenv->FindClass("java/util/ArrayList")));
|
|
|
|
|
class_TransactionInfo = static_cast<jclass>(jenv->NewGlobalRef(
|
|
|
|
|
jenv->FindClass("com/m2049r/xmrwallet/model/TransactionInfo")));
|
|
|
|
|
class_TransactionInfo$Transfer = static_cast<jclass>(jenv->NewGlobalRef(
|
|
|
|
|
jenv->FindClass("com/m2049r/xmrwallet/model/TransactionInfo$Transfer")));
|
|
|
|
|
class_Transfer = static_cast<jclass>(jenv->NewGlobalRef(
|
|
|
|
|
jenv->FindClass("com/m2049r/xmrwallet/model/Transfer")));
|
|
|
|
|
class_WalletListener = static_cast<jclass>(jenv->NewGlobalRef(
|
|
|
|
|
jenv->FindClass("com/m2049r/xmrwallet/model/WalletListener")));
|
|
|
|
|
return JNI_VERSION_1_6;
|
|
|
|
@ -174,7 +174,6 @@ struct MyWalletListener : Bitmonero::WalletListener {
|
|
|
|
|
detachJVM(jenv, envStat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief refreshed - called when wallet refreshed by background thread or explicitly refreshed by calling "refresh" synchronously
|
|
|
|
|
*/
|
|
|
|
@ -189,7 +188,6 @@ struct MyWalletListener : Bitmonero::WalletListener {
|
|
|
|
|
jmethodID listenerClass_refreshed = jenv->GetMethodID(class_WalletListener, "refreshed",
|
|
|
|
|
"()V");
|
|
|
|
|
jenv->CallVoidMethod(jlistener, listenerClass_refreshed);
|
|
|
|
|
|
|
|
|
|
detachJVM(jenv, envStat);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -767,9 +765,6 @@ Java_com_m2049r_xmrwallet_model_Wallet_createTransactionJ(JNIEnv *env, jobject i
|
|
|
|
|
const char *_payment_id = env->GetStringUTFChars(payment_id, JNI_FALSE);
|
|
|
|
|
Bitmonero::PendingTransaction::Priority _priority =
|
|
|
|
|
static_cast<Bitmonero::PendingTransaction::Priority>(priority);
|
|
|
|
|
|
|
|
|
|
LOGD("Priority_Last is %i", static_cast<int>(Bitmonero::PendingTransaction::Priority_Last));
|
|
|
|
|
|
|
|
|
|
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
|
|
|
|
|
|
|
|
|
|
Bitmonero::PendingTransaction *tx = wallet->createTransaction(_dst_addr, _payment_id,
|
|
|
|
@ -883,9 +878,58 @@ Java_com_m2049r_xmrwallet_model_TransactionHistory_getTransactionByIdJ(JNIEnv *e
|
|
|
|
|
return reinterpret_cast<jlong>(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobject newTransferInstance(JNIEnv *env, uint64_t amount, const std::string &address) {
|
|
|
|
|
jmethodID c = env->GetMethodID(class_Transfer, "<init>",
|
|
|
|
|
"(JLjava/lang/String;)V");
|
|
|
|
|
jstring _address = env->NewStringUTF(address.c_str());
|
|
|
|
|
jobject transfer = env->NewObject(class_Transfer, c, amount, _address);
|
|
|
|
|
env->DeleteLocalRef(_address);
|
|
|
|
|
return transfer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobject newTransferList(JNIEnv *env, Bitmonero::TransactionInfo *info) {
|
|
|
|
|
const std::vector<Bitmonero::TransactionInfo::Transfer> &transfers = info->transfers();
|
|
|
|
|
// make new ArrayList
|
|
|
|
|
|
|
|
|
|
jmethodID java_util_ArrayList_ = env->GetMethodID(class_ArrayList, "<init>", "(I)V");
|
|
|
|
|
jmethodID java_util_ArrayList_add = env->GetMethodID(class_ArrayList, "add",
|
|
|
|
|
"(Ljava/lang/Object;)Z");
|
|
|
|
|
jobject result = env->NewObject(class_ArrayList, java_util_ArrayList_, transfers.size());
|
|
|
|
|
// create Transfer objects and stick them in the List
|
|
|
|
|
LOGD("size %i", transfers.size());
|
|
|
|
|
for (const Bitmonero::TransactionInfo::Transfer &s: transfers) {
|
|
|
|
|
jobject element = newTransferInstance(env, s.amount, s.address);
|
|
|
|
|
env->CallBooleanMethod(result, java_util_ArrayList_add, element);
|
|
|
|
|
env->DeleteLocalRef(element);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobject newTransactionInfo(JNIEnv *env, Bitmonero::TransactionInfo *info) {
|
|
|
|
|
jmethodID c = env->GetMethodID(class_TransactionInfo, "<init>", "(J)V");
|
|
|
|
|
return env->NewObject(class_TransactionInfo, c, reinterpret_cast<jlong>(info));
|
|
|
|
|
jmethodID c = env->GetMethodID(class_TransactionInfo, "<init>",
|
|
|
|
|
"(IZZJJJLjava/lang/String;JLjava/lang/String;JLjava/util/List;)V");
|
|
|
|
|
//"(IZZJJJLjava/lang/String;JLjava/lang/String;J)V");
|
|
|
|
|
LOGD("newTransactionInfo %s", info->hash().c_str());
|
|
|
|
|
jobject transfers = newTransferList(env, info);
|
|
|
|
|
jstring _hash = env->NewStringUTF(info->hash().c_str());
|
|
|
|
|
jstring _paymentId = env->NewStringUTF(info->paymentId().c_str());
|
|
|
|
|
jobject result = env->NewObject(class_TransactionInfo, c,
|
|
|
|
|
info->direction(),
|
|
|
|
|
info->isPending(),
|
|
|
|
|
info->isFailed(),
|
|
|
|
|
info->amount(),
|
|
|
|
|
info->fee(),
|
|
|
|
|
info->blockHeight(),
|
|
|
|
|
_hash,
|
|
|
|
|
static_cast<jlong> (info->timestamp()),
|
|
|
|
|
_paymentId,
|
|
|
|
|
info->confirmations(),
|
|
|
|
|
transfers);
|
|
|
|
|
env->DeleteLocalRef(transfers);
|
|
|
|
|
env->DeleteLocalRef(_hash);
|
|
|
|
|
env->DeleteLocalRef(_paymentId);
|
|
|
|
|
LOGD("newTransactionInfo X");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
@ -896,7 +940,7 @@ jobject cpp2java(JNIEnv *env, std::vector<Bitmonero::TransactionInfo *> vector)
|
|
|
|
|
jmethodID java_util_ArrayList_add = env->GetMethodID(class_ArrayList, "add",
|
|
|
|
|
"(Ljava/lang/Object;)Z");
|
|
|
|
|
|
|
|
|
|
//LOGD(std::to_string(vector.size()).c_str());
|
|
|
|
|
LOGD("%s", std::to_string(vector.size()).c_str());
|
|
|
|
|
jobject arrayList = env->NewObject(class_ArrayList, java_util_ArrayList_, vector.size());
|
|
|
|
|
for (Bitmonero::TransactionInfo *s: vector) {
|
|
|
|
|
jobject info = newTransactionInfo(env, s);
|
|
|
|
@ -907,31 +951,15 @@ jobject cpp2java(JNIEnv *env, std::vector<Bitmonero::TransactionInfo *> vector)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
|
Java_com_m2049r_xmrwallet_model_TransactionHistory_getAll(JNIEnv *env, jobject instance) {
|
|
|
|
|
Bitmonero::TransactionHistory *history = getHandle<Bitmonero::TransactionHistory>(env,
|
|
|
|
|
instance);
|
|
|
|
|
return cpp2java(env, history->getAll());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_com_m2049r_xmrwallet_model_TransactionHistory_refresh(JNIEnv *env, jobject instance) {
|
|
|
|
|
Java_com_m2049r_xmrwallet_model_TransactionHistory_refreshJ(JNIEnv *env, jobject instance) {
|
|
|
|
|
Bitmonero::TransactionHistory *history = getHandle<Bitmonero::TransactionHistory>(env,
|
|
|
|
|
instance);
|
|
|
|
|
LOGD("history->refresh()");
|
|
|
|
|
history->refresh();
|
|
|
|
|
LOGD("history->refresh() done");
|
|
|
|
|
return cpp2java(env, history->getAll());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* this is wrong - history object belongs to wallet
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
|
Java_com_m2049r_xmrwallet_model_TransactionHistory_dispose(JNIEnv *env, jobject instance) {
|
|
|
|
|
Bitmonero::TransactionHistory *history = getHandle<Bitmonero::TransactionHistory>(env,
|
|
|
|
|
instance);
|
|
|
|
|
if (history != nullptr) {
|
|
|
|
|
setHandle<long>(env, instance, 0);
|
|
|
|
|
delete history;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// TransactionInfo
|
|
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
|
Java_com_m2049r_xmrwallet_model_TransactionInfo_getDirectionJ(JNIEnv *env, jobject instance) {
|
|
|
|
@ -974,7 +1002,7 @@ Java_com_m2049r_xmrwallet_model_TransactionInfo_getConfirmations(JNIEnv *env, jo
|
|
|
|
|
Bitmonero::TransactionInfo *info = getHandle<Bitmonero::TransactionInfo>(env, instance);
|
|
|
|
|
return info->confirmations();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO remove all these
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
|
Java_com_m2049r_xmrwallet_model_TransactionInfo_getHash(JNIEnv *env, jobject instance) {
|
|
|
|
|
Bitmonero::TransactionInfo *info = getHandle<Bitmonero::TransactionInfo>(env, instance);
|
|
|
|
@ -993,36 +1021,6 @@ Java_com_m2049r_xmrwallet_model_TransactionInfo_getPaymentId(JNIEnv *env, jobjec
|
|
|
|
|
return env->NewStringUTF(info->paymentId().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobject newTransferInstance(JNIEnv *env, jobject transactionInfo, long amount,
|
|
|
|
|
const std::string &address) {
|
|
|
|
|
|
|
|
|
|
jmethodID methodID = env->GetMethodID(class_TransactionInfo$Transfer, "<init>",
|
|
|
|
|
"(JL/java.lang/String;)V");
|
|
|
|
|
jstring _address = env->NewStringUTF(address.c_str());
|
|
|
|
|
jobject transfer = env->NewObject(class_TransactionInfo$Transfer, methodID, amount, _address);
|
|
|
|
|
env->DeleteLocalRef(_address);
|
|
|
|
|
return transfer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
|
Java_com_m2049r_xmrwallet_model_TransactionInfo_getTransfersJ(JNIEnv *env, jobject instance) {
|
|
|
|
|
Bitmonero::TransactionInfo *info = getHandle<Bitmonero::TransactionInfo>(env, instance);
|
|
|
|
|
const std::vector<Bitmonero::TransactionInfo::Transfer> &transfers = info->transfers();
|
|
|
|
|
// make new ArrayList
|
|
|
|
|
|
|
|
|
|
jmethodID java_util_ArrayList_ = env->GetMethodID(class_ArrayList, "<init>", "(I)V");
|
|
|
|
|
jmethodID java_util_ArrayList_add = env->GetMethodID(class_ArrayList, "add",
|
|
|
|
|
"(Ljava/lang/Object;)Z");
|
|
|
|
|
jobject result = env->NewObject(class_ArrayList, java_util_ArrayList_, transfers.size());
|
|
|
|
|
// create Transfer objects and stick them in the List
|
|
|
|
|
for (const Bitmonero::TransactionInfo::Transfer &s: transfers) {
|
|
|
|
|
jobject element = newTransferInstance(env, instance, s.amount, s.address);
|
|
|
|
|
env->CallBooleanMethod(result, java_util_ArrayList_add, element);
|
|
|
|
|
env->DeleteLocalRef(element);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
|
Java_com_m2049r_xmrwallet_model_TransactionInfo_getTransferCount(JNIEnv *env, jobject instance) {
|
|
|
|
|
Bitmonero::TransactionInfo *info = getHandle<Bitmonero::TransactionInfo>(env, instance);
|
|
|
|
|