@@ -11,7 +11,7 @@ import 'package:cw_bitcoin/psbt_transaction_builder.dart';
11
11
import 'package:cw_bitcoin/bitcoin_transaction_priority.dart' ;
12
12
import 'package:cw_bitcoin/bitcoin_unspent.dart' ;
13
13
import 'package:cw_bitcoin/electrum_transaction_info.dart' ;
14
- import 'package:cw_bitcoin/electrum_wallet_addresses.dart' ;
14
+ // import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
15
15
import 'package:cw_core/encryption_file_utils.dart' ;
16
16
import 'package:cw_bitcoin/electrum_derivations.dart' ;
17
17
import 'package:cw_bitcoin/bitcoin_wallet_addresses.dart' ;
@@ -240,6 +240,36 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
240
240
);
241
241
}
242
242
243
+ Future <bool > getNodeSupportsSilentPayments () async {
244
+ return true ;
245
+ // As of today (august 2024), only ElectrumRS supports silent payments
246
+ // if (!(await getNodeIsElectrs())) {
247
+ // return false;
248
+ // }
249
+
250
+ // if (node == null) {
251
+ // return false;
252
+ // }
253
+
254
+ // try {
255
+ // final tweaksResponse = await electrumClient.getTweaks(height: 0);
256
+
257
+ // if (tweaksResponse != null) {
258
+ // node!.supportsSilentPayments = true;
259
+ // node!.save();
260
+ // return node!.supportsSilentPayments!;
261
+ // }
262
+ // } on RequestFailedTimeoutException catch (_) {
263
+ // node!.supportsSilentPayments = false;
264
+ // node!.save();
265
+ // return node!.supportsSilentPayments!;
266
+ // } catch (_) {}
267
+
268
+ // node!.supportsSilentPayments = false;
269
+ // node!.save();
270
+ // return node!.supportsSilentPayments!;
271
+ }
272
+
243
273
LedgerConnection ? _ledgerConnection;
244
274
BitcoinLedgerApp ? _bitcoinLedgerApp;
245
275
@@ -327,11 +357,11 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
327
357
328
358
_isolate? .then ((value) => value.kill (priority: Isolate .immediate));
329
359
330
- if (rpc! .isConnected) {
331
- syncStatus = SyncedSyncStatus ();
332
- } else {
333
- syncStatus = NotConnectedSyncStatus ();
334
- }
360
+ // if (rpc!.isConnected) {
361
+ // syncStatus = SyncedSyncStatus();
362
+ // } else {
363
+ // syncStatus = NotConnectedSyncStatus();
364
+ // }
335
365
}
336
366
}
337
367
@@ -367,7 +397,7 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
367
397
return ;
368
398
}
369
399
370
- await updateCoins (unspentCoins);
400
+ await updateCoins (unspentCoins. toSet () );
371
401
await refreshUnspentCoinsInfo ();
372
402
}
373
403
@@ -449,6 +479,20 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
449
479
// }
450
480
// }
451
481
482
+ @action
483
+ Future <void > registerSilentPaymentsKey () async {
484
+ final registered = await electrumClient.tweaksRegister (
485
+ secViewKey: walletAddresses.silentAddress! .b_scan.toHex (),
486
+ pubSpendKey: walletAddresses.silentAddress! .B_spend .toHex (),
487
+ labels: walletAddresses.silentAddresses
488
+ .where ((addr) => addr.type == SilentPaymentsAddresType .p2sp && addr.labelIndex >= 1 )
489
+ .map ((addr) => addr.labelIndex)
490
+ .toList (),
491
+ );
492
+
493
+ print ("registered: $registered " );
494
+ }
495
+
452
496
@action
453
497
void _updateSilentAddressRecord (BitcoinUnspent unspent) {
454
498
final receiveAddressRecord = unspent.bitcoinAddressRecord as BitcoinReceivedSPAddressRecord ;
@@ -593,41 +637,42 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
593
637
@override
594
638
@action
595
639
Future <Map <String , ElectrumTransactionInfo >> fetchTransactions () async {
596
- try {
597
- final Map <String , ElectrumTransactionInfo > historiesWithDetails = {};
598
-
599
- await Future .wait (
600
- BITCOIN_ADDRESS_TYPES .map (
601
- (type) => fetchTransactionsForAddressType (historiesWithDetails, type),
602
- ),
603
- );
604
-
605
- transactionHistory.transactions.values.forEach ((tx) async {
606
- final isPendingSilentPaymentUtxo =
607
- (tx.isPending || tx.confirmations == 0 ) && historiesWithDetails[tx.id] == null ;
608
-
609
- if (isPendingSilentPaymentUtxo) {
610
- final info = await fetchTransactionInfo (hash: tx.id, height: tx.height);
611
-
612
- if (info != null ) {
613
- tx.confirmations = info.confirmations;
614
- tx.isPending = tx.confirmations == 0 ;
615
- transactionHistory.addOne (tx);
616
- await transactionHistory.save ();
617
- }
618
- }
619
- });
620
-
621
- return historiesWithDetails;
622
- } catch (e) {
623
- print ("fetchTransactions $e " );
624
- return {};
625
- }
640
+ throw UnimplementedError ();
641
+ // try {
642
+ // final Map<String, ElectrumTransactionInfo> historiesWithDetails = {};
643
+
644
+ // await Future.wait(
645
+ // BITCOIN_ADDRESS_TYPES.map(
646
+ // (type) => fetchTransactionsForAddressType(historiesWithDetails, type),
647
+ // ),
648
+ // );
649
+
650
+ // transactionHistory.transactions.values.forEach((tx) async {
651
+ // final isPendingSilentPaymentUtxo =
652
+ // (tx.isPending || tx.confirmations == 0) && historiesWithDetails[tx.id] == null;
653
+
654
+ // if (isPendingSilentPaymentUtxo) {
655
+ // final info = await fetchTransactionInfo(hash: tx.id, height: tx.height);
656
+
657
+ // if (info != null) {
658
+ // tx.confirmations = info.confirmations;
659
+ // tx.isPending = tx.confirmations == 0;
660
+ // transactionHistory.addOne(tx);
661
+ // await transactionHistory.save();
662
+ // }
663
+ // }
664
+ // });
665
+
666
+ // return historiesWithDetails;
667
+ // } catch (e) {
668
+ // print("fetchTransactions $e");
669
+ // return {};
670
+ // }
626
671
}
627
672
628
673
@override
629
674
@action
630
- Future <void > updateTransactions () async {
675
+ Future <void > updateTransactions ([ List < BitcoinAddressRecord > ? addresses] ) async {
631
676
super .updateTransactions ();
632
677
633
678
transactionHistory.transactions.values.forEach ((tx) {
@@ -641,32 +686,32 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
641
686
});
642
687
}
643
688
644
- @action
645
- Future <ElectrumBalance > fetchBalances () async {
646
- final balance = await super .fetchBalances ();
647
-
648
- int totalFrozen = balance.frozen;
649
- int totalConfirmed = balance.confirmed;
650
-
651
- // Add values from unspent coins that are not fetched by the address list
652
- // i.e. scanned silent payments
653
- transactionHistory.transactions.values.forEach ((tx) {
654
- if (tx.unspents != null ) {
655
- tx.unspents! .forEach ((unspent) {
656
- if (unspent.bitcoinAddressRecord is BitcoinSilentPaymentAddressRecord ) {
657
- if (unspent.isFrozen) totalFrozen += unspent.value;
658
- totalConfirmed += unspent.value;
659
- }
660
- });
661
- }
662
- });
689
+ // @action
690
+ // Future<ElectrumBalance> fetchBalances() async {
691
+ // final balance = await super.fetchBalances();
692
+
693
+ // int totalFrozen = balance.frozen;
694
+ // int totalConfirmed = balance.confirmed;
695
+
696
+ // // Add values from unspent coins that are not fetched by the address list
697
+ // // i.e. scanned silent payments
698
+ // transactionHistory.transactions.values.forEach((tx) {
699
+ // if (tx.unspents != null) {
700
+ // tx.unspents!.forEach((unspent) {
701
+ // if (unspent.bitcoinAddressRecord is BitcoinSilentPaymentAddressRecord) {
702
+ // if (unspent.isFrozen) totalFrozen += unspent.value;
703
+ // totalConfirmed += unspent.value;
704
+ // }
705
+ // });
706
+ // }
707
+ // });
663
708
664
- return ElectrumBalance (
665
- confirmed: totalConfirmed,
666
- unconfirmed: balance.unconfirmed,
667
- frozen: totalFrozen,
668
- );
669
- }
709
+ // return ElectrumBalance(
710
+ // confirmed: totalConfirmed,
711
+ // unconfirmed: balance.unconfirmed,
712
+ // frozen: totalFrozen,
713
+ // );
714
+ // }
670
715
671
716
@override
672
717
@action
@@ -713,15 +758,15 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
713
758
}
714
759
}
715
760
716
- @override
717
- @action
718
- void onHeadersResponse (ElectrumHeaderResponse response) {
719
- super .onHeadersResponse (response);
761
+ // @override
762
+ // @action
763
+ // void onHeadersResponse(ElectrumHeaderResponse response) {
764
+ // super.onHeadersResponse(response);
720
765
721
- if (alwaysScan == true && syncStatus is SyncedSyncStatus ) {
722
- _setListeners (walletInfo.restoreHeight);
723
- }
724
- }
766
+ // if (alwaysScan == true && syncStatus is SyncedSyncStatus) {
767
+ // _setListeners(walletInfo.restoreHeight);
768
+ // }
769
+ // }
725
770
726
771
@override
727
772
@action
0 commit comments