mirror of
https://github.com/mollyim/monero-wallet-sdk.git
synced 2025-03-30 18:08:08 -04:00
lib: fix wallet height handling and JNI signature
This commit is contained in:
parent
48fb61d1b3
commit
3c3fc3507c
@ -40,7 +40,7 @@ void initializeJniCache(JNIEnv* env) {
|
||||
"callRemoteNode",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[B)Lim/molly/monero/HttpResponse;");
|
||||
WalletNative_onRefresh = walletNative
|
||||
.getMethodId(env, "onRefresh", "(JZ)V");
|
||||
.getMethodId(env, "onRefresh", "(IZ)V");
|
||||
WalletNative_onSuspendRefresh = walletNative
|
||||
.getMethodId(env, "onSuspendRefresh", "(Z)V");
|
||||
|
||||
|
@ -97,7 +97,7 @@ bool Wallet::parseFrom(std::istream& input) {
|
||||
return false;
|
||||
if (!serialization::serialize(ar, m_wallet))
|
||||
return false;
|
||||
m_blockchain_height = m_wallet.get_blockchain_current_height();
|
||||
set_current_blockchain_height(m_wallet.get_blockchain_current_height());
|
||||
captureTxHistorySnapshot(m_tx_history);
|
||||
m_account_ready = true;
|
||||
return true;
|
||||
@ -127,6 +127,12 @@ std::string Wallet::public_address() const {
|
||||
return account.get_public_address_str(m_wallet.nettype());
|
||||
}
|
||||
|
||||
void Wallet::set_current_blockchain_height(uint64_t height) {
|
||||
LOG_FATAL_IF(height >= CRYPTONOTE_MAX_BLOCK_NUMBER,
|
||||
"Blockchain max height reached");
|
||||
m_blockchain_height = height;
|
||||
}
|
||||
|
||||
cryptonote::account_base& Wallet::require_account() {
|
||||
LOG_FATAL_IF(!m_account_ready, "Account is not initialized");
|
||||
return m_wallet.get_account();
|
||||
@ -317,7 +323,7 @@ void Wallet::captureTxHistorySnapshot(std::vector<TxInfo>& snapshot) {
|
||||
}
|
||||
|
||||
void Wallet::handleNewBlock(uint64_t height, bool refresh_running) {
|
||||
m_blockchain_height = height;
|
||||
set_current_blockchain_height(height);
|
||||
if (m_balance_changed) {
|
||||
m_tx_history_mutex.lock();
|
||||
captureTxHistorySnapshot(m_tx_history);
|
||||
@ -339,8 +345,9 @@ void Wallet::notifyRefresh(bool debounce) {
|
||||
static std::chrono::steady_clock::time_point last_time;
|
||||
// If debouncing is requested and the blockchain height is a multiple of 100, it limits
|
||||
// the notifications to once every 200 ms.
|
||||
uint32_t height = current_blockchain_height();
|
||||
if (debounce) {
|
||||
if (m_blockchain_height % 100 == 0) {
|
||||
if (height % 100 == 0) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (now - last_time >= 200.ms) {
|
||||
last_time = now;
|
||||
@ -352,7 +359,7 @@ void Wallet::notifyRefresh(bool debounce) {
|
||||
}
|
||||
if (!debounce) {
|
||||
m_callback.callVoidMethod(getJniEnv(), WalletNative_onRefresh,
|
||||
m_blockchain_height, m_balance_changed);
|
||||
height, m_balance_changed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,10 +566,7 @@ Java_im_molly_monero_WalletNative_nativeGetCurrentBlockchainHeight(
|
||||
jobject thiz,
|
||||
jlong handle) {
|
||||
auto* wallet = reinterpret_cast<Wallet*>(handle);
|
||||
uint64_t height = wallet->current_blockchain_height();
|
||||
LOG_FATAL_IF(height >= CRYPTONOTE_MAX_BLOCK_NUMBER,
|
||||
"Blockchain max height reached");
|
||||
return static_cast<jint>(height);
|
||||
return wallet->current_blockchain_height();
|
||||
}
|
||||
|
||||
ScopedJvmLocalRef<jobject> nativeToJvmTxInfo(JNIEnv* env,
|
||||
|
@ -95,7 +95,8 @@ class Wallet : tools::i_wallet2_callback {
|
||||
|
||||
std::string public_address() const;
|
||||
|
||||
uint64_t current_blockchain_height() const { return m_blockchain_height; }
|
||||
void set_current_blockchain_height(uint64_t height);
|
||||
uint32_t current_blockchain_height() const { return static_cast<uint32_t>(m_blockchain_height); }
|
||||
|
||||
// Extra state that must be persistent but isn't restored by wallet2's serializer.
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
|
Loading…
x
Reference in New Issue
Block a user