react-native-nitro-ark 0.0.77-rc.1 → 0.0.77-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include <optional>
|
|
6
6
|
#include <stdexcept>
|
|
7
7
|
#include <string>
|
|
8
|
+
#include <type_traits>
|
|
8
9
|
#include <vector>
|
|
9
10
|
|
|
10
11
|
#include "generated/ark_cxx.h"
|
|
@@ -35,30 +36,39 @@ void ThrowJavaException(JNIEnv* env, const char* message) {
|
|
|
35
36
|
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Throwing Java exception: %s", message);
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (cls == nullptr)
|
|
39
|
+
template <typename T, typename J>
|
|
40
|
+
std::optional<T> GetOptionalNumber(JNIEnv* env, jobject obj, const char* className, const char* methodName,
|
|
41
|
+
const char* methodSig) {
|
|
42
|
+
if (obj == nullptr) {
|
|
43
43
|
return std::nullopt;
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
}
|
|
45
|
+
jclass cls = env->FindClass(className);
|
|
46
|
+
if (cls == nullptr) {
|
|
46
47
|
return std::nullopt;
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
std::optional<T> result = std::nullopt;
|
|
51
|
+
jmethodID mid = env->GetMethodID(cls, methodName, methodSig);
|
|
52
|
+
if (mid != nullptr) {
|
|
53
|
+
if constexpr (std::is_same_v<J, jint>) {
|
|
54
|
+
jint value = env->CallIntMethod(obj, mid);
|
|
55
|
+
result = static_cast<T>(value);
|
|
56
|
+
} else if constexpr (std::is_same_v<J, jlong>) {
|
|
57
|
+
jlong value = env->CallLongMethod(obj, mid);
|
|
58
|
+
result = static_cast<T>(value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
env->DeleteLocalRef(cls);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
std::optional<int32_t> GetOptionalInt(JNIEnv* env, jobject obj) {
|
|
67
|
+
return GetOptionalNumber<int32_t, jint>(env, obj, "java/lang/Integer", "intValue", "()I");
|
|
49
68
|
}
|
|
50
69
|
|
|
51
70
|
std::optional<int64_t> GetOptionalLong(JNIEnv* env, jobject obj) {
|
|
52
|
-
|
|
53
|
-
return std::nullopt;
|
|
54
|
-
jclass cls = env->FindClass("java/lang/Long");
|
|
55
|
-
if (cls == nullptr)
|
|
56
|
-
return std::nullopt;
|
|
57
|
-
jmethodID mid = env->GetMethodID(cls, "longValue", "()J");
|
|
58
|
-
if (mid == nullptr)
|
|
59
|
-
return std::nullopt;
|
|
60
|
-
jlong value = env->CallLongMethod(obj, mid);
|
|
61
|
-
return static_cast<int64_t>(value);
|
|
71
|
+
return GetOptionalNumber<int64_t, jlong>(env, obj, "java/lang/Long", "longValue", "()J");
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
void HandleException(JNIEnv* env, const std::exception& e) {
|
|
@@ -232,7 +242,7 @@ JNIEXPORT void JNICALL Java_com_margelo_nitro_nitroark_NitroArkNative_loadWallet
|
|
|
232
242
|
opts.mnemonic = mnemonic;
|
|
233
243
|
|
|
234
244
|
auto birthday_height = GetOptionalInt(env, jBirthdayHeight);
|
|
235
|
-
uint32_t birthday_height_val = 0;
|
|
245
|
+
thread_local uint32_t birthday_height_val = 0;
|
|
236
246
|
if (birthday_height.has_value()) {
|
|
237
247
|
birthday_height_val = static_cast<uint32_t>(birthday_height.value());
|
|
238
248
|
opts.birthday_height = &birthday_height_val;
|
|
@@ -275,8 +285,7 @@ JNIEXPORT void JNICALL Java_com_margelo_nitro_nitroark_NitroArkNative_loadWallet
|
|
|
275
285
|
}
|
|
276
286
|
}
|
|
277
287
|
|
|
278
|
-
JNIEXPORT void JNICALL Java_com_margelo_nitro_nitroark_NitroArkNative_maintenance(JNIEnv* env,
|
|
279
|
-
jobject /*thiz*/) {
|
|
288
|
+
JNIEXPORT void JNICALL Java_com_margelo_nitro_nitroark_NitroArkNative_maintenance(JNIEnv* env, jobject /*thiz*/) {
|
|
280
289
|
try {
|
|
281
290
|
bark_cxx::maintenance();
|
|
282
291
|
} catch (const std::exception& e) {
|
|
Binary file
|
|
Binary file
|