From 96be5d2697b28bfe05fbd54cdda69fb24c66ec20 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Mon, 4 Mar 2024 10:35:52 -0800 Subject: [PATCH] cleanup --- .../lib/lightning_transaction_history.dart | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 cw_lightning/lib/lightning_transaction_history.dart diff --git a/cw_lightning/lib/lightning_transaction_history.dart b/cw_lightning/lib/lightning_transaction_history.dart deleted file mode 100644 index 6625f8702..000000000 --- a/cw_lightning/lib/lightning_transaction_history.dart +++ /dev/null @@ -1,90 +0,0 @@ -import 'dart:convert'; - -import 'package:cw_core/pathForWallet.dart'; -import 'package:cw_core/transaction_history.dart'; -import 'package:cw_core/utils/file.dart'; -import 'package:cw_core/wallet_info.dart'; -import 'package:cw_lightning/lightning_transaction_info.dart'; -import 'package:mobx/mobx.dart'; - -part 'lightning_transaction_history.g.dart'; - -const transactionsHistoryFileName = 'transactions.json'; - -class LightningTransactionHistory = LightningTransactionHistoryBase - with _$LightningTransactionHistory; - -abstract class LightningTransactionHistoryBase - extends TransactionHistoryBase with Store { - LightningTransactionHistoryBase( - {required this.walletInfo, required String password}) - : _password = password, - _height = 0 { - transactions = ObservableMap(); - } - - final WalletInfo walletInfo; - String _password; - int _height; - - Future init() async => await _load(); - - @override - void addOne(LightningTransactionInfo transaction) => - transactions[transaction.id] = transaction; - - @override - void addMany(Map transactions) => - transactions.forEach((_, tx) => _update(tx)); - - @override - Future save() async { - try { - final dirPath = - await pathForWalletDir(name: walletInfo.name, type: walletInfo.type); - final path = '$dirPath/$transactionsHistoryFileName'; - final data = - json.encode({'height': _height, 'transactions': transactions}); - await writeData(path: path, password: _password, data: data); - } catch (e) { - print('Error while save bitcoin transaction history: ${e.toString()}'); - } - } - - Future changePassword(String password) async { - _password = password; - await save(); - } - - Future> _read() async { - final dirPath = - await pathForWalletDir(name: walletInfo.name, type: walletInfo.type); - final path = '$dirPath/$transactionsHistoryFileName'; - final content = await read(path: path, password: _password); - return json.decode(content) as Map; - } - - Future _load() async { - try { - final content = await _read(); - final txs = content['transactions'] as Map? ?? {}; - - txs.entries.forEach((entry) { - final val = entry.value; - - if (val is Map) { - final tx = LightningTransactionInfo.fromJson(val, walletInfo.type); - _update(tx); - } - }); - - _height = content['height'] as int; - } catch (e) { - print(e); - } - } - - void _update(LightningTransactionInfo transaction) => - transactions[transaction.id] = transaction; - -}