Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNM: Better ledger dummy #90

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 27 additions & 54 deletions impls/monero.dart/lib/monero.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ library;
// ignore_for_file: non_constant_identifier_names, camel_case_types

import 'dart:ffi';
import 'dart:ffi' as ffi;
import 'dart:io';
import 'dart:typed_data';

import 'package:ffi/ffi.dart';
import 'package:monero/src/generated_bindings_monero.g.dart';
Expand Down Expand Up @@ -3279,6 +3281,8 @@ int MONERO_Wallet_getBytesSent(wallet ptr) {
return getBytesSent;
}

// Ledger Stuff

bool Wallet_getStateIsConnected(wallet ptr) {
debugStart?.call('MONERO_Wallet_getStateIsConnected');
lib ??= MoneroC(DynamicLibrary.open(libPath));
Expand All @@ -3287,68 +3291,37 @@ bool Wallet_getStateIsConnected(wallet ptr) {
return ret;
}

Pointer<UnsignedChar> Wallet_getSendToDevice(wallet ptr) {
debugStart?.call('MONERO_Wallet_getSendToDevice');
lib ??= MoneroC(DynamicLibrary.open(libPath));
final ret = lib!.MONERO_Wallet_getSendToDevice(ptr);
debugEnd?.call('MONERO_Wallet_getSendToDevice');
return ret;
}
typedef LedgerExchangeFunctionNative = Int Function(
Pointer<UnsignedChar> command,
UnsignedInt cmd_len,
Pointer<UnsignedChar> response,
UnsignedInt max_resp_len);

int Wallet_getSendToDeviceLength(wallet ptr) {
debugStart?.call('MONERO_Wallet_getSendToDeviceLength');
void Wallet_setLedgerExchange(
wallet ptr, Uint8List Function(Uint8List, int) sendToLedgerDevice) {
debugStart?.call('MONERO_Wallet_setLedgerExchange');
lib ??= MoneroC(DynamicLibrary.open(libPath));
final ret = lib!.MONERO_Wallet_getSendToDeviceLength(ptr);
debugEnd?.call('MONERO_Wallet_getSendToDeviceLength');
return ret;
}

Pointer<UnsignedChar> Wallet_getReceivedFromDevice(wallet ptr) {
debugStart?.call('MONERO_Wallet_getReceivedFromDevice');
lib ??= MoneroC(DynamicLibrary.open(libPath));
final ret = lib!.MONERO_Wallet_getReceivedFromDevice(ptr);
debugEnd?.call('MONERO_Wallet_getReceivedFromDevice');
return ret;
}
int sendToLedgerDeviceWrapper(Pointer<UnsignedChar> command, int cmd_len,
Pointer<UnsignedChar> response, int max_resp_len) {
final command_ = command.cast<Uint8>().asTypedList(cmd_len);

int Wallet_getReceivedFromDeviceLength(wallet ptr) {
debugStart?.call('MONERO_Wallet_getReceivedFromDeviceLength');
lib ??= MoneroC(DynamicLibrary.open(libPath));
final ret = lib!.MONERO_Wallet_getReceivedFromDeviceLength(ptr);
debugEnd?.call('MONERO_Wallet_getReceivedFromDeviceLength');
return ret;
}
final res = sendToLedgerDevice(command_, max_resp_len);

bool Wallet_getWaitsForDeviceSend(wallet ptr) {
debugStart?.call('MONERO_Wallet_getWaitsForDeviceSend');
lib ??= MoneroC(DynamicLibrary.open(libPath));
final ret = lib!.MONERO_Wallet_getWaitsForDeviceSend(ptr);
debugEnd?.call('MONERO_Wallet_getWaitsForDeviceSend');
return ret;
}
calloc.free(command);

bool Wallet_getWaitsForDeviceReceive(wallet ptr) {
debugStart?.call('MONERO_Wallet_getWaitsForDeviceReceive');
lib ??= MoneroC(DynamicLibrary.open(libPath));
final ret = lib!.MONERO_Wallet_getWaitsForDeviceReceive(ptr);
debugEnd?.call('MONERO_Wallet_getWaitsForDeviceReceive');
return ret;
}
for (var i = 0; i < res.length; i++) {
response.cast<Uint8>().asTypedList(res.length)[i] = res[i];
}

void Wallet_setDeviceReceivedData(
wallet ptr, Pointer<UnsignedChar> data, int len) {
debugStart?.call('MONERO_Wallet_setDeviceReceivedData');
lib ??= MoneroC(DynamicLibrary.open(libPath));
final ret = lib!.MONERO_Wallet_setDeviceReceivedData(ptr, data, len);
debugEnd?.call('MONERO_Wallet_setDeviceReceivedData');
return ret;
}
return res.length;
}

void Wallet_setDeviceSendData(wallet ptr, Pointer<UnsignedChar> data, int len) {
debugStart?.call('MONERO_Wallet_setDeviceSendData');
lib ??= MoneroC(DynamicLibrary.open(libPath));
final ret = lib!.MONERO_Wallet_setDeviceSendData(ptr, data, len);
debugEnd?.call('MONERO_Wallet_setDeviceSendData');
final sendToLedgerDevice_ =
Pointer.fromFunction<LedgerExchangeFunctionNative>(
sendToLedgerDeviceWrapper, 0);
final ret = lib!.MONERO_Wallet_setLedgerExchange(ptr, sendToLedgerDevice_);
debugEnd?.call('MONERO_Wallet_setLedgerExchange');
return ret;
}

Expand Down
6 changes: 3 additions & 3 deletions impls/monero.dart/lib/src/checksum_monero.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: constant_identifier_names
const String wallet2_api_c_h_sha256 = "198a27486ce4f014b737f52ec2879a90838c3b3ca088de8dc7d55b79a10f4a5b";
const String wallet2_api_c_cpp_sha256 = "22b0c9dd542fb55edfe9e17da67e97ddf5f80bcdd3e126e1bd64cce54234bde1-b089f9ee69924882c5d14dd1a6991deb05d9d1cd";
const String wallet2_api_c_exp_sha256 = "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522";
const String wallet2_api_c_h_sha256 = "6fa19c7357e6674ee044cca718648bee2be9d2ab819395bd9c4fb8e63e0bcca7";
const String wallet2_api_c_cpp_sha256 = "bc35885da4f8744ec9989f52b7e3212b9d028da754fe7816d990299eec61da65-b089f9ee69924882c5d14dd1a6991deb05d9d1cd";
const String wallet2_api_c_exp_sha256 = "a81491e78d8f4568236856376d432705b48312c252050c1faeabc24c193764ce";
161 changes: 32 additions & 129 deletions impls/monero.dart/lib/src/generated_bindings_monero.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4399,143 +4399,46 @@ class MoneroC {
_MONERO_Wallet_getStateIsConnectedPtr.asFunction<
bool Function(ffi.Pointer<ffi.Void>)>();

ffi.Pointer<ffi.UnsignedChar> MONERO_Wallet_getSendToDevice(
void MONERO_Wallet_setLedgerExchange(
ffi.Pointer<ffi.Void> wallet_ptr,
ffi.Pointer<
ffi.NativeFunction<
ffi.Int Function(
ffi.Pointer<ffi.UnsignedChar> command,
ffi.UnsignedInt cmd_len,
ffi.Pointer<ffi.UnsignedChar> response,
ffi.UnsignedInt max_resp_len)>>
sendToLedgerDevice,
) {
return _MONERO_Wallet_getSendToDevice(
return _MONERO_Wallet_setLedgerExchange(
wallet_ptr,
sendToLedgerDevice,
);
}

late final _MONERO_Wallet_getSendToDevicePtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<ffi.UnsignedChar> Function(
ffi.Pointer<ffi.Void>)>>('MONERO_Wallet_getSendToDevice');
late final _MONERO_Wallet_getSendToDevice =
_MONERO_Wallet_getSendToDevicePtr.asFunction<
ffi.Pointer<ffi.UnsignedChar> Function(ffi.Pointer<ffi.Void>)>();

int MONERO_Wallet_getSendToDeviceLength(
ffi.Pointer<ffi.Void> wallet_ptr,
) {
return _MONERO_Wallet_getSendToDeviceLength(
wallet_ptr,
);
}

late final _MONERO_Wallet_getSendToDeviceLengthPtr =
_lookup<ffi.NativeFunction<ffi.Size Function(ffi.Pointer<ffi.Void>)>>(
'MONERO_Wallet_getSendToDeviceLength');
late final _MONERO_Wallet_getSendToDeviceLength =
_MONERO_Wallet_getSendToDeviceLengthPtr.asFunction<
int Function(ffi.Pointer<ffi.Void>)>();

ffi.Pointer<ffi.UnsignedChar> MONERO_Wallet_getReceivedFromDevice(
ffi.Pointer<ffi.Void> wallet_ptr,
) {
return _MONERO_Wallet_getReceivedFromDevice(
wallet_ptr,
);
}

late final _MONERO_Wallet_getReceivedFromDevicePtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<ffi.UnsignedChar> Function(
ffi.Pointer<ffi.Void>)>>('MONERO_Wallet_getReceivedFromDevice');
late final _MONERO_Wallet_getReceivedFromDevice =
_MONERO_Wallet_getReceivedFromDevicePtr.asFunction<
ffi.Pointer<ffi.UnsignedChar> Function(ffi.Pointer<ffi.Void>)>();

int MONERO_Wallet_getReceivedFromDeviceLength(
ffi.Pointer<ffi.Void> wallet_ptr,
) {
return _MONERO_Wallet_getReceivedFromDeviceLength(
wallet_ptr,
);
}

late final _MONERO_Wallet_getReceivedFromDeviceLengthPtr =
_lookup<ffi.NativeFunction<ffi.Size Function(ffi.Pointer<ffi.Void>)>>(
'MONERO_Wallet_getReceivedFromDeviceLength');
late final _MONERO_Wallet_getReceivedFromDeviceLength =
_MONERO_Wallet_getReceivedFromDeviceLengthPtr.asFunction<
int Function(ffi.Pointer<ffi.Void>)>();

bool MONERO_Wallet_getWaitsForDeviceSend(
ffi.Pointer<ffi.Void> wallet_ptr,
) {
return _MONERO_Wallet_getWaitsForDeviceSend(
wallet_ptr,
);
}

late final _MONERO_Wallet_getWaitsForDeviceSendPtr =
_lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Pointer<ffi.Void>)>>(
'MONERO_Wallet_getWaitsForDeviceSend');
late final _MONERO_Wallet_getWaitsForDeviceSend =
_MONERO_Wallet_getWaitsForDeviceSendPtr.asFunction<
bool Function(ffi.Pointer<ffi.Void>)>();

bool MONERO_Wallet_getWaitsForDeviceReceive(
ffi.Pointer<ffi.Void> wallet_ptr,
) {
return _MONERO_Wallet_getWaitsForDeviceReceive(
wallet_ptr,
);
}

late final _MONERO_Wallet_getWaitsForDeviceReceivePtr =
_lookup<ffi.NativeFunction<ffi.Bool Function(ffi.Pointer<ffi.Void>)>>(
'MONERO_Wallet_getWaitsForDeviceReceive');
late final _MONERO_Wallet_getWaitsForDeviceReceive =
_MONERO_Wallet_getWaitsForDeviceReceivePtr.asFunction<
bool Function(ffi.Pointer<ffi.Void>)>();

void MONERO_Wallet_setDeviceReceivedData(
ffi.Pointer<ffi.Void> wallet_ptr,
ffi.Pointer<ffi.UnsignedChar> data,
int len,
) {
return _MONERO_Wallet_setDeviceReceivedData(
wallet_ptr,
data,
len,
);
}

late final _MONERO_Wallet_setDeviceReceivedDataPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.UnsignedChar>,
ffi.Size)>>('MONERO_Wallet_setDeviceReceivedData');
late final _MONERO_Wallet_setDeviceReceivedData =
_MONERO_Wallet_setDeviceReceivedDataPtr.asFunction<
late final _MONERO_Wallet_setLedgerExchangePtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<
ffi.NativeFunction<
ffi.Int Function(
ffi.Pointer<ffi.UnsignedChar> command,
ffi.UnsignedInt cmd_len,
ffi.Pointer<ffi.UnsignedChar> response,
ffi.UnsignedInt max_resp_len)>>)>>(
'MONERO_Wallet_setLedgerExchange');
late final _MONERO_Wallet_setLedgerExchange =
_MONERO_Wallet_setLedgerExchangePtr.asFunction<
void Function(
ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.UnsignedChar>, int)>();

void MONERO_Wallet_setDeviceSendData(
ffi.Pointer<ffi.Void> wallet_ptr,
ffi.Pointer<ffi.UnsignedChar> data,
int len,
) {
return _MONERO_Wallet_setDeviceSendData(
wallet_ptr,
data,
len,
);
}

late final _MONERO_Wallet_setDeviceSendDataPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.UnsignedChar>,
ffi.Size)>>('MONERO_Wallet_setDeviceSendData');
late final _MONERO_Wallet_setDeviceSendData =
_MONERO_Wallet_setDeviceSendDataPtr.asFunction<
void Function(
ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.UnsignedChar>, int)>();
ffi.Pointer<
ffi.NativeFunction<
ffi.Int Function(
ffi.Pointer<ffi.UnsignedChar> command,
ffi.UnsignedInt cmd_len,
ffi.Pointer<ffi.UnsignedChar> response,
ffi.UnsignedInt max_resp_len)>>)>();

