From 8b3d0f2c357614044db594476045c48d8fd7378c Mon Sep 17 00:00:00 2001 From: cyan Date: Mon, 19 May 2025 12:09:32 +0200 Subject: [PATCH] feat: callback-based ledger connection (#137) * feat: callback-based ledger connection * int -> void use sendToLedgerDeviceCallback only when needed * fix(ledger): fix binds, make functions static * update ledger patch * monero.dart: add ledger callback api --- impls/monero.dart/lib/monero.dart | 48 +++-- .../monero.dart/lib/src/checksum_monero.dart | 4 +- .../lib/src/generated_bindings_monero.g.dart | 146 +++++++-------- impls/monero.dart/lib/src/monero.dart | 51 +++-- impls/monero.dart/lib/src/wallet2.dart | 9 - impls/monero.ts/checksum_monero.ts | 4 +- .../src/main/cpp/monero_checksum.h | 4 +- .../src/main/cpp/wallet2_api_c.cpp | 63 +++---- .../src/main/cpp/wallet2_api_c.h | 19 +- ...g-___clear_cache-when-targetting-iOS.patch | 6 +- patches/monero/0002-store-crash-fix.patch | 6 +- ...0003-uint64_t-missing-definition-fix.patch | 6 +- ...se-proper-error-handling-in-get_seed.patch | 6 +- patches/monero/0005-UR-functions.patch | 6 +- .../0006-add-dummy-device-for-ledger.patch | 174 +++++++++++------- patches/monero/0007-polyseed.patch | 14 +- patches/monero/0008-coin-control.patch | 12 +- ...-and-tx-key-getter-for-PendingTransc.patch | 8 +- ...coverDeterministicWalletFromSpendKey.patch | 14 +- .../0011-add-monero-submodule-support.patch | 6 +- .../monero/0012-fix-iOS-depends-build.patch | 6 +- ...ude-locale-only-when-targeting-WIN32.patch | 11 +- ...-change-earliest-fork-height-message.patch | 6 +- ...015-remove-trivially_copyable-assert.patch | 6 +- patches/monero/0016-pr-9880.patch | 6 +- ...-fix-unary_function-__unary_function.patch | 6 +- 26 files changed, 333 insertions(+), 314 deletions(-) diff --git a/impls/monero.dart/lib/monero.dart b/impls/monero.dart/lib/monero.dart index 17f0a13..a80924e 100644 --- a/impls/monero.dart/lib/monero.dart +++ b/impls/monero.dart/lib/monero.dart @@ -3515,87 +3515,95 @@ int MONERO_Wallet_getBytesSent(wallet ptr) { } @Deprecated("TODO") -bool Wallet_getStateIsConnected(wallet ptr) { +bool Wallet_getStateIsConnected() { debugStart?.call('MONERO_Wallet_getStateIsConnected'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getStateIsConnected(ptr); + final ret = lib!.MONERO_Wallet_getStateIsConnected(); debugEnd?.call('MONERO_Wallet_getStateIsConnected'); return ret; } @Deprecated("TODO") -Pointer Wallet_getSendToDevice(wallet ptr) { +Pointer Wallet_getSendToDevice() { debugStart?.call('MONERO_Wallet_getSendToDevice'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getSendToDevice(ptr); + final ret = lib!.MONERO_Wallet_getSendToDevice(); debugEnd?.call('MONERO_Wallet_getSendToDevice'); return ret; } @Deprecated("TODO") -int Wallet_getSendToDeviceLength(wallet ptr) { +int Wallet_getSendToDeviceLength() { debugStart?.call('MONERO_Wallet_getSendToDeviceLength'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getSendToDeviceLength(ptr); + final ret = lib!.MONERO_Wallet_getSendToDeviceLength(); debugEnd?.call('MONERO_Wallet_getSendToDeviceLength'); return ret; } @Deprecated("TODO") -Pointer Wallet_getReceivedFromDevice(wallet ptr) { +Pointer Wallet_getReceivedFromDevice() { debugStart?.call('MONERO_Wallet_getReceivedFromDevice'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getReceivedFromDevice(ptr); + final ret = lib!.MONERO_Wallet_getReceivedFromDevice(); debugEnd?.call('MONERO_Wallet_getReceivedFromDevice'); return ret; } @Deprecated("TODO") -int Wallet_getReceivedFromDeviceLength(wallet ptr) { +int Wallet_getReceivedFromDeviceLength() { debugStart?.call('MONERO_Wallet_getReceivedFromDeviceLength'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getReceivedFromDeviceLength(ptr); + final ret = lib!.MONERO_Wallet_getReceivedFromDeviceLength(); debugEnd?.call('MONERO_Wallet_getReceivedFromDeviceLength'); return ret; } @Deprecated("TODO") -bool Wallet_getWaitsForDeviceSend(wallet ptr) { +bool Wallet_getWaitsForDeviceSend() { debugStart?.call('MONERO_Wallet_getWaitsForDeviceSend'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getWaitsForDeviceSend(ptr); + final ret = lib!.MONERO_Wallet_getWaitsForDeviceSend(); debugEnd?.call('MONERO_Wallet_getWaitsForDeviceSend'); return ret; } @Deprecated("TODO") -bool Wallet_getWaitsForDeviceReceive(wallet ptr) { +bool Wallet_getWaitsForDeviceReceive() { debugStart?.call('MONERO_Wallet_getWaitsForDeviceReceive'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_getWaitsForDeviceReceive(ptr); + final ret = lib!.MONERO_Wallet_getWaitsForDeviceReceive(); debugEnd?.call('MONERO_Wallet_getWaitsForDeviceReceive'); return ret; } @Deprecated("TODO") -void Wallet_setDeviceReceivedData( - wallet ptr, Pointer data, int len) { +void Wallet_setDeviceReceivedData(Pointer data, int len) { debugStart?.call('MONERO_Wallet_setDeviceReceivedData'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_setDeviceReceivedData(ptr, data, len); + final ret = lib!.MONERO_Wallet_setDeviceReceivedData(data, len); debugEnd?.call('MONERO_Wallet_setDeviceReceivedData'); return ret; } @Deprecated("TODO") -void Wallet_setDeviceSendData(wallet ptr, Pointer data, int len) { +void Wallet_setDeviceSendData(Pointer data, int len) { debugStart?.call('MONERO_Wallet_setDeviceSendData'); lib ??= MoneroC(DynamicLibrary.open(libPath)); - final ret = lib!.MONERO_Wallet_setDeviceSendData(ptr, data, len); + final ret = lib!.MONERO_Wallet_setDeviceSendData(data, len); debugEnd?.call('MONERO_Wallet_setDeviceSendData'); return ret; } - + +@Deprecated("TODO") +void Wallet_setLedgerCallback(Pointer, UnsignedInt)>> callback) { + debugStart?.call('MONERO_Wallet_setDeviceSendData'); + lib ??= MoneroC(DynamicLibrary.open(libPath)); + final ret = lib!.MONERO_Wallet_setLedgerCallback(callback); + debugEnd?.call('MONERO_Wallet_setDeviceSendData'); + return ret; +} + // WalletManager @Deprecated("TODO") typedef WalletManager = Pointer; diff --git a/impls/monero.dart/lib/src/checksum_monero.dart b/impls/monero.dart/lib/src/checksum_monero.dart index b907f7c..fdbfbaa 100644 --- a/impls/monero.dart/lib/src/checksum_monero.dart +++ b/impls/monero.dart/lib/src/checksum_monero.dart @@ -1,4 +1,4 @@ // ignore_for_file: constant_identifier_names -const String wallet2_api_c_h_sha256 = "9e80c4b59a0509aa02fbf01e8df2881b89f82225d1765bfa7856cbdbaf7af116"; -const String wallet2_api_c_cpp_sha256 = "d229507db508e574bd2badf4819a38dbead8c16a84311ad32c22c887a6003439-0232839913b13cf0ab0bb7ad25fff0c05f37d2fe"; +const String wallet2_api_c_h_sha256 = "91218f60e937753a606b1db899ee2ed66a1b02144eb2d79b950ce59804397f84"; +const String wallet2_api_c_cpp_sha256 = "282128494f3419c128dff7ed67daadd9c2ad0600d10557e829df03d9bc1ad891-0232839913b13cf0ab0bb7ad25fff0c05f37d2fe"; const String wallet2_api_c_exp_sha256 = "d0f95f1f3bc49f1f59fe4eb0b61826128d7d3bb75405d5a01a252d02db03097d"; diff --git a/impls/monero.dart/lib/src/generated_bindings_monero.g.dart b/impls/monero.dart/lib/src/generated_bindings_monero.g.dart index 77e2899..81649b1 100644 --- a/impls/monero.dart/lib/src/generated_bindings_monero.g.dart +++ b/impls/monero.dart/lib/src/generated_bindings_monero.g.dart @@ -4351,120 +4351,83 @@ class MoneroC { late final _MONERO_Wallet_getBytesSent = _MONERO_Wallet_getBytesSentPtr .asFunction)>(); - bool MONERO_Wallet_getStateIsConnected( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getStateIsConnected( - wallet_ptr, - ); + bool MONERO_Wallet_getStateIsConnected() { + return _MONERO_Wallet_getStateIsConnected(); } late final _MONERO_Wallet_getStateIsConnectedPtr = - _lookup)>>( + _lookup>( 'MONERO_Wallet_getStateIsConnected'); late final _MONERO_Wallet_getStateIsConnected = - _MONERO_Wallet_getStateIsConnectedPtr.asFunction< - bool Function(ffi.Pointer)>(); + _MONERO_Wallet_getStateIsConnectedPtr.asFunction(); - ffi.Pointer MONERO_Wallet_getSendToDevice( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getSendToDevice( - wallet_ptr, - ); + ffi.Pointer MONERO_Wallet_getSendToDevice() { + return _MONERO_Wallet_getSendToDevice(); } - late final _MONERO_Wallet_getSendToDevicePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('MONERO_Wallet_getSendToDevice'); - late final _MONERO_Wallet_getSendToDevice = - _MONERO_Wallet_getSendToDevicePtr.asFunction< - ffi.Pointer Function(ffi.Pointer)>(); + late final _MONERO_Wallet_getSendToDevicePtr = + _lookup Function()>>( + 'MONERO_Wallet_getSendToDevice'); + late final _MONERO_Wallet_getSendToDevice = _MONERO_Wallet_getSendToDevicePtr + .asFunction Function()>(); - int MONERO_Wallet_getSendToDeviceLength( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getSendToDeviceLength( - wallet_ptr, - ); + int MONERO_Wallet_getSendToDeviceLength() { + return _MONERO_Wallet_getSendToDeviceLength(); } late final _MONERO_Wallet_getSendToDeviceLengthPtr = - _lookup)>>( + _lookup>( 'MONERO_Wallet_getSendToDeviceLength'); late final _MONERO_Wallet_getSendToDeviceLength = - _MONERO_Wallet_getSendToDeviceLengthPtr.asFunction< - int Function(ffi.Pointer)>(); + _MONERO_Wallet_getSendToDeviceLengthPtr.asFunction(); - ffi.Pointer MONERO_Wallet_getReceivedFromDevice( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getReceivedFromDevice( - wallet_ptr, - ); + ffi.Pointer MONERO_Wallet_getReceivedFromDevice() { + return _MONERO_Wallet_getReceivedFromDevice(); } - late final _MONERO_Wallet_getReceivedFromDevicePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('MONERO_Wallet_getReceivedFromDevice'); + late final _MONERO_Wallet_getReceivedFromDevicePtr = + _lookup Function()>>( + 'MONERO_Wallet_getReceivedFromDevice'); late final _MONERO_Wallet_getReceivedFromDevice = _MONERO_Wallet_getReceivedFromDevicePtr.asFunction< - ffi.Pointer Function(ffi.Pointer)>(); + ffi.Pointer Function()>(); - int MONERO_Wallet_getReceivedFromDeviceLength( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getReceivedFromDeviceLength( - wallet_ptr, - ); + int MONERO_Wallet_getReceivedFromDeviceLength() { + return _MONERO_Wallet_getReceivedFromDeviceLength(); } late final _MONERO_Wallet_getReceivedFromDeviceLengthPtr = - _lookup)>>( + _lookup>( 'MONERO_Wallet_getReceivedFromDeviceLength'); late final _MONERO_Wallet_getReceivedFromDeviceLength = _MONERO_Wallet_getReceivedFromDeviceLengthPtr.asFunction< - int Function(ffi.Pointer)>(); + int Function()>(); - bool MONERO_Wallet_getWaitsForDeviceSend( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getWaitsForDeviceSend( - wallet_ptr, - ); + bool MONERO_Wallet_getWaitsForDeviceSend() { + return _MONERO_Wallet_getWaitsForDeviceSend(); } late final _MONERO_Wallet_getWaitsForDeviceSendPtr = - _lookup)>>( + _lookup>( 'MONERO_Wallet_getWaitsForDeviceSend'); late final _MONERO_Wallet_getWaitsForDeviceSend = - _MONERO_Wallet_getWaitsForDeviceSendPtr.asFunction< - bool Function(ffi.Pointer)>(); + _MONERO_Wallet_getWaitsForDeviceSendPtr.asFunction(); - bool MONERO_Wallet_getWaitsForDeviceReceive( - ffi.Pointer wallet_ptr, - ) { - return _MONERO_Wallet_getWaitsForDeviceReceive( - wallet_ptr, - ); + bool MONERO_Wallet_getWaitsForDeviceReceive() { + return _MONERO_Wallet_getWaitsForDeviceReceive(); } late final _MONERO_Wallet_getWaitsForDeviceReceivePtr = - _lookup)>>( + _lookup>( 'MONERO_Wallet_getWaitsForDeviceReceive'); late final _MONERO_Wallet_getWaitsForDeviceReceive = - _MONERO_Wallet_getWaitsForDeviceReceivePtr.asFunction< - bool Function(ffi.Pointer)>(); + _MONERO_Wallet_getWaitsForDeviceReceivePtr.asFunction(); void MONERO_Wallet_setDeviceReceivedData( - ffi.Pointer wallet_ptr, ffi.Pointer data, int len, ) { return _MONERO_Wallet_setDeviceReceivedData( - wallet_ptr, data, len, ); @@ -4472,22 +4435,17 @@ class MoneroC { late final _MONERO_Wallet_setDeviceReceivedDataPtr = _lookup< ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, + ffi.Void Function(ffi.Pointer, ffi.Size)>>('MONERO_Wallet_setDeviceReceivedData'); late final _MONERO_Wallet_setDeviceReceivedData = _MONERO_Wallet_setDeviceReceivedDataPtr.asFunction< - void Function( - ffi.Pointer, ffi.Pointer, int)>(); + void Function(ffi.Pointer, int)>(); void MONERO_Wallet_setDeviceSendData( - ffi.Pointer wallet_ptr, ffi.Pointer data, int len, ) { return _MONERO_Wallet_setDeviceSendData( - wallet_ptr, data, len, ); @@ -4495,14 +4453,40 @@ class MoneroC { late final _MONERO_Wallet_setDeviceSendDataPtr = _lookup< ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, + ffi.Void Function(ffi.Pointer, ffi.Size)>>('MONERO_Wallet_setDeviceSendData'); late final _MONERO_Wallet_setDeviceSendData = _MONERO_Wallet_setDeviceSendDataPtr.asFunction< + void Function(ffi.Pointer, int)>(); + + void MONERO_Wallet_setLedgerCallback( + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer command, + ffi.UnsignedInt cmd_len)>> + sendToLedgerDevice, + ) { + return _MONERO_Wallet_setLedgerCallback( + sendToLedgerDevice, + ); + } + + late final _MONERO_Wallet_setLedgerCallbackPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer command, + ffi.UnsignedInt cmd_len)>>)>>( + 'MONERO_Wallet_setLedgerCallback'); + late final _MONERO_Wallet_setLedgerCallback = + _MONERO_Wallet_setLedgerCallbackPtr.asFunction< void Function( - ffi.Pointer, ffi.Pointer, int)>(); + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer command, + ffi.UnsignedInt cmd_len)>>)>(); ffi.Pointer MONERO_WalletManager_createWallet( ffi.Pointer wm_ptr, diff --git a/impls/monero.dart/lib/src/monero.dart b/impls/monero.dart/lib/src/monero.dart index b2eb8c7..e142d6b 100644 --- a/impls/monero.dart/lib/src/monero.dart +++ b/impls/monero.dart/lib/src/monero.dart @@ -1033,14 +1033,12 @@ class MoneroWallet implements Wallet2Wallet { return monero.Wallet_getPolyseed(walletPtr, passphrase: passphrase); } - @override - Pointer getReceivedFromDevice() { - return monero.Wallet_getReceivedFromDevice(walletPtr); + static Pointer getReceivedFromDevice() { + return monero.Wallet_getReceivedFromDevice(); } - @override - int getReceivedFromDeviceLength() { - return monero.Wallet_getReceivedFromDeviceLength(walletPtr); + static int getReceivedFromDeviceLength() { + return monero.Wallet_getReceivedFromDeviceLength(); } @override @@ -1052,20 +1050,17 @@ class MoneroWallet implements Wallet2Wallet { String getSeedLanguage() { return monero.Wallet_getSeedLanguage(walletPtr); } - - @override - Pointer getSendToDevice() { - return monero.Wallet_getSendToDevice(walletPtr); + + static Pointer getSendToDevice() { + return monero.Wallet_getSendToDevice(); } - @override - int getSendToDeviceLength() { - return monero.Wallet_getSendToDeviceLength(walletPtr); + static int getSendToDeviceLength() { + return monero.Wallet_getSendToDeviceLength(); } - @override - bool getStateIsConnected() { - return monero.Wallet_getStateIsConnected(walletPtr); + static bool getStateIsConnected() { + return monero.Wallet_getStateIsConnected(); } @override @@ -1083,14 +1078,12 @@ class MoneroWallet implements Wallet2Wallet { return monero.Wallet_getUserNote(walletPtr, txid: txid); } - @override - bool getWaitsForDeviceReceive() { - return monero.Wallet_getWaitsForDeviceReceive(walletPtr); + static bool getWaitsForDeviceReceive() { + return monero.Wallet_getWaitsForDeviceReceive(); } - @override - bool getWaitsForDeviceSend() { - return monero.Wallet_getWaitsForDeviceSend(walletPtr); + static bool getWaitsForDeviceSend() { + return monero.Wallet_getWaitsForDeviceSend(); } @override @@ -1357,14 +1350,16 @@ class MoneroWallet implements Wallet2Wallet { return monero.Wallet_setDevicePin(walletPtr, passphrase: passphrase); } - @override - void setDeviceReceivedData(Pointer data, int len) { - monero.Wallet_setDeviceReceivedData(walletPtr, data, len); + static void setDeviceReceivedData(Pointer data, int len) { + monero.Wallet_setDeviceReceivedData(data, len); } - @override - void setDeviceSendData(Pointer data, int len) { - monero.Wallet_setDeviceSendData(walletPtr, data, len); + static void setDeviceSendData(Pointer data, int len) { + monero.Wallet_setDeviceSendData(data, len); + } + + static void setLedgerCallback(Pointer, UnsignedInt)>> callback) { + monero.Wallet_setLedgerCallback(callback); } @override diff --git a/impls/monero.dart/lib/src/wallet2.dart b/impls/monero.dart/lib/src/wallet2.dart index 2c07548..8c41ffa 100644 --- a/impls/monero.dart/lib/src/wallet2.dart +++ b/impls/monero.dart/lib/src/wallet2.dart @@ -364,15 +364,6 @@ abstract class Wallet2Wallet { String deviceShowAddress({required int accountIndex, required int addressIndex}); bool reconnectDevice(); int getBytesReceived(); - bool getStateIsConnected(); - Pointer getSendToDevice(); - int getSendToDeviceLength(); - Pointer getReceivedFromDevice(); - int getReceivedFromDeviceLength(); - bool getWaitsForDeviceSend(); - bool getWaitsForDeviceReceive(); - void setDeviceReceivedData(Pointer data, int len); - void setDeviceSendData(Pointer data, int len); int getBytesSent(); Wallet2WalletListener getWalletListener(); } diff --git a/impls/monero.ts/checksum_monero.ts b/impls/monero.ts/checksum_monero.ts index 0972f78..7ed01a3 100644 --- a/impls/monero.ts/checksum_monero.ts +++ b/impls/monero.ts/checksum_monero.ts @@ -1,5 +1,5 @@ export const moneroChecksum = { - wallet2_api_c_h_sha256: "9e80c4b59a0509aa02fbf01e8df2881b89f82225d1765bfa7856cbdbaf7af116", - wallet2_api_c_cpp_sha256: "d229507db508e574bd2badf4819a38dbead8c16a84311ad32c22c887a6003439-0232839913b13cf0ab0bb7ad25fff0c05f37d2fe", + wallet2_api_c_h_sha256: "91218f60e937753a606b1db899ee2ed66a1b02144eb2d79b950ce59804397f84", + wallet2_api_c_cpp_sha256: "282128494f3419c128dff7ed67daadd9c2ad0600d10557e829df03d9bc1ad891-0232839913b13cf0ab0bb7ad25fff0c05f37d2fe", wallet2_api_c_exp_sha256: "d0f95f1f3bc49f1f59fe4eb0b61826128d7d3bb75405d5a01a252d02db03097d", } diff --git a/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h b/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h index 4e0fb1c..d3d7414 100644 --- a/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h +++ b/monero_libwallet2_api_c/src/main/cpp/monero_checksum.h @@ -1,6 +1,6 @@ #ifndef MONEROC_CHECKSUMS #define MONEROC_CHECKSUMS -const char * MONERO_wallet2_api_c_h_sha256 = "9e80c4b59a0509aa02fbf01e8df2881b89f82225d1765bfa7856cbdbaf7af116"; -const char * MONERO_wallet2_api_c_cpp_sha256 = "d229507db508e574bd2badf4819a38dbead8c16a84311ad32c22c887a6003439-0232839913b13cf0ab0bb7ad25fff0c05f37d2fe"; +const char * MONERO_wallet2_api_c_h_sha256 = "91218f60e937753a606b1db899ee2ed66a1b02144eb2d79b950ce59804397f84"; +const char * MONERO_wallet2_api_c_cpp_sha256 = "282128494f3419c128dff7ed67daadd9c2ad0600d10557e829df03d9bc1ad891-0232839913b13cf0ab0bb7ad25fff0c05f37d2fe"; const char * MONERO_wallet2_api_c_exp_sha256 = "d0f95f1f3bc49f1f59fe4eb0b61826128d7d3bb75405d5a01a252d02db03097d"; #endif diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp index 19192cf..fce37c4 100644 --- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp +++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -2102,62 +2102,63 @@ uint64_t MONERO_Wallet_getBytesSent(void* wallet_ptr) { DEBUG_END() } -bool MONERO_Wallet_getStateIsConnected(void* wallet_ptr) { +bool MONERO_Wallet_getStateIsConnected() { DEBUG_START() - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getStateIsConnected(); + return Monero::Wallet::getStateIsConnected(); DEBUG_END() } -unsigned char* MONERO_Wallet_getSendToDevice(void* wallet_ptr) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getSendToDevice(); -} - -size_t MONERO_Wallet_getSendToDeviceLength(void* wallet_ptr) { +unsigned char* MONERO_Wallet_getSendToDevice() { DEBUG_START() - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getSendToDeviceLength(); + return Monero::Wallet::getSendToDevice(); DEBUG_END() } -unsigned char* MONERO_Wallet_getReceivedFromDevice(void* wallet_ptr) { - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getReceivedFromDevice(); -} - -size_t MONERO_Wallet_getReceivedFromDeviceLength(void* wallet_ptr) { +size_t MONERO_Wallet_getSendToDeviceLength() { DEBUG_START() - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getReceivedFromDeviceLength(); + return Monero::Wallet::getSendToDeviceLength(); DEBUG_END() } -bool MONERO_Wallet_getWaitsForDeviceSend(void* wallet_ptr) { +unsigned char* MONERO_Wallet_getReceivedFromDevice() { DEBUG_START() - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getWaitsForDeviceSend(); + return Monero::Wallet::getReceivedFromDevice(); DEBUG_END() } -bool MONERO_Wallet_getWaitsForDeviceReceive(void* wallet_ptr) { +size_t MONERO_Wallet_getReceivedFromDeviceLength() { DEBUG_START() - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->getWaitsForDeviceReceive(); + return Monero::Wallet::getReceivedFromDeviceLength(); DEBUG_END() } -void MONERO_Wallet_setDeviceReceivedData(void* wallet_ptr, unsigned char* data, size_t len) { +bool MONERO_Wallet_getWaitsForDeviceSend() { DEBUG_START() - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->setDeviceReceivedData(data, len); + return Monero::Wallet::getWaitsForDeviceSend(); DEBUG_END() } -void MONERO_Wallet_setDeviceSendData(void* wallet_ptr, unsigned char* data, size_t len) { +bool MONERO_Wallet_getWaitsForDeviceReceive() { DEBUG_START() - Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); - return wallet->setDeviceSendData(data, len); + return Monero::Wallet::getWaitsForDeviceReceive(); + DEBUG_END() +} + +void MONERO_Wallet_setDeviceReceivedData(unsigned char* data, size_t len) { + DEBUG_START() + Monero::Wallet::setDeviceReceivedData(data, len); + DEBUG_END() +} + +void MONERO_Wallet_setDeviceSendData(unsigned char* data, size_t len) { + DEBUG_START() + Monero::Wallet::setDeviceSendData(data, len); + DEBUG_END() +} + +void MONERO_Wallet_setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)) { + DEBUG_START() + Monero::Wallet::setLedgerCallback(sendToLedgerDevice); DEBUG_END() } diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h index 17c647c..580e746 100644 --- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h +++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h @@ -832,15 +832,16 @@ extern ADDAPI uint64_t MONERO_Wallet_getBytesReceived(void* wallet_ptr); // virtual uint64_t getBytesSent() = 0; extern ADDAPI uint64_t MONERO_Wallet_getBytesSent(void* wallet_ptr); // HIDAPI_DUMMY -extern ADDAPI bool MONERO_Wallet_getStateIsConnected(void* wallet_ptr); -extern ADDAPI unsigned char* MONERO_Wallet_getSendToDevice(void* wallet_ptr); -extern ADDAPI size_t MONERO_Wallet_getSendToDeviceLength(void* wallet_ptr); -extern ADDAPI unsigned char* MONERO_Wallet_getReceivedFromDevice(void* wallet_ptr); -extern ADDAPI size_t MONERO_Wallet_getReceivedFromDeviceLength(void* wallet_ptr); -extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceSend(void* wallet_ptr); -extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceReceive(void* wallet_ptr); -extern ADDAPI void MONERO_Wallet_setDeviceReceivedData(void* wallet_ptr, unsigned char* data, size_t len); -extern ADDAPI void MONERO_Wallet_setDeviceSendData(void* wallet_ptr, unsigned char* data, size_t len); +extern ADDAPI bool MONERO_Wallet_getStateIsConnected(); +extern ADDAPI unsigned char* MONERO_Wallet_getSendToDevice(); +extern ADDAPI size_t MONERO_Wallet_getSendToDeviceLength(); +extern ADDAPI unsigned char* MONERO_Wallet_getReceivedFromDevice(); +extern ADDAPI size_t MONERO_Wallet_getReceivedFromDeviceLength(); +extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceSend(); +extern ADDAPI bool MONERO_Wallet_getWaitsForDeviceReceive(); +extern ADDAPI void MONERO_Wallet_setDeviceReceivedData(unsigned char* data, size_t len); +extern ADDAPI void MONERO_Wallet_setDeviceSendData(unsigned char* data, size_t len); +extern ADDAPI void MONERO_Wallet_setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)); // }; // struct WalletManager diff --git a/patches/monero/0001-fix-missing-___clear_cache-when-targetting-iOS.patch b/patches/monero/0001-fix-missing-___clear_cache-when-targetting-iOS.patch index d8d3dca..4dc4e8f 100644 --- a/patches/monero/0001-fix-missing-___clear_cache-when-targetting-iOS.patch +++ b/patches/monero/0001-fix-missing-___clear_cache-when-targetting-iOS.patch @@ -1,7 +1,7 @@ -From 6e284a2ef552f1f47e8ca9edcf8651312c9e37dd Mon Sep 17 00:00:00 2001 +From 36259ba9f88bc135b243329400bec9290abb04c6 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Tue, 2 Apr 2024 16:51:56 +0200 -Subject: [PATCH 01/14] fix missing ___clear_cache when targetting iOS +Subject: [PATCH 01/17] fix missing ___clear_cache when targetting iOS --- .gitmodules | 3 ++- @@ -30,5 +30,5 @@ index 102f8acf9..ce72c9bb9 160000 -Subproject commit 102f8acf90a7649ada410de5499a7ec62e49e1da +Subproject commit ce72c9bb9cb799e0d9171094b9abb009e04c5bfc -- -2.48.1 +2.49.0 diff --git a/patches/monero/0002-store-crash-fix.patch b/patches/monero/0002-store-crash-fix.patch index 5a2c16a..a09dcf1 100644 --- a/patches/monero/0002-store-crash-fix.patch +++ b/patches/monero/0002-store-crash-fix.patch @@ -1,7 +1,7 @@ -From b4f4b38af1ab974872862fc20735e41941b955e9 Mon Sep 17 00:00:00 2001 +From 459ac9f7a64cc527528a41dc45ed4cefe83091cb Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Sat, 11 May 2024 16:25:10 +0200 -Subject: [PATCH 02/14] store crash fix +Subject: [PATCH 02/17] store crash fix Monero wallet crashes (sometimes) when it is syncing, while the proper solution (that can be seen in feather) @@ -204,5 +204,5 @@ index 2f4ad52f1..daad1e940 100644 i_wallet2_callback* m_callback; hw::device::device_type m_key_device_type; -- -2.48.1 +2.49.0 diff --git a/patches/monero/0003-uint64_t-missing-definition-fix.patch b/patches/monero/0003-uint64_t-missing-definition-fix.patch index 1b6e305..70ce8bf 100644 --- a/patches/monero/0003-uint64_t-missing-definition-fix.patch +++ b/patches/monero/0003-uint64_t-missing-definition-fix.patch @@ -1,7 +1,7 @@ -From a74f616e3c1671a883182b0db1c6fc11a1242c01 Mon Sep 17 00:00:00 2001 +From c51ee39835aaac64da39b1c10bc068182f6e28cb Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Mon, 2 Sep 2024 16:40:31 +0200 -Subject: [PATCH 03/14] uint64_t missing definition fix +Subject: [PATCH 03/17] uint64_t missing definition fix --- contrib/epee/include/net/http_base.h | 2 +- @@ -21,5 +21,5 @@ index 4af4da790..ae4c0d05e 100644 #include -- -2.48.1 +2.49.0 diff --git a/patches/monero/0004-use-proper-error-handling-in-get_seed.patch b/patches/monero/0004-use-proper-error-handling-in-get_seed.patch index 33207f3..aa30e4f 100644 --- a/patches/monero/0004-use-proper-error-handling-in-get_seed.patch +++ b/patches/monero/0004-use-proper-error-handling-in-get_seed.patch @@ -1,7 +1,7 @@ -From f9b222f1611d7cfbaf0ac52cd6194724c7554def Mon Sep 17 00:00:00 2001 +From 0c1524dd9a4f6b4450b277623ffa620f69931102 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Mon, 24 Jun 2024 10:49:12 +0200 -Subject: [PATCH 04/14] use proper error handling in get_seed +Subject: [PATCH 04/17] use proper error handling in get_seed --- src/wallet/api/wallet.cpp | 17 ++++++++++++----- @@ -67,5 +67,5 @@ index c9c2dbc82..b827b826f 100644 return true; -- -2.48.1 +2.49.0 diff --git a/patches/monero/0005-UR-functions.patch b/patches/monero/0005-UR-functions.patch index c3cca26..0ba79b7 100644 --- a/patches/monero/0005-UR-functions.patch +++ b/patches/monero/0005-UR-functions.patch @@ -1,7 +1,7 @@ -From ff70c74c8b331758ace1f14df0ca107731dda49d Mon Sep 17 00:00:00 2001 +From 467ee9154b5c1b903559bf1dbe848cbabc62ba7d Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 12 Mar 2024 10:09:50 +0100 -Subject: [PATCH 05/14] UR functions +Subject: [PATCH 05/17] UR functions This commit adds UR functions for UR tasks, I believe that the right place to get @@ -1006,5 +1006,5 @@ index daad1e940..a752f15b9 100644 bool import_key_images(signed_tx_set & signed_tx, size_t offset=0, bool only_selected_transfers=false); crypto::public_key get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const; -- -2.48.1 +2.49.0 diff --git a/patches/monero/0006-add-dummy-device-for-ledger.patch b/patches/monero/0006-add-dummy-device-for-ledger.patch index 22ee249..6098565 100644 --- a/patches/monero/0006-add-dummy-device-for-ledger.patch +++ b/patches/monero/0006-add-dummy-device-for-ledger.patch @@ -1,22 +1,23 @@ -From 904fe95204ba02d1a8c81fc46c1423ba1685c94f Mon Sep 17 00:00:00 2001 +From 11ddba5ab1470fb46a87ea9b702bf11f88763ecc Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto -Date: Wed, 26 Jun 2024 15:04:38 +0200 -Subject: [PATCH 06/14] add dummy device for ledger +Date: Thu, 8 May 2025 13:14:23 +0200 +Subject: [PATCH 06/17] add dummy device for ledger --- CMakeLists.txt | 6 +- + external/randomx | 2 +- src/device/CMakeLists.txt | 6 +- - src/device/device.cpp | 10 ++- + src/device/device.cpp | 10 +- src/device/device.hpp | 12 +-- - src/device/device_io_dummy.cpp | 133 ++++++++++++++++++++++++++++++ - src/device/device_io_dummy.hpp | 74 +++++++++++++++++ + src/device/device_io_dummy.cpp | 161 ++++++++++++++++++++++++++++++ + src/device/device_io_dummy.hpp | 82 +++++++++++++++ src/device/device_ledger.cpp | 6 +- src/device/device_ledger.hpp | 7 +- - src/wallet/api/wallet.cpp | 94 +++++++++++++++++++++ - src/wallet/api/wallet.h | 18 ++++ - src/wallet/api/wallet2_api.h | 12 +++ + src/wallet/api/wallet.cpp | 100 +++++++++++++++++++ + src/wallet/api/wallet.h | 14 +++ + src/wallet/api/wallet2_api.h | 13 +++ src/wallet/api/wallet_manager.cpp | 12 ++- - 12 files changed, 365 insertions(+), 25 deletions(-) + 13 files changed, 405 insertions(+), 26 deletions(-) create mode 100644 src/device/device_io_dummy.cpp create mode 100644 src/device/device_io_dummy.hpp @@ -131,10 +132,10 @@ index 392703a24..ffd419779 100644 diff --git a/src/device/device_io_dummy.cpp b/src/device/device_io_dummy.cpp new file mode 100644 -index 000000000..edb4beea3 +index 000000000..01e6fc7b7 --- /dev/null +++ b/src/device/device_io_dummy.cpp -@@ -0,0 +1,133 @@ +@@ -0,0 +1,161 @@ +// Copyright (c) 2017-2022, The Monero Project +// +// All rights reserved. @@ -189,6 +190,10 @@ index 000000000..edb4beea3 +size_t hw::io::device_io_dummy::receivedFromDeviceLength = 0; +bool hw::io::device_io_dummy::waitsForDeviceSend = false; +bool hw::io::device_io_dummy::waitsForDeviceReceive = false; ++void (*hw::io::device_io_dummy::sendToLedgerDeviceCallback)(unsigned char *command, unsigned int cmd_len) = nullptr; ++std::mutex hw::io::device_io_dummy::mutex; ++std::condition_variable hw::io::device_io_dummy::cv_send; ++std::condition_variable hw::io::device_io_dummy::cv_receive; + +namespace hw { + namespace io { @@ -227,22 +232,29 @@ index 000000000..edb4beea3 + + int device_io_dummy::exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input) { + MDEBUG("exchange(): locking mutex"); -+ boost::unique_lock lock(mutex); ++ std::unique_lock lock(mutex); + sendToDevice = command; + sendToDeviceLength = cmd_len; + waitsForDeviceSend = true; + waitsForDeviceReceive = true; ++ ++ // Call the callback if it's set ++ if (sendToLedgerDeviceCallback != nullptr) { ++ MDEBUG("exchange(): calling sendToLedgerDeviceCallback"); ++ sendToLedgerDeviceCallback(command, cmd_len); ++ } + MDEBUG("exchange(): waitsForDeviceSend"); -+ // NOTE: waitsForDeviceSend should be changed by external code ++ // Wait for the send flag to be cleared by external code + while (waitsForDeviceSend) { -+ usleep(1000); -+ MDEBUG("exchange(): waitsForDeviceSend (still)"); ++ cv_send.wait(lock); ++ MDEBUG("exchange(): waitsForDeviceSend notified"); + } + + MDEBUG("exchange(): waitsForDeviceReceive"); ++ // Wait for the receive flag to be cleared by external code + while (waitsForDeviceReceive) { -+ usleep(1000); -+ MDEBUG("exchange(): waitsForDeviceReceive (still)"); ++ cv_receive.wait(lock); ++ MDEBUG("exchange(): waitsForDeviceReceive notified"); + } + + if (receivedFromDeviceLength > max_resp_len) { @@ -250,7 +262,8 @@ index 000000000..edb4beea3 + return 1; + } + -+ memset(response,0,max_resp_len); ++ ++ memset(response, 0, max_resp_len); + memcpy(response, receivedFromDevice, receivedFromDeviceLength); + return receivedFromDeviceLength; + } @@ -263,18 +276,34 @@ index 000000000..edb4beea3 + MDEBUG("release()"); + } + ++ void device_io_dummy::setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)) { ++ MDEBUG("setLedgerCallback()"); ++ sendToLedgerDeviceCallback = sendToLedgerDevice; ++ } + ++ void device_io_dummy::setDeviceReceivedData(unsigned char* data, size_t len) { ++ MDEBUG("setDeviceReceivedData(len: " << len << ")"); ++ std::unique_lock lock(mutex); + ++ receivedFromDevice = data; ++ receivedFromDeviceLength = len; ++ ++ waitsForDeviceSend = false; ++ waitsForDeviceReceive = false; ++ ++ cv_send.notify_all(); ++ cv_receive.notify_all(); ++ } + } +} +#endif // HAVE_HIDAPI \ No newline at end of file diff --git a/src/device/device_io_dummy.hpp b/src/device/device_io_dummy.hpp new file mode 100644 -index 000000000..a1733616d +index 000000000..1128b9c1d --- /dev/null +++ b/src/device/device_io_dummy.hpp -@@ -0,0 +1,74 @@ +@@ -0,0 +1,82 @@ +// Copyright (c) 2017-2022, The Monero Project +// +// All rights reserved. @@ -309,6 +338,8 @@ index 000000000..a1733616d + +#include "device_io.hpp" +#include "device_io_hid.hpp" ++#include ++#include + +namespace hw { + namespace io { @@ -320,9 +351,11 @@ index 000000000..a1733616d + }; + class device_io_dummy : device_io { + private: -+ boost::mutex mutex; ++ static std::mutex mutex; + + public: ++ static std::condition_variable cv_send; ++ static std::condition_variable cv_receive; + static bool stateIsConnected; + static unsigned char* sendToDevice; + static size_t sendToDeviceLength; @@ -330,6 +363,7 @@ index 000000000..a1733616d + static size_t receivedFromDeviceLength; + static bool waitsForDeviceSend; + static bool waitsForDeviceReceive; ++ static void (*sendToLedgerDeviceCallback)(unsigned char *command, unsigned int cmd_len); + + device_io_dummy() = default; + device_io_dummy(int a, int b, int c, int d); @@ -343,7 +377,10 @@ index 000000000..a1733616d + void disconnect(); + bool connected() const; + -+ int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input); ++ int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input); ++ ++ static void setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)); ++ static void setDeviceReceivedData(unsigned char* data, size_t len); + }; + }; +}; @@ -415,7 +452,7 @@ index 03058c4f1..39454ca6d 100644 unsigned char buffer_send[BUFFER_SEND_SIZE]; unsigned int length_recv; diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index 3fcd6f332..25ade04a7 100644 +index 3fcd6f332..844a1c451 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -48,6 +48,9 @@ @@ -428,91 +465,87 @@ index 3fcd6f332..25ade04a7 100644 using namespace std; using namespace cryptonote; -@@ -3178,4 +3181,95 @@ uint64_t WalletImpl::getBytesSent() +@@ -3178,4 +3181,101 @@ uint64_t WalletImpl::getBytesSent() return m_wallet->get_bytes_sent(); } + +// HIDAPI_DUMMY -+bool WalletImpl::getStateIsConnected() { ++bool Wallet::getStateIsConnected() { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return false; + #else + return hw::io::device_io_dummy::stateIsConnected; + #endif +} + -+unsigned char* WalletImpl::getSendToDevice() { ++unsigned char* Wallet::getSendToDevice() { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return {}; + #else + return hw::io::device_io_dummy::sendToDevice; + #endif +} + -+size_t WalletImpl::getSendToDeviceLength() { ++size_t Wallet::getSendToDeviceLength() { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return -1; + #else + return hw::io::device_io_dummy::sendToDeviceLength; + #endif +} + -+unsigned char* WalletImpl::getReceivedFromDevice() { ++unsigned char* Wallet::getReceivedFromDevice() { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return {}; + #else + return hw::io::device_io_dummy::receivedFromDevice; + #endif +} + -+size_t WalletImpl::getReceivedFromDeviceLength() { ++size_t Wallet::getReceivedFromDeviceLength() { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return -1; + #else + return hw::io::device_io_dummy::receivedFromDeviceLength; + #endif +} + -+bool WalletImpl::getWaitsForDeviceSend() { ++bool Wallet::getWaitsForDeviceSend() { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return false; + #else -+ return hw::io::device_io_dummy::receivedFromDeviceLength; ++ return hw::io::device_io_dummy::waitsForDeviceSend; + #endif +} + -+bool WalletImpl::getWaitsForDeviceReceive() { ++bool Wallet::getWaitsForDeviceReceive() { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return false; + #else + return hw::io::device_io_dummy::waitsForDeviceReceive; + #endif +} + -+void WalletImpl::setDeviceReceivedData(unsigned char* data, size_t len) { ++void Wallet::setDeviceReceivedData(unsigned char* data, size_t len) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return; + #else -+ hw::io::device_io_dummy::receivedFromDevice = static_cast(malloc(len)); -+ hw::io::device_io_dummy::receivedFromDeviceLength = len; -+ memset(hw::io::device_io_dummy::receivedFromDevice, 0, len); -+ memcpy(hw::io::device_io_dummy::receivedFromDevice, data, len); -+ hw::io::device_io_dummy::waitsForDeviceReceive = false; ++ hw::io::device_io_dummy::setDeviceReceivedData(data, len); + #endif +} + -+void WalletImpl::setDeviceSendData(unsigned char* data, size_t len) { ++void Wallet::setDeviceSendData(unsigned char* data, size_t len) { + #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) -+ setStatusError("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); + return; + #else + hw::io::device_io_dummy::sendToDevice = static_cast(malloc(len)); @@ -520,15 +553,25 @@ index 3fcd6f332..25ade04a7 100644 + memset(hw::io::device_io_dummy::sendToDevice, 0, len); + memcpy(hw::io::device_io_dummy::sendToDevice, data, len); + hw::io::device_io_dummy::waitsForDeviceSend = false; ++ hw::io::device_io_dummy::cv_send.notify_all(); ++ #endif ++} ++ ++void Wallet::setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)) { ++ #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI)) ++ MERROR("MONERO compiled with #if !(defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI))"); ++ return; ++ #else ++ hw::io::device_io_dummy::setLedgerCallback(sendToLedgerDevice); + #endif +} + } // namespace diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h -index edf8bb8ce..4e9c21ecb 100644 +index edf8bb8ce..6bfb61cb8 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h -@@ -301,6 +301,24 @@ private: +@@ -301,6 +301,20 @@ private: // cache connection status to avoid unnecessary RPC calls mutable std::atomic m_is_connected; boost::optional m_daemon_login{}; @@ -546,33 +589,30 @@ index edf8bb8ce..4e9c21ecb 100644 + bool getWaitsForDeviceSend(); + + bool getWaitsForDeviceReceive(); -+ -+ void setDeviceReceivedData(unsigned char *data, size_t len); -+ -+ void setDeviceSendData(unsigned char *data, size_t len); }; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index 764adbfbf..53ec4abfc 100644 +index 764adbfbf..a48a6be54 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h -@@ -1150,6 +1150,18 @@ struct Wallet +@@ -1150,6 +1150,19 @@ struct Wallet //! get bytes sent virtual uint64_t getBytesSent() = 0; + + // HIDAPI_DUMMY -+ virtual bool getStateIsConnected() = 0; -+ virtual unsigned char* getSendToDevice() = 0; -+ virtual size_t getSendToDeviceLength() = 0; -+ virtual unsigned char* getReceivedFromDevice() = 0; -+ virtual size_t getReceivedFromDeviceLength() = 0; -+ virtual bool getWaitsForDeviceSend() = 0; -+ virtual bool getWaitsForDeviceReceive() = 0; ++ static bool getStateIsConnected(); ++ static unsigned char* getSendToDevice(); ++ static size_t getSendToDeviceLength(); ++ static unsigned char* getReceivedFromDevice(); ++ static size_t getReceivedFromDeviceLength(); ++ static bool getWaitsForDeviceSend(); ++ static bool getWaitsForDeviceReceive(); + -+ virtual void setDeviceReceivedData(unsigned char* data, size_t len) = 0; -+ virtual void setDeviceSendData(unsigned char* data, size_t len) = 0; ++ static void setDeviceReceivedData(unsigned char* data, size_t len); ++ static void setDeviceSendData(unsigned char* data, size_t len); ++ static void setLedgerCallback(void (*sendToLedgerDevice)(unsigned char *command, unsigned int cmd_len)); }; /** @@ -600,5 +640,5 @@ index e81b8f83a..277be6ac9 100644 std::vector WalletManagerImpl::findWallets(const std::string &path) -- -2.48.1 +2.49.0 diff --git a/patches/monero/0007-polyseed.patch b/patches/monero/0007-polyseed.patch index b590a33..e83678e 100644 --- a/patches/monero/0007-polyseed.patch +++ b/patches/monero/0007-polyseed.patch @@ -1,7 +1,7 @@ -From c54ab3f0984159bd47c63b78074caaaac082727a Mon Sep 17 00:00:00 2001 +From 3c3d441cabcaae9eb5d3db2f5cd6c506feb97168 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 12 Mar 2024 09:42:37 +0100 -Subject: [PATCH 07/14] polyseed +Subject: [PATCH 07/17] polyseed Co-authored-by: Czarek Nakamoto --- @@ -814,7 +814,7 @@ index 000000000..2c8c777a7 +#endif //POLYSEED_HPP \ No newline at end of file diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index 25ade04a7..51911bf99 100644 +index 844a1c451..050212ff7 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -728,6 +728,28 @@ bool WalletImpl::recoverFromDevice(const std::string &path, const std::string &p @@ -902,7 +902,7 @@ index 25ade04a7..51911bf99 100644 { return m_wallet->get_seed_language(); diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h -index 4e9c21ecb..32e12284b 100644 +index 6bfb61cb8..e7873dd78 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -79,9 +79,19 @@ public: @@ -926,7 +926,7 @@ index 4e9c21ecb..32e12284b 100644 void setSeedLanguage(const std::string &arg) override; // void setListener(Listener *) {} diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index 53ec4abfc..be1c3704e 100644 +index a48a6be54..8fa0bbd42 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -709,6 +709,10 @@ struct Wallet @@ -940,7 +940,7 @@ index 53ec4abfc..be1c3704e 100644 /** * @brief StartRefresh - Start/resume refresh thread (refresh every 10 seconds) */ -@@ -1320,6 +1324,27 @@ struct WalletManager +@@ -1321,6 +1325,27 @@ struct WalletManager uint64_t kdf_rounds = 1, WalletListener * listener = nullptr) = 0; @@ -1282,5 +1282,5 @@ index a752f15b9..a619bdd15 100644 uint32_t m_multisig_threshold; std::vector m_multisig_signers; -- -2.48.1 +2.49.0 diff --git a/patches/monero/0008-coin-control.patch b/patches/monero/0008-coin-control.patch index 442921d..d0f2811 100644 --- a/patches/monero/0008-coin-control.patch +++ b/patches/monero/0008-coin-control.patch @@ -1,7 +1,7 @@ -From 753d7eee48d8e9ab5950e48dc984cc1038c11dd1 Mon Sep 17 00:00:00 2001 +From 722abaf1f84d8444d40e277f8b97e54250195856 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 12 Mar 2024 11:07:57 +0100 -Subject: [PATCH 08/14] coin control +Subject: [PATCH 08/17] coin control --- src/simplewallet/simplewallet.cpp | 2 +- @@ -504,7 +504,7 @@ index 000000000..c43e45abd + +#endif //FEATHER_COINS_INFO_H diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index 51911bf99..933cc2531 100644 +index 050212ff7..b259528ef 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -35,6 +35,7 @@ @@ -760,7 +760,7 @@ index 51911bf99..933cc2531 100644 { return m_subaddress.get(); diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h -index 32e12284b..a82f270e4 100644 +index e7873dd78..bc782dd4a 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -46,6 +46,7 @@ class PendingTransactionImpl; @@ -813,7 +813,7 @@ index 32e12284b..a82f270e4 100644 // multi-threaded refresh stuff diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index be1c3704e..013b5bcba 100644 +index 8fa0bbd42..7e67f02fd 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -263,6 +263,51 @@ struct AddressBook @@ -1095,5 +1095,5 @@ index a619bdd15..4f324c238 100644 void set_unspent(size_t idx); bool is_spent(const transfer_details &td, bool strict = true) const; -- -2.48.1 +2.49.0 diff --git a/patches/monero/0009-Add-hex-encoding-and-tx-key-getter-for-PendingTransc.patch b/patches/monero/0009-Add-hex-encoding-and-tx-key-getter-for-PendingTransc.patch index 9e04787..9741055 100644 --- a/patches/monero/0009-Add-hex-encoding-and-tx-key-getter-for-PendingTransc.patch +++ b/patches/monero/0009-Add-hex-encoding-and-tx-key-getter-for-PendingTransc.patch @@ -1,7 +1,7 @@ -From 0ba0339b11d8f7f66f2d5cd27075d438a76351b4 Mon Sep 17 00:00:00 2001 +From f386189cf3c5b433251b2cf493ba264a1a79fb7e Mon Sep 17 00:00:00 2001 From: M Date: Fri, 21 Apr 2023 15:43:47 -0400 -Subject: [PATCH 09/14] Add hex encoding and tx key getter for +Subject: [PATCH 09/17] Add hex encoding and tx key getter for PendingTransction in wallet api. --- @@ -51,7 +51,7 @@ index 403bfe281..0cc6c58e9 100644 private: friend class WalletImpl; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index 013b5bcba..f421fdc05 100644 +index 7e67f02fd..7f1462a44 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -127,6 +127,8 @@ struct PendingTransaction @@ -64,5 +64,5 @@ index 013b5bcba..f421fdc05 100644 /** -- -2.48.1 +2.49.0 diff --git a/patches/monero/0010-Add-recoverDeterministicWalletFromSpendKey.patch b/patches/monero/0010-Add-recoverDeterministicWalletFromSpendKey.patch index 022604d..8d939f8 100644 --- a/patches/monero/0010-Add-recoverDeterministicWalletFromSpendKey.patch +++ b/patches/monero/0010-Add-recoverDeterministicWalletFromSpendKey.patch @@ -1,7 +1,7 @@ -From cb02355313d504e6a44f8f70b8eb2be64167ffd4 Mon Sep 17 00:00:00 2001 +From 55f5311122fb9d19e870fa4a330c59d76ca92aac Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Wed, 11 Oct 2023 16:47:59 +0200 -Subject: [PATCH 10/14] Add recoverDeterministicWalletFromSpendKey +Subject: [PATCH 10/17] Add recoverDeterministicWalletFromSpendKey This function is used by Cake Wallet to enable polyseed (dart implementation) support. @@ -19,7 +19,7 @@ Co-authored-by: Godwin Asuquo 5 files changed, 75 insertions(+) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index 933cc2531..d8fe108b4 100644 +index b259528ef..20ccbfb35 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -824,6 +824,35 @@ bool WalletImpl::recover(const std::string &path, const std::string &password, c @@ -59,7 +59,7 @@ index 933cc2531..d8fe108b4 100644 { diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h -index a82f270e4..9e1fbb40b 100644 +index bc782dd4a..bfe81c590 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -77,6 +77,10 @@ public: @@ -74,10 +74,10 @@ index a82f270e4..9e1fbb40b 100644 const std::string &password, const std::string &device_name); diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index f421fdc05..c8d6bb179 100644 +index 7f1462a44..27e8b1426 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h -@@ -1323,6 +1323,25 @@ struct WalletManager +@@ -1324,6 +1324,25 @@ struct WalletManager return createWalletFromKeys(path, password, language, testnet ? TESTNET : MAINNET, restoreHeight, addressString, viewKeyString, spendKeyString); } @@ -149,5 +149,5 @@ index 28fcd36c9..be3ff8184 100644 const std::string &password, NetworkType nettype, -- -2.48.1 +2.49.0 diff --git a/patches/monero/0011-add-monero-submodule-support.patch b/patches/monero/0011-add-monero-submodule-support.patch index cbe6f35..413aaba 100644 --- a/patches/monero/0011-add-monero-submodule-support.patch +++ b/patches/monero/0011-add-monero-submodule-support.patch @@ -1,7 +1,7 @@ -From 846d3f60093add6653d9102d841288066fc08311 Mon Sep 17 00:00:00 2001 +From ec93b6bf725eeff0999fdd9d603c4578cb19ae07 Mon Sep 17 00:00:00 2001 From: cyan Date: Thu, 7 Nov 2024 16:46:24 +0000 -Subject: [PATCH 11/14] add monero submodule support +Subject: [PATCH 11/17] add monero submodule support --- CMakeLists.txt | 6 +++--- @@ -61,5 +61,5 @@ index 3188c88db..9fbdb3c05 100644 if (ptx_vector.empty()) { -- -2.48.1 +2.49.0 diff --git a/patches/monero/0012-fix-iOS-depends-build.patch b/patches/monero/0012-fix-iOS-depends-build.patch index dcf7c86..5d75424 100644 --- a/patches/monero/0012-fix-iOS-depends-build.patch +++ b/patches/monero/0012-fix-iOS-depends-build.patch @@ -1,7 +1,7 @@ -From 53cc0482e55a39b5dbf2261fea11fcb160778800 Mon Sep 17 00:00:00 2001 +From 73d6ad9d513f776afb1c1f5f2d74e3b06fad7eeb Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Thu, 21 Nov 2024 06:05:03 -0500 -Subject: [PATCH 12/14] fix iOS depends build +Subject: [PATCH 12/17] fix iOS depends build --- CMakeLists.txt | 4 ---- @@ -100,5 +100,5 @@ index 71b8f78cc..0f53f024e 100644 #if TARGET_OS_MAC && (!defined(MAC_OS_X_VERSION_MIN_REQUIRED) || MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7) return boost::logic::tribool(IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited); -- -2.48.1 +2.49.0 diff --git a/patches/monero/0013-include-locale-only-when-targeting-WIN32.patch b/patches/monero/0013-include-locale-only-when-targeting-WIN32.patch index 64ef6aa..453d651 100644 --- a/patches/monero/0013-include-locale-only-when-targeting-WIN32.patch +++ b/patches/monero/0013-include-locale-only-when-targeting-WIN32.patch @@ -1,8 +1,7 @@ -From 1eacd30724559749be5adeb31d763f44c3f221f9 Mon Sep 17 00:00:00 2001 +From db52bcebe23b29b35ae538f01e72ed4f7f66f931 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Mon, 18 Nov 2024 10:57:37 -0500 -Subject: [PATCH 13/14] include locale only when targeting WIN32 - +Subject: [PATCH 13/17] include locale only when targeting WIN32 --- CMakeLists.txt | 6 +++++- @@ -10,7 +9,7 @@ Subject: [PATCH 13/14] include locale only when targeting WIN32 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt -index 1eac121db..3a4e8f7e1 100644 +index 1eac121db..5938be622 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1089,7 +1089,11 @@ if(NOT Boost_FOUND) @@ -27,7 +26,7 @@ index 1eac121db..3a4e8f7e1 100644 # Boost System is header-only since 1.69 if (Boost_VERSION_STRING VERSION_LESS 1.69.0) diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index d8fe108b4..e3e838b13 100644 +index 20ccbfb35..c43803033 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -46,7 +46,9 @@ @@ -41,5 +40,5 @@ index d8fe108b4..e3e838b13 100644 #include "bc-ur/src/bc-ur.hpp" #if defined(HIDAPI_DUMMY) && !defined(HAVE_HIDAPI) -- -2.48.1 +2.49.0 diff --git a/patches/monero/0014-change-earliest-fork-height-message.patch b/patches/monero/0014-change-earliest-fork-height-message.patch index e73f776..c097694 100644 --- a/patches/monero/0014-change-earliest-fork-height-message.patch +++ b/patches/monero/0014-change-earliest-fork-height-message.patch @@ -1,7 +1,7 @@ -From 2d31234e859bff817d30d91b21d9412375668aae Mon Sep 17 00:00:00 2001 +From be01eac2724d22cd7225bb17fba7a443efe8d8d6 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Wed, 29 Jan 2025 16:13:28 +0100 -Subject: [PATCH 14/14] change earliest fork height message +Subject: [PATCH 14/17] change earliest fork height message --- src/wallet/wallet2.cpp | 2 +- @@ -21,5 +21,5 @@ index 8720e18b1..69da11d9c 100644 bool close_enough = (int64_t)height >= (int64_t)earliest_height - early_blocks && earliest_height != std::numeric_limits::max(); // start using the rules that many blocks beforehand if (close_enough) -- -2.48.1 +2.49.0 diff --git a/patches/monero/0015-remove-trivially_copyable-assert.patch b/patches/monero/0015-remove-trivially_copyable-assert.patch index d78268f..4f22f32 100644 --- a/patches/monero/0015-remove-trivially_copyable-assert.patch +++ b/patches/monero/0015-remove-trivially_copyable-assert.patch @@ -1,7 +1,7 @@ -From 71cf45cfbd571ec58e8b2a1d408ff74804bf7e1d Mon Sep 17 00:00:00 2001 +From b62446750e904978cd1a8f90d5f2d1437a3db5a9 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Thu, 20 Feb 2025 08:36:28 +0100 -Subject: [PATCH] remove trivially_copyable assert +Subject: [PATCH 15/17] remove trivially_copyable assert --- contrib/epee/include/span.h | 1 - @@ -20,5 +20,5 @@ index 01dc387d6..2ad733a2f 100644 return {reinterpret_cast(std::addressof(src)), sizeof(T)}; } -- -2.48.1 +2.49.0 diff --git a/patches/monero/0016-pr-9880.patch b/patches/monero/0016-pr-9880.patch index dbf604f..22d1825 100644 --- a/patches/monero/0016-pr-9880.patch +++ b/patches/monero/0016-pr-9880.patch @@ -1,14 +1,14 @@ -From 31ef09596a9d8d547905577823ff52d33e10a3d2 Mon Sep 17 00:00:00 2001 +From ab4e853571329b3ccb745c393220c047b03f2b2c Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Tue, 1 Apr 2025 11:30:45 +0200 -Subject: [PATCH] pr-9880 +Subject: [PATCH 16/17] pr-9880 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt -index 5938be6..1c47285 100644 +index 5938be622..1c4728578 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,7 +216,7 @@ function(forbid_undefined_symbols) diff --git a/patches/monero/0017-fix-unary_function-__unary_function.patch b/patches/monero/0017-fix-unary_function-__unary_function.patch index 22e5275..b964dbe 100644 --- a/patches/monero/0017-fix-unary_function-__unary_function.patch +++ b/patches/monero/0017-fix-unary_function-__unary_function.patch @@ -1,14 +1,14 @@ -From 0a3a2df040e177b5741706e0a0c76fac585f0356 Mon Sep 17 00:00:00 2001 +From 32f2e6cc2e184bfdaa92a5d45a15983c896f6816 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Thu, 10 Apr 2025 13:28:05 +0200 -Subject: [PATCH] fix: unary_function -> __unary_function +Subject: [PATCH 17/17] fix: unary_function -> __unary_function --- src/cryptonote_basic/cryptonote_basic_impl.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cryptonote_basic/cryptonote_basic_impl.h b/src/cryptonote_basic/cryptonote_basic_impl.h -index b423573..a9aef7a 100644 +index b423573c5..a9aef7a2a 100644 --- a/src/cryptonote_basic/cryptonote_basic_impl.h +++ b/src/cryptonote_basic/cryptonote_basic_impl.h @@ -40,7 +40,11 @@ namespace cryptonote {