mirror of
https://github.com/mollyim/monero-wallet-sdk.git
synced 2024-10-01 03:45:36 -04:00
lib: start mnemonics wrapper development
This commit is contained in:
parent
845b556150
commit
bcbc9c33e3
@ -48,26 +48,45 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
set(CMAKE_VISIBILITY_INLINES_HIDDEN true)
|
||||
|
||||
# Project library
|
||||
add_library(${PROJECT_NAME} SHARED)
|
||||
### Project libraries
|
||||
|
||||
target_sources(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC
|
||||
http_client.cc
|
||||
jni_cache.cc
|
||||
jni_loader.cc
|
||||
jvm.cc
|
||||
logging.cc
|
||||
wallet.cc
|
||||
set(COMMON_SOURCES
|
||||
common/jvm.cc
|
||||
)
|
||||
|
||||
set(WALLET_SOURCES
|
||||
wallet/http_client.cc
|
||||
wallet/jni_cache.cc
|
||||
wallet/jni_loader.cc
|
||||
wallet/logging.cc
|
||||
wallet/wallet.cc
|
||||
)
|
||||
|
||||
add_library(monero_wallet SHARED ${COMMON_SOURCES} ${WALLET_SOURCES})
|
||||
|
||||
target_link_libraries(
|
||||
${PROJECT_NAME}
|
||||
monero_wallet
|
||||
PRIVATE
|
||||
Monero::wallet_api
|
||||
Monero::wallet2
|
||||
log
|
||||
)
|
||||
|
||||
set(MNEMONICS_SOURCES
|
||||
mnemonics/jni_loader.cc
|
||||
)
|
||||
|
||||
add_library(monero_mnemonics SHARED ${COMMON_SOURCES} ${MNEMONICS_SOURCES})
|
||||
|
||||
target_link_libraries(
|
||||
monero_mnemonics
|
||||
PRIVATE
|
||||
Monero::electrum_words
|
||||
log
|
||||
)
|
||||
|
||||
target_include_directories(monero_wallet PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
target_include_directories(monero_mnemonics PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
# Hide symbols from statically-linked dependencies
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
|
||||
set_target_properties(monero_wallet PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
|
||||
set_target_properties(monero_mnemonics PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
|
||||
|
@ -42,7 +42,6 @@ ExternalProject_Add(
|
||||
--with-date_time
|
||||
--with-filesystem
|
||||
--with-iostreams
|
||||
--with-program_options
|
||||
--with-regex
|
||||
--with-serialization
|
||||
--with-system
|
||||
@ -53,7 +52,6 @@ ExternalProject_Add(
|
||||
"<INSTALL_DIR>/lib/libboost_date_time.a"
|
||||
"<INSTALL_DIR>/lib/libboost_filesystem.a"
|
||||
"<INSTALL_DIR>/lib/libboost_iostreams.a"
|
||||
"<INSTALL_DIR>/lib/libboost_program_options.a"
|
||||
"<INSTALL_DIR>/lib/libboost_regex.a"
|
||||
"<INSTALL_DIR>/lib/libboost_serialization.a"
|
||||
"<INSTALL_DIR>/lib/libboost_system.a"
|
||||
@ -88,7 +86,6 @@ link_boost_library(chrono)
|
||||
link_boost_library(date_time)
|
||||
link_boost_library(filesystem system)
|
||||
link_boost_library(iostreams)
|
||||
link_boost_library(program_options)
|
||||
link_boost_library(regex)
|
||||
link_boost_library(serialization)
|
||||
link_boost_library(system)
|
||||
|
10
lib/android/src/main/cpp/common/arraysize.h
Normal file
10
lib/android/src/main/cpp/common/arraysize.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef COMMON_ARRAYSIZE_H
|
||||
#define COMMON_ARRAYSIZE_H
|
||||
|
||||
// The arraysize(arr) macro returns the # of elements in an array arr.
|
||||
template <typename T, size_t N>
|
||||
char (&ArraySizeHelper(T (&array)[N]))[N];
|
||||
|
||||
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
||||
|
||||
#endif // COMMON_ARRAYSIZE_H
|
@ -1,5 +1,5 @@
|
||||
#ifndef COMMON_H_
|
||||
#define COMMON_H_
|
||||
#ifndef COMMON_DEBUG_H_
|
||||
#define COMMON_DEBUG_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <android/log.h>
|
||||
@ -47,10 +47,4 @@
|
||||
#define __print_assert(cond, tag, fmt...) \
|
||||
__android_log_assert(cond, tag, __second(0, ## fmt, NULL) __rest(fmt))
|
||||
|
||||
// The arraysize(arr) macro returns the # of elements in an array arr.
|
||||
template <typename T, size_t N>
|
||||
char (&ArraySizeHelper(T (&array)[N]))[N];
|
||||
|
||||
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
||||
|
||||
#endif // COMMON_H_
|
||||
#endif // COMMON_DEBUG_H_
|
@ -1,5 +1,5 @@
|
||||
#ifndef ERASER_H_
|
||||
#define ERASER_H_
|
||||
#ifndef COMMON_ERASER_H_
|
||||
#define COMMON_ERASER_H_
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
@ -35,4 +35,4 @@ class Eraser {
|
||||
|
||||
} // namespace monero
|
||||
|
||||
#endif // ERASER_H_
|
||||
#endif // COMMON_ERASER_H_
|
@ -1,5 +1,5 @@
|
||||
#ifndef JVM_H_
|
||||
#define JVM_H_
|
||||
#ifndef COMMON_JVM_H_
|
||||
#define COMMON_JVM_H_
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
namespace monero {
|
||||
|
||||
@ -323,4 +323,4 @@ std::vector<char> jvmToNativeByteArray(JNIEnv* env,
|
||||
|
||||
} // namespace monero
|
||||
|
||||
#endif // JVM_H_
|
||||
#endif // COMMON_JVM_H_
|
16
lib/android/src/main/cpp/mnemonics/jni_loader.cc
Normal file
16
lib/android/src/main/cpp/mnemonics/jni_loader.cc
Normal file
@ -0,0 +1,16 @@
|
||||
#include "common/jvm.h"
|
||||
|
||||
namespace monero {
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint
|
||||
JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
JNIEnv* env = initializeJvm(vm, JNI_VERSION_1_6);
|
||||
if (env == nullptr) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
} // namespace monero
|
@ -25,6 +25,7 @@ macro(monero_find_all_headers headers_found module_root_dir)
|
||||
endmacro()
|
||||
|
||||
add_subdirectory(easylogging)
|
||||
add_subdirectory(randomx)
|
||||
add_subdirectory(electrum_words)
|
||||
add_subdirectory(lmdb)
|
||||
add_subdirectory(wallet_api)
|
||||
add_subdirectory(randomx)
|
||||
add_subdirectory(wallet2)
|
||||
|
@ -0,0 +1,50 @@
|
||||
set(ELECTRUM_WORDS_SOURCES
|
||||
src/mnemonics/electrum-words.cpp
|
||||
)
|
||||
|
||||
set(ELECTRUM_WORDS_OVERRIDES
|
||||
mlog_override.cc
|
||||
)
|
||||
|
||||
set(ELECTRUM_WORDS_INCLUDES
|
||||
contrib/epee/include
|
||||
src
|
||||
src/mnemonics
|
||||
)
|
||||
|
||||
list(TRANSFORM ELECTRUM_WORDS_SOURCES PREPEND "${MONERO_DIR}/")
|
||||
list(TRANSFORM ELECTRUM_WORDS_INCLUDES PREPEND "${MONERO_DIR}/")
|
||||
|
||||
set(EASYLOGGING_SOURCE_DIR "${MONERO_DIR}/external/easylogging++")
|
||||
|
||||
add_library(
|
||||
electrum_words STATIC ${ELECTRUM_WORDS_SOURCES} ${ELECTRUM_WORDS_OVERRIDES}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
electrum_words
|
||||
PUBLIC
|
||||
"${ELECTRUM_WORDS_INCLUDES}"
|
||||
)
|
||||
|
||||
# Include external project header directories here. Workaround for:
|
||||
# https://gitlab.kitware.com/cmake/cmake/issues/15052
|
||||
target_include_directories(
|
||||
electrum_words
|
||||
SYSTEM PUBLIC
|
||||
"${BOOST_INCLUDE_DIR}"
|
||||
"${LIBSODIUM_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
electrum_words
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
Monero::easylogging
|
||||
Libsodium::libsodium
|
||||
)
|
||||
|
||||
# Mnemonics depends on boost::crc that is a header-only library
|
||||
add_dependencies(electrum_words Boost)
|
||||
|
||||
add_library(Monero::electrum_words ALIAS electrum_words)
|
@ -0,0 +1,10 @@
|
||||
#include <string>
|
||||
|
||||
#include "easylogging++.h"
|
||||
|
||||
void mlog_configure(const std::string& filename_base,
|
||||
bool console,
|
||||
const std::size_t max_log_file_size,
|
||||
const std::size_t max_log_files) {
|
||||
// No-op.
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
set(WALLET_API_SOURCES
|
||||
set(WALLET2_SOURCES
|
||||
contrib/epee/src/abstract_http_client.cpp
|
||||
contrib/epee/src/byte_slice.cpp
|
||||
contrib/epee/src/byte_stream.cpp
|
||||
@ -92,20 +92,20 @@ set(WALLET_API_SOURCES
|
||||
)
|
||||
|
||||
if(ANDROID_ABI STREQUAL "x86_64")
|
||||
list(APPEND WALLET_API_SOURCES src/crypto/CryptonightR_template.S)
|
||||
list(APPEND WALLET2_SOURCES src/crypto/CryptonightR_template.S)
|
||||
endif()
|
||||
|
||||
set(WALLET_API_OVERRIDES
|
||||
set(WALLET2_OVERRIDES
|
||||
mlog_override.cc
|
||||
i18n_override.cc
|
||||
perf_timer_override.cc
|
||||
)
|
||||
|
||||
set(WALLET_API_PRECOMPILED_HEADERS
|
||||
set(WALLET2_PRECOMPILED_HEADERS
|
||||
boringssl_compat.h
|
||||
)
|
||||
|
||||
set(WALLET_API_INCLUDES
|
||||
set(WALLET2_INCLUDES
|
||||
contrib/epee/include
|
||||
external
|
||||
external/rapidjson/include
|
||||
@ -117,8 +117,8 @@ set(WALLET_API_INCLUDES
|
||||
src/wallet/api
|
||||
)
|
||||
|
||||
list(TRANSFORM WALLET_API_SOURCES PREPEND "${MONERO_DIR}/")
|
||||
list(TRANSFORM WALLET_API_INCLUDES PREPEND "${MONERO_DIR}/")
|
||||
list(TRANSFORM WALLET2_SOURCES PREPEND "${MONERO_DIR}/")
|
||||
list(TRANSFORM WALLET2_INCLUDES PREPEND "${MONERO_DIR}/")
|
||||
|
||||
set(GENERATED_HEADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_include")
|
||||
|
||||
@ -129,26 +129,26 @@ configure_file("${MONERO_DIR}/src/crypto/wallet/empty.h.in" "${GENERATED_HEADERS
|
||||
add_definitions(-DFORCE_USE_HEAP=1)
|
||||
|
||||
add_library(
|
||||
wallet_api STATIC ${WALLET_API_SOURCES} ${WALLET_API_OVERRIDES}
|
||||
wallet2 STATIC ${WALLET2_SOURCES} ${WALLET2_OVERRIDES}
|
||||
)
|
||||
|
||||
target_precompile_headers(
|
||||
wallet_api
|
||||
wallet2
|
||||
PRIVATE
|
||||
"${WALLET_API_PRECOMPILED_HEADERS}"
|
||||
"${WALLET2_PRECOMPILED_HEADERS}"
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
wallet_api
|
||||
wallet2
|
||||
PUBLIC
|
||||
"${WALLET_API_INCLUDES}"
|
||||
"${WALLET2_INCLUDES}"
|
||||
"${GENERATED_HEADERS_DIR}"
|
||||
)
|
||||
|
||||
# Include external project header directories here. Workaround for:
|
||||
# https://gitlab.kitware.com/cmake/cmake/issues/15052
|
||||
target_include_directories(
|
||||
wallet_api
|
||||
wallet2
|
||||
SYSTEM PUBLIC
|
||||
"${BOOST_INCLUDE_DIR}"
|
||||
"${LIBSODIUM_INCLUDE_DIR}"
|
||||
@ -157,21 +157,19 @@ target_include_directories(
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
wallet_api
|
||||
wallet2
|
||||
PUBLIC
|
||||
Monero::easylogging
|
||||
PRIVATE
|
||||
Monero::lmdb
|
||||
Monero::randomx
|
||||
OpenSSL::SSL
|
||||
# Boost::chrono
|
||||
Boost::filesystem
|
||||
Boost::iostreams
|
||||
# Boost::program_options
|
||||
Boost::serialization
|
||||
Boost::thread
|
||||
Libsodium::libsodium
|
||||
Unbound::unbound
|
||||
)
|
||||
|
||||
add_library(Monero::wallet_api ALIAS wallet_api)
|
||||
add_library(Monero::wallet2 ALIAS wallet2)
|
@ -1,5 +1,5 @@
|
||||
#ifndef FD_H_
|
||||
#define FD_H_
|
||||
#ifndef WALLET_FD_H_
|
||||
#define WALLET_FD_H_
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
@ -8,8 +8,9 @@
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
|
||||
#include "common/jvm.h"
|
||||
|
||||
#include "jni_cache.h"
|
||||
#include "jvm.h"
|
||||
|
||||
namespace monero {
|
||||
|
||||
@ -27,8 +28,7 @@ class ScopedFd {
|
||||
|
||||
ScopedFd(JNIEnv* env, const JvmRef<jobject>& parcel_file_descriptor) : m_fd(-1) {
|
||||
if (!parcel_file_descriptor.is_null()) {
|
||||
m_fd = parcel_file_descriptor.callIntMethod(env,
|
||||
ParcelFileDescriptor_detachFd);
|
||||
m_fd = parcel_file_descriptor.callIntMethod(env, ParcelFileDescriptor_detachFd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,4 +67,4 @@ class ScopedFd {
|
||||
|
||||
} // namespace monero
|
||||
|
||||
#endif // FD_H_
|
||||
#endif // WALLET_FD_H_
|
@ -1,7 +1,6 @@
|
||||
#include "http_client.h"
|
||||
|
||||
#include "jni_cache.h"
|
||||
#include "fd.h"
|
||||
|
||||
namespace monero {
|
||||
|
@ -1,7 +1,8 @@
|
||||
#ifndef HTTP_CLIENT_H_
|
||||
#define HTTP_CLIENT_H_
|
||||
#ifndef WALLET_HTTP_CLIENT_H_
|
||||
#define WALLET_HTTP_CLIENT_H_
|
||||
|
||||
#include "common/jvm.h"
|
||||
|
||||
#include "jvm.h"
|
||||
#include "fd.h"
|
||||
|
||||
#include "net/abstract_http_client.h"
|
||||
@ -77,4 +78,4 @@ class RemoteNodeClientFactory : public HttpClientFactory {
|
||||
|
||||
} // namespace monero
|
||||
|
||||
#endif // HTTP_CLIENT_H_
|
||||
#endif // WALLET_HTTP_CLIENT_H_
|
@ -1,7 +1,7 @@
|
||||
#ifndef JNI_CACHE_H_
|
||||
#define JNI_CACHE_H_
|
||||
#ifndef WALLET_JNI_CACHE_H__
|
||||
#define WALLET_JNI_CACHE_H__
|
||||
|
||||
#include "jvm.h"
|
||||
#include "common/jvm.h"
|
||||
|
||||
namespace monero {
|
||||
|
||||
@ -24,4 +24,4 @@ extern jmethodID ParcelFileDescriptor_detachFd;
|
||||
|
||||
} // namespace monero
|
||||
|
||||
#endif // JNI_CACHE_H_
|
||||
#endif // WALLET_JNI_CACHE_H__
|
@ -1,5 +1,7 @@
|
||||
#include "jni_cache.h"
|
||||
#include "jvm.h"
|
||||
|
||||
#include "common/jvm.h"
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
namespace monero {
|
@ -82,7 +82,7 @@ void JvmLogSink::set_logger(JNIEnv* env, const JvmRef<jobject>& logger) {
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_im_molly_monero_NativeKt_nativeSetLogger(
|
||||
Java_im_molly_monero_NativeLoaderKt_nativeSetLogger(
|
||||
JNIEnv* env,
|
||||
jclass clazz,
|
||||
jobject j_logger) {
|
@ -1,11 +1,11 @@
|
||||
#ifndef LOGGING_H_
|
||||
#define LOGGING_H_
|
||||
#ifndef WALLET_LOGGING_H_
|
||||
#define WALLET_LOGGING_H_
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "jvm.h"
|
||||
#include "common/jvm.h"
|
||||
|
||||
namespace monero {
|
||||
|
||||
@ -47,4 +47,4 @@ class JvmLogSink {
|
||||
|
||||
} // namespace monero
|
||||
|
||||
#endif // LOGGING_H_
|
||||
#endif // WALLET_LOGGING_H_
|
@ -6,9 +6,10 @@
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
|
||||
#include "common.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/eraser.h"
|
||||
|
||||
#include "jni_cache.h"
|
||||
#include "eraser.h"
|
||||
#include "fd.h"
|
||||
|
||||
#include "string_tools.h"
|
@ -1,10 +1,11 @@
|
||||
#ifndef WALLET_H_
|
||||
#define WALLET_H_
|
||||
#ifndef WALLET_WALLET_H_
|
||||
#define WALLET_WALLET_H_
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "common/jvm.h"
|
||||
|
||||
#include "http_client.h"
|
||||
#include "jvm.h"
|
||||
|
||||
#include "wallet2.h"
|
||||
|
||||
@ -187,4 +188,4 @@ class Wallet : tools::i_wallet2_callback {
|
||||
|
||||
} // namespace monero
|
||||
|
||||
#endif // WALLET_H_
|
||||
#endif // WALLET_WALLET_H_
|
@ -1,17 +0,0 @@
|
||||
package im.molly.monero
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
internal object MoneroJni {
|
||||
private val initialized = AtomicBoolean()
|
||||
|
||||
fun loadLibrary(logger: Logger) {
|
||||
if (initialized.getAndSet(true)) {
|
||||
return
|
||||
}
|
||||
System.loadLibrary("monero_jni")
|
||||
nativeSetLogger(logger)
|
||||
}
|
||||
}
|
||||
|
||||
private external fun nativeSetLogger(logger: Logger)
|
25
lib/android/src/main/kotlin/im/molly/monero/NativeLoader.kt
Normal file
25
lib/android/src/main/kotlin/im/molly/monero/NativeLoader.kt
Normal file
@ -0,0 +1,25 @@
|
||||
package im.molly.monero
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
internal object NativeLoader {
|
||||
private val wallet = AtomicBoolean()
|
||||
private val mnemonics = AtomicBoolean()
|
||||
|
||||
fun loadWalletLibrary(logger: Logger) {
|
||||
if (wallet.getAndSet(true)) {
|
||||
return
|
||||
}
|
||||
System.loadLibrary("monero_wallet")
|
||||
nativeSetLogger(logger)
|
||||
}
|
||||
|
||||
fun loadMnemonicsLibrary() {
|
||||
if (mnemonics.getAndSet(true)) {
|
||||
return
|
||||
}
|
||||
System.loadLibrary("monero_mnemonics")
|
||||
}
|
||||
}
|
||||
|
||||
private external fun nativeSetLogger(logger: Logger)
|
@ -55,7 +55,7 @@ class WalletNative private constructor(
|
||||
private val logger = loggerFor<WalletNative>()
|
||||
|
||||
init {
|
||||
MoneroJni.loadLibrary(logger = logger)
|
||||
NativeLoader.loadWalletLibrary(logger = logger)
|
||||
}
|
||||
|
||||
private val handle: Long = nativeCreate(network.id)
|
||||
|
@ -31,7 +31,7 @@ internal class WalletServiceImpl(
|
||||
if (isIsolated) {
|
||||
setLoggingAdapter(this)
|
||||
}
|
||||
MoneroJni.loadLibrary(logger = logger)
|
||||
NativeLoader.loadWalletLibrary(logger = logger)
|
||||
}
|
||||
|
||||
private var listener: IWalletServiceListener? = null
|
||||
|
Loading…
Reference in New Issue
Block a user