ffi.Pointer<ffi.Void> MONERO_WalletManager_createWallet(
ffi.Pointer<ffi.Void> wm_ptr,
Expand Down
6 changes: 3 additions & 3 deletions impls/monero.ts/checksum_monero.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const moneroChecksum = {
wallet2_api_c_h_sha256: "198a27486ce4f014b737f52ec2879a90838c3b3ca088de8dc7d55b79a10f4a5b",
wallet2_api_c_cpp_sha256: "22b0c9dd542fb55edfe9e17da67e97ddf5f80bcdd3e126e1bd64cce54234bde1-b089f9ee69924882c5d14dd1a6991deb05d9d1cd",
wallet2_api_c_exp_sha256: "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522",
wallet2_api_c_h_sha256: "6fa19c7357e6674ee044cca718648bee2be9d2ab819395bd9c4fb8e63e0bcca7",
wallet2_api_c_cpp_sha256: "bc35885da4f8744ec9989f52b7e3212b9d028da754fe7816d990299eec61da65-b089f9ee69924882c5d14dd1a6991deb05d9d1cd",
wallet2_api_c_exp_sha256: "a81491e78d8f4568236856376d432705b48312c252050c1faeabc24c193764ce",
}
9 changes: 1 addition & 8 deletions monero_libwallet2_api_c/monero_libwallet2_api_c.exp
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,7 @@ _MONERO_Wallet_reconnectDevice
_MONERO_Wallet_getBytesReceived
_MONERO_Wallet_getBytesSent
_MONERO_Wallet_getStateIsConnected
_MONERO_Wallet_getSendToDevice
_MONERO_Wallet_getSendToDeviceLength
_MONERO_Wallet_getReceivedFromDevice
_MONERO_Wallet_getReceivedFromDeviceLength
_MONERO_Wallet_getWaitsForDeviceSend
_MONERO_Wallet_getWaitsForDeviceReceive
_MONERO_Wallet_setDeviceReceivedData
_MONERO_Wallet_setDeviceSendData
_MONERO_Wallet_setLedgerExchange
_MONERO_WalletManager_createWallet
_MONERO_WalletManager_openWallet
_MONERO_WalletManager_recoveryWallet
Expand Down
6 changes: 3 additions & 3 deletions monero_libwallet2_api_c/src/main/cpp/monero_checksum.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef MONEROC_CHECKSUMS
#define MONEROC_CHECKSUMS
const char * MONERO_wallet2_api_c_h_sha256 = "198a27486ce4f014b737f52ec2879a90838c3b3ca088de8dc7d55b79a10f4a5b";
const char * MONERO_wallet2_api_c_cpp_sha256 = "22b0c9dd542fb55edfe9e17da67e97ddf5f80bcdd3e126e1bd64cce54234bde1-b089f9ee69924882c5d14dd1a6991deb05d9d1cd";
const char * MONERO_wallet2_api_c_exp_sha256 = "c1f785d62709fd8b849063ecf4fe8854d9e3b05b568b9716de98d33e7bdaf522";
const char * MONERO_wallet2_api_c_h_sha256 = "6fa19c7357e6674ee044cca718648bee2be9d2ab819395bd9c4fb8e63e0bcca7";
const char * MONERO_wallet2_api_c_cpp_sha256 = "bc35885da4f8744ec9989f52b7e3212b9d028da754fe7816d990299eec61da65-b089f9ee69924882c5d14dd1a6991deb05d9d1cd";
const char * MONERO_wallet2_api_c_exp_sha256 = "a81491e78d8f4568236856376d432705b48312c252050c1faeabc24c193764ce";
#endif
39 changes: 2 additions & 37 deletions monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,44 +1612,9 @@ bool MONERO_Wallet_getStateIsConnected(void* wallet_ptr) {
return wallet->getStateIsConnected();
}

unsigned char* MONERO_Wallet_getSendToDevice(void* wallet_ptr) {
void MONERO_Wallet_setLedgerExchange(void* wallet_ptr, int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len)) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->getSendToDevice();
}

