mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 20:54:33 +00:00
get current address nonce
This commit is contained in:
parent
521a9bb0a3
commit
1de0eec6cc
1 changed files with 46 additions and 0 deletions
|
@ -451,6 +451,52 @@ abstract class EthereumAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<EthereumResponse<int>> getAddressNonce({
|
||||||
|
required String address,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
final uri = Uri.parse(
|
||||||
|
"$stackBaseServer/state?addrs=$address&parts=nonce",
|
||||||
|
);
|
||||||
|
final response = await get(uri);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final json = jsonDecode(response.body);
|
||||||
|
if (json["data"] is List) {
|
||||||
|
final map = json["data"].first as Map;
|
||||||
|
|
||||||
|
final nonce = map["nonce"] as int;
|
||||||
|
|
||||||
|
return EthereumResponse(
|
||||||
|
nonce,
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw EthApiException(json["message"] as String);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw EthApiException(
|
||||||
|
"getWalletTokenBalance($address) failed with status code: "
|
||||||
|
"${response.statusCode}",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} on EthApiException catch (e) {
|
||||||
|
return EthereumResponse(
|
||||||
|
null,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance.log(
|
||||||
|
"getWalletTokenBalance(): $e\n$s",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
|
return EthereumResponse(
|
||||||
|
null,
|
||||||
|
EthApiException(e.toString()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Future<EthereumResponse<GasTracker>> getGasOracle() async {
|
static Future<EthereumResponse<GasTracker>> getGasOracle() async {
|
||||||
try {
|
try {
|
||||||
final response = await get(
|
final response = await get(
|
||||||
|
|
Loading…
Reference in a new issue