42
import 'package:cw_core/wallet_keys_file.dart';
43
import 'package:cw_core/wallet_type.dart';
44
import 'package:cw_core/unspent_coin_type.dart';
45
+import 'package:cw_core/output_info.dart';
46
import 'package:flutter/foundation.dart';
47
import 'package:hive/hive.dart';
48
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart' as ledger;
217
@override
218
bool isTestnet;
219
219
- bool get hasSilentPaymentsScanning => type == WalletType.bitcoin;
220
+ bool get hasSilentPaymentsScanning => type == WalletType.bitcoin && keys.privateKey.isNotEmpty;
221
222
@observable
223
bool nodeSupportsSilentPayments = true;
283
}
284
285
@override
285
- BitcoinWalletKeys get keys => BitcoinWalletKeys(
286
- wif: WifEncoder.encode(hd.privateKey.raw, netVer: network.wifNetVer),
287
- privateKey: hd.privateKey.toHex(),
288
- publicKey: hd.publicKey.toHex(),
289
- );
286
+ BitcoinWalletKeys get keys {
287
+ String? wif;
288
+ String? privateKey;
289
+ String? publicKey;
290
+ try {
291
+ wif = WifEncoder.encode(hd.privateKey.raw, netVer: network.wifNetVer);
292
+ } catch (_) {}
293
+ try {
294
+ privateKey = hd.privateKey.toHex();
295
+ } catch (_) {}
296
+ try {
297
+ publicKey = hd.publicKey.toHex();
298
+ } catch (_) {}
299
+ return BitcoinWalletKeys(
300
+ wif: wif ?? '',
301
+ privateKey: privateKey ?? '',
302
+ publicKey: publicKey ?? '',
303
+ xpub: xpub,
304
+ );
305
+ }
306
307
String _password;
308
List<BitcoinUnspent> unspentCoins;
688
);
689
spendsSilentPayment = true;
690
isSilentPayment = true;
675
- } else if (!isHardwareWallet) {
691
+ } else if (!isHardwareWallet && keys.privateKey.isNotEmpty) {
692
privkey =
693
generateECPrivate(hd: hd, index: utx.bitcoinAddressRecord.index, network: network);
694
}
1136
memo: estimatedTx.memo,
1137
outputOrdering: BitcoinOrdering.none,
1138
enableRBF: true,
1139
+ cwOutputs: transactionCredentials.outputs,
1140
);
1141
1142
return PendingBitcoinTransaction(
1149
network: network,
1150
hasChange: estimatedTx.hasChange,
1151
isSendAll: estimatedTx.isSendAll,
1135
- hasTaprootInputs: false, // ToDo: (Konsti) Support Taproot
1152
+ hasTaprootInputs: false, // ToDo: (Konsti) Support Taproot,
1153
+ isViewOnly: false,
1154
)..addListener((transaction) async {
1155
transactionHistory.addOne(transaction);
1156
await updateBalance();
1184
bool hasTaprootInputs = false;
1185
1186
final transaction = txb.buildTransaction((txDigest, utxo, publicKey, sighash) {
1187
+ if (keys.privateKey.isEmpty) return "";
1188
String error = "Cannot find private key.";
1189
1190
ECPrivateInfo? key;
1222
}
1223
});
1224
1206
- return PendingBitcoinTransaction(transaction, type,
1207
- electrumClient: electrumClient,
1208
- amount: estimatedTx.amount,
1209
- fee: estimatedTx.fee,
1210
- feeRate: feeRateInt.toString(),
1211
- network: network,
1212
- hasChange: estimatedTx.hasChange,
1213
- isSendAll: estimatedTx.isSendAll,
1214
- hasTaprootInputs: hasTaprootInputs,
1215
- utxos: estimatedTx.utxos,
1216
- publicKeys: estimatedTx.publicKeys)
1217
- ..addListener((transaction) async {
1225
+ return PendingBitcoinTransaction(
1226
+ transaction,
1227
+ type,
1228
+ electrumClient: electrumClient,
1229
+ amount: estimatedTx.amount,
1230
+ fee: estimatedTx.fee,
1231
+ feeRate: feeRateInt.toString(),
1232
+ network: network,
1233
+ hasChange: estimatedTx.hasChange,
1234
+ isSendAll: estimatedTx.isSendAll,
1235
+ hasTaprootInputs: hasTaprootInputs,
1236
+ utxos: estimatedTx.utxos,
1237
+ publicKeys: estimatedTx.publicKeys,
1238
+ isViewOnly: keys.privateKey.isEmpty,
1239
+ )..addListener((transaction) async {
1240
transactionHistory.addOne(transaction);
1241
if (estimatedTx.spendsSilentPayment) {
1242
transactionHistory.transactions.values.forEach((tx) {
1264
required BigInt fee,
1265
required BasedUtxoNetwork network,
1266
required List<UtxoWithAddress> utxos,
1267
+ required List<OutputInfo> cwOutputs,
1268
required Map<String, PublicKeyWithDerivationPath> publicKeys,
1269
String? memo,
1270
bool enableRBF = false,
1402
@action
1403
@override
1404
Future<void> rescan({required int height, bool? doSingleScan}) async {
1405
+ if (keys.privateKey.isEmpty) return;
1406
+
1407
silentPaymentsScanningActive = true;
1408
_setListeners(height, doSingleScan: doSingleScan);
1409
}
1900
network: network,
1901
hasChange: changeOutputs.isNotEmpty,
1902
feeRate: newFee.toString(),
1903
+ isViewOnly: keys.privateKey.isEmpty,
1904
)..addListener((transaction) async {
1905
transactionHistory.transactions.values.forEach((tx) {
1906
if (tx.id == hash) {