11import 'dart:convert' ;
22
3- import 'package:flutter/cupertino.dart' ;
43import 'package:hive/hive.dart' ;
54import 'package:paymint/utilities/logger.dart' ;
65
76import 'electrumx.dart' ;
87
98class CachedElectrumX {
10- final ElectrumX electrumXClient;
11- final String hivePath;
9+ final ElectrumX ? electrumXClient;
10+ final String ? hivePath;
1211
13- final String server;
14- final int port;
15- final bool useSSL;
12+ final String ? server;
13+ final int ? port;
14+ final bool ? useSSL;
1615
1716 static const minCacheConfirms = 30 ;
1817
@@ -25,19 +24,21 @@ class CachedElectrumX {
2524 });
2625
2726 factory CachedElectrumX .from (
28- {@ required ElectrumXNode node, String hivePath}) =>
27+ {required ElectrumXNode node, required String hivePath}) =>
2928 CachedElectrumX (
30- server: node.address,
31- port: node.port,
32- useSSL: node.useSSL,
33- hivePath: hivePath);
29+ server: node.address,
30+ port: node.port,
31+ useSSL: node.useSSL,
32+ hivePath: hivePath,
33+ electrumXClient: null ,
34+ );
3435
3536 Future <Map <String , dynamic >> getAnonymitySet (
36- {@ required String groupId,
37+ {required String groupId,
3738 String blockhash = "" ,
38- @ required String coinName,
39- @ required bool callOutSideMainIsolate}) async {
40- if (coinName == null || coinName .isEmpty) {
39+ required String coinName,
40+ required bool callOutSideMainIsolate}) async {
41+ if (coinName.isEmpty) {
4142 throw Exception ("Invalid argument: coinName cannot be empty!" );
4243 }
4344
@@ -66,9 +67,9 @@ class CachedElectrumX {
6667
6768 ElectrumX client = electrumXClient ??
6869 ElectrumX (
69- server: this .server,
70- port: this .port,
71- useSSL: this .useSSL,
70+ server: this .server! ,
71+ port: this .port! ,
72+ useSSL: this .useSSL! ,
7273 );
7374
7475 final newSet = await client.getAnonymitySet (
@@ -117,11 +118,11 @@ class CachedElectrumX {
117118 ///
118119 /// ElectrumX api only called if the tx does not exist in local db
119120 Future <Map <String , dynamic >> getTransaction (
120- {@ required String tx_hash,
121- bool verbose: true ,
122- @ required String coinName,
123- @ required bool callOutSideMainIsolate}) async {
124- if (coinName == null || coinName .isEmpty) {
121+ {required String tx_hash,
122+ bool verbose = true ,
123+ required String coinName,
124+ required bool callOutSideMainIsolate}) async {
125+ if (coinName.isEmpty) {
125126 throw Exception ("Invalid argument: coinName cannot be empty!" );
126127 }
127128
@@ -136,9 +137,9 @@ class CachedElectrumX {
136137 if (cachedTx == null ) {
137138 final client = electrumXClient ??
138139 ElectrumX (
139- server: this .server,
140- port: this .port,
141- useSSL: this .useSSL,
140+ server: this .server! ,
141+ port: this .port! ,
142+ useSSL: this .useSSL! ,
142143 );
143144 final Map <String , dynamic > result =
144145 await client.getTransaction (tx_hash: tx_hash, verbose: verbose);
@@ -165,11 +166,11 @@ class CachedElectrumX {
165166 }
166167
167168 Future <List <dynamic >> getUsedCoinSerials ({
168- @ required String coinName,
169- @ required bool callOutSideMainIsolate,
170- int startNumber,
169+ required String coinName,
170+ required bool callOutSideMainIsolate,
171+ int ? startNumber,
171172 }) async {
172- if (coinName == null || coinName .isEmpty) {
173+ if (coinName.isEmpty) {
173174 throw Exception ("Invalid argument: coinName cannot be empty!" );
174175 }
175176
@@ -183,17 +184,13 @@ class CachedElectrumX {
183184 await Hive .openBox ('${coinName }_usedSerialsCache' );
184185 List <dynamic > cachedSerials = await usedSerialsCache.get ("serials" );
185186
186- if (cachedSerials == null ) {
187- cachedSerials = [];
188- }
189-
190187 final startNumber = cachedSerials.length;
191188
192189 final client = electrumXClient ??
193190 ElectrumX (
194- server: this .server,
195- port: this .port,
196- useSSL: this .useSSL,
191+ server: this .server! ,
192+ port: this .port! ,
193+ useSSL: this .useSSL! ,
197194 );
198195
199196 final serials = await client.getUsedCoinSerials (startNumber: startNumber);
@@ -214,7 +211,7 @@ class CachedElectrumX {
214211 }
215212
216213 /// Clear all cached transactions for the specified coin
217- Future <void > clearSharedTransactionCache ({String coinName}) async {
214+ Future <void > clearSharedTransactionCache ({required String coinName}) async {
218215 final txCache = await Hive .openBox ('${coinName }_txCache' );
219216 await txCache.clear ();
220217 final setCache = await Hive .openBox ('${coinName }_anonymitySetCache' );
0 commit comments