mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
new getFeeRate, add retry logic to usedCoinSerials, and comment cleanup
This commit is contained in:
parent
c21af7196f
commit
8fc2043910
4 changed files with 24 additions and 192 deletions
|
@ -743,7 +743,6 @@ class ElectrumXClient {
|
||||||
bool verbose = true,
|
bool verbose = true,
|
||||||
String? requestID,
|
String? requestID,
|
||||||
}) async {
|
}) async {
|
||||||
// Use electrum_adapter package's getTransaction method.
|
|
||||||
Logging.instance.log("attempting to fetch blockchain.transaction.get...",
|
Logging.instance.log("attempting to fetch blockchain.transaction.get...",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
var channel =
|
var channel =
|
||||||
|
@ -752,46 +751,12 @@ class ElectrumXClient {
|
||||||
dynamic response = await client.getTransaction(txHash);
|
dynamic response = await client.getTransaction(txHash);
|
||||||
Logging.instance.log("Fetching blockchain.transaction.get finished",
|
Logging.instance.log("Fetching blockchain.transaction.get finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
return Map<String, dynamic>.from(response as Map);
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
dynamic response;
|
|
||||||
try {
|
|
||||||
response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'blockchain.transaction.get',
|
|
||||||
args: [
|
|
||||||
txHash,
|
|
||||||
verbose,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
if (!verbose) {
|
if (!verbose) {
|
||||||
return {"rawtx": response["result"] as String};
|
return {"rawtx": response as String};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response is! Map) {
|
return Map<String, dynamic>.from(response as Map);
|
||||||
final String msg = "getTransaction($txHash) returned a non-Map response"
|
|
||||||
" of type ${response.runtimeType}.\nResponse: $response";
|
|
||||||
Logging.instance.log(msg, level: LogLevel.Fatal);
|
|
||||||
throw Exception(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response["result"] == null) {
|
|
||||||
final String msg = "getTransaction($txHash) returned null result."
|
|
||||||
"\nResponse: $response";
|
|
||||||
Logging.instance.log(msg, level: LogLevel.Fatal);
|
|
||||||
throw Exception(msg);
|
|
||||||
}
|
|
||||||
return Map<String, dynamic>.from(response["result"] as Map);
|
|
||||||
} catch (e, s) {
|
|
||||||
Logging.instance.log(
|
|
||||||
"getTransaction($txHash) response: $response"
|
|
||||||
"\nError: $e\nStack trace: $s",
|
|
||||||
level: LogLevel.Error);
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the whole Lelantus anonymity set for denomination in the groupId.
|
/// Returns the whole Lelantus anonymity set for denomination in the groupId.
|
||||||
|
@ -813,7 +778,6 @@ class ElectrumXClient {
|
||||||
String blockhash = "",
|
String blockhash = "",
|
||||||
String? requestID,
|
String? requestID,
|
||||||
}) async {
|
}) async {
|
||||||
// Use electrum_adapter package's getSparkAnonymitySet method.
|
|
||||||
Logging.instance.log("attempting to fetch lelantus.getanonymityset...",
|
Logging.instance.log("attempting to fetch lelantus.getanonymityset...",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
var channel = await electrum_adapter.connect(host, port: port);
|
var channel = await electrum_adapter.connect(host, port: port);
|
||||||
|
@ -823,27 +787,6 @@ class ElectrumXClient {
|
||||||
Logging.instance.log("Fetching lelantus.getanonymityset finished",
|
Logging.instance.log("Fetching lelantus.getanonymityset finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
return anonymitySet;
|
return anonymitySet;
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
try {
|
|
||||||
Logging.instance.log("attempting to fetch lelantus.getanonymityset...",
|
|
||||||
level: LogLevel.Info);
|
|
||||||
final response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'lelantus.getanonymityset',
|
|
||||||
args: [
|
|
||||||
groupId,
|
|
||||||
blockhash,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
Logging.instance.log("Fetching lelantus.getanonymityset finished",
|
|
||||||
level: LogLevel.Info);
|
|
||||||
return Map<String, dynamic>.from(response["result"] as Map);
|
|
||||||
} catch (e) {
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO add example to docs
|
//TODO add example to docs
|
||||||
|
@ -854,7 +797,6 @@ class ElectrumXClient {
|
||||||
dynamic mints,
|
dynamic mints,
|
||||||
String? requestID,
|
String? requestID,
|
||||||
}) async {
|
}) async {
|
||||||
// Use electrum_adapter package's getLelantusMintData method.
|
|
||||||
Logging.instance.log("attempting to fetch lelantus.getmintmetadata...",
|
Logging.instance.log("attempting to fetch lelantus.getmintmetadata...",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
var channel = await electrum_adapter.connect(host, port: port);
|
var channel = await electrum_adapter.connect(host, port: port);
|
||||||
|
@ -863,22 +805,6 @@ class ElectrumXClient {
|
||||||
Logging.instance.log("Fetching lelantus.getmintmetadata finished",
|
Logging.instance.log("Fetching lelantus.getmintmetadata finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
return mintData;
|
return mintData;
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
try {
|
|
||||||
final response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'lelantus.getmintmetadata',
|
|
||||||
args: [
|
|
||||||
mints,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
return response["result"];
|
|
||||||
} catch (e) {
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO add example to docs
|
//TODO add example to docs
|
||||||
|
@ -887,50 +813,31 @@ class ElectrumXClient {
|
||||||
String? requestID,
|
String? requestID,
|
||||||
required int startNumber,
|
required int startNumber,
|
||||||
}) async {
|
}) async {
|
||||||
// Use electrum_adapter package's getLelantusUsedCoinSerials method.
|
|
||||||
Logging.instance.log("attempting to fetch lelantus.getusedcoinserials...",
|
Logging.instance.log("attempting to fetch lelantus.getusedcoinserials...",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
var channel = await electrum_adapter.connect('firo.stackwallet.com');
|
var channel = await electrum_adapter.connect('firo.stackwallet.com');
|
||||||
var client = electrum_adapter.FiroElectrumClient(channel);
|
var client = electrum_adapter.FiroElectrumClient(channel);
|
||||||
Map<String, dynamic> usedCoinSerials =
|
|
||||||
|
int retryCount = 3;
|
||||||
|
dynamic usedCoinSerials;
|
||||||
|
|
||||||
|
while (retryCount > 0 && usedCoinSerials is! List) {
|
||||||
|
usedCoinSerials =
|
||||||
await client.getLelantusUsedCoinSerials(startNumber: startNumber);
|
await client.getLelantusUsedCoinSerials(startNumber: startNumber);
|
||||||
|
// TODO add 2 minute timeout.
|
||||||
Logging.instance.log("Fetching lelantus.getusedcoinserials finished",
|
Logging.instance.log("Fetching lelantus.getusedcoinserials finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
return usedCoinSerials;
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
try {
|
|
||||||
int retryCount = 3;
|
|
||||||
dynamic result;
|
|
||||||
|
|
||||||
while (retryCount > 0 && result is! List) {
|
|
||||||
final response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'lelantus.getusedcoinserials',
|
|
||||||
args: [
|
|
||||||
"$startNumber",
|
|
||||||
],
|
|
||||||
requestTimeout: const Duration(minutes: 2),
|
|
||||||
);
|
|
||||||
|
|
||||||
result = response["result"];
|
|
||||||
retryCount--;
|
retryCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Map<String, dynamic>.from(result as Map);
|
return Map<String, dynamic>.from(usedCoinSerials as Map);
|
||||||
} catch (e) {
|
|
||||||
Logging.instance.log(e, level: LogLevel.Error);
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the latest Lelantus set id
|
/// Returns the latest Lelantus set id
|
||||||
///
|
///
|
||||||
/// ex: 1
|
/// ex: 1
|
||||||
Future<int> getLelantusLatestCoinId({String? requestID}) async {
|
Future<int> getLelantusLatestCoinId({String? requestID}) async {
|
||||||
// Use electrum_adapter package's getLelantusLatestCoinId method.
|
|
||||||
Logging.instance.log("attempting to fetch lelantus.getlatestcoinid...",
|
Logging.instance.log("attempting to fetch lelantus.getlatestcoinid...",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
var channel = await electrum_adapter.connect('firo.stackwallet.com');
|
var channel = await electrum_adapter.connect('firo.stackwallet.com');
|
||||||
|
@ -939,20 +846,6 @@ class ElectrumXClient {
|
||||||
Logging.instance.log("Fetching lelantus.getlatestcoinid finished",
|
Logging.instance.log("Fetching lelantus.getlatestcoinid finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
return latestCoinId;
|
return latestCoinId;
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
try {
|
|
||||||
final response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'lelantus.getlatestcoinid',
|
|
||||||
);
|
|
||||||
return response["result"] as int;
|
|
||||||
} catch (e) {
|
|
||||||
Logging.instance.log(e, level: LogLevel.Error);
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============== Spark ======================================================
|
// ============== Spark ======================================================
|
||||||
|
@ -976,7 +869,6 @@ class ElectrumXClient {
|
||||||
String? requestID,
|
String? requestID,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
// Use electrum_adapter package's getSparkAnonymitySet method.
|
|
||||||
Logging.instance.log("attempting to fetch spark.getsparkanonymityset...",
|
Logging.instance.log("attempting to fetch spark.getsparkanonymityset...",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
var channel = await electrum_adapter.connect('firo.stackwallet.com');
|
var channel = await electrum_adapter.connect('firo.stackwallet.com');
|
||||||
|
@ -986,23 +878,6 @@ class ElectrumXClient {
|
||||||
Logging.instance.log("Fetching spark.getsparkanonymityset finished",
|
Logging.instance.log("Fetching spark.getsparkanonymityset finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
return anonymitySet;
|
return anonymitySet;
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
Logging.instance.log("attempting to fetch spark.getsparkanonymityset...",
|
|
||||||
level: LogLevel.Info);
|
|
||||||
final response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'spark.getsparkanonymityset',
|
|
||||||
args: [
|
|
||||||
coinGroupId,
|
|
||||||
startBlockHash,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
Logging.instance.log("Fetching spark.getsparkanonymityset finished",
|
|
||||||
level: LogLevel.Info);
|
|
||||||
return Map<String, dynamic>.from(response["result"] as Map);
|
|
||||||
*/
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
@ -1022,26 +897,12 @@ class ElectrumXClient {
|
||||||
var client = electrum_adapter.FiroElectrumClient(channel);
|
var client = electrum_adapter.FiroElectrumClient(channel);
|
||||||
Map<String, dynamic> usedCoinsTags =
|
Map<String, dynamic> usedCoinsTags =
|
||||||
await client.getUsedCoinsTags(startNumber: startNumber);
|
await client.getUsedCoinsTags(startNumber: startNumber);
|
||||||
|
// TODO: Add 2 minute timeout.
|
||||||
Logging.instance.log("Fetching spark.getusedcoinstags finished",
|
Logging.instance.log("Fetching spark.getusedcoinstags finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
final map = Map<String, dynamic>.from(usedCoinsTags);
|
final map = Map<String, dynamic>.from(usedCoinsTags);
|
||||||
final set = Set<String>.from(map["tags"] as List);
|
final set = Set<String>.from(map["tags"] as List);
|
||||||
return await compute(_ffiHashTagsComputeWrapper, set);
|
return await compute(_ffiHashTagsComputeWrapper, set);
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
final response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'spark.getusedcoinstags',
|
|
||||||
args: [
|
|
||||||
"$startNumber",
|
|
||||||
],
|
|
||||||
requestTimeout: const Duration(minutes: 2),
|
|
||||||
);
|
|
||||||
final map = Map<String, dynamic>.from(response["result"] as Map);
|
|
||||||
final set = Set<String>.from(map["tags"] as List);
|
|
||||||
return await compute(_ffiHashTagsComputeWrapper, set);
|
|
||||||
*/
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logging.instance.log(e, level: LogLevel.Error);
|
Logging.instance.log(e, level: LogLevel.Error);
|
||||||
rethrow;
|
rethrow;
|
||||||
|
@ -1063,7 +924,6 @@ class ElectrumXClient {
|
||||||
required List<String> sparkCoinHashes,
|
required List<String> sparkCoinHashes,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
// Use electrum_adapter package's getSparkMintMetaData method.
|
|
||||||
Logging.instance.log("attempting to fetch spark.getsparkmintmetadata...",
|
Logging.instance.log("attempting to fetch spark.getsparkmintmetadata...",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
var channel = await electrum_adapter.connect('firo.stackwallet.com');
|
var channel = await electrum_adapter.connect('firo.stackwallet.com');
|
||||||
|
@ -1073,20 +933,6 @@ class ElectrumXClient {
|
||||||
Logging.instance.log("Fetching spark.getsparkmintmetadata finished",
|
Logging.instance.log("Fetching spark.getsparkmintmetadata finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
return List<Map<String, dynamic>>.from(mintMetaData);
|
return List<Map<String, dynamic>>.from(mintMetaData);
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
final response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'spark.getsparkmintmetadata',
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
"coinHashes": sparkCoinHashes,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
);
|
|
||||||
return List<Map<String, dynamic>>.from(response["result"] as List);
|
|
||||||
*/
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logging.instance.log(e, level: LogLevel.Error);
|
Logging.instance.log(e, level: LogLevel.Error);
|
||||||
rethrow;
|
rethrow;
|
||||||
|
@ -1100,7 +946,6 @@ class ElectrumXClient {
|
||||||
String? requestID,
|
String? requestID,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
// Use electrum_adapter package's getSparkLatestCoinId method.
|
|
||||||
Logging.instance.log("attempting to fetch spark.getsparklatestcoinid...",
|
Logging.instance.log("attempting to fetch spark.getsparklatestcoinid...",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
var channel = await electrum_adapter.connect(host, port: port);
|
var channel = await electrum_adapter.connect(host, port: port);
|
||||||
|
@ -1109,15 +954,6 @@ class ElectrumXClient {
|
||||||
Logging.instance.log("Fetching spark.getsparklatestcoinid finished",
|
Logging.instance.log("Fetching spark.getsparklatestcoinid finished",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
return latestCoinId;
|
return latestCoinId;
|
||||||
|
|
||||||
/*
|
|
||||||
// Original ElectrumXClient:
|
|
||||||
final response = await request(
|
|
||||||
requestID: requestID,
|
|
||||||
command: 'spark.getsparklatestcoinid',
|
|
||||||
);
|
|
||||||
return response["result"] as int;
|
|
||||||
*/
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logging.instance.log(e, level: LogLevel.Error);
|
Logging.instance.log(e, level: LogLevel.Error);
|
||||||
rethrow;
|
rethrow;
|
||||||
|
@ -1134,15 +970,9 @@ class ElectrumXClient {
|
||||||
/// "rate": 1000,
|
/// "rate": 1000,
|
||||||
/// }
|
/// }
|
||||||
Future<Map<String, dynamic>> getFeeRate({String? requestID}) async {
|
Future<Map<String, dynamic>> getFeeRate({String? requestID}) async {
|
||||||
try {
|
var channel = await electrum_adapter.connect(host, port: port);
|
||||||
final response = await request(
|
var client = electrum_adapter.FiroElectrumClient(channel);
|
||||||
requestID: requestID,
|
return await client.getFeeRate();
|
||||||
command: 'blockchain.getfeerate',
|
|
||||||
);
|
|
||||||
return Map<String, dynamic>.from(response["result"] as Map);
|
|
||||||
} catch (e) {
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the estimated transaction fee per kilobyte for a transaction to be confirmed within a certain number of [blocks].
|
/// Return the estimated transaction fee per kilobyte for a transaction to be confirmed within a certain number of [blocks].
|
||||||
|
|
|
@ -1186,6 +1186,8 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
||||||
coin: cryptoCurrency.coin,
|
coin: cryptoCurrency.coin,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
print("txn: $txn");
|
||||||
|
|
||||||
final vout = jsonUTXO["tx_pos"] as int;
|
final vout = jsonUTXO["tx_pos"] as int;
|
||||||
|
|
||||||
final outputs = txn["vout"] as List;
|
final outputs = txn["vout"] as List;
|
||||||
|
|
|
@ -528,8 +528,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "72f5801f78b6e73165c44d349a514badf0ee0d78"
|
ref: dd443e293feb3b37eb494ab7c8dadef9205de14c
|
||||||
resolved-ref: "72f5801f78b6e73165c44d349a514badf0ee0d78"
|
resolved-ref: dd443e293feb3b37eb494ab7c8dadef9205de14c
|
||||||
url: "https://github.com/cypherstack/electrum_adapter.git"
|
url: "https://github.com/cypherstack/electrum_adapter.git"
|
||||||
source: git
|
source: git
|
||||||
version: "3.0.0"
|
version: "3.0.0"
|
||||||
|
|
|
@ -176,7 +176,7 @@ dependencies:
|
||||||
electrum_adapter:
|
electrum_adapter:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/cypherstack/electrum_adapter.git
|
url: https://github.com/cypherstack/electrum_adapter.git
|
||||||
ref: 80d28a8b033af7bcf90cd6c7a3ee74160dc791a1
|
ref: dd443e293feb3b37eb494ab7c8dadef9205de14c
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in a new issue