Fix freeze coin info (#73)
* Enable stdout/stderr logging to logcat on android * coin control fix
This commit is contained in:
@@ -32,6 +32,7 @@ if(${HOST_ABI} STREQUAL "x86_64-linux-android" OR
|
||||
${HOST_ABI} STREQUAL "aarch64-linux-android" OR
|
||||
${HOST_ABI} STREQUAL "armv7a-linux-androideabi")
|
||||
add_link_options(-stdlib=libc++ -static-libstdc++)
|
||||
set(EXTRA_LIBS_ANDROID log)
|
||||
endif()
|
||||
|
||||
add_library( wallet2_api_c
|
||||
|
||||
@@ -9,6 +9,71 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOG_TAG "moneroc"
|
||||
#define BUFFER_SIZE 1024*32
|
||||
|
||||
static int stdoutToLogcat(const char *buf, int size) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, buf);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int stderrToLogcat(const char *buf, int size) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, LOG_TAG, buf);
|
||||
return size;
|
||||
}
|
||||
|
||||
void redirectStdoutThread(int pipe_stdout[2]) {
|
||||
char bufferStdout[BUFFER_SIZE];
|
||||
while (true) {
|
||||
int read_size = read(pipe_stdout[0], bufferStdout, sizeof(bufferStdout) - 1);
|
||||
if (read_size > 0) {
|
||||
bufferStdout[read_size] = '\0';
|
||||
stdoutToLogcat(bufferStdout, read_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void redirectStderrThread(int pipe_stderr[2]) {
|
||||
char bufferStderr[BUFFER_SIZE];
|
||||
while (true) {
|
||||
int read_size = read(pipe_stderr[0], bufferStderr, sizeof(bufferStderr) - 1);
|
||||
if (read_size > 0) {
|
||||
bufferStderr[read_size] = '\0';
|
||||
stderrToLogcat(bufferStderr, read_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setupAndroidLogging() {
|
||||
static int pfdStdout[2];
|
||||
static int pfdStderr[2];
|
||||
|
||||
pipe(pfdStdout);
|
||||
pipe(pfdStderr);
|
||||
|
||||
dup2(pfdStdout[1], STDOUT_FILENO);
|
||||
dup2(pfdStderr[1], STDERR_FILENO);
|
||||
|
||||
std::thread stdoutThread(redirectStdoutThread, pfdStdout);
|
||||
std::thread stderrThread(redirectStderrThread, pfdStderr);
|
||||
|
||||
stdoutThread.detach();
|
||||
stderrThread.detach();
|
||||
}
|
||||
|
||||
#endif // __ANDROID__
|
||||
|
||||
__attribute__((constructor))
|
||||
void library_init() {
|
||||
#ifdef __ANDROID__
|
||||
setupAndroidLogging(); // This will now run automatically when the library is loaded
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* vectorToString(const std::vector<std::string>& vec, const std::string separator) {
|
||||
// Check if the vector is empty
|
||||
|
||||
97
patches/monero/0019-fix-for-coin-control-patch.patch
Normal file
97
patches/monero/0019-fix-for-coin-control-patch.patch
Normal file
@@ -0,0 +1,97 @@
|
||||
From 8f93306ed526e0e573b33fc7dd40abbba7e7a00a Mon Sep 17 00:00:00 2001
|
||||
From: Czarek Nakamoto <cyjan@mrcyjanek.net>
|
||||
Date: Tue, 15 Oct 2024 18:00:05 +0200
|
||||
Subject: [PATCH] fix for coin control patch
|
||||
|
||||
---
|
||||
src/wallet/api/coins.cpp | 1 +
|
||||
src/wallet/api/wallet.cpp | 36 +++++++++++++++++++++++++++++++++++-
|
||||
2 files changed, 36 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/wallet/api/coins.cpp b/src/wallet/api/coins.cpp
|
||||
index 2321c638d..ef12141cf 100644
|
||||
--- a/src/wallet/api/coins.cpp
|
||||
+++ b/src/wallet/api/coins.cpp
|
||||
@@ -114,6 +114,7 @@ void CoinsImpl::setFrozen(int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
+ LOG_ERROR("Freezing coin: " << index);
|
||||
m_wallet->m_wallet->freeze(index);
|
||||
refresh();
|
||||
}
|
||||
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
|
||||
index ec7d60ec0..db127dae4 100644
|
||||
--- a/src/wallet/api/wallet.cpp
|
||||
+++ b/src/wallet/api/wallet.cpp
|
||||
@@ -2116,6 +2116,7 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
|
||||
}
|
||||
}
|
||||
bool error = false;
|
||||
+ uint64_t amountSum = 0;
|
||||
for (size_t i = 0; i < dst_addr.size() && !error; i++) {
|
||||
if(!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), dst_addr[i])) {
|
||||
// TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982
|
||||
@@ -2137,6 +2138,7 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
|
||||
de.original = dst_addr[i];
|
||||
de.addr = info.address;
|
||||
de.amount = (*amount)[i];
|
||||
+ amountSum += (*amount)[i];
|
||||
de.is_subaddress = info.is_subaddress;
|
||||
de.is_integrated = info.has_payment_id;
|
||||
dsts.push_back(de);
|
||||
@@ -2147,18 +2149,50 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
|
||||
}
|
||||
}
|
||||
}
|
||||
+ // uint64_t maxAllowedSpend = m_wallet->unlocked_balance(subaddr_account, true);
|
||||
+ // if (maxAllowedSpend < amountSum) {
|
||||
+ // error = true;
|
||||
+ // setStatusError(tr("Amount you are trying to spend is larger than unlocked amount"));
|
||||
+ // break;
|
||||
+ // }
|
||||
std::vector<crypto::key_image> preferred_input_list;
|
||||
if (!preferred_inputs.empty()) {
|
||||
+ LOG_ERROR("empty");
|
||||
+
|
||||
for (const auto &public_key : preferred_inputs) {
|
||||
crypto::key_image keyImage;
|
||||
bool r = epee::string_tools::hex_to_pod(public_key, keyImage);
|
||||
- if (!r) {
|
||||
+ if (!r) {
|
||||
error = true;
|
||||
setStatusError(tr("failed to parse key image"));
|
||||
break;
|
||||
}
|
||||
+ if (m_wallet->frozen(keyImage)) {
|
||||
+ error = true;
|
||||
+ setStatusError(tr("refusing to spend frozen coin"));
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
preferred_input_list.push_back(keyImage);
|
||||
}
|
||||
+ } else {
|
||||
+ LOG_ERROR("not empty");
|
||||
+
|
||||
+ boost::shared_lock<boost::shared_mutex> transfers_lock(m_wallet->m_transfers_mutex);
|
||||
+ for (size_t i = 0; i < m_wallet->get_num_transfer_details(); ++i) {
|
||||
+ const tools::wallet2::transfer_details &td = m_wallet->get_transfer_details(i);
|
||||
+ LOG_ERROR("COIN: " << i << ": " << td.amount() << "; "<<td.m_spent << ";" << td.m_frozen << ";" << m_wallet->frozen(td));
|
||||
+ if (td.m_spent) continue;
|
||||
+ LOG_ERROR("is frozen");
|
||||
+ if (!td.m_frozen) {
|
||||
+ LOG_ERROR("isn't:");
|
||||
+ LOG_ERROR("hash: " << td.m_key_image << "; " << td.amount());
|
||||
+ preferred_input_list.push_back(td.m_key_image);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ for (const auto &de : preferred_input_list) {
|
||||
+ LOG_ERROR("preferred input: " << de);
|
||||
}
|
||||
if (error) {
|
||||
break;
|
||||
--
|
||||
2.39.5 (Apple Git-154)
|
||||
|
||||
Reference in New Issue
Block a user