mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 02:24:30 +00:00
return new client to CachedElectrumXClient from callback in interface
This commit is contained in:
parent
a52f45a4ae
commit
3d942f3e0b
2 changed files with 19 additions and 7 deletions
|
@ -22,12 +22,12 @@ import 'package:string_validator/string_validator.dart';
|
||||||
|
|
||||||
class CachedElectrumXClient {
|
class CachedElectrumXClient {
|
||||||
final ElectrumXClient electrumXClient;
|
final ElectrumXClient electrumXClient;
|
||||||
final ElectrumClient electrumAdapterClient;
|
ElectrumClient electrumAdapterClient;
|
||||||
final Future<void> Function() electrumAdapterUpdateCallback;
|
final Future<ElectrumClient> Function() electrumAdapterUpdateCallback;
|
||||||
|
|
||||||
static const minCacheConfirms = 30;
|
static const minCacheConfirms = 30;
|
||||||
|
|
||||||
const CachedElectrumXClient({
|
CachedElectrumXClient({
|
||||||
required this.electrumXClient,
|
required this.electrumXClient,
|
||||||
required this.electrumAdapterClient,
|
required this.electrumAdapterClient,
|
||||||
required this.electrumAdapterUpdateCallback,
|
required this.electrumAdapterUpdateCallback,
|
||||||
|
@ -36,7 +36,7 @@ class CachedElectrumXClient {
|
||||||
factory CachedElectrumXClient.from({
|
factory CachedElectrumXClient.from({
|
||||||
required ElectrumXClient electrumXClient,
|
required ElectrumXClient electrumXClient,
|
||||||
required ElectrumClient electrumAdapterClient,
|
required ElectrumClient electrumAdapterClient,
|
||||||
required Future<void> Function() electrumAdapterUpdateCallback,
|
required Future<ElectrumClient> Function() electrumAdapterUpdateCallback,
|
||||||
}) =>
|
}) =>
|
||||||
CachedElectrumXClient(
|
CachedElectrumXClient(
|
||||||
electrumXClient: electrumXClient,
|
electrumXClient: electrumXClient,
|
||||||
|
@ -47,8 +47,13 @@ class CachedElectrumXClient {
|
||||||
/// If the client is closed, use the callback to update it.
|
/// If the client is closed, use the callback to update it.
|
||||||
_checkElectrumAdapterClient() async {
|
_checkElectrumAdapterClient() async {
|
||||||
if (electrumAdapterClient.peer.isClosed) {
|
if (electrumAdapterClient.peer.isClosed) {
|
||||||
|
ElectrumClient? _electrumAdapterClient =
|
||||||
await electrumAdapterUpdateCallback?.call();
|
await electrumAdapterUpdateCallback?.call();
|
||||||
// throw Exception("ElectrumAdapterClient is closed");
|
if (_electrumAdapterClient != null) {
|
||||||
|
electrumAdapterClient = _electrumAdapterClient;
|
||||||
|
} else {
|
||||||
|
throw Exception("ElectrumAdapterClient is closed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +220,8 @@ class CachedElectrumXClient {
|
||||||
if (cachedTx == null) {
|
if (cachedTx == null) {
|
||||||
await _checkElectrumAdapterClient();
|
await _checkElectrumAdapterClient();
|
||||||
|
|
||||||
|
print(121212);
|
||||||
|
print(electrumAdapterClient.peer.isClosed);
|
||||||
final Map<String, dynamic> result =
|
final Map<String, dynamic> result =
|
||||||
await electrumAdapterClient.getTransaction(txHash);
|
await electrumAdapterClient.getTransaction(txHash);
|
||||||
|
|
||||||
|
|
|
@ -983,7 +983,7 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
||||||
electrumXCachedClient = CachedElectrumXClient.from(
|
electrumXCachedClient = CachedElectrumXClient.from(
|
||||||
electrumXClient: electrumXClient,
|
electrumXClient: electrumXClient,
|
||||||
electrumAdapterClient: electrumAdapterClient,
|
electrumAdapterClient: electrumAdapterClient,
|
||||||
electrumAdapterUpdateCallback: updateNode,
|
electrumAdapterUpdateCallback: updateClient,
|
||||||
);
|
);
|
||||||
subscribableElectrumXClient = SubscribableElectrumXClient.from(
|
subscribableElectrumXClient = SubscribableElectrumXClient.from(
|
||||||
node: newNode,
|
node: newNode,
|
||||||
|
@ -1295,6 +1295,11 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
||||||
await updateElectrumX(newNode: node);
|
await updateElectrumX(newNode: node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<ElectrumClient> updateClient() async {
|
||||||
|
await updateNode();
|
||||||
|
return electrumAdapterClient;
|
||||||
|
}
|
||||||
|
|
||||||
FeeObject? _cachedFees;
|
FeeObject? _cachedFees;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in a new issue