size_t MONERO_Wallet_getSendToDeviceLength(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->getSendToDeviceLength();
}

unsigned char* MONERO_Wallet_getReceivedFromDevice(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->getReceivedFromDevice();
}

size_t MONERO_Wallet_getReceivedFromDeviceLength(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->getReceivedFromDeviceLength();
}

bool MONERO_Wallet_getWaitsForDeviceSend(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->getWaitsForDeviceSend();
}

bool MONERO_Wallet_getWaitsForDeviceReceive(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->getWaitsForDeviceReceive();
}

void MONERO_Wallet_setDeviceReceivedData(void* wallet_ptr, unsigned char* data, size_t len) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->setDeviceReceivedData(data, len);
}

void MONERO_Wallet_setDeviceSendData(void* wallet_ptr, unsigned char* data, size_t len) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
return wallet->setDeviceSendData(data, len);
return wallet->setLedgerExchange(sendToLedgerDevice);
}

void* MONERO_WalletManager_createWallet(void* wm_ptr, const char* path, const char* password, const char* language, int networkType) {
Expand Down
9 changes: 1 addition & 8 deletions monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,14 +835,7 @@ extern ADDAPI uint64_t MONERO_Wallet_getBytesReceived(void* wallet_ptr);
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 void MONERO_Wallet_setLedgerExchange(void* wallet_ptr, int (*sendToLedgerDevice) (unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len));
// };

// struct WalletManager
Expand Down
Loading
Loading