fix: merge fixes

This commit is contained in:
Rafael Saes 2023-11-18 19:11:00 -03:00
parent bc24ed5fab
commit aff2651cba
12 changed files with 186 additions and 103 deletions
cw_bitcoin/lib
cw_bitcoin_cash/linux/flutter/ephemeral/.plugin_symlinks
cw_core
cw_haven
cw_nano
lib
linux/flutter
macos/Flutter

View file

@ -222,7 +222,9 @@ abstract class ElectrumWalletBase
throw BitcoinTransactionNoInputsException();
}
final allAmountFee = 222;
final allAmountFee = transactionCredentials.feeRate != null
? feeAmountWithFeeRate(transactionCredentials.feeRate!, inputs.length, outputs.length)
: feeAmountForPriority(transactionCredentials.priority!, inputs.length, outputs.length);
final allAmount = allInputsAmount - allAmountFee;
@ -292,18 +294,13 @@ abstract class ElectrumWalletBase
for (int i = 0; i < inputs.length; i++) {
final utx = inputs[i];
leftAmount = utx.value - leftAmount;
leftAmount = leftAmount - utx.value;
totalInputAmount += utx.value;
if (leftAmount <= 0) {
break;
}
final isSilentPayment = utx.bitcoinAddressRecord.silentPaymentTweak != null;
outpoints.add(bitcoin.Outpoint(txid: utx.hash, index: utx.vout));
if (isSilentPayment) {
print(utx.bitcoinAddressRecord.silentPaymentTweak);
if (utx.bitcoinAddressRecord.silentPaymentTweak != null) {
// https://github.com/bitcoin/bips/blob/c55f80c53c98642357712c1839cfdc0551d531c4/bip-0352.mediawiki#user-content-Spending
final d = bitcoin.PrivateKey.fromHex(bitcoin.getSecp256k1(),
walletAddresses.silentAddress!.spendPrivkey.toCompressedHex())
@ -356,6 +353,10 @@ abstract class ElectrumWalletBase
}
txb.addInput(utx.hash, utx.vout, null, null, keyPair, utx.value);
if (leftAmount <= 0) {
break;
}
}
if (txb.inputs.isEmpty) {
@ -371,6 +372,7 @@ abstract class ElectrumWalletBase
final outputAmount = hasMultiDestination ? item.formattedCryptoAmount : amount;
final outputAddress = item.isParsedAddress ? item.extractedAddress! : item.address;
if (outputAddress.startsWith('tsp1')) {
print([outputAddress, outputAmount!]);
silentPaymentDestinations
.add(bitcoin.SilentPaymentDestination.fromAddress(outputAddress, outputAmount!));
} else {
@ -390,19 +392,20 @@ abstract class ElectrumWalletBase
// TODO: DRY code: pubkeyToOutputScript (?)
final point = bitcoin.ECPublic.fromHex(generatedPubkey).toTapPoint();
final p2tr = bitcoin.P2trAddress(program: point);
txb.addOutput(p2tr.toScriptPubKey().toBytes(), amount);
print([p2tr.toScriptPubKey().toBytes(), output.$2]);
txb.addOutput(p2tr.toScriptPubKey().toBytes(), output.$2);
});
});
}
final estimatedSize = estimatedTransactionSize(inputs.length, outputs.length + 1);
var feeAmount = 222;
var feeAmount = 0;
// if (transactionCredentials.feeRate != null) {
// feeAmount = transactionCredentials.feeRate! * estimatedSize;
// } else {
// feeAmount = feeRate(transactionCredentials.priority!) * estimatedSize;
// }
if (transactionCredentials.feeRate != null) {
feeAmount = transactionCredentials.feeRate! * estimatedSize;
} else {
feeAmount = feeRate(transactionCredentials.priority!) * estimatedSize;
}
final changeValue = totalInputAmount - amount - feeAmount;
@ -553,10 +556,10 @@ abstract class ElectrumWalletBase
runningIsolate.kill(priority: Isolate.immediate);
}
if (currentChainTip <= height) {
syncStatus = SyncedSyncStatus();
return;
}
// if (currentChainTip <= height) {
// syncStatus = SyncedSyncStatus();
// return;
// }
final receivePort = ReceivePort();
_isolate = Isolate.spawn(
@ -578,32 +581,8 @@ abstract class ElectrumWalletBase
await for (var message in receivePort) {
if (message is BitcoinUnspent) {
final myNewUnspent = message;
final hasUnspent = unspentCoins.any((element) {
if (element.address == message.address) {
unspentCoins.remove(element);
unspentCoins.add(myNewUnspent);
return true;
}
return false;
});
if (!hasUnspent) {
unspentCoins.add(myNewUnspent);
}
final myNewAddress = message.bitcoinAddressRecord;
final hasAddress = walletAddresses.addresses.any((element) {
if (element.address == message.address) {
walletAddresses.addresses.remove(element);
walletAddresses.addresses.add(myNewAddress);
return true;
}
return false;
});
if (!hasAddress) {
walletAddresses.addresses.add(myNewAddress);
}
unspentCoins.add(message);
walletAddresses.addresses.add(message.bitcoinAddressRecord);
await save();
await updateUnspent();
@ -722,8 +701,6 @@ abstract class ElectrumWalletBase
final addressHashes = <String, BitcoinAddressRecord>{};
final normalizedHistories = <Map<String, dynamic>>[];
walletAddresses.addresses.forEach((addressRecord) {
if (addressRecord.address ==
"tb1pch9qmsq87wy4my4akd60x2r2yt784zfmfwqeuk7w7g7u45za4ktq9pdnmf") {}
final sh = scriptHash(addressRecord.address, networkType: networkType);
addressHashes[sh] = addressRecord;
});
@ -998,10 +975,10 @@ class SyncResponse {
Future<void> startRefresh(ScanData scanData) async {
final currentChainTip = scanData.chainTip;
if (scanData.height >= currentChainTip) {
scanData.sendPort.send(SyncResponse(scanData.height, SyncedSyncStatus()));
return;
}
// if (scanData.height >= currentChainTip) {
// scanData.sendPort.send(SyncResponse(scanData.height, SyncedSyncStatus()));
// return;
// }
var checkpointTxPos = scanData.checkpointTxPos;
final height = scanData.height;
@ -1115,9 +1092,13 @@ Future<void> startRefresh(ScanData scanData) async {
continue;
}
print("UNSPENT COIN FOUND!");
if (result.length > 1) {
print("MULTIPLE UNSPENT COINS FOUND!");
} else {
print("UNSPENT COIN FOUND!");
}
print(result);
result.forEach((key, value) {
final outpoint = outpointsByP2TRpubkey[key];

View file

@ -0,0 +1 @@
/home/rafael/.pub-cache/git/tor-09ba92cb11d4e3cacf97256e57863b805f79f2e5/

View file

@ -113,6 +113,15 @@ packages:
url: "https://pub.dev"
source: hosted
version: "8.4.3"
cake_backup:
dependency: "direct main"
description:
path: "."
ref: main
resolved-ref: "3aba867dcab6737f6707782f5db15d71f303db38"
url: "https://github.com/cake-tech/cake_backup.git"
source: git
version: "1.0.0+1"
characters:
dependency: transitive
description:
@ -169,6 +178,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.2"
cryptography:
dependency: transitive
description:
name: cryptography
sha256: df156c5109286340817d21fa7b62f9140f17915077127dd70f8bd7a2a0997a35
url: "https://pub.dev"
source: hosted
version: "2.5.0"
cupertino_icons:
dependency: transitive
description:
name: cupertino_icons
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
url: "https://pub.dev"
source: hosted
version: "1.0.6"
dart_style:
dependency: transitive
description:
@ -625,6 +650,14 @@ packages:
url: "https://github.com/cake-tech/tor.git"
source: git
version: "0.0.1"
tuple:
dependency: transitive
description:
name: tuple
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
url: "https://pub.dev"
source: hosted
version: "2.0.2"
typed_data:
dependency: transitive
description:

View file

@ -113,6 +113,15 @@ packages:
url: "https://pub.dev"
source: hosted
version: "8.4.3"
cake_backup:
dependency: transitive
description:
path: "."
ref: main
resolved-ref: "3aba867dcab6737f6707782f5db15d71f303db38"
url: "https://github.com/cake-tech/cake_backup.git"
source: git
version: "1.0.0+1"
characters:
dependency: transitive
description:
@ -169,6 +178,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.2"
cryptography:
dependency: transitive
description:
name: cryptography
sha256: df156c5109286340817d21fa7b62f9140f17915077127dd70f8bd7a2a0997a35
url: "https://pub.dev"
source: hosted
version: "2.5.0"
cupertino_icons:
dependency: transitive
description:
name: cupertino_icons
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
url: "https://pub.dev"
source: hosted
version: "1.0.6"
cw_core:
dependency: "direct main"
description:
@ -632,6 +657,14 @@ packages:
url: "https://github.com/cake-tech/tor.git"
source: git
version: "0.0.1"
tuple:
dependency: transitive
description:
name: tuple
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
url: "https://pub.dev"
source: hosted
version: "2.0.2"
typed_data:
dependency: transitive
description:

View file

@ -137,6 +137,15 @@ packages:
url: "https://pub.dev"
source: hosted
version: "8.6.1"
cake_backup:
dependency: transitive
description:
path: "."
ref: main
resolved-ref: "3aba867dcab6737f6707782f5db15d71f303db38"
url: "https://github.com/cake-tech/cake_backup.git"
source: git
version: "1.0.0+1"
characters:
dependency: transitive
description:
@ -193,6 +202,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.3"
cryptography:
dependency: transitive
description:
name: cryptography
sha256: df156c5109286340817d21fa7b62f9140f17915077127dd70f8bd7a2a0997a35
url: "https://pub.dev"
source: hosted
version: "2.5.0"
cupertino_icons:
dependency: transitive
description:
name: cupertino_icons
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
url: "https://pub.dev"
source: hosted
version: "1.0.6"
cw_core:
dependency: "direct main"
description:
@ -773,6 +798,14 @@ packages:
url: "https://github.com/cake-tech/tor.git"
source: git
version: "0.0.1"
tuple:
dependency: transitive
description:
name: tuple
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
url: "https://pub.dev"
source: hosted
version: "2.0.2"
typed_data:
dependency: transitive
description:

View file

@ -356,10 +356,9 @@ Future<void> setup({
getIt.get<KeyService>(),
(WalletType type) => getIt.get<WalletService>(param1: type)));
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) =>
WalletNewVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
type: type));
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) => WalletNewVM(
getIt.get<AppStore>(), getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
type: type));
getIt.registerFactoryParam<WalletRestorationFromQRVM, WalletType, void>((WalletType type, _) {
return WalletRestorationFromQRVM(getIt.get<AppStore>(),
@ -919,8 +918,8 @@ Future<void> setup({
(param1, isCreate) => NewWalletTypePage(onTypeSelected: param1, isCreate: isCreate ?? true));
getIt.registerFactoryParam<PreSeedPage, WalletType, AdvancedPrivacySettingsViewModel>(
(WalletType type, AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel)
=> PreSeedPage(type, advancedPrivacySettingsViewModel));
(WalletType type, AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel) =>
PreSeedPage(type, advancedPrivacySettingsViewModel));
getIt.registerFactoryParam<TradeDetailsViewModel, Trade, void>((trade, _) =>
TradeDetailsViewModel(
@ -1014,11 +1013,10 @@ Future<void> setup({
getIt.registerFactory(() => YatService());
getIt.registerFactory(() =>
AddressResolver(
yatService: getIt.get<YatService>(),
wallet: getIt.get<AppStore>().wallet!,
settingsStore: getIt.get<SettingsStore>()));
getIt.registerFactory(() => AddressResolver(
yatService: getIt.get<YatService>(),
wallet: getIt.get<AppStore>().wallet!,
settingsStore: getIt.get<SettingsStore>()));
getIt.registerFactoryParam<FullscreenQRPage, QrViewData, void>(
(QrViewData viewData, _) => FullscreenQRPage(qrViewData: viewData));
@ -1167,8 +1165,8 @@ Future<void> setup({
IoniaPaymentStatusPage(
getIt.get<IoniaPaymentStatusViewModel>(param1: paymentInfo, param2: committedInfo)));
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, void, void>(
(type, _) => AdvancedPrivacySettingsViewModel(getIt.get<SettingsStore>()));
getIt.registerFactoryParam<AdvancedPrivacySettingsViewModel, WalletType, void>(
(type, _) => AdvancedPrivacySettingsViewModel(type, getIt.get<SettingsStore>()));
getIt.registerFactoryParam<WalletUnlockLoadableViewModel, WalletUnlockArguments, void>((args, _) {
final currentWalletName =

View file

@ -70,15 +70,3 @@ class UnspentCoinsListFormState extends State<UnspentCoinsListForm> {
})));
}
}
void showUnspentCoinsAlert(BuildContext context) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: '',
alertContent: 'Information about unspent coins',
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
}

View file

@ -2,6 +2,7 @@ import 'package:cake_wallet/entities/exchange_api_mode.dart';
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/entities/seed_phrase_length.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
part 'advanced_privacy_settings_view_model.g.dart';
@ -10,7 +11,7 @@ class AdvancedPrivacySettingsViewModel = AdvancedPrivacySettingsViewModelBase
with _$AdvancedPrivacySettingsViewModel;
abstract class AdvancedPrivacySettingsViewModelBase with Store {
AdvancedPrivacySettingsViewModelBase(this._settingsStore) : _addCustomNode = false;
AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore) : _addCustomNode = false;
@computed
ExchangeApiMode get exchangeStatus => _settingsStore.exchangeStatus;
@ -21,6 +22,8 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
@observable
bool _addCustomNode = false;
final WalletType type;
final SettingsStore _settingsStore;
bool get hasSeedPhraseLengthOption =>

View file

@ -28,16 +28,16 @@ abstract class UnspentCoinsListViewModelBase with Store {
getUnspentCoinInfo(elem.hash, elem.address, elem.value, elem.vout, elem.keyImage);
return UnspentCoinsItem(
address: elem.address,
amount: '${formatAmountToString(elem.value)} ${wallet.currency.title}',
hash: elem.hash,
isFrozen: info.isFrozen,
note: info.note,
isSending: info.isSending,
amountRaw: elem.value,
vout: elem.vout,
keyImage: elem.keyImage,
isChange: elem.isChange,
address: elem.address,
amount: '${formatAmountToString(elem.value)} ${wallet.currency.title}',
hash: elem.hash,
isFrozen: info.isFrozen,
note: info.note,
isSending: info.isSending,
amountRaw: elem.value,
vout: elem.vout,
keyImage: elem.keyImage,
isChange: elem.isChange,
);
}));
@ -59,14 +59,33 @@ abstract class UnspentCoinsListViewModelBase with Store {
}
UnspentCoinsInfo getUnspentCoinInfo(
String hash, String address, int value, int vout, String? keyImage) =>
_unspentCoinsInfo.values.firstWhere((element) =>
element.walletId == wallet.id &&
String hash, String address, int value, int vout, String? keyImage) {
print([wallet.id, hash, address, value, vout, keyImage]);
return _unspentCoinsInfo.values.firstWhere((element) {
if (element.walletId == "bitcoin_Usable Math")
print([
element.walletId,
element.walletId == wallet.id,
element.hash,
element.hash == hash,
element.address,
element.address == address,
element.value,
element.value == value,
element.vout,
element.vout == vout,
element.keyImage,
element.keyImage == keyImage,
]);
return element.walletId == wallet.id &&
element.hash == hash &&
element.address == address &&
element.value == value &&
element.vout == vout &&
element.keyImage == keyImage);
// element.value == value &&
// element.vout == vout &&
element.keyImage == keyImage;
});
}
String formatAmountToString(int fullBalance) {
if (wallet.type == WalletType.monero)

View file

@ -8,7 +8,6 @@
#include <cw_monero/cw_monero_plugin.h>
#include <devicelocale/devicelocale_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
@ -18,9 +17,6 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) devicelocale_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DevicelocalePlugin");
devicelocale_plugin_register_with_registrar(devicelocale_registrar);
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

View file

@ -5,11 +5,11 @@
list(APPEND FLUTTER_PLUGIN_LIST
cw_monero
devicelocale
flutter_secure_storage_linux
url_launcher_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
tor
)
set(PLUGIN_BUNDLED_LIBRARIES)

View file

@ -8,7 +8,6 @@ import Foundation
import cw_monero
import device_info_plus
import devicelocale
import flutter_secure_storage_macos
import in_app_review
import package_info_plus
import path_provider_foundation
@ -21,7 +20,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
CwMoneroPlugin.register(with: registry.registrar(forPlugin: "CwMoneroPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DevicelocalePlugin.register(with: registry.registrar(forPlugin: "DevicelocalePlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
InAppReviewPlugin.register(with: registry.registrar(forPlugin: "InAppReviewPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))